VMM: Make new virtio implementation work with new vmm 2LS
[akaros.git] / tests / old / msr_cycling_vcores.c
1 /* tests/msr_cycling_vcores.c
2  *
3  * This requests the max_vcores in the system, waits a bit, then gives them
4  * back, looping forever.  We can't give up all vcores, based on the current
5  * kernel, so we hold on to vcore0 to do the thinking. */
6
7 #include <ros/resource.h>
8 #include <parlib/parlib.h>
9 #include <stdio.h>
10 #include <parlib/vcore.h>
11 #include <parlib/timing.h>
12 #include <parlib/mcs.h>
13 #include <parlib/uthread.h>
14
15 mcs_barrier_t b;
16 uint64_t begin = 0, end = 0;
17
18 int main(int argc, char** argv)
19 {
20         printf("Good chance this doesn't work anymore!\n");
21         mcs_barrier_init(&b, max_vcores());
22
23         vcore_request_total(max_vcores());
24         printf("We're screwed!\n");
25
26         /* should never make it here */
27         return -1;
28 }
29
30 void vcore_entry(void)
31 {
32         uint32_t vcoreid = vcore_id();
33
34         if (vcoreid) {
35                 mcs_barrier_wait(&b, vcoreid);
36                 udelay(5000000);
37                 if (vcoreid == 1)
38                         printf("Proc %d's vcores are yielding\n", getpid());
39                 sys_yield(0);
40         } else {
41                 /* trip the barrier here, all future times are in the loop */
42                 mcs_barrier_wait(&b, vcoreid);
43                 while (1) {
44                         udelay(15000000);
45                         printf("Proc %d requesting its cores again\n", getpid());
46                         begin = read_tsc();
47                         vcore_request_total(max_vcores());
48                         mcs_barrier_wait(&b, vcoreid);
49                         end = read_tsc();
50                         printf("Took %llu usec (%llu nsec) to get my yielded cores back.\n",
51                                udiff(begin, end), ndiff(begin, end));
52                         printf("[T]:010:%llu:%llu\n",
53                                udiff(begin, end), ndiff(begin, end));
54                 }
55         }
56         printf("We're screwed!\n");
57         exit(-1);
58 }