diff --git a/include/ck_spinlock.h b/include/ck_spinlock.h index d1cc03c..1c2bf66 100644 --- a/include/ck_spinlock.h +++ b/include/ck_spinlock.h @@ -29,11 +29,26 @@ #include #include +#include #include #include #include #include -#include + +/* + * On tested x86, x86_64, PPC64 and SPARC64 targets, + * ck_spinlock_fas proved to have lowest latency + * in fast path testing or negligible degradation + * from faster but less robust implementations. + */ +#define CK_SPINLOCK_INITIALIZER CK_SPINLOCK_FAS_INITIALIZER +#define ck_spinlock_t ck_spinlock_fas_t +#define ck_spinlock_init(x) ck_spinlock_fas_init(x) +#define ck_spinlock_lock(x) ck_spinlock_fas_lock(x) +#define ck_spinlock_lock_eb(x) ck_spinlock_fas_lock_eb(x) +#define ck_spinlock_unlock(x) ck_spinlock_fas_unlock(x) +#define ck_spinlock_locked(x) ck_spinlock_fas_locked(x) +#define ck_spinlock_trylock(x) ck_spinlock_fas_trylock(x) #ifndef CK_F_SPINLOCK_ANDERSON #define CK_F_SPINLOCK_ANDERSON diff --git a/regressions/ck_spinlock/benchmark/Makefile b/regressions/ck_spinlock/benchmark/Makefile index da8866f..61e70db 100644 --- a/regressions/ck_spinlock/benchmark/Makefile +++ b/regressions/ck_spinlock/benchmark/Makefile @@ -8,10 +8,17 @@ OBJECTS=ck_ticket.THROUGHPUT ck_ticket.LATENCY \ ck_clh.THROUGHPUT ck_clh.LATENCY \ linux_spinlock.THROUGHPUT linux_spinlock.LATENCY \ ck_ticket_pb.THROUGHPUT ck_ticket_pb.LATENCY \ - ck_anderson.THROUGHPUT ck_anderson.LATENCY + ck_anderson.THROUGHPUT ck_anderson.LATENCY \ + ck_spinlock.THROUGHPUT ck_spinlock.LATENCY all: $(OBJECTS) +ck_spinlock.THROUGHPUT: ck_spinlock.c + $(CC) -DTHROUGHPUT $(CFLAGS) -o ck_spinlock.THROUGHPUT ck_spinlock.c + +ck_spinlock.LATENCY: ck_spinlock.c + $(CC) -DLATENCY $(CFLAGS) -o ck_spinlock.LATENCY ck_spinlock.c + ck_ticket.THROUGHPUT: ck_ticket.c $(CC) -DTHROUGHPUT $(CFLAGS) -o ck_ticket.THROUGHPUT ck_ticket.c diff --git a/regressions/ck_spinlock/benchmark/ck_spinlock.c b/regressions/ck_spinlock/benchmark/ck_spinlock.c new file mode 100644 index 0000000..138541e --- /dev/null +++ b/regressions/ck_spinlock/benchmark/ck_spinlock.c @@ -0,0 +1,7 @@ +#include "../ck_spinlock.h" + +#ifdef THROUGHPUT +#include "throughput.h" +#elif defined(LATENCY) +#include "latency.h" +#endif diff --git a/regressions/ck_spinlock/ck_spinlock.h b/regressions/ck_spinlock/ck_spinlock.h new file mode 100644 index 0000000..a3de26e --- /dev/null +++ b/regressions/ck_spinlock/ck_spinlock.h @@ -0,0 +1,5 @@ +#define LOCK_NAME "ck_spinlock" +#define LOCK_DEFINE static ck_spinlock_t CK_CC_CACHELINE lock = CK_SPINLOCK_INITIALIZER +#define LOCK ck_spinlock_lock_eb(&lock) +#define UNLOCK ck_spinlock_unlock(&lock) + diff --git a/regressions/ck_spinlock/validate/Makefile b/regressions/ck_spinlock/validate/Makefile index 68fc00f..a080ad5 100644 --- a/regressions/ck_spinlock/validate/Makefile +++ b/regressions/ck_spinlock/validate/Makefile @@ -1,11 +1,14 @@ .PHONY: clean all: ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock \ - ck_ticket_pb ck_anderson + ck_ticket_pb ck_anderson ck_spinlock linux_spinlock: linux_spinlock.c $(CC) $(CFLAGS) -o linux_spinlock linux_spinlock.c +ck_spinlock: ck_spinlock.c + $(CC) $(CFLAGS) -o ck_spinlock ck_spinlock.c + ck_ticket_pb: ck_ticket_pb.c $(CC) $(CFLAGS) -o ck_ticket_pb ck_ticket_pb.c @@ -32,7 +35,7 @@ ck_dec: ck_dec.c clean: rm -rf ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock ck_ticket_pb \ - ck_anderson test_and_set *.dSYM + ck_anderson ck_spinlock *.dSYM include ../../../build/regressions.build CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE -lm diff --git a/regressions/ck_spinlock/validate/ck_spinlock.c b/regressions/ck_spinlock/validate/ck_spinlock.c new file mode 100644 index 0000000..e682905 --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_spinlock.c @@ -0,0 +1,2 @@ +#include "../ck_spinlock.h" +#include "validate.h"