From 630fbaa3ab7006185e5855e75af312e56610976e Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Tue, 15 Oct 2024 19:56:46 +0100 Subject: [PATCH] implement thread_get_nice & thread_get_recent_cpu --- src/threads/thread.c | 4 ++-- src/threads/thread.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index c74d86b..bf65702 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -4,6 +4,7 @@ #include #include #include +#include "threads/fixed-point.h" #include "threads/flags.h" #include "threads/interrupt.h" #include "threads/intr-stubs.h" @@ -399,8 +400,7 @@ thread_get_load_avg (void) int thread_get_recent_cpu (void) { - /* Not yet implemented. */ - return 0; + return fp_round (fp_mul_int (thread_current ()->recent_cpu, 100)); } /* Idle thread. Executes when no other thread is ready to run. diff --git a/src/threads/thread.h b/src/threads/thread.h index 3019926..f85b814 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -4,6 +4,7 @@ #include #include #include +#include "threads/fixed-point.h" /* States in a thread's life cycle. */ enum thread_status @@ -95,7 +96,7 @@ struct thread /* MLFQS items */ int nice; /* Nice value for this thread */ - int32_t recent_cpu; /* Amount of time this process received */ + fp32_t recent_cpu; /* Amount of time this process received */ #ifdef USERPROG /* Owned by userprog/process.c. */