]> rtime.felk.cvut.cz Git - jailhouse-test.git/commitdiff
Add benchmark for Linux user-space
authorMaxim Baryshnikov <barysmax@fel.cvut.cz>
Tue, 24 May 2016 23:09:57 +0000 (01:09 +0200)
committerMaxim Baryshnikov <barysmax@fel.cvut.cz>
Tue, 24 May 2016 23:09:57 +0000 (01:09 +0200)
qemu-launch-scripts/bench-linux.c [new file with mode: 0644]

diff --git a/qemu-launch-scripts/bench-linux.c b/qemu-launch-scripts/bench-linux.c
new file mode 100644 (file)
index 0000000..e9a3cd5
--- /dev/null
@@ -0,0 +1,70 @@
+
+//#define L4
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+#ifdef L4
+
+#include <l4/util/rdtsc.h>
+#include <l4/sys/kip.h>
+#include <l4/re/env.h>
+
+#endif//L4
+
+#define WORKSET_SIZE (6*1024*1024)
+//#define ALL_WORKSETS_BENCH 
+
+struct s {
+       int dummy[56];
+       struct s *ptr;
+};
+
+struct s array[0x1000000/sizeof(struct s)];
+#define REPEATS (0x20000000)
+
+static __inline__ uint64_t rdtsc(void)
+{
+       uint32_t a, d;
+       //asm("cpuid");
+       asm volatile("rdtsc" : "=a" (a), "=d" (d));
+
+       return (((uint64_t)a) | (((uint64_t)d) << 32));
+}
+
+int main(int argc, char *argv[])
+{
+       
+       unsigned int size;
+#ifdef ALL_WORKSETS_BENCH
+       for (size = 1024; size <= sizeof(array); size *= 2)
+#else //!ALL_WORKSETS_BENCH
+       size = WORKSET_SIZE;
+       if (argc - 1) {
+               char * nxt_cr;
+               size = strtoul(argv[1], &nxt_cr, 0);
+       }
+       while (1)       
+#endif
+       {
+               unsigned int i;
+               for (i=0; i < size / sizeof(array[0]); i++)
+                       array[i].ptr = &array[i+1];
+               array[ size / sizeof(array[0]) - 1].ptr = &array[0];
+
+               i = REPEATS;
+               volatile struct s *p = &array[0];
+               uint64_t tic, tac;
+               tic = rdtsc();
+               while (i--) {
+                       p = p->ptr;
+               //      printf("%p\n", p);
+               }
+               tac = rdtsc();
+               printf("%d %llu\n", size, (tac - tic) / REPEATS);
+               fflush(stdout);
+       }
+       return 0;       
+}