implement behaviour for thread recent_cpu to be defined based on parent recent_cpu, 0 for initial thread

This commit is contained in:
EDiasAlberto
2024-10-16 18:27:21 +01:00
parent 96fa718be1
commit 0db3551a9a
2 changed files with 15 additions and 5 deletions

View File

@@ -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);

View File

@@ -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. */