From eacd93b32d29d351be2f66b6533d148180ee2626 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 16 Oct 2024 22:56:47 +0100 Subject: [PATCH] Optimise load_avg and recent_cpu updates - only run when BSD scheduler is enabled --- src/threads/thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index e4d392b..230789e 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -155,7 +155,7 @@ thread_tick (void) /* Update system load_avg and all threads recent_cpu every second. */ int64_t ticks = timer_ticks (); - if (ticks % TIMER_FREQ == 0) + if (thread_mlfqs && (ticks % TIMER_FREQ == 0)) { fp32_t old_coeff = fp_mul (fp_div_int (int_to_fp (59), 60), load_avg); fp32_t new_coeff = fp_div_int (int_to_fp (threads_ready ()), 60); @@ -165,7 +165,7 @@ thread_tick (void) } /* Update current thread's recent_cpu. */ - if (t != idle_thread) + if (thread_mlfqs && (t != idle_thread)) { t->recent_cpu = fp_add_int (t->recent_cpu, 1); if (ticks % 4 == 0) // recent_cpu was updated, update priority.