ck_rw_cohort: renamed ck_rw_cohort namespace

ck_pring
Brendon Scheinman 12 years ago
parent 646cb2cb06
commit a352b46d0b

6
.gitignore vendored

@ -142,6 +142,6 @@ regressions/ck_queue/validate/ck_slist
regressions/ck_cohort/validate/validate
regressions/ck_cohort/benchmark/ck_cohort.LATENCY
regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT
regressions/ck_cohort_rw/validate/validate
regressions/ck_cohort_rw/benchmark/latency
regressions/ck_cohort_rw/benchmark/throughput
regressions/ck_rw_cohort/validate/validate
regressions/ck_rw_cohort/benchmark/latency
regressions/ck_rw_cohort/benchmark/throughput

@ -25,8 +25,8 @@
* SUCH DAMAGE.
*/
#ifndef _CK_COHORT_RW_H
#define _CK_COHORT_RW_H
#ifndef _CK_RW_COHORT_H
#define _CK_RW_COHORT_H
/*
* This is an implementation of NUMA-aware reader-writer locks as described in:
@ -39,24 +39,24 @@
#include <stddef.h>
#include <ck_cohort.h>
#define CK_COHORT_RW_NAME(N) ck_cohort_rw_##N
#define CK_COHORT_RW_INSTANCE(N) struct CK_COHORT_RW_NAME(N)
#define CK_COHORT_RW_INIT(N, RW, WL) ck_cohort_rw_##N##_init(RW, WL)
#define CK_COHORT_RW_READ_LOCK(N, RW, C, GC, LC) ck_cohort_rw_##N##_read_lock(RW, C, GC, LC)
#define CK_COHORT_RW_READ_UNLOCK(N, RW) ck_cohort_rw_##N##_read_unlock(RW)
#define CK_COHORT_RW_WRITE_LOCK(N, RW, C, GC, LC) ck_cohort_rw_##N##_write_lock(RW, C, GC, LC)
#define CK_COHORT_RW_WRITE_UNLOCK(N, RW, C, GC, LC) ck_cohort_rw_##N##_write_unlock(RW, C, GC, LC)
#define CK_COHORT_RW_DEFAULT_WAIT_LIMIT 1000
#define CK_RW_COHORT_NAME(N) ck_rw_cohort_##N
#define CK_RW_COHORT_INSTANCE(N) struct CK_RW_COHORT_NAME(N)
#define CK_RW_COHORT_INIT(N, RW, WL) ck_rw_cohort_##N##_init(RW, WL)
#define CK_RW_COHORT_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_##N##_read_lock(RW, C, GC, LC)
#define CK_RW_COHORT_READ_UNLOCK(N, RW) ck_rw_cohort_##N##_read_unlock(RW)
#define CK_RW_COHORT_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_##N##_write_lock(RW, C, GC, LC)
#define CK_RW_COHORT_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_##N##_write_unlock(RW, C, GC, LC)
#define CK_RW_COHORT_DEFAULT_WAIT_LIMIT 1000
#define CK_COHORT_RW_PROTOTYPE(N) \
CK_COHORT_RW_INSTANCE(N) { \
#define CK_RW_COHORT_PROTOTYPE(N) \
CK_RW_COHORT_INSTANCE(N) { \
unsigned int read_counter; \
unsigned int write_barrier; \
unsigned int wait_limit; \
}; \
\
CK_CC_INLINE static void \
ck_cohort_rw_##N##_init(CK_COHORT_RW_INSTANCE(N) *rw_cohort, \
ck_rw_cohort_##N##_init(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \
unsigned int wait_limit) \
{ \
rw_cohort->read_counter = 0; \
@ -67,7 +67,7 @@
} \
\
CK_CC_INLINE static void \
ck_cohort_rw_##N##_write_lock(CK_COHORT_RW_INSTANCE(N) *rw_cohort, \
ck_rw_cohort_##N##_write_lock(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
@ -85,7 +85,7 @@
} \
\
CK_CC_INLINE static void \
ck_cohort_rw_##N##_write_unlock(CK_COHORT_RW_INSTANCE(N) *rw_cohort, \
ck_rw_cohort_##N##_write_unlock(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
@ -94,7 +94,7 @@
} \
\
CK_CC_INLINE static void \
ck_cohort_rw_##N##_read_lock(CK_COHORT_RW_INSTANCE(N) *rw_cohort, \
ck_rw_cohort_##N##_read_lock(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
@ -122,15 +122,15 @@
} \
\
CK_CC_INLINE static void \
ck_cohort_rw_##N##_read_unlock(CK_COHORT_RW_INSTANCE(N) *cohort) \
ck_rw_cohort_##N##_read_unlock(CK_RW_COHORT_INSTANCE(N) *cohort) \
{ \
ck_pr_dec_uint(&cohort->read_counter); \
}
#define CK_COHORT_RW_INITIALIZER { \
#define CK_RW_COHORT_INITIALIZER { \
.read_counter = 0, \
.write_barrier = 0, \
.wait_limit = 0 \
}
#endif /* _CK_COHORT_RW_H */
#endif /* _CK_RW_COHORT_H */

