--- /dev/null
+//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 );
+ }
+}