From 0d20391563ef1b9fad658c3b75502a2061e7182f Mon Sep 17 00:00:00 2001 From: Brendon Scheinman Date: Mon, 22 Apr 2013 11:48:41 -0500 Subject: [PATCH] ck_rw_cohort: Added benchmark tests for reader-writer cohort locks --- .gitignore | 8 ++- include/ck_rw_cohort.h | 2 +- regressions/ck_rw_cohort/benchmark/Makefile | 23 +++++-- .../ck_rw_cohort/benchmark/ck_neutral.c | 7 ++ regressions/ck_rw_cohort/benchmark/ck_rp.c | 7 ++ regressions/ck_rw_cohort/benchmark/ck_wp.c | 7 ++ .../benchmark/{latency.c => latency.h} | 22 +++--- .../benchmark/{throughput.c => throughput.h} | 68 +++++++++---------- regressions/ck_rw_cohort/ck_neutral.h | 1 + regressions/ck_rw_cohort/ck_rp.h | 1 + regressions/ck_rw_cohort/ck_wp.h | 11 +-- 11 files changed, 95 insertions(+), 62 deletions(-) create mode 100644 regressions/ck_rw_cohort/benchmark/ck_neutral.c create mode 100644 regressions/ck_rw_cohort/benchmark/ck_rp.c create mode 100644 regressions/ck_rw_cohort/benchmark/ck_wp.c rename regressions/ck_rw_cohort/benchmark/{latency.c => latency.h} (79%) rename regressions/ck_rw_cohort/benchmark/{throughput.c => throughput.h} (73%) diff --git a/.gitignore b/.gitignore index ee0d0ca..4e9157b 100644 --- a/.gitignore +++ b/.gitignore @@ -146,5 +146,9 @@ regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT regressions/ck_rw_cohort/validate/ck_neutral regressions/ck_rw_cohort/validate/ck_rp regressions/ck_rw_cohort/validate/ck_wp -regressions/ck_rw_cohort/benchmark/latency -regressions/ck_rw_cohort/benchmark/throughput +regressions/ck_rw_cohort/benchmark/ck_neutral.LATENCY +regressions/ck_rw_cohort/benchmark/ck_neutral.THROUGHPUT +regressions/ck_rw_cohort/benchmark/ck_rp.LATENCY +regressions/ck_rw_cohort/benchmark/ck_rp.THROUGHPUT +regressions/ck_rw_cohort/benchmark/ck_wp.LATENCY +regressions/ck_rw_cohort/benchmark/ck_wp.THROUGHPUT diff --git a/include/ck_rw_cohort.h b/include/ck_rw_cohort.h index e46bee2..0904000 100644 --- a/include/ck_rw_cohort.h +++ b/include/ck_rw_cohort.h @@ -236,7 +236,7 @@ #define CK_RW_COHORT_NEUTRAL_NAME(N) ck_rw_cohort_neutral_##N #define CK_RW_COHORT_NEUTRAL_INSTANCE(N) struct CK_RW_COHORT_NEUTRAL_NAME(N) -#define CK_RW_COHORT_NEUTRAL_INIT(N, RW, WL) ck_rw_cohort_neutral_##N##_init(RW, WL) +#define CK_RW_COHORT_NEUTRAL_INIT(N, RW) ck_rw_cohort_neutral_##N##_init(RW) #define CK_RW_COHORT_NEUTRAL_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_read_lock(RW, C, GC, LC) #define CK_RW_COHORT_NEUTRAL_READ_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_read_unlock(RW) #define CK_RW_COHORT_NEUTRAL_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_write_lock(RW, C, GC, LC) diff --git a/regressions/ck_rw_cohort/benchmark/Makefile b/regressions/ck_rw_cohort/benchmark/Makefile index 6a751b5..054c85c 100644 --- a/regressions/ck_rw_cohort/benchmark/Makefile +++ b/regressions/ck_rw_cohort/benchmark/Makefile @@ -1,14 +1,29 @@ .PHONY: clean distribution OBJECTS=latency throughput +OBJECTS=ck_neutral.THROUGHPUT ck_neutral.LATENCY \ + ck_rp.THROUGHPUT ck_rp.LATENCY \ + ck_wp.THROUGHPUT ck_wp.LATENCY all: $(OBJECTS) -latency: latency.c ../../../include/ck_rw_cohort.h - $(CC) $(CFLAGS) -o latency latency.c +ck_neutral.THROUGHPUT: ck_neutral.c + $(CC) -DTHROUGHPUT $(CFLAGS) -o ck_neutral.THROUGHPUT ck_neutral.c -throughput: throughput.c ../../../include/ck_rw_cohort.h - $(CC) $(CFLAGS) -o throughput throughput.c +ck_neutral.LATENCY: ck_neutral.c + $(CC) -DLATENCY $(CFLAGS) -o ck_neutral.LATENCY ck_neutral.c + +ck_rp.THROUGHPUT: ck_rp.c + $(CC) -DTHROUGHPUT $(CFLAGS) -o ck_rp.THROUGHPUT ck_rp.c + +ck_rp.LATENCY: ck_rp.c + $(CC) -DLATENCY $(CFLAGS) -o ck_rp.LATENCY ck_rp.c + +ck_wp.THROUGHPUT: ck_wp.c + $(CC) -DTHROUGHPUT $(CFLAGS) -o ck_wp.THROUGHPUT ck_wp.c + +ck_wp.LATENCY: ck_wp.c + $(CC) -DLATENCY $(CFLAGS) -o ck_wp.LATENCY ck_wp.c clean: rm -rf *.dSYM *~ *.o $(OBJECTS) diff --git a/regressions/ck_rw_cohort/benchmark/ck_neutral.c b/regressions/ck_rw_cohort/benchmark/ck_neutral.c new file mode 100644 index 0000000..9fb85db --- /dev/null +++ b/regressions/ck_rw_cohort/benchmark/ck_neutral.c @@ -0,0 +1,7 @@ +#include "../ck_neutral.h" + +#ifdef THROUGHPUT +#include "throughput.h" +#elif defined(LATENCY) +#include "latency.h" +#endif diff --git a/regressions/ck_rw_cohort/benchmark/ck_rp.c b/regressions/ck_rw_cohort/benchmark/ck_rp.c new file mode 100644 index 0000000..798e578 --- /dev/null +++ b/regressions/ck_rw_cohort/benchmark/ck_rp.c @@ -0,0 +1,7 @@ +#include "../ck_rp.h" + +#ifdef THROUGHPUT +#include "throughput.h" +#elif defined(LATENCY) +#include "latency.h" +#endif diff --git a/regressions/ck_rw_cohort/benchmark/ck_wp.c b/regressions/ck_rw_cohort/benchmark/ck_wp.c new file mode 100644 index 0000000..07b0cce --- /dev/null +++ b/regressions/ck_rw_cohort/benchmark/ck_wp.c @@ -0,0 +1,7 @@ +#include "../ck_wp.h" + +#ifdef THROUGHPUT +#include "throughput.h" +#elif defined(LATENCY) +#include "latency.h" +#endif diff --git a/regressions/ck_rw_cohort/benchmark/latency.c b/regressions/ck_rw_cohort/benchmark/latency.h similarity index 79% rename from regressions/ck_rw_cohort/benchmark/latency.c rename to regressions/ck_rw_cohort/benchmark/latency.h index f05ee2e..60d7c0d 100644 --- a/regressions/ck_rw_cohort/benchmark/latency.c +++ b/regressions/ck_rw_cohort/benchmark/latency.h @@ -60,7 +60,7 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context) CK_COHORT_PROTOTYPE(fas_fas, ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context, ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context) -CK_RW_COHORT_WP_PROTOTYPE(fas_fas) +LOCK_PROTOTYPE(fas_fas) int main(void) @@ -69,34 +69,34 @@ main(void) ck_spinlock_fas_t global_lock = CK_SPINLOCK_FAS_INITIALIZER; ck_spinlock_fas_t local_lock = CK_SPINLOCK_FAS_INITIALIZER; CK_COHORT_INSTANCE(fas_fas) cohort = CK_COHORT_INITIALIZER; - CK_RW_COHORT_WP_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_WP_INITIALIZER; + LOCK_INSTANCE(fas_fas) rw_cohort = LOCK_INITIALIZER; CK_COHORT_INIT(fas_fas, &cohort, &global_lock, &local_lock, CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT); - CK_RW_COHORT_WP_INIT(fas_fas, &rw_cohort, CK_RW_COHORT_WP_DEFAULT_WAIT_LIMIT); + LOCK_INIT(fas_fas, &rw_cohort, CK_RW_COHORT_WP_DEFAULT_WAIT_LIMIT); for (i = 0; i < STEPS; i++) { - CK_RW_COHORT_WP_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); - CK_RW_COHORT_WP_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); + WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); + WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); } s_b = rdtsc(); for (i = 0; i < STEPS; i++) { - CK_RW_COHORT_WP_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); - CK_RW_COHORT_WP_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); + WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); + WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); } e_b = rdtsc(); printf("WRITE: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS); for (i = 0; i < STEPS; i++) { - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); + READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); } s_b = rdtsc(); for (i = 0; i < STEPS; i++) { - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); + READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); } e_b = rdtsc(); printf("READ: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS); diff --git a/regressions/ck_rw_cohort/benchmark/throughput.c b/regressions/ck_rw_cohort/benchmark/throughput.h similarity index 73% rename from regressions/ck_rw_cohort/benchmark/throughput.c rename to regressions/ck_rw_cohort/benchmark/throughput.h index b629c73..787a036 100644 --- a/regressions/ck_rw_cohort/benchmark/throughput.c +++ b/regressions/ck_rw_cohort/benchmark/throughput.h @@ -78,7 +78,7 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context) CK_COHORT_PROTOTYPE(fas_fas, ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context, ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context) -CK_RW_COHORT_WP_PROTOTYPE(fas_fas) +LOCK_PROTOTYPE(fas_fas) struct cohort_record { CK_COHORT_INSTANCE(fas_fas) cohort; @@ -86,7 +86,7 @@ struct cohort_record { static struct cohort_record *cohorts; static ck_spinlock_t global_lock = CK_SPINLOCK_INITIALIZER; -static CK_RW_COHORT_WP_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_WP_INITIALIZER; +static LOCK_INSTANCE(fas_fas) rw_cohort = LOCK_INITIALIZER; static unsigned int n_cohorts; struct block { @@ -114,38 +114,38 @@ thread_rwlock(void *pun) for (i = 1, a = 0;; i++) { s_b = rdtsc(); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); - CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); - CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); + READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); e_b = rdtsc(); a += (e_b - s_b) >> 4; diff --git a/regressions/ck_rw_cohort/ck_neutral.h b/regressions/ck_rw_cohort/ck_neutral.h index 2d29c73..07c9d27 100644 --- a/regressions/ck_rw_cohort/ck_neutral.h +++ b/regressions/ck_rw_cohort/ck_neutral.h @@ -1,6 +1,7 @@ #define LOCK_PROTOTYPE CK_RW_COHORT_NEUTRAL_PROTOTYPE #define LOCK_INSTANCE CK_RW_COHORT_NEUTRAL_INSTANCE #define LOCK_INITIALIZER CK_RW_COHORT_NEUTRAL_INITIALIZER +#define LOCK_INIT(N, C, W) CK_RW_COHORT_NEUTRAL_INIT(N, C) #define READ_LOCK CK_RW_COHORT_NEUTRAL_READ_LOCK #define WRITE_LOCK CK_RW_COHORT_NEUTRAL_WRITE_LOCK #define READ_UNLOCK CK_RW_COHORT_NEUTRAL_READ_UNLOCK diff --git a/regressions/ck_rw_cohort/ck_rp.h b/regressions/ck_rw_cohort/ck_rp.h index d4b7d4e..ecc6391 100644 --- a/regressions/ck_rw_cohort/ck_rp.h +++ b/regressions/ck_rw_cohort/ck_rp.h @@ -1,6 +1,7 @@ #define LOCK_PROTOTYPE CK_RW_COHORT_RP_PROTOTYPE #define LOCK_INSTANCE CK_RW_COHORT_RP_INSTANCE #define LOCK_INITIALIZER CK_RW_COHORT_RP_INITIALIZER +#define LOCK_INIT CK_RW_COHORT_RP_INIT #define READ_LOCK CK_RW_COHORT_RP_READ_LOCK #define READ_UNLOCK CK_RW_COHORT_RP_READ_UNLOCK #define WRITE_LOCK CK_RW_COHORT_RP_WRITE_LOCK diff --git a/regressions/ck_rw_cohort/ck_wp.h b/regressions/ck_rw_cohort/ck_wp.h index bb9b6b2..afc1112 100644 --- a/regressions/ck_rw_cohort/ck_wp.h +++ b/regressions/ck_rw_cohort/ck_wp.h @@ -1,17 +1,8 @@ #define LOCK_PROTOTYPE CK_RW_COHORT_WP_PROTOTYPE #define LOCK_INSTANCE CK_RW_COHORT_WP_INSTANCE #define LOCK_INITIALIZER CK_RW_COHORT_WP_INITIALIZER +#define LOCK_INIT CK_RW_COHORT_WP_INIT #define READ_LOCK CK_RW_COHORT_WP_READ_LOCK #define WRITE_LOCK CK_RW_COHORT_WP_WRITE_LOCK #define READ_UNLOCK CK_RW_COHORT_WP_READ_UNLOCK #define WRITE_UNLOCK CK_RW_COHORT_WP_WRITE_UNLOCK -/* -#define WRITE_LOCK(N, RW, C, GC, LC)\ - CK_RW_COHORT_WP_WRITE_LOCK(N, RW, C, GC, LC) - -#define WRITE_UNLOCK(N, RW, C, GC, LC)\ - CK_RW_COHORT_WP_WRITE_UNLOCK(N, RW, C, GC, LC); - -#define READ_LOCK(N, RW, C, GC, LC)\ - CK_RW_COHORT_WP_READ_LOCK(N, RW) -*/ \ No newline at end of file