2 #include "tests/threads/tests.h"
3 #include "threads/init.h"
4 #include "threads/malloc.h"
5 #include "threads/synch.h"
6 #include "threads/thread.h"
7 #include "devices/timer.h"
9 /* Sensitive to assumption that recent_cpu updates happen exactly
10 when timer_ticks()%TIMER_FREQ == 0. */
13 test_mlfqs_recent_1 (void)
18 ASSERT (enable_mlfqs);
20 msg ("Sleeping 10 seconds to allow recent_cpu to decay, please wait...");
21 start_time = timer_ticks ();
22 timer_sleep (DIV_ROUND_UP (start_time, TIMER_FREQ) - start_time
25 start_time = timer_ticks ();
28 int elapsed = timer_elapsed (start_time);
29 if (elapsed % (TIMER_FREQ * 2) == 0 && elapsed > last_elapsed)
31 int recent_cpu = thread_get_recent_cpu ();
32 int load_avg = thread_get_load_avg ();
33 int elapsed_seconds = elapsed / TIMER_FREQ;
34 msg ("After %d seconds, recent_cpu is %d.%02d, load_avg is %d.%02d.",
36 recent_cpu / 100, recent_cpu % 100,
37 load_avg / 100, load_avg % 100);
38 if (elapsed_seconds >= 180)
41 last_elapsed = elapsed;