Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / threads / mlfqs-recent-1.c
1 #include <stdio.h>
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"
8
9 /* Sensitive to assumption that recent_cpu updates happen exactly
10    when timer_ticks()%TIMER_FREQ == 0. */
11
12 void
13 test_mlfqs_recent_1 (void) 
14 {
15   int64_t start_time;
16   int last_elapsed = 0;
17   
18   ASSERT (enable_mlfqs);
19
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
23                + 10 * TIMER_FREQ);
24
25   start_time = timer_ticks ();
26   for (;;) 
27     {
28       int elapsed = timer_elapsed (start_time);
29       if (elapsed % (TIMER_FREQ * 2) == 0 && elapsed > last_elapsed) 
30         {
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.",
35                elapsed_seconds,
36                recent_cpu / 100, recent_cpu % 100,
37                load_avg / 100, load_avg % 100);
38           if (elapsed_seconds >= 180)
39             break;
40         } 
41       last_elapsed = elapsed;
42     }
43 }