forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.c
67 lines (66 loc) · 1.51 KB
/
bench.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "types.h"
#include "user.h"
#include "fcntl.h"
#include "fs.h"
#include "stat.h"
struct proc_stat
{
int pid; // PID of each process
int runtime; // Use suitable unit of time
int total_time; // Use suitable unit of time
int num_run; // number of time the process is executed
int current_queue; // current assigned queue
int ticks[5]; // number of ticks each process has received at each of the 5 priority queue
};
int number_of_processes = 10;
int main(int argc, char *argv[])
{
int j;
for (j = 0; j < number_of_processes; j++)
{
printf(1, "%d\n", j);
int pid = fork();
if (pid < 0)
{
printf(1, "fork failed lmao\n");
continue;
}
if (pid == 0)
{
set_priority(100-(20+j));
volatile int i;
for (volatile int k = 0; k < number_of_processes; k++)
{
if (k <= j)
{
sleep(200); //io time
}
else
{
for (i = 0; i < 100000000; i++)
{
;
}
}
// cps();
}
printf(1, "%d\n", j);
exit();
}
}
for (j = 0; j < 20; j++)
{
wait();
}
struct proc_stat p;
getpinfo(&p);
printf(1, "PINFO:\n");
printf(1, "pid:%d\n", p.pid);
printf(1, "runtime:%d\n", p.runtime);
printf(1, "total_time:%d\n", p.total_time);
printf(1, "num_run:%d\n", p.num_run);
printf(1, "current queue:%d\n", p.current_queue);
for (int i = 0; i < 5; i++)
printf(1, "ticks in queue %d = %d\n", i, p.ticks[i]);
exit();
}