ck_rw_cohort: Added read-preference logic and updated validation test to use it

ck_pring
Brendon Scheinman 12 years ago
parent f93369c4fc
commit 21750b9321

5
.gitignore vendored

@ -13,6 +13,7 @@ build/Makefile
*.a *.a
*.so *.so
*.dSYM *.dSYM
.*.sw[op]
regressions/ck_cohort/benchmark/ck_cohort.LATENCY regressions/ck_cohort/benchmark/ck_cohort.LATENCY
regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT
regressions/ck_pflock/benchmark/latency regressions/ck_pflock/benchmark/latency
@ -142,6 +143,8 @@ regressions/ck_queue/validate/ck_slist
regressions/ck_cohort/validate/validate regressions/ck_cohort/validate/validate
regressions/ck_cohort/benchmark/ck_cohort.LATENCY regressions/ck_cohort/benchmark/ck_cohort.LATENCY
regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT regressions/ck_cohort/benchmark/ck_cohort.THROUGHPUT
regressions/ck_rw_cohort/validate/validate regressions/ck_rw_cohort/validate/ck_neutral
regressions/ck_rw_cohort/validate/ck_rp
regressions/ck_rw_cohort/validate/ck_wp
regressions/ck_rw_cohort/benchmark/latency regressions/ck_rw_cohort/benchmark/latency
regressions/ck_rw_cohort/benchmark/throughput regressions/ck_rw_cohort/benchmark/throughput

