diff --git a/regressions/Makefile b/regressions/Makefile index cd99943..168e9b7 100644 --- a/regressions/Makefile +++ b/regressions/Makefile @@ -14,6 +14,7 @@ all: make -C ./ck_stack/benchmark all make -C ./ck_ring/validate all make -C ./ck_hp/validate all + make -C ./ck_hp/benchmark all clean: make -C ./ck_spinlock/validate clean @@ -29,4 +30,5 @@ clean: make -C ./ck_stack/benchmark clean make -C ./ck_ring/validate clean make -C ./ck_hp/validate clean + make -C ./ck_hp/benchmark clean diff --git a/regressions/ck_fifo/benchmark/latency.c b/regressions/ck_fifo/benchmark/latency.c index 60b7ebc..3c08844 100644 --- a/regressions/ck_fifo/benchmark/latency.c +++ b/regressions/ck_fifo/benchmark/latency.c @@ -7,11 +7,11 @@ #include "../../common.h" #ifndef ENTRIES -#define ENTRIES 1024 +#define ENTRIES 4096 #endif #ifndef STEPS -#define STEPS 4000 +#define STEPS 40000 #endif int @@ -25,13 +25,13 @@ main(void) #if defined(CK_F_FIFO_SPSC) ck_fifo_spsc_t spsc_fifo; - ck_fifo_spsc_entry_t spsc_entry[4096]; + ck_fifo_spsc_entry_t spsc_entry[ENTRIES]; ck_fifo_spsc_entry_t spsc_stub; #endif #if defined(CK_F_FIFO_MPMC) ck_fifo_mpmc_t mpmc_fifo; - ck_fifo_mpmc_entry_t mpmc_entry[4096]; + ck_fifo_mpmc_entry_t mpmc_entry[ENTRIES]; ck_fifo_mpmc_entry_t mpmc_stub; #endif @@ -41,7 +41,7 @@ main(void) ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); s = rdtsc(); - for (j = 0; j < sizeof(spsc_entry) / sizeof(*spsc_entry); j++) { + for (j = 0; j < ENTRIES; j++) { ck_spinlock_fas_lock(&mutex); ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL); ck_spinlock_fas_unlock(&mutex); @@ -55,11 +55,11 @@ main(void) a = 0; for (i = 0; i < STEPS; i++) { ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); - for (j = 0; j < sizeof(spsc_entry) / sizeof(*spsc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL); s = rdtsc(); - for (j = 0; j < sizeof(spsc_entry) / sizeof(*spsc_entry); j++) { + for (j = 0; j < ENTRIES; j++) { ck_spinlock_fas_lock(&mutex); ck_fifo_spsc_dequeue(&spsc_fifo, &r); ck_spinlock_fas_unlock(&mutex); @@ -74,7 +74,7 @@ main(void) ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); s = rdtsc(); - for (j = 0; j < sizeof(spsc_entry) / sizeof(*spsc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL); e = rdtsc(); @@ -85,11 +85,11 @@ main(void) a = 0; for (i = 0; i < STEPS; i++) { ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); - for (j = 0; j < sizeof(spsc_entry) / sizeof(*spsc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL); s = rdtsc(); - for (j = 0; j < sizeof(spsc_entry) / sizeof(*spsc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_spsc_dequeue(&spsc_fifo, &r); e = rdtsc(); a += e - s; @@ -103,7 +103,7 @@ main(void) ck_fifo_mpmc_init(&mpmc_fifo, &mpmc_stub); s = rdtsc(); - for (j = 0; j < sizeof(mpmc_entry) / sizeof(*mpmc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_mpmc_enqueue(&mpmc_fifo, mpmc_entry + j, NULL); e = rdtsc(); @@ -114,11 +114,11 @@ main(void) a = 0; for (i = 0; i < STEPS; i++) { ck_fifo_mpmc_init(&mpmc_fifo, &mpmc_stub); - for (j = 0; j < sizeof(mpmc_entry) / sizeof(*mpmc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_mpmc_enqueue(&mpmc_fifo, mpmc_entry + j, NULL); s = rdtsc(); - for (j = 0; j < sizeof(mpmc_entry) / sizeof(*mpmc_entry); j++) + for (j = 0; j < ENTRIES; j++) ck_fifo_mpmc_dequeue(&mpmc_fifo, &r); e = rdtsc(); a += e - s; diff --git a/regressions/ck_hp/benchmark/Makefile b/regressions/ck_hp/benchmark/Makefile new file mode 100644 index 0000000..3a10b1b --- /dev/null +++ b/regressions/ck_hp/benchmark/Makefile @@ -0,0 +1,14 @@ +.PHONY: clean distribution + +OBJECTS=fifo_latency + +all: $(OBJECTS) + +fifo_latency: fifo_latency.c + $(CC) $(CFLAGS) -o fifo_latency ../../../src/ck_hp.c fifo_latency.c + +clean: + rm -rf *~ *.o *.dSYM $(OBJECTS) + +include ../../../build/regressions.build +CFLAGS+=-lpthread -D_GNU_SOURCE diff --git a/regressions/ck_hp/benchmark/fifo_latency.c b/regressions/ck_hp/benchmark/fifo_latency.c new file mode 100644 index 0000000..839ad6c --- /dev/null +++ b/regressions/ck_hp/benchmark/fifo_latency.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include + +#include "../../common.h" + +#ifndef ENTRIES +#define ENTRIES 4096 +#endif + +#ifndef STEPS +#define STEPS 40000 +#endif + +ck_hp_fifo_t fifo; +ck_hp_t fifo_hp; + +int +main(void) +{ + void *r; + uint64_t s, e, a; + unsigned int i; + unsigned int j; + ck_hp_fifo_entry_t hp_entry[ENTRIES]; + ck_hp_fifo_entry_t hp_stub; + ck_hp_record_t record; + + ck_hp_init(&fifo_hp, CK_HP_FIFO_SLOTS_COUNT, 1000000, NULL); + + r = malloc(CK_HP_FIFO_SLOTS_SIZE); + if (r == NULL) { + fprintf(stderr, "ERROR: Failed to allocate slots.\n"); + exit(EXIT_FAILURE); + } + ck_hp_subscribe(&fifo_hp, &record, r); + + a = 0; + for (i = 0; i < STEPS; i++) { + ck_hp_fifo_init(&fifo, &hp_stub); + + s = rdtsc(); + for (j = 0; j < ENTRIES; j++) + ck_hp_fifo_enqueue_mpmc(&record, &fifo, hp_entry + j, NULL); + e = rdtsc(); + + a += e - s; + } + printf("ck_hp_fifo_enqueue_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); + + a = 0; + for (i = 0; i < STEPS; i++) { + ck_hp_fifo_init(&fifo, &hp_stub); + for (j = 0; j < ENTRIES; j++) + ck_hp_fifo_enqueue_mpmc(&record, &fifo, hp_entry + j, NULL); + + s = rdtsc(); + for (j = 0; j < ENTRIES; j++) + ck_hp_fifo_dequeue_mpmc(&record, &fifo, &r); + e = rdtsc(); + a += e - s; + } + printf("ck_hp_fifo_dequeue_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); + + return 0; +} diff --git a/regressions/ck_stack/benchmark/latency.c b/regressions/ck_stack/benchmark/latency.c index 641285c..79b6da6 100644 --- a/regressions/ck_stack/benchmark/latency.c +++ b/regressions/ck_stack/benchmark/latency.c @@ -7,11 +7,11 @@ #include "../../common.h" #ifndef ENTRIES -#define ENTRIES 1024 +#define ENTRIES 4096 #endif #ifndef STEPS -#define STEPS 4000 +#define STEPS 40000 #endif static ck_stack_t stack; @@ -19,7 +19,7 @@ static ck_stack_t stack; int main(void) { - ck_stack_entry_t entry[4096]; + ck_stack_entry_t entry[ENTRIES]; ck_spinlock_fas_t mutex = CK_SPINLOCK_FAS_INITIALIZER; volatile ck_stack_entry_t * volatile r; uint64_t s, e, a; @@ -31,7 +31,7 @@ main(void) ck_stack_init(&stack); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) { + for (j = 0; j < ENTRIES; j++) { ck_spinlock_fas_lock(&mutex); ck_stack_push_spnc(&stack, entry + j); ck_spinlock_fas_unlock(&mutex); @@ -40,17 +40,17 @@ main(void) a += e - s; } - printf(" spinlock_push: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry))); + printf(" spinlock_push: %16" PRIu64 "\n", a / STEPS / ENTRIES); a = 0; for (i = 0; i < STEPS; i++) { ck_stack_init(&stack); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) ck_stack_push_spnc(&stack, entry + j); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) { + for (j = 0; j < ENTRIES; j++) { ck_spinlock_fas_lock(&mutex); r = ck_stack_pop_npsc(&stack); ck_spinlock_fas_unlock(&mutex); @@ -58,7 +58,7 @@ main(void) e = rdtsc(); a += e - s; } - printf(" spinlock_pop: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry))); + printf(" spinlock_pop: %16" PRIu64 "\n", a / STEPS / ENTRIES); #ifdef CK_F_STACK_PUSH_UPMC a = 0; @@ -66,13 +66,13 @@ main(void) ck_stack_init(&stack); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) ck_stack_push_upmc(&stack, entry + j); e = rdtsc(); a += e - s; } - printf("ck_stack_push_upmc: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry))); + printf("ck_stack_push_upmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); #endif /* CK_F_STACK_PUSH_UPMC */ #ifdef CK_F_STACK_PUSH_MPMC @@ -81,13 +81,13 @@ main(void) ck_stack_init(&stack); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) ck_stack_push_mpmc(&stack, entry + j); e = rdtsc(); a += e - s; } - printf("ck_stack_push_mpmc: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry))); + printf("ck_stack_push_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); #endif /* CK_F_STACK_PUSH_MPMC */ #ifdef CK_F_STACK_PUSH_MPNC @@ -96,13 +96,13 @@ main(void) ck_stack_init(&stack); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) ck_stack_push_mpnc(&stack, entry + j); e = rdtsc(); a += e - s; } - printf("ck_stack_push_mpnc: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry))); + printf("ck_stack_push_mpnc: %16" PRIu64 "\n", a / STEPS / ENTRIES); #endif /* CK_F_STACK_PUSH_MPNC */ #if defined(CK_F_STACK_PUSH_UPMC) && defined(CK_F_STACK_POP_UPMC) @@ -110,11 +110,11 @@ main(void) for (i = 0; i < STEPS; i++) { ck_stack_init(&stack); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) ck_stack_push_upmc(&stack, entry + j); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) r = ck_stack_pop_upmc(&stack); e = rdtsc(); a += e - s; @@ -127,11 +127,11 @@ main(void) for (i = 0; i < STEPS; i++) { ck_stack_init(&stack); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) ck_stack_push_mpmc(&stack, entry + j); s = rdtsc(); - for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) + for (j = 0; j < ENTRIES; j++) r = ck_stack_pop_mpmc(&stack); e = rdtsc(); a += e - s;