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)