UCQ debug code
[akaros.git] / tests / 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.h>
9 #include <stdio.h>
10 #include <vcore.h>
11 #include <timing.h>
12 #include <mcs.h>
13 #include <uthread.h>
14
15 #ifdef __sparc_v8__
16 # define udelay(x) udelay((x)/2000)
17 #endif
18
19 mcs_barrier_t b;
20 uint64_t begin = 0, end = 0;
21
22 int main(int argc, char** argv)
23 {
24         printf("Good chance this doesn't work anymore!\n");
25         mcs_barrier_init(&b, max_vcores());
26
27         vcore_request(max_vcores());
28         printf("We're screwed!\n");
29
30         /* should never make it here */
31         return -1;
32 }
33
34 void vcore_entry(void)
35 {
36         uint32_t vcoreid = vcore_id();
37
38         if (vcoreid) {
39                 mcs_barrier_wait(&b, vcoreid);
40                 udelay(5000000);
41                 if (vcoreid == 1)
42                         printf("Proc %d's vcores are yielding\n", getpid());
43                 sys_yield(0);
44         } else {
45                 /* trip the barrier here, all future times are in the loop */
46                 mcs_barrier_wait(&b, vcoreid);
47                 while (1) {
48                         udelay(15000000);
49                         printf("Proc %d requesting its cores again\n", getpid());
50                         begin = read_tsc();
51                         vcore_request(max_vcores() - 1); /* since we already have 1 */
52                         mcs_barrier_wait(&b, vcoreid);
53                         end = read_tsc();
54                         printf("Took %llu usec (%llu nsec) to get my yielded cores back.\n",
55                                udiff(begin, end), ndiff(begin, end));
56                         printf("[T]:010:%llu:%llu\n",
57                                udiff(begin, end), ndiff(begin, end));
58                 }
59         }
60         printf("We're screwed!\n");
61         exit(-1);
62 }