From 093c6efd304453cb7ad5a3214afa6a5e211b6c31 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 25 Oct 2024 09:13:19 +0100 Subject: [PATCH] Re-sort ready_list when priorities update + PRI_UPDATE_FREQ - PRI_UPDATE_FREQ is a separate value from TIME_SLICE, they just happen to be set the same. --- src/threads/thread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); }