From b76fd695c373d96191d709a6976c41c6825c515b Mon Sep 17 00:00:00 2001 From: Maxim Baryshnikov Date: Wed, 25 May 2016 01:09:57 +0200 Subject: [PATCH] Add benchmark for Linux user-space --- qemu-launch-scripts/bench-linux.c | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 qemu-launch-scripts/bench-linux.c diff --git a/qemu-launch-scripts/bench-linux.c b/qemu-launch-scripts/bench-linux.c new file mode 100644 index 0000000..e9a3cd5 --- /dev/null +++ b/qemu-launch-scripts/bench-linux.c @@ -0,0 +1,70 @@ + +//#define L4 + +#include +#include +#include +#include + +#ifdef L4 + +#include +#include +#include + +#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; +} -- 2.39.2