aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Kenna <cjk@cs.unc.edu>2012-04-11 13:32:11 -0400
committerChristopher Kenna <cjk@cs.unc.edu>2012-04-11 13:32:11 -0400
commite0732d7df71cd1db56b1ac7b4ad6132e6d1e00a8 (patch)
tree0307817df6a09ac248b36221fc7570931ffcff2e
parentb0355b8cc0609be264042c5570e8c13078888636 (diff)
benchmark to run on pound
-rw-r--r--Makefile2
-rw-r--r--bin/colorbench.c84
2 files changed, 73 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 37f7d57..7a95b91 100644
--- a/Makefile
+++ b/Makefile
@@ -220,7 +220,7 @@ obj-colortest = colortest.o color.o
220lib-colortest = -static 220lib-colortest = -static
221 221
222obj-colorbench = colorbench.o color.o 222obj-colorbench = colorbench.o color.o
223lib-colorbench = -lpthread -static 223lib-colorbench = -lpthread -lrt
224 224
225# ############################################################################## 225# ##############################################################################
226# Build everything that depends on liblitmus. 226# Build everything that depends on liblitmus.
diff --git a/bin/colorbench.c b/bin/colorbench.c
index 8547bef..0212d9c 100644
--- a/bin/colorbench.c
+++ b/bin/colorbench.c
@@ -6,6 +6,8 @@
6#include <sys/mman.h> 6#include <sys/mman.h>
7#include <errno.h> 7#include <errno.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <time.h>
10#include <unistd.h>
9 11
10#include <litmus/rt_param.h> 12#include <litmus/rt_param.h>
11 13
@@ -14,21 +16,25 @@
14#define DEBUG 1 16#define DEBUG 1
15#define NR_LOOPS 1000 17#define NR_LOOPS 1000
16 18
19/* pick ONE of these */
20#define TIME_MONO 1 /* monotonic time */
21//#define TIME_THREAD 1 /* thread cpu time */
22
17/* Ludwig */ 23/* Ludwig */
18//#define NR_CPUS 6 24//#define NR_CPUS 6
19//#define CACHE_SIZE_MB 12 25//#define CACHE_SIZE_MB 12
20//#define ASSOC 12 26//#define ASSOC 12
21 27
22/* Pound */ 28/* Pound */
23//#define NR_CPUS 4
24//#define CACHE_SIZE_MB 8
25//#define ASSOC 16
26
27/* VM */
28#define NR_CPUS 4 29#define NR_CPUS 4
29#define CACHE_SIZE_MB 4 30#define CACHE_SIZE_MB 8
30#define ASSOC 16 31#define ASSOC 16
31 32
33/* VM */
34//#define NR_CPUS 4
35//#define CACHE_SIZE_MB 4
36//#define ASSOC 16
37
32#define LINE_SIZE 64 38#define LINE_SIZE 64
33#define CACHE_SIZE (CACHE_SIZE_MB * 1024 * 1024) 39#define CACHE_SIZE (CACHE_SIZE_MB * 1024 * 1024)
34#define TOTAL_COLORS (CACHE_SIZE / ASSOC / PAGE_SIZE) 40#define TOTAL_COLORS (CACHE_SIZE / ASSOC / PAGE_SIZE)
@@ -50,9 +56,10 @@ struct pthread_state {
50 struct color_ctrl_page *color_ctrl; 56 struct color_ctrl_page *color_ctrl;
51 int *arena; 57 int *arena;
52 char fname[FNAME_LEN]; 58 char fname[FNAME_LEN];
59 FILE *file;
53}; 60};
54 61
55static pthread_barrier_t barrier; 62static pthread_barrier_t start_barrier, end_barrier;
56static int nr_threads; 63static int nr_threads;
57static int arena_size; 64static int arena_size;
58static int color_shift; 65static int color_shift;
@@ -74,7 +81,7 @@ static void mk_fname(struct pthread_state *state)
74 snprintf(state->fname, FNAME_LEN, "cache_size=%d_line=%d_assoc=%d_" 81 snprintf(state->fname, FNAME_LEN, "cache_size=%d_line=%d_assoc=%d_"
75 "colors=%d_color-shift=%d_use-colors=%d_arena-size=%d_" 82 "colors=%d_color-shift=%d_use-colors=%d_arena-size=%d_"
76 "arena-pages=%d_contig-colors=%d_thread=%d_" 83 "arena-pages=%d_contig-colors=%d_thread=%d_"
77 "cpu=%d", 84 "cpu=%d.dat",
78 CACHE_SIZE, LINE_SIZE, ASSOC, TOTAL_COLORS, 85 CACHE_SIZE, LINE_SIZE, ASSOC, TOTAL_COLORS,
79 color_shift, USE_COLORS, arena_size, 86 color_shift, USE_COLORS, arena_size,
80 ARENA_PAGES, CONTIG_COLORS, state->tid, 87 ARENA_PAGES, CONTIG_COLORS, state->tid,
@@ -105,7 +112,13 @@ int thread_init(struct pthread_state *state)
105 int err = 0; 112 int err = 0;
106 113
107 mk_fname(state); 114 mk_fname(state);
108 debug_print_thread(state, "%s\n", state->fname); 115
116 state->file = fopen(state->fname, "w");
117 if (!state->file) {
118 debug_print_thread(state, "open file failed\n");
119 err = 1;
120 goto out;
121 }
109 122
110 CPU_ZERO(&cpu_set); 123 CPU_ZERO(&cpu_set);
111 CPU_SET(cpu, &cpu_set); 124 CPU_SET(cpu, &cpu_set);
@@ -150,9 +163,38 @@ out:
150#define CHECKPRINT(func, ...) func(__VA_ARGS__) 163#define CHECKPRINT(func, ...) func(__VA_ARGS__)
151#endif 164#endif
152 165
166static void get_time(struct timespec *ts)
167{
168 int err;
169#if defined(TIME_MONO)
170 err = clock_gettime(CLOCK_MONOTONIC, ts);
171#elif defined(TIME_THREAD)
172 err = clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts);
173#endif
174 if (err)
175 fprintf(stderr, "clock_gettime failed!\n");
176}
177
178static unsigned long ts_to_long(const struct timespec *ts)
179{
180 unsigned long x = (((unsigned long)ts->tv_sec) * 1e9) +
181 ((unsigned long)ts->tv_nsec);
182 return x;
183}
184
185static unsigned long ts_difference(const struct timespec *start,
186 const struct timespec *end)
187{
188 unsigned long t1 = ts_to_long(start);
189 unsigned long t2 = ts_to_long(end);
190 return (t2 - t1);
191}
192
153void * thread_start(void *data) 193void * thread_start(void *data)
154{ 194{
155 struct pthread_state *state = (struct pthread_state*) data; 195 struct pthread_state *state = (struct pthread_state*) data;
196 struct timespec start, end;
197 unsigned long time;
156 int i; 198 int i;
157 199
158 state->retval = thread_init(state); 200 state->retval = thread_init(state);
@@ -162,9 +204,25 @@ void * thread_start(void *data)
162 loop_once(state); 204 loop_once(state);
163 205
164 for (i = 0; i < NR_LOOPS; ++i) { 206 for (i = 0; i < NR_LOOPS; ++i) {
165 pthread_barrier_wait(&barrier); 207 pthread_barrier_wait(&start_barrier);
208
209 get_time(&start);
166 loop_once(state); 210 loop_once(state);
211 get_time(&end);
212
213 pthread_barrier_wait(&end_barrier);
214
215 time = ts_difference(&start, &end);
216 fprintf(state->file, "%lu\n", time);
217 state->retval = fflush(state->file);
218 if (state->retval)
219 goto out;
220 state->retval = fsync(fileno(state->file));
221 if (state->retval)
222 goto out;
167 } 223 }
224
225 fclose(state->file);
168out: 226out:
169 pthread_exit(&state->retval); 227 pthread_exit(&state->retval);
170} 228}
@@ -239,7 +297,8 @@ int main(int argc, char **argv)
239 297
240 CHECK(pthread_attr_init, &attr); 298 CHECK(pthread_attr_init, &attr);
241 CHECK(pthread_attr_setdetachstate, &attr, PTHREAD_CREATE_JOINABLE); 299 CHECK(pthread_attr_setdetachstate, &attr, PTHREAD_CREATE_JOINABLE);
242 CHECK(pthread_barrier_init, &barrier, NULL, nr_threads); 300 CHECK(pthread_barrier_init, &start_barrier, NULL, nr_threads);
301 CHECK(pthread_barrier_init, &end_barrier, NULL, nr_threads);
243 302
244 for (i = 0; i < nr_threads; i++) { 303 for (i = 0; i < nr_threads; i++) {
245 pthread_state[i].tid= i; 304 pthread_state[i].tid= i;
@@ -261,7 +320,8 @@ int main(int argc, char **argv)
261 } 320 }
262 } 321 }
263 322
264 CHECK(pthread_barrier_destroy, &barrier); 323 CHECK(pthread_barrier_destroy, &start_barrier);
324 CHECK(pthread_barrier_destroy, &end_barrier);
265 CHECK(pthread_attr_destroy, &attr); 325 CHECK(pthread_attr_destroy, &attr);
266 326
267out: 327out: