]> rtime.felk.cvut.cz Git - jailhouse-test.git/blob - qemu-launch-scripts/bench-linux.c
Some minor fixes applied.
[jailhouse-test.git] / qemu-launch-scripts / bench-linux.c
1
2 //#define L4
3
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <stdlib.h>
8
9 #ifdef L4
10
11 #include <l4/util/rdtsc.h>
12 #include <l4/sys/kip.h>
13 #include <l4/re/env.h>
14
15 #endif//L4
16
17 #define WORKSET_SIZE (6*1024*1024)
18 #define ALL_WORKSETS_BENCH 
19
20 struct s {
21         char dummy[56];
22         struct s *ptr;
23 };
24
25 struct s array[0x2100000/sizeof(struct s)];
26 #define REPEATS (0x20000000)
27
28 static __inline__ uint64_t rdtsc(void)
29 {
30         uint32_t a, d;
31         //asm("cpuid");
32         asm volatile("rdtsc" : "=a" (a), "=d" (d));
33
34         return (((uint64_t)a) | (((uint64_t)d) << 32));
35 }
36
37 int main(int argc, char *argv[])
38 {
39         
40         unsigned int size;
41 #ifdef ALL_WORKSETS_BENCH
42         for (size = 1024; size <= sizeof(array); size *= 2)
43 #else //!ALL_WORKSETS_BENCH
44         size = WORKSET_SIZE;
45         if (argc - 1) {
46                 char * nxt_cr;
47                 size = strtoul(argv[1], &nxt_cr, 0);
48         }
49         while (1)       
50 #endif
51         {
52                 unsigned int i;
53                 for (i=0; i < size / sizeof(array[0]); i++)
54                         array[i].ptr = &array[i+1];
55                 array[ size / sizeof(array[0]) - 1].ptr = &array[0];
56
57                 i = REPEATS;
58                 volatile struct s *p = &array[0];
59                 uint64_t tic, tac;
60                 tic = rdtsc();
61                 while (i--) {
62                         p = p->ptr;
63                 //      printf("%p\n", p);
64                 }
65                 tac = rdtsc();
66                 printf("%d %llu\n", size, (tac - tic) / REPEATS);
67                 fflush(stdout);
68         }
69         return 0;       
70 }