Skip to content

Commit 24f510b

Browse files
committed
MDEV-23633 MY_RELAX_CPU performs unnecessary compare-and-swap on ARM
This follows up MDEV-14374, which was filed against MariaDB Server 10.3. Back then, on a 48-core Qualcomm Centriq 2400, the performance of delay loops for spinloops was tested both with and without the dummy compare-and-swap operation, and it was decided to keep the dummy operation. On target architectures where nothing special is available (other than x86 (IA-32, AMD64) or POWER), we perform a dummy compare-and-swap operation. This is contrary to the idea of the x86 PAUSE instruction and the __ppc_get_timebase(), which aim to keep the memory bus idle for a while, to allow other cores to better execute code while a spinloop is waiting for something to be changed. On MariaDB Server 10.4 and another implementation of the ARMv8 ISA, omitting the dummy compare-and-swap improved performance by up to 12%. So, let us avoid the dummy compare-and-swap on ARM. For now, we are retaining the dummy compare-and-swap on other ISAs (such as SPARC, MIPS, S390x, RISC-V) because we do not have any performance data for them.
1 parent 1cda462 commit 24f510b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/my_cpu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#ifdef _WIN32
5454
#elif defined HAVE_PAUSE_INSTRUCTION
5555
#elif defined(_ARCH_PWR8)
56+
#elif defined __GNUC__ && (defined __arm__ || defined __aarch64__)
5657
#else
5758
# include "my_atomic.h"
5859
#endif
@@ -80,6 +81,9 @@ static inline void MY_RELAX_CPU(void)
8081
#endif
8182
#elif defined(_ARCH_PWR8)
8283
__ppc_get_timebase();
84+
#elif defined __GNUC__ && (defined __arm__ || defined __aarch64__)
85+
/* Mainly, prevent the compiler from optimizing away delay loops */
86+
__asm__ __volatile__ ("":::"memory")
8387
#else
8488
int32 var, oldval = 0;
8589
my_atomic_cas32_strong_explicit(&var, &oldval, 1, MY_MEMORY_ORDER_RELAXED,

0 commit comments

Comments
 (0)