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 static int64_t start_time;
11 static void load_thread (void *seq_no);
16 test_mlfqs_load_avg (void)
20 ASSERT (enable_mlfqs);
22 start_time = timer_ticks ();
23 msg ("Starting %d load threads...", THREAD_CNT);
24 for (i = 0; i < THREAD_CNT; i++)
27 snprintf(name, sizeof name, "load %d", i);
28 thread_create (name, PRI_DEFAULT, load_thread, (void *) i);
30 msg ("Starting threads took %d seconds.",
31 timer_elapsed (start_time) / TIMER_FREQ);
32 thread_set_nice (-20);
34 for (i = 0; i < 90; i++)
36 int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10);
38 timer_sleep (sleep_until - timer_ticks ());
39 load_avg = thread_get_load_avg ();
40 msg ("After %d seconds, load average=%d.%02d.",
41 i * 2, load_avg / 100, load_avg % 100);
46 load_thread (void *seq_no_)
48 int seq_no = (int) seq_no_;
49 int sleep_time = TIMER_FREQ * (10 + seq_no);
50 int spin_time = sleep_time + TIMER_FREQ * THREAD_CNT;
51 int exit_time = TIMER_FREQ * (THREAD_CNT * 2);
53 timer_sleep (sleep_time - timer_elapsed (start_time));
54 while (timer_elapsed (start_time) < spin_time)
56 timer_sleep (exit_time - timer_elapsed (start_time));