CS318 - Pintos
Pintos source browser for JHU CS318 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 
17 void
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);
33  elapsed = timer_elapsed (start_time) / TIMER_FREQ;
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...");
49  timer_sleep (TIMER_FREQ * 10);
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 }
TIMER_FREQ
#define TIMER_FREQ
Number of timer interrupts per second.
Definition: timer.h:8
timer_elapsed
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
start_time
static int64_t start_time
Starts 60 threads that each sleep for 10 seconds, then spin in a tight loop for 60 seconds,...
Definition: mlfqs-load-60.c:108
int64_t
signed long long int int64_t
Definition: stdint.h:16
init.h
timer.h
timer_sleep
void timer_sleep(int64_t ticks)
Sleeps for approximately TICKS timer ticks.
Definition: timer.c:90
malloc.h
timer_ticks
int64_t timer_ticks(void)
Returns the number of timer ticks since the OS booted.
Definition: timer.c:71
pass
void pass(void)
Prints a message indicating the current test passed.
Definition: tests.c:98
ASSERT
#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
fail
void fail(const char *format,...)
Definition: lib.c:40
msg
void msg(const char *format,...)
Definition: lib.c:28
thread_mlfqs
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
test_mlfqs_load_1
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
tests.h
thread.h
synch.h
thread_get_load_avg
int thread_get_load_avg(void)
Returns 100 times the system load average.
Definition: thread.c:365