implement thread_get_nice & thread_get_recent_cpu

This commit is contained in:
2024-10-15 19:56:46 +01:00
parent 27d564ab49
commit 63742c5717
2 changed files with 5 additions and 5 deletions

View File

@@ -4,6 +4,7 @@
#include <random.h>
#include <stdio.h>
#include <string.h>
#include "threads/fixed-point.h"
#include "threads/flags.h"
#include "threads/interrupt.h"
#include "threads/intr-stubs.h"
@@ -375,8 +376,7 @@ thread_set_nice (int nice UNUSED)
int
thread_get_nice (void)
{
/* Not yet implemented. */
return 0;
return thread_current ()->nice;
}
/* Returns 100 times the system load average. */
@@ -391,8 +391,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.

View File

@@ -4,6 +4,7 @@
#include <debug.h>
#include <list.h>
#include <stdint.h>
#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. */