@ -39,24 +39,24 @@
#include <stddef.h> #include <stddef.h>
#include <ck_cohort.h> #include <ck_cohort.h>
#define CK_RW_COHORT_NAME(N) ck_rw_cohort_##N #define CK_RW_COHORT_WP_NAME(N) ck_rw_cohort_wp_##N
#define CK_RW_COHORT_INSTANCE(N) struct CK_RW_COHORT_NAME(N) #define CK_RW_COHORT_WP_INSTANCE(N) struct CK_RW_COHORT_WP_NAME(N)
#define CK_RW_COHORT_INIT(N, RW, WL) ck_rw_cohort_##N##_init(RW, WL) #define CK_RW_COHORT_WP_INIT(N, RW, WL) ck_rw_cohort_wp_##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_WP_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##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_WP_READ_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##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_WP_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##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_WP_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##N##_write_unlock(RW, C, GC, LC)
#define CK_RW_COHORT_DEFAULT_WAIT_LIMIT 1000 #define CK_RW_COHORT_WP_DEFAULT_WAIT_LIMIT 1000
#define CK_RW_COHORT_PROTOTYPE(N) \ #define CK_RW_COHORT_WP_PROTOTYPE(N) \
CK_RW_COHORT_INSTANCE(N) { \ CK_RW_COHORT_WP_INSTANCE(N) { \
unsigned int read_counter; \ unsigned int read_counter; \
unsigned int write_barrier; \ unsigned int write_barrier; \
unsigned int wait_limit; \ unsigned int wait_limit; \
}; \ }; \
\ \
CK_CC_INLINE static void \ CK_CC_INLINE static void \
ck_rw_cohort_##N##_init(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \ ck_rw_cohort_wp_##N##_init(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
unsigned int wait_limit) \ unsigned int wait_limit) \
{ \ { \
rw_cohort->read_counter = 0; \ rw_cohort->read_counter = 0; \
@ -67,7 +67,7 @@
} \ } \
\ \
CK_CC_INLINE static void \ CK_CC_INLINE static void \
ck_rw_cohort_##N##_write_lock(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \ ck_rw_cohort_wp_##N##_write_lock(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \ CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \ void *local_context) \
{ \ { \
@ -85,7 +85,7 @@
} \ } \
\ \
CK_CC_INLINE static void \ CK_CC_INLINE static void \
ck_rw_cohort_##N##_write_unlock(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \ ck_rw_cohort_wp_##N##_write_unlock(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \ CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \ void *local_context) \
{ \ { \
@ -94,7 +94,7 @@
} \ } \
\ \
CK_CC_INLINE static void \ CK_CC_INLINE static void \
ck_rw_cohort_##N##_read_lock(CK_RW_COHORT_INSTANCE(N) *rw_cohort, \ ck_rw_cohort_wp_##N##_read_lock(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \ CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \ void *local_context) \
{ \ { \
@ -125,15 +125,112 @@
} \ } \
\ \
CK_CC_INLINE static void \ CK_CC_INLINE static void \
ck_rw_cohort_##N##_read_unlock(CK_RW_COHORT_INSTANCE(N) *cohort) \ ck_rw_cohort_wp_##N##_read_unlock(CK_RW_COHORT_WP_INSTANCE(N) *cohort) \
{ \ { \
ck_pr_dec_uint(&cohort->read_counter); \ ck_pr_dec_uint(&cohort->read_counter); \
} }
#define CK_RW_COHORT_INITIALIZER { \ #define CK_RW_COHORT_WP_INITIALIZER { \
.read_counter = 0, \ .read_counter = 0, \
.write_barrier = 0, \ .write_barrier = 0, \
.wait_limit = 0 \ .wait_limit = 0 \
} }
#define CK_RW_COHORT_RP_NAME(N) ck_rw_cohort_rp_##N
#define CK_RW_COHORT_RP_INSTANCE(N) struct CK_RW_COHORT_RP_NAME(N)
#define CK_RW_COHORT_RP_INIT(N, RW, WL) ck_rw_cohort_rp_##N##_init(RW, WL)
#define CK_RW_COHORT_RP_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_read_lock(RW, C, GC, LC)
#define CK_RW_COHORT_RP_READ_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_read_unlock(RW)
#define CK_RW_COHORT_RP_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_write_lock(RW, C, GC, LC)
#define CK_RW_COHORT_RP_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_write_unlock(RW, C, GC, LC)
#define CK_RW_COHORT_RP_DEFAULT_WAIT_LIMIT 1000
#define CK_RW_COHORT_RP_PROTOTYPE(N) \
CK_RW_COHORT_RP_INSTANCE(N) { \
unsigned int read_counter; \
unsigned int read_barrier; \
unsigned int wait_limit; \
}; \
\
CK_CC_INLINE static void \
ck_rw_cohort_rp_##N##_init(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
unsigned int wait_limit) \
{ \
rw_cohort->read_counter = 0; \
rw_cohort->read_barrier = 0; \
rw_cohort->wait_limit = wait_limit; \
ck_pr_barrier(); \
return; \
} \
\
CK_CC_INLINE static void \
ck_rw_cohort_rp_##N##_write_lock(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
unsigned int wait_count = 0; \
bool raised = false; \
\
while (true) { \
CK_COHORT_LOCK(N, cohort, global_context, local_context); \
if (ck_pr_load_uint(&rw_cohort->read_counter) == 0) { \
break; \
} else { \
CK_COHORT_UNLOCK(N, cohort, global_context, local_context); \
while (ck_pr_load_uint(&rw_cohort->read_counter) > 0) { \
ck_pr_stall(); \
if (++wait_count > rw_cohort->wait_limit && raised == false) {\
ck_pr_inc_uint(&rw_cohort->read_barrier); \
raised = true; \
} \
} \
} \
} \
\
if (raised == true) { \
ck_pr_dec_uint(&rw_cohort->read_barrier); \
} \
\
return; \
} \
\
CK_CC_INLINE static void \
ck_rw_cohort_rp_##N##_write_unlock(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, void *local_context) \
{ \
(void)rw_cohort; \
CK_COHORT_UNLOCK(N, cohort, global_context, local_context); \
} \
\
CK_CC_INLINE static void \
ck_rw_cohort_rp_##N##_read_lock(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
while (ck_pr_load_uint(&rw_cohort->read_barrier) > 0) { \
ck_pr_stall(); \
} \
ck_pr_inc_uint(&rw_cohort->read_counter); \
\
while (CK_COHORT_LOCKED(N, cohort, global_context, local_context) == true) { \
ck_pr_stall(); \
} \
\
return; \
} \
\
\
CK_CC_INLINE static void \
ck_rw_cohort_rp_##N##_read_unlock(CK_RW_COHORT_RP_INSTANCE(N) *cohort) \
{ \
ck_pr_dec_uint(&cohort->read_counter); \
}
#define CK_RW_COHORT_RP_INITIALIZER { \
.read_counter = 0, \
.read_barrier = 0, \
.wait_limit = 0 \
}
#endif /* _CK_RW_COHORT_H */ #endif /* _CK_RW_COHORT_H */

