remove repeated comparator and reorder thread_init operations
This commit is contained in:
@@ -73,8 +73,6 @@ static bool is_thread (struct thread *) UNUSED;
|
||||
static void *alloc_frame (struct thread *, size_t size);
|
||||
static int calculate_bsd_priority (fp32_t recent_cpu, int nice);
|
||||
static void thread_update_recent_cpu (struct thread *t, void *aux UNUSED);
|
||||
static bool thread_priority_less (const struct list_elem *a,
|
||||
const struct list_elem *b, void *aux UNUSED);
|
||||
static void schedule (void);
|
||||
void thread_schedule_tail (struct thread *prev);
|
||||
static tid_t allocate_tid (void);
|
||||
@@ -164,7 +162,7 @@ thread_tick (void)
|
||||
size_t ready = threads_ready ();
|
||||
if (t != idle_thread)
|
||||
ready++;
|
||||
fp32_t old_coeff = fp_mul (fp_div_int (int_to_fp (59), 60), load_avg);
|
||||
fp32_t old_coeff = fp_div_int (fp_mul_int(load_avg, 59), 60);
|
||||
fp32_t new_coeff = fp_div_int (int_to_fp (ready), 60);
|
||||
load_avg = fp_add (old_coeff, new_coeff);
|
||||
|
||||
@@ -293,9 +291,7 @@ thread_unblock (struct thread *t)
|
||||
old_level = intr_disable ();
|
||||
ASSERT (t->status == THREAD_BLOCKED);
|
||||
|
||||
if (thread_mlfqs)
|
||||
list_insert_ordered (&ready_list, &t->elem, thread_priority_less, NULL);
|
||||
else
|
||||
|
||||
/* Insert the thread back into the ready list in priority order. */
|
||||
list_insert_ordered(&ready_list, &t->elem, priority_more, NULL);
|
||||
|
||||
@@ -371,16 +367,10 @@ thread_yield (void)
|
||||
|
||||
if (cur != idle_thread)
|
||||
{
|
||||
if (thread_mlfqs)
|
||||
{
|
||||
list_insert_ordered (&ready_list, &cur->elem, thread_priority_less,
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Insert the thread back into the ready list in priority order. */
|
||||
list_insert_ordered(&ready_list, &cur->elem, priority_more, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cur->status = THREAD_READY;
|
||||
@@ -643,8 +633,6 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
strlcpy (t->name, name, sizeof t->name);
|
||||
t->stack = (uint8_t *) t + PGSIZE;
|
||||
|
||||
t->priority
|
||||
= thread_mlfqs ? calculate_bsd_priority (recent_cpu, nice) : priority;
|
||||
t->nice = nice;
|
||||
t->recent_cpu = recent_cpu;
|
||||
|
||||
@@ -653,7 +641,7 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->magic = THREAD_MAGIC;
|
||||
|
||||
list_init (&t->donors_list);
|
||||
t->priority = t->base_priority;
|
||||
t->priority = thread_mlfqs ? calculate_bsd_priority (recent_cpu, nice) : t->base_priority;
|
||||
t->waiting_lock = NULL;
|
||||
|
||||
old_level = intr_disable ();
|
||||
@@ -746,17 +734,6 @@ calculate_bsd_priority (fp32_t recent_cpu, int nice)
|
||||
return priority;
|
||||
}
|
||||
|
||||
/* Returns true if thread a's priority is strictly greater than
|
||||
thread b's priority. */
|
||||
static bool
|
||||
thread_priority_less (const struct list_elem *a, const struct list_elem *b,
|
||||
void *aux UNUSED)
|
||||
{
|
||||
struct thread *ta = list_entry (a, struct thread, elem);
|
||||
struct thread *tb = list_entry (b, struct thread, elem);
|
||||
return ta->priority > tb->priority;
|
||||
}
|
||||
|
||||
/* Schedules a new process. At entry, interrupts must be off and
|
||||
the running process's state must have been changed from
|
||||
running to some other state. This function finds another
|
||||
|
||||
Reference in New Issue
Block a user