]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/benchmark/server/src/main.c
benchmarks: use better bench. bootstrap: Fix slow memory access bug.
[l4.git] / l4 / pkg / benchmark / server / src / main.c
1
2 #define L4
3
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <stdbool.h>
7
8 #ifdef L4
9
10 #include <l4/util/rdtsc.h>
11 #include <l4/sys/kip.h>
12 #include <l4/re/env.h>
13 #include <l4/util/util.h>
14
15 #endif//L4
16
17 #define WORKSET_SIZE (12*1024*1024)
18 #define ALL_WORKSETS_BENCH 
19
20 struct s {
21         int dummy[56];
22         struct s *ptr;
23 };
24
25 struct s array[0x1000000/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         while(1){
42 #ifdef ALL_WORKSETS_BENCH
43                 for (size = 1024; size <= sizeof(array); size *= 2)
44 #else //!ALL_WORKSETS_BENCH
45                 size = WORKSET_SIZE;
46                 while (1)       
47 #endif
48                 {
49                         unsigned int i;
50                         for (i=0; i < size / sizeof(array[0]); i++)
51                                 array[i].ptr = &array[i+1];
52                         array[ size / sizeof(array[0]) - 1].ptr = &array[0];
53
54                         i = REPEATS;
55                         volatile struct s *p = &array[0];
56                         uint64_t tic, tac;
57                         tic = rdtsc();
58                         while (i--) {
59                                 p = p->ptr;
60                                 //printf("%p\n", p);
61                         }
62                         tac = rdtsc();
63                         printf("%d %llu\n", size, (tac - tic) / REPEATS);
64                         fflush(stdout);
65                 }
66                 printf("10 sec wait and do again.\n");
67                 l4_sleep(10000);
68         }
69         return 0;       
70 }