forked from joelagnel/linux-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-prctl.c
72 lines (51 loc) · 1.47 KB
/
test-prctl.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
68
69
70
71
72
#include "/s/routines.h"
#define PR_SET_CORE_SCHED 57
#define cpu_relax()
static int *stop_test;
static int *start_test;
#define create_var(var) var = mmap(NULL, sizeof *var, PROT_READ | PROT_WRITE, \
MAP_SHARED | MAP_ANONYMOUS, -1, 0)
static void task(int task_id) {
unsigned long i;
bool prc = (task_id == 1);
while(!*start_test)
cpu_relax();
trace_printk("Task %d: Started test\n", task_id);
// 500 ms
for (i = 0; i < 200000000ULL; i++);
if (prc) {
trace_printk("Task %d: Setting prctl\n", task_id);
// Set prctl, tasks should be migrated away.
if (prctl(PR_SET_CORE_SCHED, 1)) {
perror("prctl failed\n");
trace_printk("Task %d: Failed prctl\n", task_id);
} else {
trace_printk("Task %d: Success prctl\n", task_id);
}
}
// 500 ms - let run a bit after migrations
for (i = 0; i < 200000000ULL; i++);
while(!*stop_test)
cpu_relax();
trace_printk("Task %d: Ended test\n", task_id);
}
#define NR_TASKS 4
void main(void) {
int pid[NR_TASKS], i;
char pid_cmd[100];
struct sched_param param;
create_var(stop_test);
create_var(start_test);
for (i = 0; i < NR_TASKS; i++) {
FORK_FN(pid[i], task, i);
pin_to_cpu_range(pid[i], 2, 3);
}
sleep_ms(100);
/* Start test */
*start_test = 1;
trace_printk("Tests started\n");
sleep_ms(2000);
*stop_test = 1;
while(wait(NULL) != -1);
trace_printk("All threads exited, test done\n");
}