diff --git a/src/threads/thread.c b/src/threads/thread.c index 880737a..b551e3d 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -55,6 +55,7 @@ static fp32_t load_avg = { 0 }; /* System load average. */ /* Scheduling. */ #define TIME_SLICE 4 /* # of timer ticks to give each thread. */ +#define PRI_UPDATE_FREQ 4 /* # of timer ticks to update priorities. */ static unsigned thread_ticks; /* # of timer ticks since last yield. */ /* If false (default), use round-robin scheduler. @@ -172,9 +173,12 @@ thread_tick (void) load_avg = fp_add (old_coeff, new_coeff); thread_foreach (update_recent_cpu, NULL); + /* Priorities have been updated, need to re-sort. */ + list_sort (&ready_list, priority_more, NULL); } - if (ticks % TIME_SLICE == 0) // recent_cpu was updated, update priority. + /* Recent cpu was updated, update priority. */ + if (ticks % PRI_UPDATE_FREQ == 0) t->priority = calculate_bsd_priority (t->recent_cpu, t->nice); }