]> rtime.felk.cvut.cz Git - l4.git/commitdiff
l4: Try to implement benchmark pkg.
authorMaxim Baryshnikov <barysmax@fel.cvut.cz>
Fri, 6 May 2016 02:53:35 +0000 (04:53 +0200)
committerMaxim Baryshnikov <barysmax@fel.cvut.cz>
Fri, 6 May 2016 02:53:35 +0000 (04:53 +0200)
l4/pkg/benchmark/Control [new file with mode: 0644]
l4/pkg/benchmark/Makefile [new file with mode: 0644]
l4/pkg/benchmark/README [new file with mode: 0644]
l4/pkg/benchmark/server/Makefile [new file with mode: 0644]
l4/pkg/benchmark/server/src/Makefile [new file with mode: 0644]
l4/pkg/benchmark/server/src/main.c [new file with mode: 0644]

diff --git a/l4/pkg/benchmark/Control b/l4/pkg/benchmark/Control
new file mode 100644 (file)
index 0000000..632074f
--- /dev/null
@@ -0,0 +1,2 @@
+requires: stdlibs
+Maintainer: adam@os.inf.tu-dresden.de
diff --git a/l4/pkg/benchmark/Makefile b/l4/pkg/benchmark/Makefile
new file mode 100644 (file)
index 0000000..f8ca7cc
--- /dev/null
@@ -0,0 +1,4 @@
+PKGDIR = .
+L4DIR  ?= $(PKGDIR)/../..
+
+include $(L4DIR)/mk/subdir.mk
diff --git a/l4/pkg/benchmark/README b/l4/pkg/benchmark/README
new file mode 100644 (file)
index 0000000..3e44ff4
--- /dev/null
@@ -0,0 +1 @@
+Simple Hello Example.
diff --git a/l4/pkg/benchmark/server/Makefile b/l4/pkg/benchmark/server/Makefile
new file mode 100644 (file)
index 0000000..04ac0da
--- /dev/null
@@ -0,0 +1,4 @@
+PKGDIR         ?= ..
+L4DIR          ?= $(PKGDIR)/../..
+
+include $(L4DIR)/mk/subdir.mk
diff --git a/l4/pkg/benchmark/server/src/Makefile b/l4/pkg/benchmark/server/src/Makefile
new file mode 100644 (file)
index 0000000..45ae57d
--- /dev/null
@@ -0,0 +1,7 @@
+PKGDIR         ?= ../..
+L4DIR          ?= $(PKGDIR)/../..
+
+TARGET         = benchmark
+SRC_C          = main.c
+
+include $(L4DIR)/mk/prog.mk
diff --git a/l4/pkg/benchmark/server/src/main.c b/l4/pkg/benchmark/server/src/main.c
new file mode 100644 (file)
index 0000000..4181d76
--- /dev/null
@@ -0,0 +1,103 @@
+//taken from [..see below..] and modifed a little.
+/*
+ * lib_mem.c - library of routines used to analyze the memory hierarchy
+ *
+ * @(#)lib_mem.c 1.15 staelin@hpliclu2.hpli.hpl.hp.com
+ *
+ * Copyright (c) 2000 Carl Staelin.
+ * Copyright (c) 1994 Larry McVoy.  
+ * Distributed under the FSF GPL with
+ * additional restriction that results may published only if
+ * (1) the benchmark is unmodified, and
+ * (2) the version in the sccsid below is included in the report.
+ * Support for this development by Sun Microsystems is gratefully acknowledged.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <l4/util/rdtsc.h>
+#include <l4/sys/l4int.h>
+
+void use_dummy(int result);
+size_t* words_initialize(size_t max, int scale);
+l4_uint64_t parse_param( char param, int argc, char* argv[]);
+
+static volatile l4_uint64_t use_result_dummy;
+void use_dummy(int result) { use_result_dummy += result; }
+
+/*
+ * words_initialize
+ *
+ * This is supposed to create the order in which the words in a 
+ * "cache line" are used.  Since we rarely know the cache line
+ * size with any real reliability, we need to jump around so
+ * as to maximize the number of potential cache misses, and to
+ * minimize the possibility of re-using a cache line.
+ */
+size_t* words_initialize(size_t max, int scale)
+{
+       size_t  i, j, nbits;
+       size_t* words = (size_t*)calloc(max, sizeof(size_t));
+
+       if (!words) return NULL;
+
+       //bzero(words, max * sizeof(size_t));
+       for (i = max>>1, nbits = 0; i != 0; i >>= 1, nbits++)
+               ;
+       for (i = 0; i < max; ++i) {
+               /* now reverse the bits */
+               for (j = 0; j < nbits; j++) {
+                       if (i & (1<<j)) {
+                               words[i] |= (1<<(nbits-j-1));
+                       }
+               }
+               words[i] *= scale;
+       }
+       return words;
+}
+
+l4_uint64_t parse_param( char param, int argc, char* argv[])
+{
+       int i;
+       for (i = 1; i < argc; i++){
+               if ('-' == argv[i][0] && param == argv[i][1] ){
+                       return atoll(argv[i+1]);                
+               }
+       }
+       return 0;
+}
+
+#define DEF_SIZE (1000000)
+#define DEF_STRIDE (10)
+
+
+int main(int argc, char* argv[])
+{
+                       
+       l4_uint64_t time_start, time_end, time_diff, j=0, i, stride = DEF_STRIDE;;
+       l4_uint64_t size = DEF_SIZE;;
+       //size = parse_param('s', argc, argv);
+       //if ( !size ) 
+       //stride = parse_param('t', argc, argv); 
+       //if ( !stride ) 
+       
+       size_t * arry = words_initialize(size, 5);
+       if (!arry) {
+               printf("Init failed.");
+               return -1;
+       }       
+       
+       printf("Start benchmark: array size is %llu, stride is %llu\n", size, stride);
+       while(1){
+               time_start = l4_tsc_to_us(l4_rdtsc());              
+               for (i = 0; i < size; i += stride) {
+                       j += arry[i];
+               }
+               time_end = l4_tsc_to_us(l4_rdtsc());
+               use_dummy(j);
+               time_diff = (time_end-time_start);
+               printf("time: %lld us, size/time %lld", time_diff,  size/time_diff );
+       }
+}