1 /* Verifies that a single busy thread raises the load average to
2 0.5 in 38 to 45 seconds. The expected time is 42 seconds, as
4 perl -e '$i++,$a=(59*$a+1)/60while$a<=.5;print "$i\n"'
6 Then, verifies that 10 seconds of inactivity drop the load
7 average back below 0.5 again. */
10 #include "tests/threads/tests.h"
11 #include "threads/init.h"
12 #include "threads/malloc.h"
13 #include "threads/synch.h"
14 #include "threads/thread.h"
15 #include "devices/timer.h"
18 test_mlfqs_load_1 (void)
24 ASSERT (enable_mlfqs);
26 msg ("spinning for up to 45 seconds, please wait...");
28 start_time = timer_ticks ();
31 load_avg = thread_get_load_avg ();
32 ASSERT (load_avg >= 0);
33 elapsed = timer_elapsed (start_time) / TIMER_FREQ;
36 else if (load_avg > 100)
37 fail ("load average is %d.%02d "
38 "but should be between 0 and 1 (after %d seconds)",
39 load_avg / 100, load_avg % 100, elapsed);
40 else if (elapsed > 45)
41 fail ("load average stayed below 0.5 for more than 45 seconds");
45 fail ("load average took only %d seconds to rise above 0.5", elapsed);
46 msg ("load average rose to 0.5 after %d seconds", elapsed);
48 msg ("sleeping for another 10 seconds, please wait...");
49 timer_sleep (TIMER_FREQ * 10);
51 load_avg = thread_get_load_avg ();
53 fail ("load average fell below 0");
55 fail ("load average stayed above 0.5 for more than 10 seconds");
56 msg ("load average fell back below 0.5 (to %d.%02d)",
57 load_avg / 100, load_avg % 100);