implement behaviour for thread recent_cpu to be defined based on parent recent_cpu, 0 for initial thread
This commit is contained in:
@@ -65,7 +65,7 @@ static void kernel_thread (thread_func *, void *aux);
|
|||||||
static void idle (void *aux UNUSED);
|
static void idle (void *aux UNUSED);
|
||||||
static struct thread *running_thread (void);
|
static struct thread *running_thread (void);
|
||||||
static struct thread *next_thread_to_run (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 bool is_thread (struct thread *) UNUSED;
|
||||||
static void *alloc_frame (struct thread *, size_t size);
|
static void *alloc_frame (struct thread *, size_t size);
|
||||||
static void schedule (void);
|
static void schedule (void);
|
||||||
@@ -96,7 +96,8 @@ thread_init (void)
|
|||||||
|
|
||||||
/* Set up a thread structure for the running thread. */
|
/* Set up a thread structure for the running thread. */
|
||||||
initial_thread = 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->status = THREAD_RUNNING;
|
||||||
initial_thread->tid = allocate_tid ();
|
initial_thread->tid = allocate_tid ();
|
||||||
}
|
}
|
||||||
@@ -193,7 +194,8 @@ thread_create (const char *name, int priority,
|
|||||||
return TID_ERROR;
|
return TID_ERROR;
|
||||||
|
|
||||||
/* Initialize thread. */
|
/* 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 ();
|
tid = t->tid = allocate_tid ();
|
||||||
|
|
||||||
/* Prepare thread for first run by initializing its stack.
|
/* Prepare thread for first run by initializing its stack.
|
||||||
@@ -373,6 +375,13 @@ calculate_priority (void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fp32_t
|
||||||
|
calculate_recent_cpu (void)
|
||||||
|
{
|
||||||
|
/* Not yet implemented */
|
||||||
|
return { 0 };
|
||||||
|
}
|
||||||
|
|
||||||
/* Sets the current thread's nice value to NICE. */
|
/* Sets the current thread's nice value to NICE. */
|
||||||
void
|
void
|
||||||
thread_set_nice (int nice)
|
thread_set_nice (int nice)
|
||||||
@@ -476,7 +485,7 @@ is_thread (struct thread *t)
|
|||||||
/* Does basic initialization of T as a blocked thread named
|
/* Does basic initialization of T as a blocked thread named
|
||||||
NAME. */
|
NAME. */
|
||||||
static void
|
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;
|
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->stack = (uint8_t *) t + PGSIZE;
|
||||||
t->priority = priority;
|
t->priority = priority;
|
||||||
t->magic = THREAD_MAGIC;
|
t->magic = THREAD_MAGIC;
|
||||||
|
t->recent_cpu = recent_cpu;
|
||||||
|
|
||||||
old_level = intr_disable ();
|
old_level = intr_disable ();
|
||||||
list_push_back (&all_list, &t->allelem);
|
list_push_back (&all_list, &t->allelem);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ struct thread
|
|||||||
|
|
||||||
/* MLFQS items */
|
/* MLFQS items */
|
||||||
int nice; /* Nice value for this thread */
|
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
|
#ifdef USERPROG
|
||||||
/* Owned by userprog/process.c. */
|
/* Owned by userprog/process.c. */
|
||||||
|
|||||||
Reference in New Issue
Block a user