]> rtime.felk.cvut.cz Git - hercules2020/jailhouse-build.git/blob - test/prem-test.c
Update PREM test and main Makefile
[hercules2020/jailhouse-build.git] / test / prem-test.c
1 /* Run this as: for i in $(seq 0 5); do prem-test $i & done */
2
3 #define _GNU_SOURCE         /* See feature_test_macros(7) */
4 #include <err.h>
5 #include <sched.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10
11 #ifndef SYS_prem_guard_set
12 #define SYS_prem_guard_set 792
13 #endif
14
15 enum prem_phase {
16         PREM_COMPATIBLE = 0,
17         PREM_MEMORY     = 1,
18         PREM_COMPUTE    = 2,
19 };
20
21 long prem_guard_set(enum prem_phase phase,
22                     unsigned long memory_budget,
23                     unsigned long timeout)
24 {
25         return syscall(SYS_prem_guard_set, phase, memory_budget, timeout);
26 }
27
28 int main(int argc, char *argv[])
29 {
30         cpu_set_t set;
31         int cpu = 0;
32
33         if (argc > 1)
34                 cpu = atoi(argv[1]);
35
36         /* Ensure that memory phase starts and ends on the same CPU */
37         CPU_ZERO(&set);
38         CPU_SET(cpu, &set);
39         if (sched_setaffinity(getpid(), sizeof(set), &set) < 0)
40                 err(1, "sched_setaffinity");
41         printf("Pinned to CPU %d\n", cpu);
42
43         prem_guard_set(PREM_MEMORY, 22, 33);
44         for (int i = 0; i < 100; i++)
45                 printf("Memory phase PID %d\n", getpid());
46         prem_guard_set(PREM_COMPATIBLE, 44, 55);
47         return 0;
48 }