From 571bb264b0254751f24eb2db1912b07906bba57a Mon Sep 17 00:00:00 2001 From: Paul Khuong Date: Fri, 22 Nov 2019 12:26:39 -0500 Subject: [PATCH] spinlock/fas: improve codegen for the uncontended path Mark acquisition failures as unlikely: there's no point in reaching the spinloop slow path more quickly. TESTED=existing regression tests. --- include/spinlock/fas.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/spinlock/fas.h b/include/spinlock/fas.h index 4e6c123..bfe91fe 100644 --- a/include/spinlock/fas.h +++ b/include/spinlock/fas.h @@ -77,10 +77,11 @@ CK_CC_INLINE static void ck_spinlock_fas_lock(struct ck_spinlock_fas *lock) { - while (ck_pr_fas_uint(&lock->value, true) == true) { - while (ck_pr_load_uint(&lock->value) == true) - ck_pr_stall(); - } + while (CK_CC_UNLIKELY(ck_pr_fas_uint(&lock->value, true) == true)) { + do { + ck_pr_stall(); + } while (ck_pr_load_uint(&lock->value) == true); + } ck_pr_fence_lock(); return;