Skip to content

Commit bf3b784

Browse files
author
Samy Al Bahra
committed
regressions: add pthread_mutex to spinlock test.
1 parent d20bc48 commit bf3b784

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

regressions/ck_spinlock/benchmark/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ OBJECTS=ck_ticket.THROUGHPUT ck_ticket.LATENCY \
1010
ck_ticket_pb.THROUGHPUT ck_ticket_pb.LATENCY \
1111
ck_anderson.THROUGHPUT ck_anderson.LATENCY \
1212
ck_spinlock.THROUGHPUT ck_spinlock.LATENCY \
13+
pthread.THROUGHPUT pthread.LATENCY \
1314
ck_hclh.THROUGHPUT ck_hclh.LATENCY
1415

1516
all: $(OBJECTS)
@@ -80,6 +81,12 @@ ck_anderson.THROUGHPUT: ck_anderson.c
8081
ck_anderson.LATENCY: ck_anderson.c
8182
$(CC) -DLATENCY $(CFLAGS) -o ck_anderson.LATENCY ck_anderson.c -lm
8283

84+
pthread.THROUGHPUT: pthread.c
85+
$(CC) -DTHROUGHPUT $(CFLAGS) -o pthread.THROUGHPUT pthread.c -lm
86+
87+
pthread.LATENCY: pthread.c
88+
$(CC) -DLATENCY $(CFLAGS) -o pthread.LATENCY pthread.c -lm
89+
8390
clean:
8491
rm -rf *.dSYM *.exe $(OBJECTS)
8592

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "../pthread.h"
2+
3+
#ifdef THROUGHPUT
4+
#include "throughput.h"
5+
#elif defined(LATENCY)
6+
#include "latency.h"
7+
#endif

regressions/ck_spinlock/pthread.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <ck_cc.h>
2+
#include <pthread.h>
3+
4+
CK_CC_INLINE static void
5+
spin_lock(volatile unsigned int *lock)
6+
{
7+
#ifdef __x86_64__
8+
__asm__ __volatile__(
9+
"\n1:\t"
10+
"lock ; decl %0\n\t"
11+
"jns 2f\n"
12+
"3:\n"
13+
"rep;nop\n\t"
14+
"cmpl $0,%0\n\t"
15+
"jle 3b\n\t"
16+
"jmp 1b\n"
17+
"2:\t" : "=m" (*lock) : : "memory");
18+
#else
19+
*lock = 1;
20+
#endif
21+
22+
return;
23+
}
24+
25+
CK_CC_INLINE static void
26+
spin_unlock(volatile unsigned int *lock)
27+
{
28+
#ifdef __x86_64__
29+
__asm__ __volatile__("movl $1,%0" :"=m" (*lock) :: "memory");
30+
#else
31+
*lock = 0;
32+
return;
33+
#endif
34+
}
35+
36+
#define LOCK_NAME "pthread_mutex"
37+
#define LOCK_DEFINE pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER
38+
#define LOCK pthread_mutex_lock(&lock)
39+
#define UNLOCK pthread_mutex_unlock(&lock)
40+

0 commit comments

Comments
 (0)