Add ck_hp_fifo latency tests.

ck_pring
Samy Al Bahra 14 years ago
parent 809089d623
commit c546565588

@ -14,6 +14,7 @@ all:
make -C ./ck_stack/benchmark all make -C ./ck_stack/benchmark all
make -C ./ck_ring/validate all make -C ./ck_ring/validate all
make -C ./ck_hp/validate all make -C ./ck_hp/validate all
make -C ./ck_hp/benchmark all
clean: clean:
make -C ./ck_spinlock/validate clean make -C ./ck_spinlock/validate clean
@ -29,4 +30,5 @@ clean:
make -C ./ck_stack/benchmark clean make -C ./ck_stack/benchmark clean
make -C ./ck_ring/validate clean make -C ./ck_ring/validate clean
make -C ./ck_hp/validate clean make -C ./ck_hp/validate clean
make -C ./ck_hp/benchmark clean

@ -7,11 +7,11 @@
#include "../../common.h" #include "../../common.h"
#ifndef ENTRIES #ifndef ENTRIES
#define ENTRIES 1024 #define ENTRIES 4096
#endif #endif
#ifndef STEPS #ifndef STEPS
#define STEPS 4000 #define STEPS 40000
#endif #endif
int int
@ -25,13 +25,13 @@ main(void)
#if defined(CK_F_FIFO_SPSC) #if defined(CK_F_FIFO_SPSC)
ck_fifo_spsc_t spsc_fifo; 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; ck_fifo_spsc_entry_t spsc_stub;
#endif #endif
#if defined(CK_F_FIFO_MPMC) #if defined(CK_F_FIFO_MPMC)
ck_fifo_mpmc_t mpmc_fifo; 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; ck_fifo_mpmc_entry_t mpmc_stub;
#endif #endif
@ -41,7 +41,7 @@ main(void)
ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); ck_fifo_spsc_init(&spsc_fifo, &spsc_stub);
s = rdtsc(); 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_spinlock_fas_lock(&mutex);
ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL); ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL);
ck_spinlock_fas_unlock(&mutex); ck_spinlock_fas_unlock(&mutex);
@ -55,11 +55,11 @@ main(void)
a = 0; a = 0;
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); 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); ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL);
s = rdtsc(); 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_spinlock_fas_lock(&mutex);
ck_fifo_spsc_dequeue(&spsc_fifo, &r); ck_fifo_spsc_dequeue(&spsc_fifo, &r);
ck_spinlock_fas_unlock(&mutex); ck_spinlock_fas_unlock(&mutex);
@ -74,7 +74,7 @@ main(void)
ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); ck_fifo_spsc_init(&spsc_fifo, &spsc_stub);
s = rdtsc(); 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); ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL);
e = rdtsc(); e = rdtsc();
@ -85,11 +85,11 @@ main(void)
a = 0; a = 0;
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
ck_fifo_spsc_init(&spsc_fifo, &spsc_stub); 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); ck_fifo_spsc_enqueue(&spsc_fifo, spsc_entry + j, NULL);
s = rdtsc(); 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); ck_fifo_spsc_dequeue(&spsc_fifo, &r);
e = rdtsc(); e = rdtsc();
a += e - s; a += e - s;
@ -103,7 +103,7 @@ main(void)
ck_fifo_mpmc_init(&mpmc_fifo, &mpmc_stub); ck_fifo_mpmc_init(&mpmc_fifo, &mpmc_stub);
s = rdtsc(); 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); ck_fifo_mpmc_enqueue(&mpmc_fifo, mpmc_entry + j, NULL);
e = rdtsc(); e = rdtsc();
@ -114,11 +114,11 @@ main(void)
a = 0; a = 0;
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
ck_fifo_mpmc_init(&mpmc_fifo, &mpmc_stub); 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); ck_fifo_mpmc_enqueue(&mpmc_fifo, mpmc_entry + j, NULL);
s = rdtsc(); 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); ck_fifo_mpmc_dequeue(&mpmc_fifo, &r);
e = rdtsc(); e = rdtsc();
a += e - s; a += e - s;

@ -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

@ -0,0 +1,69 @@
#include <ck_hp.h>
#include <ck_hp_fifo.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#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;
}

