-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Server Programmability
-
Programmability 2025-06-09
-
None
-
3
-
TBD
-
None
-
None
-
None
-
None
-
None
-
None
Like on the Wiredtiger storage system (https://github.com/wiredtiger/wiredtiger/pull/11961/files) it would be beneficial if ARM >= v8.5 can use the `sb` instruction instead of `isb`.
Here the occurrence I have found in the Mongo codebase: https://github.com/mongodb/mongo/blob/38069eac48d44e29205464e139d29d378cfa2cb4/src/mongo/platform/pause.h#L62
The patch can be something like:
diff --git a/src/mongo/platform/pause.h b/src/mongo/platform/pause.h index 67fe3d9439d8..6e0630d3b786 100644 --- a/src/mongo/platform/pause.h +++ b/src/mongo/platform/pause.h @@ -38,6 +38,15 @@ */ #ifndef _MSC_VER +/* ARM specific for HWCAP_SB detection at runtime */ +#if defined(__aarch64__) && defined(__linux__) +#include <sys/auxv.h> + +#ifndef HWCAP_SB +#define HWCAP_SB (1 << 29) +#endif +#endif // __aarch64__ __linux__ + #if defined(x86_64) || defined(__x86_64__) #include <xmmintrin.h> @@ -58,8 +67,30 @@ #elif defined(__aarch64__) || defined(__arm__) +static inline void arm_arch_pause(void) { +#if defined(__linux__) + static int use_spin_delay_sb = -1; + + if (__builtin_expect(use_spin_delay_sb == 1, 1)) { + __asm__ volatile(".inst 0xd50330ff" ::: "memory"); // SB instruction encoding + } + else if (use_spin_delay_sb == 0) { + __asm__ volatile("isb" ::: "memory"); + } + else { + // Initialize variable and check if SB is supported + if (getauxval(AT_HWCAP) & HWCAP_SB) + use_spin_delay_sb = 1; + else + use_spin_delay_sb = 0; + } +#else + __asm__ volatile("isb" ::: "memory"); +#endif +} + /* See https://jira.mongodb.org/browse/WT-6872 for details on using `isb` instead of `yield`. */ -#define MONGO_YIELD_CORE_FOR_SMT() __asm__ volatile("isb" ::: "memory") +#define MONGO_YIELD_CORE_FOR_SMT() arm_arch_pause() #elif defined(__s390x__)