From d3a033237aec51f0e2a789717d4199cb8c8c31fa Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sun, 27 Feb 2011 11:50:26 -0500 Subject: [PATCH] Avoid modulus for wrap-around calculation in ck_anderson. This change has shown a 32% reduction in latency for the reference SPARCv9 platform. --- include/ck_spinlock.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/ck_spinlock.h b/include/ck_spinlock.h index 9135386..e655a6f 100644 --- a/include/ck_spinlock.h +++ b/include/ck_spinlock.h @@ -99,7 +99,7 @@ ck_spinlock_anderson_lock(struct ck_spinlock_anderson *lock, * to reallocate beginning slots to more than one thread. To avoid this * use a compare-and-swap. */ - if (lock->wrap) { + if (lock->wrap != 0) { position = ck_pr_load_uint(&lock->next); do { @@ -108,11 +108,12 @@ ck_spinlock_anderson_lock(struct ck_spinlock_anderson *lock, else next = position + 1; } while (ck_pr_cas_uint_value(&lock->next, position, next, &position) == false); - } else - position = ck_pr_faa_uint(&lock->next, 1); - /* Make sure to wrap around. */ - position %= count; + position %= count; + } else { + position = ck_pr_faa_uint(&lock->next, 1); + position &= count - 1; + } /* Spin until slot is marked as unlocked. First slot is initialized to false. */ while (ck_pr_load_uint(&lock->slots[position].locked) == true)