From 44c0cc85496c43c0369196a5295c3be1dd5e23e9 Mon Sep 17 00:00:00 2001 From: Geoff Blake Date: Mon, 1 Nov 2021 11:26:22 -0500 Subject: [PATCH] Add spin_delay implementation for Arm processors by using a single ISB instruction. The ISB instruction induces a few ns pause on Arm CPUs, similar to the PAUSE instruction on x86. --- src/include/storage/s_lock.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index dccbd299ce..ce84a12b1e 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -337,6 +337,18 @@ tas(volatile slock_t *lock) #define S_UNLOCK(lock) __sync_lock_release(lock) +#define SPIN_DELAY() spin_delay() + +static __inline__ void +spin_delay(void) +{ + /* + * Using an ISB instruction has shown to be beneficial for + * tight spin-loops on modern Arm64 processors. + */ + __asm__ __volatile__(" isb; \n"); +} + #endif /* HAVE_GCC__SYNC_INT32_TAS */ #endif /* __arm__ || __arm || __aarch64__ || __aarch64 */ -- 2.25.1