-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpriority_boost.c
More file actions
74 lines (58 loc) · 1.63 KB
/
priority_boost.c
File metadata and controls
74 lines (58 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "types.h"
#include "stat.h"
#include "user.h"
#include "pstat.h"
#define check(exp, msg) if(exp) {} else {\
printf(1, "%s:%d check (" #exp ") failed: %s\n", __FILE__, __LINE__, msg);\
exit();}
#define DDEBUG 1
#ifdef DDEBUG
# define DEBUG_PRINT(x) printf x
#else
# define DEBUG_PRINT(x) do {} while (0)
#endif
int workload(int n) {
int i, j = 0;
for (i = 0; i < n; i++) {
j += i * j + 1;
}
return j;
}
int
main(int argc, char *argv[])
{
struct pstat st;
check(getpinfo(&st) == 0, "getpinfo");
// Push this thread to the bottom
workload(80000000);
int j;
int c_pid = fork();
// Child
if (c_pid == 0) {
workload(800000000);
exit();
}
sleep(400);
workload(8000000);
check(getpinfo(&st) == 0, "getpinfo");
for (j = 0; j < NPROC; j++) {
if (st.inuse[j] && st.pid[j] == getpid()) {
for (int k = 3; k >= 0; k--) {
DEBUG_PRINT((1, "\t level %d ticks used %d\n", k, st.ticks[j][k]));
}
check(getpinfo(&st) == 0, "getpinfo");
DEBUG_PRINT((1, "\t The priority of the parent process is %d\n", st.priority[j]));
check(st.priority[j] > 0, "the priority should be boosted to higher\n");
sleep(100);
check(getpinfo(&st) == 0, "getpinfo");
DEBUG_PRINT((1, "After priority gets updated and scheduled for some time\npid: %d\n", st.pid[j]));
for (int k = 3; k >= 0; k--) {
DEBUG_PRINT((1, "\t level %d ticks used %d\n", k, st.ticks[j][k]));
}
}
}
// Wait for child processes to finish..
wait();
printf(1, "TEST PASSED");
exit();
}