PKUOS - Pintos
Pintos source browser for PKU Operating System course
mlfqs-load-1.c
Go to the documentation of this file.
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
3 you can verify:
4 perl -e '$i++,$a=(59*$a+1)/60while$a<=.5;print "$i\n"'
5
6 Then, verifies that 10 seconds of inactivity drop the load
7 average back below 0.5 again. */
8
9#include <stdio.h>
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"
16
17void
19{
21 int elapsed;
22 int load_avg;
23
25
26 msg ("spinning for up to 45 seconds, please wait...");
27
29 for (;;)
30 {
31 load_avg = thread_get_load_avg ();
32 ASSERT (load_avg >= 0);
34 if (load_avg > 100)
35 fail ("load average is %d.%02d "
36 "but should be between 0 and 1 (after %d seconds)",
37 load_avg / 100, load_avg % 100, elapsed);
38 else if (load_avg > 50)
39 break;
40 else if (elapsed > 45)
41 fail ("load average stayed below 0.5 for more than 45 seconds");
42 }
43
44 if (elapsed < 38)
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);
47
48 msg ("sleeping for another 10 seconds, please wait...");
50
51 load_avg = thread_get_load_avg ();
52 if (load_avg < 0)
53 fail ("load average fell below 0");
54 if (load_avg > 50)
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);
58
59 pass ();
60}
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
Definition: debug.h:31
void fail(const char *format,...)
Definition: lib.c:40
void msg(const char *format,...)
Definition: lib.c:28
void test_mlfqs_load_1(void)
Verifies that a single busy thread raises the load average to 0.5 in 38 to 45 seconds.
Definition: mlfqs-load-1.c:18
static int64_t start_time
Starts 60 threads that each sleep for 10 seconds, then spin in a tight loop for 60 seconds,...
signed long long int int64_t
Definition: stdint.h:16
void pass(void)
Prints a message indicating the current test passed.
Definition: tests.c:98
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
int thread_get_load_avg(void)
Returns 100 times the system load average.
Definition: thread.c:365
int64_t timer_ticks(void)
Returns the number of timer ticks since the OS booted.
Definition: timer.c:71
int64_t timer_elapsed(int64_t then)
Returns the number of timer ticks elapsed since THEN, which should be a value once returned by timer_...
Definition: timer.c:82
void timer_sleep(int64_t ticks)
Sleeps for approximately TICKS timer ticks.
Definition: timer.c:90
#define TIMER_FREQ
Number of timer interrupts per second.
Definition: timer.h:8