implement recent_cpu calculations on every second
This commit is contained in:
@@ -199,6 +199,10 @@ static void
|
||||
timer_interrupt (struct intr_frame *args UNUSED)
|
||||
{
|
||||
ticks++;
|
||||
if (ticks % TIMER_FREQ == 0)
|
||||
{
|
||||
calculate_recent_cpu ();
|
||||
}
|
||||
for (struct list_elem *e = list_begin (&sleeping_threads);
|
||||
e != list_end (&sleeping_threads); e = list_next (e))
|
||||
{
|
||||
|
||||
@@ -375,11 +375,15 @@ calculate_priority (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp32_t
|
||||
void
|
||||
calculate_recent_cpu (void)
|
||||
{
|
||||
/* Not yet implemented */
|
||||
return { 0 };
|
||||
struct thread *t = thread_current ();
|
||||
fp32_t curr_recent_cpu = t->recent_cpu;
|
||||
fp32_t curr_load_avg = fp_mul_int(thread_get_load_avg (), 2);
|
||||
fp32_t recent_cpu_coeff = fp_div(curr_load_avg, fp_add_int(curr_load_avg, 1));
|
||||
fp32_t new_recent_cpu = fp_add_int(fp_mul(recent_cpu_coeff, curr_recent_cpu), thread_get_nice ());
|
||||
t->recent_cpu = new_recent_cpu;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user