summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2010-11-09 18:34:45 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2010-11-09 18:34:45 -0500
commit9acc84176fc4aae0622ebfc7edb3200018ce6969 (patch)
treeba95888d056aa5d56bbb7060907ea7e7d422a31f
parent72cdd86d0bfb3de36bdcdaecd3d457671d8ce349 (diff)
add memtrash, a background workload task
This is the old background workload task used for the synthetic experiments.
-rw-r--r--Makefile5
-rw-r--r--bin/memthrash.c26
2 files changed, 30 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index eb09b1b..8a491d2 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ vpath %.c bin/
15# ############################################################################## 15# ##############################################################################
16# Targets 16# Targets
17 17
18all = cache_cost 18all = cache_cost memthrash
19 19
20.PHONY: all clean 20.PHONY: all clean
21all: ${all} 21all: ${all}
@@ -25,5 +25,8 @@ clean:
25obj-cache_cost = cache_cost.o 25obj-cache_cost = cache_cost.o
26cache_cost: ${obj-cache_cost} 26cache_cost: ${obj-cache_cost}
27 27
28obj-memthrash = memthrash.o
29memthrash: ${obj-memthrash}
30
28# dependency discovery 31# dependency discovery
29include ${LIBLITMUS}/inc/depend.makefile 32include ${LIBLITMUS}/inc/depend.makefile
diff --git a/bin/memthrash.c b/bin/memthrash.c
new file mode 100644
index 0000000..9b2275b
--- /dev/null
+++ b/bin/memthrash.c
@@ -0,0 +1,26 @@
1#include <stdio.h>
2#include <stdlib.h>
3
4#include <time.h>
5
6#define NUM_VARS 5000000
7
8long data[NUM_VARS];
9
10int main(int argc, char** argv)
11{
12 int i;
13 long sum;
14 srand(time(NULL));
15 while (1) {
16 for (i = 0; i < NUM_VARS; i++)
17 data[i] = rand();
18 sum = 0;
19 for (i = 0; i < NUM_VARS; i++)
20 sum += (i % 2 ? 1 : -1) * data[i];
21 for (i = NUM_VARS - 1; i >= 0; i--)
22 sum += (i % 2 ? -1 : 1) / data[i];
23 if (argc > 1)
24 printf("sum: %ld\n", sum);
25 }
26}