@ -7,11 +7,11 @@
#include "../../common.h" #include "../../common.h"
#ifndef ENTRIES #ifndef ENTRIES
#define ENTRIES 1024 #define ENTRIES 4096
#endif #endif
#ifndef STEPS #ifndef STEPS
#define STEPS 4000 #define STEPS 40000
#endif #endif
static ck_stack_t stack; static ck_stack_t stack;
@ -19,7 +19,7 @@ static ck_stack_t stack;
int int
main(void) main(void)
{ {
ck_stack_entry_t entry[4096]; ck_stack_entry_t entry[ENTRIES];
ck_spinlock_fas_t mutex = CK_SPINLOCK_FAS_INITIALIZER; ck_spinlock_fas_t mutex = CK_SPINLOCK_FAS_INITIALIZER;
volatile ck_stack_entry_t * volatile r; volatile ck_stack_entry_t * volatile r;
uint64_t s, e, a; uint64_t s, e, a;
@ -31,7 +31,7 @@ main(void)
ck_stack_init(&stack); ck_stack_init(&stack);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) { for (j = 0; j < ENTRIES; j++) {
ck_spinlock_fas_lock(&mutex); ck_spinlock_fas_lock(&mutex);
ck_stack_push_spnc(&stack, entry + j); ck_stack_push_spnc(&stack, entry + j);
ck_spinlock_fas_unlock(&mutex); ck_spinlock_fas_unlock(&mutex);
@ -40,17 +40,17 @@ main(void)
a += e - s; 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; a = 0;
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
ck_stack_init(&stack); 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); ck_stack_push_spnc(&stack, entry + j);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) { for (j = 0; j < ENTRIES; j++) {
ck_spinlock_fas_lock(&mutex); ck_spinlock_fas_lock(&mutex);
r = ck_stack_pop_npsc(&stack); r = ck_stack_pop_npsc(&stack);
ck_spinlock_fas_unlock(&mutex); ck_spinlock_fas_unlock(&mutex);
@ -58,7 +58,7 @@ main(void)
e = rdtsc(); e = rdtsc();
a += e - s; 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 #ifdef CK_F_STACK_PUSH_UPMC
a = 0; a = 0;
@ -66,13 +66,13 @@ main(void)
ck_stack_init(&stack); ck_stack_init(&stack);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) for (j = 0; j < ENTRIES; j++)
ck_stack_push_upmc(&stack, entry + j); ck_stack_push_upmc(&stack, entry + j);
e = rdtsc(); e = rdtsc();
a += e - s; 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 */ #endif /* CK_F_STACK_PUSH_UPMC */
#ifdef CK_F_STACK_PUSH_MPMC #ifdef CK_F_STACK_PUSH_MPMC
@ -81,13 +81,13 @@ main(void)
ck_stack_init(&stack); ck_stack_init(&stack);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) for (j = 0; j < ENTRIES; j++)
ck_stack_push_mpmc(&stack, entry + j); ck_stack_push_mpmc(&stack, entry + j);
e = rdtsc(); e = rdtsc();
a += e - s; 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 */ #endif /* CK_F_STACK_PUSH_MPMC */
#ifdef CK_F_STACK_PUSH_MPNC #ifdef CK_F_STACK_PUSH_MPNC
@ -96,13 +96,13 @@ main(void)
ck_stack_init(&stack); ck_stack_init(&stack);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) for (j = 0; j < ENTRIES; j++)
ck_stack_push_mpnc(&stack, entry + j); ck_stack_push_mpnc(&stack, entry + j);
e = rdtsc(); e = rdtsc();
a += e - s; 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 */ #endif /* CK_F_STACK_PUSH_MPNC */
#if defined(CK_F_STACK_PUSH_UPMC) && defined(CK_F_STACK_POP_UPMC) #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++) { for (i = 0; i < STEPS; i++) {
ck_stack_init(&stack); 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); ck_stack_push_upmc(&stack, entry + j);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) for (j = 0; j < ENTRIES; j++)
r = ck_stack_pop_upmc(&stack); r = ck_stack_pop_upmc(&stack);
e = rdtsc(); e = rdtsc();
a += e - s; a += e - s;
@ -127,11 +127,11 @@ main(void)
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
ck_stack_init(&stack); 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); ck_stack_push_mpmc(&stack, entry + j);
s = rdtsc(); s = rdtsc();
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) for (j = 0; j < ENTRIES; j++)
r = ck_stack_pop_mpmc(&stack); r = ck_stack_pop_mpmc(&stack);
e = rdtsc(); e = rdtsc();
a += e - s; a += e - s;

Loading…
Cancel
Save