-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stride.c
More file actions
63 lines (50 loc) · 1.18 KB
/
Copy pathtest_stride.c
File metadata and controls
63 lines (50 loc) · 1.18 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
/**
* This program requests portion of CPU resources with given parameter
* value by calling set_cpu_share() system call.
* After that, periodically increases cnt values until its LIFETIME.
*/
#include "types.h"
#include "stat.h"
#include "user.h"
#define LIFETIME 5000 // (ticks)
#define COUNT_PERIOD 1000000 // (iteration)
int
main(int argc, char *argv[])
{
uint i;
int cnt = 0;
int cpu_share=10;
uint start_tick;
uint curr_tick;
if (argc < 2) {
printf(1, "usage: sched_test_stride cpu_share(%)\n");
exit();
}
cpu_share = atoi(argv[1]);
set_cpu_share(cpu_share);
// Register this process to the Stride scheduler
if (set_cpu_share(cpu_share) < 0) {
printf(1, "cannot set cpu share\n");
exit();
}
// Get start time
start_tick = uptime();
i = 0;
while (1) {
i++;
// Prevent code optimization
__sync_synchronize();
if (i == COUNT_PERIOD) {
cnt++;
// Get current time
curr_tick = uptime();
if (curr_tick - start_tick > LIFETIME) {
// Terminate process
printf(1, "STRIDE(%d), cnt: %d\n", cpu_share, cnt);
break;
}
i = 0;
}
}
exit();
}