From 7a1aa21e1e041c1d6dd2e0b5f606de0590a0824c Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Wed, 16 Oct 2024 18:34:56 +0100 Subject: [PATCH] implement logic to increment recent_cpu on every timer_interrupt () call --- src/devices/timer.c | 1 + src/threads/thread.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/devices/timer.c b/src/devices/timer.c index 4bb602e..63e15f6 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -208,6 +208,7 @@ timer_interrupt (struct intr_frame *args UNUSED) else break; } + thread_increment_recent_cpu (); thread_tick (); } diff --git a/src/threads/thread.c b/src/threads/thread.c index 86cd872..47cd5c4 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -382,6 +382,19 @@ calculate_recent_cpu (void) return { 0 }; } +void +thread_increment_recent_cpu (void) +{ + struct thread *t = thread_current (); + if (t == idle_thread) + { + return; + } + fp32_t old_recent_cpu = t->recent_cpu; + old_recent_cpu.raw = old_recent_cpu.raw + 1; + t->recent_cpu = old_recent_cpu; +} + /* Sets the current thread's nice value to NICE. */ void thread_set_nice (int nice)