@ -60,7 +60,7 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context)
CK_COHORT_PROTOTYPE(fas_fas, 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_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_RW_COHORT_PROTOTYPE(fas_fas) CK_RW_COHORT_WP_PROTOTYPE(fas_fas)
int int
main(void) main(void)
@ -69,34 +69,34 @@ main(void)
ck_spinlock_fas_t global_lock = CK_SPINLOCK_FAS_INITIALIZER; ck_spinlock_fas_t global_lock = CK_SPINLOCK_FAS_INITIALIZER;
ck_spinlock_fas_t local_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_INSTANCE(fas_fas) cohort = CK_COHORT_INITIALIZER;
CK_RW_COHORT_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_INITIALIZER; CK_RW_COHORT_WP_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_WP_INITIALIZER;
CK_COHORT_INIT(fas_fas, &cohort, &global_lock, &local_lock, CK_COHORT_INIT(fas_fas, &cohort, &global_lock, &local_lock,
CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT); CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT);
CK_RW_COHORT_INIT(fas_fas, &rw_cohort, CK_RW_COHORT_DEFAULT_WAIT_LIMIT); CK_RW_COHORT_WP_INIT(fas_fas, &rw_cohort, CK_RW_COHORT_WP_DEFAULT_WAIT_LIMIT);
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
CK_RW_COHORT_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); CK_RW_COHORT_WP_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); CK_RW_COHORT_WP_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
} }
s_b = rdtsc(); s_b = rdtsc();
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
CK_RW_COHORT_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); CK_RW_COHORT_WP_WRITE_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); CK_RW_COHORT_WP_WRITE_UNLOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
} }
e_b = rdtsc(); e_b = rdtsc();
printf("WRITE: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS); printf("WRITE: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS);
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
} }
s_b = rdtsc(); s_b = rdtsc();
for (i = 0; i < STEPS; i++) { for (i = 0; i < STEPS; i++) {
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, &cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
} }
e_b = rdtsc(); e_b = rdtsc();
printf("READ: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS); printf("READ: rwlock %15" PRIu64 "\n", (e_b - s_b) / STEPS);

@ -78,7 +78,7 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context)
CK_COHORT_PROTOTYPE(fas_fas, 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_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_RW_COHORT_PROTOTYPE(fas_fas) CK_RW_COHORT_WP_PROTOTYPE(fas_fas)
struct cohort_record { struct cohort_record {
CK_COHORT_INSTANCE(fas_fas) cohort; CK_COHORT_INSTANCE(fas_fas) cohort;
@ -86,7 +86,7 @@ struct cohort_record {
static struct cohort_record *cohorts; static struct cohort_record *cohorts;
static ck_spinlock_t global_lock = CK_SPINLOCK_INITIALIZER; static ck_spinlock_t global_lock = CK_SPINLOCK_INITIALIZER;
static CK_RW_COHORT_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_INITIALIZER; static CK_RW_COHORT_WP_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_WP_INITIALIZER;
static unsigned int n_cohorts; static unsigned int n_cohorts;
struct block { struct block {
@ -114,38 +114,38 @@ thread_rwlock(void *pun)
for (i = 1, a = 0;; i++) { for (i = 1, a = 0;; i++) {
s_b = rdtsc(); s_b = rdtsc();
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); CK_RW_COHORT_WP_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); CK_RW_COHORT_WP_READ_UNLOCK(fas_fas, &rw_cohort);
e_b = rdtsc(); e_b = rdtsc();
a += (e_b - s_b) >> 4; a += (e_b - s_b) >> 4;

@ -0,0 +1,7 @@
#define LOCK_PROTOTYPE CK_RW_COHORT_NEUTRAL_PROTOTYPE
#define LOCK_INSTANCE CK_RW_COHORT_NEUTRAL_INSTANCE
#define LOCK_INITIALIZER CK_RW_COHORT_NEUTRAL_INITIALIZER
#define READ_LOCK CK_RW_COHORT_NEUTRAL_READ_LOCK
#define WRITE_LOCK CK_RW_COHORT_NEUTRAL_WRITE_LOCK
#define READ_UNLOCK CK_RW_COHORT_NEUTRAL_READ_UNLOCK
#define WRITE_UNLOCK CK_RW_COHORT_NEUTRAL_WRITE_UNLOCK

@ -0,0 +1,7 @@
#define LOCK_PROTOTYPE CK_RW_COHORT_RP_PROTOTYPE
#define LOCK_INSTANCE CK_RW_COHORT_RP_INSTANCE
#define LOCK_INITIALIZER CK_RW_COHORT_RP_INITIALIZER
#define READ_LOCK CK_RW_COHORT_RP_READ_LOCK
#define READ_UNLOCK CK_RW_COHORT_RP_READ_UNLOCK
#define WRITE_LOCK CK_RW_COHORT_RP_WRITE_LOCK
#define WRITE_UNLOCK CK_RW_COHORT_RP_WRITE_UNLOCK

@ -0,0 +1,17 @@
#define LOCK_PROTOTYPE CK_RW_COHORT_WP_PROTOTYPE
#define LOCK_INSTANCE CK_RW_COHORT_WP_INSTANCE
#define LOCK_INITIALIZER CK_RW_COHORT_WP_INITIALIZER
#define READ_LOCK CK_RW_COHORT_WP_READ_LOCK
#define WRITE_LOCK CK_RW_COHORT_WP_WRITE_LOCK
#define READ_UNLOCK CK_RW_COHORT_WP_READ_UNLOCK
#define WRITE_UNLOCK CK_RW_COHORT_WP_WRITE_UNLOCK
/*
#define WRITE_LOCK(N, RW, C, GC, LC)\
CK_RW_COHORT_WP_WRITE_LOCK(N, RW, C, GC, LC)
#define WRITE_UNLOCK(N, RW, C, GC, LC)\
CK_RW_COHORT_WP_WRITE_UNLOCK(N, RW, C, GC, LC);
#define READ_LOCK(N, RW, C, GC, LC)\
CK_RW_COHORT_WP_READ_LOCK(N, RW)
*/

@ -1,11 +1,18 @@
.PHONY: check clean distribution .PHONY: check clean distribution
OBJECTS=validate #OBJECTS=ck_neutral ck_rp ck_wp
OBJECTS=ck_rp ck_wp
all: $(OBJECTS) all: $(OBJECTS)
validate: validate.c ../../../include/ck_rw_cohort.h ck_neutral: ck_neutral.c ../../../include/ck_rw_cohort.h
$(CC) $(CFLAGS) -o validate validate.c -g $(CC) $(CFLAGS) -o ck_neutral ck_neutral.c -g
ck_rp: ck_rp.c ../../../include/ck_rw_cohort.h
$(CC) $(CFLAGS) -o ck_rp ck_rp.c -g
ck_wp: ck_wp.c ../../../include/ck_rw_cohort.h
$(CC) $(CFLAGS) -o ck_wp ck_wp.c -g
check: all check: all
./validate $(CORES) 1 ./validate $(CORES) 1

@ -0,0 +1,2 @@
#include "../ck_neutral.h"
#include "validate.h"

@ -0,0 +1,2 @@
#include "../ck_rp.h"
#include "validate.h"

@ -0,0 +1,2 @@
#include "../ck_wp.h"
#include "validate.h"

@ -46,6 +46,7 @@
#define ITERATE 1000000 #define ITERATE 1000000
#endif #endif
static struct affinity a; static struct affinity a;
static unsigned int locked; static unsigned int locked;
static int nthr; static int nthr;
@ -75,10 +76,10 @@ ck_spinlock_fas_locked_with_context(ck_spinlock_fas_t *lock, void *context)
CK_COHORT_PROTOTYPE(fas_fas, 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_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_RW_COHORT_PROTOTYPE(fas_fas) LOCK_PROTOTYPE(fas_fas)
static CK_COHORT_INSTANCE(fas_fas) *cohorts; static CK_COHORT_INSTANCE(fas_fas) *cohorts;
static CK_RW_COHORT_INSTANCE(fas_fas) rw_cohort = CK_RW_COHORT_INITIALIZER; static LOCK_INSTANCE(fas_fas) rw_cohort = LOCK_INITIALIZER;
static int n_cohorts; static int n_cohorts;
static void * static void *
@ -97,7 +98,7 @@ thread(void *null CK_CC_UNUSED)
cohort = cohorts + (core / (int)(a.delta)) % n_cohorts; cohort = cohorts + (core / (int)(a.delta)) % n_cohorts;
while (i--) { while (i--) {
CK_RW_COHORT_WRITE_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); WRITE_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
{ {
l = ck_pr_load_uint(&locked); l = ck_pr_load_uint(&locked);
if (l != 0) { if (l != 0) {
@ -132,16 +133,16 @@ thread(void *null CK_CC_UNUSED)
ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l);
} }
} }
CK_RW_COHORT_WRITE_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); WRITE_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
CK_RW_COHORT_READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL); READ_LOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
{ {
l = ck_pr_load_uint(&locked); l = ck_pr_load_uint(&locked);
if (l != 0) { if (l != 0) {
ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l); ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l);
} }
} }
CK_RW_COHORT_READ_UNLOCK(fas_fas, &rw_cohort); READ_UNLOCK(fas_fas, &rw_cohort, cohort, NULL, NULL);
} }
return (NULL); return (NULL);
Loading…
Cancel
Save