Skip to content

Commit

Permalink
regressions: add pthread_mutex to spinlock test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samy Al Bahra committed Jan 13, 2025
1 parent d20bc48 commit bf3b784
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions regressions/ck_spinlock/benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OBJECTS=ck_ticket.THROUGHPUT ck_ticket.LATENCY \
ck_ticket_pb.THROUGHPUT ck_ticket_pb.LATENCY \
ck_anderson.THROUGHPUT ck_anderson.LATENCY \
ck_spinlock.THROUGHPUT ck_spinlock.LATENCY \
pthread.THROUGHPUT pthread.LATENCY \
ck_hclh.THROUGHPUT ck_hclh.LATENCY

all: $(OBJECTS)
Expand Down Expand Up @@ -80,6 +81,12 @@ ck_anderson.THROUGHPUT: ck_anderson.c
ck_anderson.LATENCY: ck_anderson.c
$(CC) -DLATENCY $(CFLAGS) -o ck_anderson.LATENCY ck_anderson.c -lm

pthread.THROUGHPUT: pthread.c
$(CC) -DTHROUGHPUT $(CFLAGS) -o pthread.THROUGHPUT pthread.c -lm

pthread.LATENCY: pthread.c
$(CC) -DLATENCY $(CFLAGS) -o pthread.LATENCY pthread.c -lm

clean:
rm -rf *.dSYM *.exe $(OBJECTS)

Expand Down
7 changes: 7 additions & 0 deletions regressions/ck_spinlock/benchmark/pthread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "../pthread.h"

#ifdef THROUGHPUT
#include "throughput.h"
#elif defined(LATENCY)
#include "latency.h"
#endif
40 changes: 40 additions & 0 deletions regressions/ck_spinlock/pthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <ck_cc.h>
#include <pthread.h>

CK_CC_INLINE static void
spin_lock(volatile unsigned int *lock)
{
#ifdef __x86_64__
__asm__ __volatile__(
"\n1:\t"
"lock ; decl %0\n\t"
"jns 2f\n"
"3:\n"
"rep;nop\n\t"
"cmpl $0,%0\n\t"
"jle 3b\n\t"
"jmp 1b\n"
"2:\t" : "=m" (*lock) : : "memory");
#else
*lock = 1;
#endif

return;
}

CK_CC_INLINE static void
spin_unlock(volatile unsigned int *lock)
{
#ifdef __x86_64__
__asm__ __volatile__("movl $1,%0" :"=m" (*lock) :: "memory");
#else
*lock = 0;
return;
#endif
}

#define LOCK_NAME "pthread_mutex"
#define LOCK_DEFINE pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER
#define LOCK pthread_mutex_lock(&lock)
#define UNLOCK pthread_mutex_unlock(&lock)

0 comments on commit bf3b784

Please sign in to comment.