From b0fbcb8210e14c5e6844028fbc68e75b44ae15e0 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Wed, 6 Apr 2011 18:44:22 -0400 Subject: [PATCH] regressions: ck_spinlock, make throughput test more robust. Use explicit entry barrier. Move thread counters to separate cache lines. --- .../ck_spinlock/benchmark/throughput.h | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/regressions/ck_spinlock/benchmark/throughput.h b/regressions/ck_spinlock/benchmark/throughput.h index 9b1dd8e..6e1dbba 100644 --- a/regressions/ck_spinlock/benchmark/throughput.h +++ b/regressions/ck_spinlock/benchmark/throughput.h @@ -53,8 +53,14 @@ struct block { static struct affinity a; static unsigned int ready; -static uint64_t *count; + +struct counters { + uint64_t value; +} CK_CC_CACHELINE; + +static struct counters *count; static uint64_t nthr; +static unsigned int barrier; int critical __attribute__((aligned(64))); @@ -101,10 +107,14 @@ fairness(void *null) } while (ck_pr_load_uint(&ready) == 0); + + ck_pr_inc_uint(&barrier); + while (ck_pr_load_uint(&barrier) != nthr); + while (ready) { LOCK; - count[i]++; + count[i].value++; if (critical) { base = lrand48() % critical; for (j = 0; j < base; j++); @@ -160,12 +170,12 @@ main(int argc, char *argv[]) a.delta = atoi(argv[2]); a.request = 0; - count = malloc(sizeof(uint64_t) * nthr); + count = malloc(sizeof(*count) * nthr); if (count == NULL) { fprintf(stderr, "ERROR: Could not create acquisition buffer\n"); exit(EXIT_FAILURE); } - bzero(count, sizeof(uint64_t) * nthr); + bzero(count, sizeof(*count) * nthr); fprintf(stderr, "Creating threads (fairness)..."); for (i = 0; i < nthr; i++) { @@ -187,15 +197,15 @@ main(int argc, char *argv[]) fprintf(stderr, "done\n\n"); for (i = 0, v = 0; i < nthr; i++) { - printf("%d %15" PRIu64 "\n", i, count[i]); - v += count[i]; + printf("%d %15" PRIu64 "\n", i, count[i].value); + v += count[i].value; } printf("\n# total : %15" PRIu64 "\n", v); printf("# throughput : %15" PRIu64 " a/s\n", (v /= nthr) / 10); for (i = 0, d = 0; i < nthr; i++) - d += (count[i] - v) * (count[i] - v); + d += (count[i].value - v) * (count[i].value - v); printf("# average : %15" PRIu64 "\n", v); printf("# deviation : %.2f (%.2f%%)\n\n", sqrt(d / nthr), (sqrt(d / nthr) / v) * 100.00);