Merge contributions from gleb-bsd to main merged repo #6

Merged
ed1223 merged 11 commits from gleb/BSD into BSD-merged 2024-10-17 15:55:24 +00:00
3 changed files with 48 additions and 7 deletions
Showing only changes of commit 4a5de13d1e - Show all commits

View File

@@ -199,6 +199,10 @@ static void
timer_interrupt (struct intr_frame *args UNUSED) timer_interrupt (struct intr_frame *args UNUSED)
{ {
ticks++; ticks++;
if (ticks % TIMER_FREQ == 0)
{
calculate_recent_cpu ();
}
for (struct list_elem *e = list_begin (&sleeping_threads); for (struct list_elem *e = list_begin (&sleeping_threads);
e != list_end (&sleeping_threads); e = list_next (e)) e != list_end (&sleeping_threads); e = list_next (e))
{ {

View File

@@ -375,11 +375,15 @@ calculate_priority (void)
return 0; return 0;
} }
fp32_t void
calculate_recent_cpu (void) calculate_recent_cpu (void)
{ {
/* Not yet implemented */ struct thread *t = thread_current ();
return { 0 }; 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 void