Moved rdtsc and affinity logic to a single file which other regression tests use. Single point of reference will ease porting these to future architectures and platforms. Removed invalid Copyright statement. Added CK_CC_USED to force some code generation that I found useful for debugging. Added ck_stack latency tests and a modified version of djoseph's modifications to benchmark.h for spinlock latency tests.ck_pring
parent
6d975931f9
commit
bcaadcf094
@ -1,17 +1,14 @@
|
||||
.PHONY: clean distribution
|
||||
|
||||
OBJECTS=serial validate
|
||||
OBJECTS=validate
|
||||
|
||||
all: $(OBJECTS)
|
||||
|
||||
validate: validate.c
|
||||
$(CC) $(CFLAGS) -o validate validate.c -lpthread
|
||||
|
||||
serial: serial.c
|
||||
$(CC) $(CFLAGS) -o serial serial.c
|
||||
|
||||
clean:
|
||||
rm -rf *.dSYM *~ *.o $(OBJECTS)
|
||||
|
||||
include ../../../build/regressions.build
|
||||
CFLAGS+=-ggdb -D_GNU_SOURCE
|
||||
CFLAGS+=-D_GNU_SOURCE
|
||||
|
@ -1,145 +0,0 @@
|
||||
#include <ck_bytelock.h>
|
||||
#include <ck_spinlock.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef STEPS
|
||||
#define STEPS 100000ULL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is a naive reader/writer spinlock.
|
||||
*/
|
||||
struct rwlock {
|
||||
unsigned int readers;
|
||||
ck_spinlock_fas_t writer;
|
||||
};
|
||||
typedef struct rwlock rwlock_t;
|
||||
|
||||
static CK_CC_INLINE void
|
||||
rwlock_init(rwlock_t *rw)
|
||||
{
|
||||
|
||||
ck_pr_store_uint(&rw->readers, 0);
|
||||
ck_spinlock_fas_init(&rw->writer);
|
||||
return;
|
||||
}
|
||||
|
||||
static CK_CC_INLINE void
|
||||
rwlock_write_lock(rwlock_t *rw)
|
||||
{
|
||||
|
||||
ck_spinlock_fas_lock(&rw->writer);
|
||||
while (ck_pr_load_uint(&rw->readers) != 0)
|
||||
ck_pr_stall();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static CK_CC_INLINE void
|
||||
rwlock_write_unlock(rwlock_t *rw)
|
||||
{
|
||||
|
||||
ck_spinlock_fas_unlock(&rw->writer);
|
||||
return;
|
||||
}
|
||||
|
||||
static CK_CC_INLINE void
|
||||
rwlock_read_lock(rwlock_t *rw)
|
||||
{
|
||||
|
||||
for (;;) {
|
||||
while (ck_pr_load_uint(&rw->writer.value) != 0)
|
||||
ck_pr_stall();
|
||||
|
||||
ck_pr_inc_uint(&rw->readers);
|
||||
if (ck_pr_load_uint(&rw->writer.value) == 0)
|
||||
break;
|
||||
ck_pr_dec_uint(&rw->readers);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static CK_CC_INLINE void
|
||||
rwlock_read_unlock(rwlock_t *rw)
|
||||
{
|
||||
|
||||
ck_pr_dec_uint(&rw->readers);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static inline uint64_t
|
||||
rdtsc(void)
|
||||
{
|
||||
#if defined(__x86_64__)
|
||||
uint32_t eax = 0, edx;
|
||||
|
||||
__asm__ __volatile__("cpuid;"
|
||||
"rdtsc;"
|
||||
: "+a" (eax), "=d" (edx)
|
||||
:
|
||||
: "%rcx", "%rbx", "memory");
|
||||
|
||||
__asm__ __volatile__("xorl %%eax, %%eax;"
|
||||
"cpuid;"
|
||||
:
|
||||
:
|
||||
: "%rax", "%rbx", "%rcx", "%rdx", "memory");
|
||||
|
||||
return (((uint64_t)edx << 32) | eax);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
uint64_t s_b, e_b;
|
||||
uint64_t i;
|
||||
ck_bytelock_t bytelock = CK_BYTELOCK_INITIALIZER;
|
||||
rwlock_t naive;
|
||||
|
||||
ck_bytelock_write_lock(&bytelock, 1);
|
||||
ck_bytelock_write_unlock(&bytelock);
|
||||
|
||||
s_b = rdtsc();
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_bytelock_write_lock(&bytelock, 1);
|
||||
ck_bytelock_write_unlock(&bytelock);
|
||||
}
|
||||
e_b = rdtsc();
|
||||
printf("WRITE: bytelock %15" PRIu64 "\n", e_b - s_b);
|
||||
|
||||
rwlock_init(&naive);
|
||||
rwlock_write_lock(&naive);
|
||||
rwlock_write_unlock(&naive);
|
||||
|
||||
s_b = rdtsc();
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
rwlock_write_lock(&naive);
|
||||
rwlock_write_unlock(&naive);
|
||||
}
|
||||
e_b = rdtsc();
|
||||
printf("WRITE: naive %15" PRIu64 "\n", e_b - s_b);
|
||||
|
||||
s_b = rdtsc();
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_bytelock_read_lock(&bytelock, 1);
|
||||
ck_bytelock_read_unlock(&bytelock, 1);
|
||||
}
|
||||
e_b = rdtsc();
|
||||
printf("READ: bytelock %15" PRIu64 "\n", e_b - s_b);
|
||||
|
||||
s_b = rdtsc();
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
rwlock_write_lock(&naive);
|
||||
rwlock_write_unlock(&naive);
|
||||
}
|
||||
e_b = rdtsc();
|
||||
printf("READ: naive %15" PRIu64 "\n", e_b - s_b);
|
||||
|
||||
return (0);
|
||||
}
|
@ -1,41 +1,73 @@
|
||||
.PHONY: all clean
|
||||
|
||||
all: ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock \
|
||||
ck_ticket_pb ck_anderson test_and_set
|
||||
OBJECTS=ck_ticket.THROUGHPUT ck_ticket.LATENCY \
|
||||
ck_mcs.THROUGHPUT ck_mcs.LATENCY \
|
||||
ck_dec.THROUGHPUT ck_dec.LATENCY \
|
||||
ck_cas.THROUGHPUT ck_cas.LATENCY \
|
||||
ck_fas.THROUGHPUT ck_fas.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
|
||||
|
||||
linux_spinlock: linux_spinlock.c
|
||||
$(CC) $(CFLAGS) -o linux_spinlock linux_spinlock.c
|
||||
all: $(OBJECTS)
|
||||
|
||||
ck_ticket_pb: ck_ticket_pb.c
|
||||
$(CC) $(CFLAGS) -o ck_ticket_pb ck_ticket_pb.c
|
||||
ck_ticket.THROUGHPUT: ck_ticket.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_ticket.THROUGHPUT ck_ticket.c
|
||||
|
||||
ck_clh: ck_clh.c
|
||||
$(CC) $(CFLAGS) -o ck_clh ck_clh.c
|
||||
ck_ticket.LATENCY: ck_ticket.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_ticket.LATENCY ck_ticket.c
|
||||
|
||||
test_and_set: test_and_set.c
|
||||
$(CC) $(CFLAGS) -o test_and_set test_and_set.c
|
||||
ck_mcs.THROUGHPUT: ck_mcs.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_mcs.THROUGHPUT ck_mcs.c
|
||||
|
||||
ck_anderson: ck_anderson.c
|
||||
$(CC) $(CFLAGS) -o ck_anderson ck_anderson.c
|
||||
ck_mcs.LATENCY: ck_mcs.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_mcs.LATENCY ck_mcs.c
|
||||
|
||||
ck_fas: ck_fas.c
|
||||
$(CC) $(CFLAGS) -o ck_fas ck_fas.c
|
||||
ck_dec.THROUGHPUT: ck_dec.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_dec.THROUGHPUT ck_dec.c
|
||||
|
||||
ck_ticket: ck_ticket.c
|
||||
$(CC) $(CFLAGS) -o ck_ticket ck_ticket.c
|
||||
ck_dec.LATENCY: ck_dec.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_dec.LATENCY ck_dec.c
|
||||
|
||||
ck_cas: ck_cas.c
|
||||
$(CC) $(CFLAGS) -o ck_cas ck_cas.c
|
||||
ck_cas.THROUGHPUT: ck_cas.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_cas.THROUGHPUT ck_cas.c
|
||||
|
||||
ck_mcs: ck_mcs.c
|
||||
$(CC) $(CFLAGS) -o ck_mcs ck_mcs.c
|
||||
ck_cas.LATENCY: ck_cas.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_cas.LATENCY ck_cas.c
|
||||
|
||||
ck_dec: ck_dec.c
|
||||
$(CC) $(CFLAGS) -o ck_dec ck_dec.c
|
||||
ck_fas.THROUGHPUT: ck_fas.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_fas.THROUGHPUT ck_fas.c
|
||||
|
||||
ck_fas.LATENCY: ck_fas.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_fas.LATENCY ck_fas.c
|
||||
|
||||
ck_clh.THROUGHPUT: ck_clh.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_clh.THROUGHPUT ck_clh.c
|
||||
|
||||
ck_clh.LATENCY: ck_clh.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_clh.LATENCY ck_clh.c
|
||||
|
||||
linux_spinlock.THROUGHPUT: linux_spinlock.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o linux_spinlock.THROUGHPUT linux_spinlock.c
|
||||
|
||||
linux_spinlock.LATENCY: linux_spinlock.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o linux_spinlock.LATENCY linux_spinlock.c
|
||||
|
||||
ck_ticket_pb.THROUGHPUT: ck_ticket_pb.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_ticket_pb.THROUGHPUT ck_ticket_pb.c
|
||||
|
||||
ck_ticket_pb.LATENCY: ck_ticket_pb.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_ticket_pb.LATENCY ck_ticket_pb.c
|
||||
|
||||
ck_anderson.THROUGHPUT: ck_anderson.c
|
||||
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_anderson.THROUGHPUT ck_anderson.c
|
||||
|
||||
ck_anderson.LATENCY: ck_anderson.c
|
||||
$(CC) -DLATENCY $(CFLAGS) -o ck_anderson.LATENCY ck_anderson.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
|
||||
rm -rf *.dSYM $(OBJECTS)
|
||||
|
||||
include ../../../build/regressions.build
|
||||
CFLAGS+=-D_GNU_SOURCE -lpthread -lm
|
||||
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SPACE=" "
|
||||
SYSTEM=`uname -s`
|
||||
|
||||
case "$SYSTEM" in
|
||||
"FreeBSD")
|
||||
CORES=`sysctl -n hw.ncpu`
|
||||
;;
|
||||
"Darwin")
|
||||
CORES=`sysctl -n hw.activecpu`
|
||||
;;
|
||||
"Linux")
|
||||
CORES=`grep processor /proc/cpuinfo|wc -l`
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Detected $CORES cores."
|
||||
echo
|
||||
|
||||
for k in ck_clh ck_anderson ck_cas ck_dec ck_fas ck_mcs ck_ticket ck_ticket_pb; do
|
||||
echo "===[ Beginning $k benchmarks..."
|
||||
echo "# Cores $SPACE Total $SPACE Average $SPACE Deviation" > ${k}.data
|
||||
|
||||
for j in `seq 1 $CORES`; do
|
||||
printf " Beginning $j cores..."
|
||||
printf " $j $SPACE " >> ${k}.data;
|
||||
./$k $j 1 0 2> /dev/null | awk '/deviation/ {printf("%16f ",$4)} /average/ {printf("%16.4d ",$4)} /total/ {printf("%16d ",$4)}' >> ${k}.data
|
||||
echo >> ${k}.data
|
||||
printf "done\n"
|
||||
done
|
||||
done
|
@ -1,2 +1,8 @@
|
||||
#include "../ck_anderson.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
||||
|
@ -1,2 +1,8 @@
|
||||
#include "../ck_cas.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "../ck_clh.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "../ck_dec.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "../ck_fas.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "../ck_mcs.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
@ -1,2 +1,8 @@
|
||||
#include "../ck_ticket.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "../ck_ticket_pb.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
@ -0,0 +1,48 @@
|
||||
#include <ck_bytelock.h>
|
||||
#include <ck_spinlock.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../../common.h"
|
||||
|
||||
#ifndef STEPS
|
||||
#define STEPS 30000000
|
||||
#endif
|
||||
|
||||
LOCK_DEFINE;
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
CK_CC_UNUSED unsigned int nthr = 1;
|
||||
|
||||
#ifdef LOCK_INIT
|
||||
LOCK_INIT;
|
||||
#endif
|
||||
|
||||
#ifdef LOCK_STATE
|
||||
LOCK_STATE;
|
||||
#endif
|
||||
|
||||
uint64_t s_b, e_b, i;
|
||||
|
||||
s_b = rdtsc();
|
||||
for (i = 0; i < STEPS; ++i) {
|
||||
#ifdef LOCK
|
||||
LOCK;
|
||||
UNLOCK;
|
||||
LOCK;
|
||||
UNLOCK;
|
||||
LOCK;
|
||||
UNLOCK;
|
||||
LOCK;
|
||||
UNLOCK;
|
||||
#endif
|
||||
}
|
||||
e_b = rdtsc();
|
||||
printf("%15" PRIu64 "\n", (e_b - s_b) / 4 / STEPS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -1,2 +1,7 @@
|
||||
#include "../linux_spinlock.h"
|
||||
#include "benchmark.h"
|
||||
|
||||
#ifdef THROUGHPUT
|
||||
#include "throughput.h"
|
||||
#elif defined(LATENCY)
|
||||
#include "latency.h"
|
||||
#endif
|
||||
|
@ -1,2 +0,0 @@
|
||||
#include "../test_and_set.h"
|
||||
#include "benchmark.h"
|
@ -1,34 +0,0 @@
|
||||
static inline void
|
||||
spin_lock(volatile unsigned int *lock)
|
||||
{
|
||||
#if defined(__x86__) || defined(__x86_64__)
|
||||
asm volatile(
|
||||
"\n1:\t"
|
||||
"pause\n"
|
||||
"lock decl %0\n\t"
|
||||
"jns 2f\n"
|
||||
"jmp 1b\n"
|
||||
"2:\t" : "=m" (*lock) : : "memory");
|
||||
#else
|
||||
*lock = 0;
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static inline void
|
||||
spin_unlock(volatile unsigned int *lock)
|
||||
{
|
||||
#if defined(__x86__) || defined(__x86_64__)
|
||||
asm volatile("movl $1,%0" :"=m" (*lock) :: "memory");
|
||||
#else
|
||||
*lock = 1;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#define LOCK_NAME "test_and_set"
|
||||
#define LOCK_DEFINE volatile unsigned int lock = 1
|
||||
#define LOCK spin_lock(&lock)
|
||||
#define UNLOCK spin_unlock(&lock)
|
||||
|
@ -1,2 +0,0 @@
|
||||
#include "../test_and_set.h"
|
||||
#include "validate.h"
|
@ -0,0 +1,14 @@
|
||||
.PHONY: clean distribution
|
||||
|
||||
OBJECTS=latency
|
||||
|
||||
all: $(OBJECTS)
|
||||
|
||||
latency: latency.c
|
||||
$(CC) $(CFLAGS) -o latency latency.c
|
||||
|
||||
clean:
|
||||
rm -rf *~ *.o *.dSYM $(OBJECTS)
|
||||
|
||||
include ../../../build/regressions.build
|
||||
CFLAGS+=-lpthread
|
@ -0,0 +1,125 @@
|
||||
#include <ck_stack.h>
|
||||
#include <ck_spinlock.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../common.h"
|
||||
|
||||
#ifndef ENTRIES
|
||||
#define ENTRIES 1024
|
||||
#endif
|
||||
|
||||
#ifndef STEPS
|
||||
#define STEPS 4000
|
||||
#endif
|
||||
|
||||
static ck_stack_t stack;
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
ck_stack_entry_t entry[4096];
|
||||
ck_spinlock_fas_t mutex = CK_SPINLOCK_FAS_INITIALIZER;
|
||||
volatile ck_stack_entry_t * volatile r;
|
||||
uint64_t s, e, a;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
|
||||
a = 0;
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_stack_init(&stack);
|
||||
|
||||
s = rdtsc();
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++) {
|
||||
ck_spinlock_fas_lock(&mutex);
|
||||
ck_stack_push_spnc(&stack, entry + j);
|
||||
ck_spinlock_fas_unlock(&mutex);
|
||||
}
|
||||
e = rdtsc();
|
||||
|
||||
a += e - s;
|
||||
}
|
||||
printf(" push_spinlock: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry)));
|
||||
|
||||
#ifdef CK_F_STACK_PUSH_UPMC
|
||||
a = 0;
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_stack_init(&stack);
|
||||
|
||||
s = rdtsc();
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); 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)));
|
||||
#endif /* CK_F_STACK_PUSH_UPMC */
|
||||
|
||||
#ifdef CK_F_STACK_PUSH_MPMC
|
||||
a = 0;
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_stack_init(&stack);
|
||||
|
||||
s = rdtsc();
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); 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)));
|
||||
#endif /* CK_F_STACK_PUSH_MPMC */
|
||||
|
||||
#ifdef CK_F_STACK_PUSH_MPNC
|
||||
a = 0;
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_stack_init(&stack);
|
||||
|
||||
s = rdtsc();
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); 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)));
|
||||
#endif /* CK_F_STACK_PUSH_MPNC */
|
||||
|
||||
#if defined(CK_F_STACK_PUSH_UPMC) && defined(CK_F_STACK_POP_UPMC)
|
||||
a = 0;
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_stack_init(&stack);
|
||||
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++)
|
||||
ck_stack_push_upmc(&stack, entry + j);
|
||||
|
||||
s = rdtsc();
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++)
|
||||
r = ck_stack_pop_upmc(&stack);
|
||||
e = rdtsc();
|
||||
a += e - s;
|
||||
}
|
||||
printf(" ck_stack_pop_upmc: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry)));
|
||||
#endif /* CK_F_STACK_PUSH_UPMC && CK_F_STACK_POP_UPMC */
|
||||
|
||||
#if defined(CK_F_STACK_POP_MPMC) && defined(CK_F_STACK_PUSH_MPMC)
|
||||
a = 0;
|
||||
for (i = 0; i < STEPS; i++) {
|
||||
ck_stack_init(&stack);
|
||||
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++)
|
||||
ck_stack_push_mpmc(&stack, entry + j);
|
||||
|
||||
s = rdtsc();
|
||||
for (j = 0; j < sizeof(entry) / sizeof(*entry); j++)
|
||||
r = ck_stack_pop_mpmc(&stack);
|
||||
e = rdtsc();
|
||||
a += e - s;
|
||||
}
|
||||
printf(" ck_stack_pop_mpmc: %16" PRIu64 "\n", a / STEPS / (sizeof(entry) / sizeof(*entry)));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SPACE=" "
|
||||
SYSTEM=`uname -s`
|
||||
|
||||
case "$SYSTEM" in
|
||||
"Darwin")
|
||||
CORES=`sysctl -n hw.activecpu`
|
||||
;;
|
||||
"Linux")
|
||||
CORES=`grep processor /proc/cpuinfo|wc -l`
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Detected $CORES cores."
|
||||
echo
|
||||
|
||||
for k in push pair pop; do
|
||||
echo "===[ Beginning $k benchmarks..."
|
||||
printf "# Cores $SPACE" > ${k}.data
|
||||
|
||||
for i in *_${k}; do
|
||||
printf "$i $SPACE" >> ${k}.data
|
||||
done
|
||||
|
||||
echo >> ${k}.data
|
||||
|
||||
for j in `seq 1 $CORES`; do
|
||||
echo "===[ Beginning $j cores..."
|
||||
|
||||
printf " $j $SPACE " >> ${k}.data;
|
||||
for i in *_${k}; do
|
||||
printf " Executing $i..."
|
||||
./$i $j 1 0 | awk '{printf("%.8f ",$2)}' >> ${k}.data
|
||||
printf "done\n"
|
||||
done
|
||||
echo >> ${k}.data
|
||||
done
|
||||
done
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2011 Samy Al Bahra.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ck_cc.h>
|
||||
#include <ck_pr.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#ifndef CORES
|
||||
#define CORES 8
|
||||
#endif
|
||||
|
||||
struct affinity {
|
||||
unsigned int delta;
|
||||
unsigned int request;
|
||||
};
|
||||
|
||||
#define AFFINITY_INITIALIZER {0, 0}
|
||||
|
||||
#ifdef __linux__
|
||||
#ifndef gettid
|
||||
static pid_t
|
||||
gettid(void)
|
||||
{
|
||||
return syscall(__NR_gettid);
|
||||
}
|
||||
#endif /* gettid */
|
||||
|
||||
CK_CC_UNUSED static int
|
||||
aff_iterate(struct affinity *acb)
|
||||
{
|
||||
cpu_set_t s;
|
||||
unsigned int c;
|
||||
|
||||
c = ck_pr_faa_uint(&acb->request, acb->delta);
|
||||
CPU_ZERO(&s);
|
||||
CPU_SET(c % CORES, &s);
|
||||
|
||||
return sched_setaffinity(gettid(), sizeof(s), &s);
|
||||
}
|
||||
#else
|
||||
CK_CC_UNUSED static int
|
||||
aff_iterate(struct affinity *acb CK_CC_UNUSED)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
CK_CC_INLINE static uint64_t
|
||||
rdtsc(void)
|
||||
{
|
||||
#if defined(__x86_64__)
|
||||
uint32_t eax = 0, edx;
|
||||
|
||||
__asm__ __volatile__("cpuid;"
|
||||
"rdtsc;"
|
||||
: "+a" (eax), "=d" (edx)
|
||||
:
|
||||
: "%ecx", "%ebx", "memory");
|
||||
|
||||
__asm__ __volatile__("xorl %%eax, %%eax;"
|
||||
"cpuid;"
|
||||
:
|
||||
:
|
||||
: "%eax", "%ebx", "%ecx", "%edx", "memory");
|
||||
|
||||
return (((uint64_t)edx << 32) | eax);
|
||||
#elif defined(__sparcv9__)
|
||||
uint64_t r;
|
||||
|
||||
__asm__ __volatile__("rd %%tick, %0" : "=r" (r) :: "memory");
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in new issue