-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvmnest.c
48 lines (41 loc) · 884 Bytes
/
vmnest.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
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include <vmm/vmm.h>
volatile uint64_t logout;
struct virtual_machine vm = {.halt_exit = true, .logout = &logout};
static volatile int count, done, lim = 1000;
int mc;
static void vmcall(void *a)
{
while (count < lim) {
__asm__ __volatile__("vmcall\n\t");
count++;
}
done = 1;
while (1);
__asm__ __volatile__("hlt\n\t");
}
int main(int argc, char **argv)
{
int iter = 0;
int d = 0;
if (argc > 1)
lim = strtoul(argv[1], 0, 0);
if (argc > 2) d++;
if (vthread_attr_init(&vm, 0) < 0)
err(1, "vthread_attr_init: %r: ");
vthread_create(&vm, 0, vmcall, NULL);
while (! done) {
logout |= 1;
if (d) printf("lock.");
while ((! done) && (logout & 1))
;
if (d) printf("out\n");
iter++;
}
printf("host iter %d guest iter %d\n", iter, count);
return 0;
}