diff --git a/include/ck_cohort.h b/include/ck_cohort.h index c5bf00d..5db1a4c 100644 --- a/include/ck_cohort.h +++ b/include/ck_cohort.h @@ -28,6 +28,11 @@ #ifndef _CK_COHORT_H #define _CK_COHORT_H +/* This is an implementation of lock cohorts as described in: + * Dice, D.; Marathe, V.; and Shavit, N. 2012. + * Lock Cohorting: A General Technique for Designing NUMA Locks + */ + #include #include #include @@ -39,13 +44,13 @@ #define CK_COHORT_NAME(N) ck_cohort_##N #define CK_COHORT_INSTANCE(N) struct CK_COHORT_NAME(N) -#define CK_COHORT_INIT(N, C, GL, LL) ck_cohort_##N##_init(C, GL, LL) +#define CK_COHORT_INIT(N, C, GL, LL, P) ck_cohort_##N##_init(C, GL, LL, P) #define CK_COHORT_LOCK(N, C, GC, LC) ck_cohort_##N##_lock(C, GC, LC) #define CK_COHORT_UNLOCK(N, C, GC, LC) ck_cohort_##N##_unlock(C, GC, LC) #define CK_COHORT_PROTOTYPE(N, GT, GL, GU, LT, LL, LU) \ \ - struct CK_COHORT_NAME(N) { \ + CK_COHORT_INSTANCE(N) { \ GT *global_lock; \ LT *local_lock; \ unsigned int release_state; \ @@ -56,16 +61,15 @@ \ CK_CC_INLINE static void \ ck_cohort_##N##_init(struct ck_cohort_##N *cohort, \ - GT *global_lock, LT *local_lock) \ + GT *global_lock, LT *local_lock, unsigned int pass_limit) \ { \ ck_pr_store_ptr(&cohort->global_lock, global_lock); \ ck_pr_store_ptr(&cohort->local_lock, local_lock); \ ck_pr_store_uint(&cohort->release_state, \ - CK_COHORT_RELEASE_STATE_GLOBAL); \ + CK_COHORT_RELEASE_STATE_GLOBAL); \ ck_pr_store_uint(&cohort->waiting_threads, 0); \ ck_pr_store_uint(&cohort->acquire_count, 0); \ - ck_pr_store_uint(&cohort->local_pass_limit, \ - CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT); \ + ck_pr_store_uint(&cohort->local_pass_limit, pass_limit); \ return; \ } \ \ diff --git a/regressions/ck_cohort/benchmark/throughput.c b/regressions/ck_cohort/benchmark/throughput.c index a1fb319..f9f53d3 100644 --- a/regressions/ck_cohort/benchmark/throughput.c +++ b/regressions/ck_cohort/benchmark/throughput.c @@ -187,7 +187,8 @@ main(int argc, char *argv[]) fprintf(stderr, "Creating cohorts..."); for (i = 0 ; i < n_cohorts ; i++) { - CK_COHORT_INIT(ticket_ticket, cohorts + i, &global_ticket_lock, local_fas_locks + i); + CK_COHORT_INIT(ticket_ticket, cohorts + i, &global_ticket_lock, local_fas_locks + i, + CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT); } fprintf(stderr, "done\n"); diff --git a/regressions/ck_cohort/ck_cohort.h b/regressions/ck_cohort/ck_cohort.h index 1112812..3194311 100644 --- a/regressions/ck_cohort/ck_cohort.h +++ b/regressions/ck_cohort/ck_cohort.h @@ -19,6 +19,7 @@ ck_spinlock_fas_t, ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context,\ ck_spinlock_fas_t, ck_spinlock_fas_lock_with_context, ck_spinlock_fas_unlock_with_context)\ static CK_COHORT_INSTANCE(fas_fas) CK_CC_CACHELINE cohort = CK_COHORT_INITIALIZER -#define LOCK_INIT CK_COHORT_INIT(fas_fas, &cohort, &global_fas_lock, &local_fas_lock) +#define LOCK_INIT CK_COHORT_INIT(fas_fas, &cohort, &global_fas_lock, &local_fas_lock,\ + CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT) #define LOCK CK_COHORT_LOCK(fas_fas, &cohort, NULL, NULL) #define UNLOCK CK_COHORT_UNLOCK(fas_fas, &cohort, NULL, NULL) diff --git a/regressions/ck_cohort/validate/validate.c b/regressions/ck_cohort/validate/validate.c index 579154f..8b31e90 100644 --- a/regressions/ck_cohort/validate/validate.c +++ b/regressions/ck_cohort/validate/validate.c @@ -157,7 +157,8 @@ main(int argc, char *argv[]) cohorts = malloc(sizeof(CK_COHORT_INSTANCE(fas_fas)) * n_cohorts); for (i = 0 ; i < n_cohorts ; i++) { local_lock = malloc(sizeof(ck_spinlock_fas_t)); - CK_COHORT_INIT(fas_fas, cohorts + i, &global_fas_lock, local_lock); + CK_COHORT_INIT(fas_fas, cohorts + i, &global_fas_lock, local_lock, + CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT); } fprintf(stderr, "done\n");