@ -4,10 +4,10 @@ OBJECTS=latency throughput
all: $(OBJECTS)
latency: latency.c ../../../include/ck_cohort_rw.h
latency: latency.c ../../../include/ck_rw_cohort.h
$(CC) $(CFLAGS) -o latency latency.c
throughput: throughput.c ../../../include/ck_cohort_rw.h
throughput: throughput.c ../../../include/ck_rw_cohort.h
$(CC) $(CFLAGS) -o throughput throughput.c
clean:

@ -25,7 +25,7 @@
* SUCH DAMAGE.
*/
#include <ck_cohort_rw.h>
#include <ck_rw_cohort.h>
#include <ck_spinlock.h>
#include <inttypes.h>
#include <stdio.h>
@ -60,7 +60,7 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context)
CK_COHORT_PROTOTYPE(fas_fas,
ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context,
ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context)
CK_COHORT_RW_PROTOTYPE(fas_fas)
CK_RW_COHORT_PROTOTYPE(fas_fas)
int
main(void)
@ -69,34 +69,34 @@ main(void)
ck_spinlock_fas_t global_lock = CK_SPINLOCK_FAS_INITIALIZER;
ck_spinlock_fas_t local_lock = CK_SPINLOCK_FAS_INITIALIZER;
CK_COHORT_INSTANCE(fas_fas) cohort = CK_COHORT_INITIALIZER;
CK_COHORT_RW_INSTANCE(fas_fas) rw_cohort = CK_COHORT_RW_INITIALIZER;
CK_RW_COHORT_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_INITIALIZER;
CK_COHORT_INIT(fas_fas, &cohort, &global_lock, &local_lock,
CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT);
CK_COHORT_RW_INIT(fas_fas, &rw_cohort, CK_COHORT_RW_DEFAULT_WAIT_LIMIT);
CK_RW_COHORT_INIT(fas_fas, &rw_cohort, CK_RW_COHORT_DEFAULT_WAIT_LIMIT);
for (i = 0; i < STEPS; i++) {
CK_COHORT_RW_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_COHORT_RW_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
}
s_b = rdtsc();
for (i = 0; i < STEPS; i++) {
CK_COHORT_RW_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_COHORT_RW_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
}
e_b = rdtsc();
printf("WRITE: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS);
for (i = 0; i < STEPS; i++) {
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
}
s_b = rdtsc();
for (i = 0; i < STEPS; i++) {
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
}
e_b = rdtsc();
printf("READ: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS);

@ -26,7 +26,7 @@
*/
#include <ck_cohort.h>
#include <ck_cohort_rw.h>
#include <ck_rw_cohort.h>
#include <ck_spinlock.h>
#include <inttypes.h>
#include <pthread.h>
@ -78,7 +78,7 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context)
CK_COHORT_PROTOTYPE(fas_fas,
ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context,
ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context)
CK_COHORT_RW_PROTOTYPE(fas_fas)
CK_RW_COHORT_PROTOTYPE(fas_fas)
struct cohort_record {
CK_COHORT_INSTANCE(fas_fas) cohort;
@ -86,7 +86,7 @@ struct cohort_record {
static struct cohort_record *cohorts;
static ck_spinlock_t global_lock = CK_SPINLOCK_INITIALIZER;
static CK_COHORT_RW_INSTANCE(fas_fas) rw_cohort = CK_COHORT_RW_INITIALIZER;
static CK_RW_COHORT_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_INITIALIZER;
static unsigned int n_cohorts;
struct block {
@ -114,38 +114,38 @@ thread_rwlock(void *pun)
for (i = 1, a = 0;; i++) {
s_b = rdtsc();
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
e_b = rdtsc();
a += (e_b - s_b) >> 4;

@ -4,7 +4,7 @@ OBJECTS=validate
all: $(OBJECTS)
validate: validate.c ../../../include/ck_cohort_rw.h
validate: validate.c ../../../include/ck_rw_cohort.h
$(CC) $(CFLAGS) -o validate validate.c -g
check: all

@ -37,7 +37,7 @@
#include <sys/time.h>
#include <ck_pr.h>
#include <ck_cohort_rw.h>
#include <ck_rw_cohort.h>
#include <ck_spinlock.h>
#include "../../common.h"
@ -75,10 +75,10 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context)
CK_COHORT_PROTOTYPE(fas_fas,
ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context,
ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context, ck_spinlock_fas_locked_with_context)
CK_COHORT_RW_PROTOTYPE(fas_fas)
CK_RW_COHORT_PROTOTYPE(fas_fas)
static CK_COHORT_INSTANCE(fas_fas) *cohorts;
static CK_COHORT_RW_INSTANCE(fas_fas) rw_cohort = CK_COHORT_RW_INITIALIZER;
static CK_RW_COHORT_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_INITIALIZER;
static int n_cohorts;
static void *
@ -97,7 +97,7 @@ thread(void *null CK_CC_UNUSED)
cohort = cohorts + (core / (int)(a.delta)) % n_cohorts;
while (i--) {
CK_COHORT_RW_WRITE_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_WRITE_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
{
l = ck_pr_load_uint(&locked);
if (l != 0) {
@ -132,16 +132,16 @@ thread(void *null CK_CC_UNUSED)
ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l);
}
}
CK_COHORT_RW_WRITE_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_WRITE_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_COHORT_RW_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
{
l = ck_pr_load_uint(&locked);
if (l != 0) {
ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l);
}
}
CK_COHORT_RW_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort);
}
return (NULL);
Loading…
Cancel
Save