From 0db3551a9ad0eefb5bb40306e9fef002c3fcab87 Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Wed, 16 Oct 2024 18:27:21 +0100 Subject: [PATCH] implement behaviour for thread recent_cpu to be defined based on parent recent_cpu, 0 for initial thread --- src/threads/thread.c | 18 ++++++++++++++---- src/threads/thread.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index bf65702..86cd872 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -65,7 +65,7 @@ static void kernel_thread (thread_func *, void *aux); static void idle (void *aux UNUSED); static struct thread *running_thread (void); static struct thread *next_thread_to_run (void); -static void init_thread (struct thread *, const char *name, int priority); +static void init_thread (struct thread *, const char *name, int priority, fp32_t recent_cpu); static bool is_thread (struct thread *) UNUSED; static void *alloc_frame (struct thread *, size_t size); static void schedule (void); @@ -96,7 +96,8 @@ thread_init (void) /* Set up a thread structure for the running thread. */ initial_thread = running_thread (); - init_thread (initial_thread, "main", PRI_DEFAULT); + fp32_t initial_thread_recent_cpu = { 0 }; + init_thread (initial_thread, "main", PRI_DEFAULT, initial_thread_recent_cpu); initial_thread->status = THREAD_RUNNING; initial_thread->tid = allocate_tid (); } @@ -193,7 +194,8 @@ thread_create (const char *name, int priority, return TID_ERROR; /* Initialize thread. */ - init_thread (t, name, priority); + fp32_t parent_recent_cpu = thread_current ()->recent_cpu; + init_thread (t, name, priority, parent_recent_cpu); tid = t->tid = allocate_tid (); /* Prepare thread for first run by initializing its stack. @@ -373,6 +375,13 @@ calculate_priority (void) return 0; } +fp32_t +calculate_recent_cpu (void) +{ + /* Not yet implemented */ + return { 0 }; +} + /* Sets the current thread's nice value to NICE. */ void thread_set_nice (int nice) @@ -476,7 +485,7 @@ is_thread (struct thread *t) /* Does basic initialization of T as a blocked thread named NAME. */ static void -init_thread (struct thread *t, const char *name, int priority) +init_thread (struct thread *t, const char *name, int priority, fp32_t recent_cpu) { enum intr_level old_level; @@ -490,6 +499,7 @@ init_thread (struct thread *t, const char *name, int priority) t->stack = (uint8_t *) t + PGSIZE; t->priority = priority; t->magic = THREAD_MAGIC; + t->recent_cpu = recent_cpu; old_level = intr_disable (); list_push_back (&all_list, &t->allelem); diff --git a/src/threads/thread.h b/src/threads/thread.h index f85b814..1124b8d 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -96,7 +96,7 @@ struct thread /* MLFQS items */ int nice; /* Nice value for this thread */ - fp32_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. */