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 *aux);
16 test_mlfqs_load_60 (void)
20 ASSERT (enable_mlfqs);
22 start_time = timer_ticks ();
23 msg ("Starting %d niced 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, NULL);
30 msg ("Starting threads took %d seconds.",
31 timer_elapsed (start_time) / TIMER_FREQ);
33 for (i = 0; i < 90; i++)
35 int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10);
37 timer_sleep (sleep_until - timer_ticks ());
38 load_avg = thread_get_load_avg ();
39 msg ("After %d seconds, load average=%d.%02d.",
40 i * 2, load_avg / 100, load_avg % 100);
45 load_thread (void *aux UNUSED)
47 int64_t sleep_time = 10 * TIMER_FREQ;
48 int64_t spin_time = sleep_time + 60 * TIMER_FREQ;
49 int64_t exit_time = spin_time + 60 * TIMER_FREQ;
52 timer_sleep (sleep_time - timer_elapsed (start_time));
53 while (timer_elapsed (start_time) < spin_time)
55 timer_sleep (exit_time - timer_elapsed (start_time));