forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedulertest.c
46 lines (42 loc) · 1.13 KB
/
schedulertest.c
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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#define N 5000000
#define loop 20
#define NFORK 5
int main() {
for(int i = 0; i < NFORK; i++) {
int f = fork();
if(f < 0) {
printf(2, "fork() failed\n");
exit();
} else if(f == 0) {
volatile int id = getpid();
sleep(100 - 9 * i);
#ifdef PBS
setpriority(70 + (id % 4), id);
#endif
// printf(1, "process %d started\n", id);
for(int i = 0; i < loop; i++) {
for(int j = 0; j < N; j++) {
id++;
id--;
}
}
// printf(1, "process %d completed\n", id);
exit();
}
}
int totalr = 0, totalw = 0;
for(int i = 0; i < NFORK; i++){
int rtime, wtime;
waitx(&wtime, &rtime);
totalr += rtime;
totalw += wtime;
printf(1, "%d: %d, %d\n",i, wtime, rtime);
}
printf(1, "Average:\n rtime:%d, wtime:%d\n", totalr / NFORK, totalw / NFORK);
printf(1, "Total:\n rtime:%d, wtime:%d\n", totalr, totalw);
exit();
}