This is an automated email from the ASF dual-hosted git repository.
chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 2c4b3cdc1 perf(butil): use isb instead of yield for cpu_relax on ARM64
(#3755)
2c4b3cdc1 is described below
commit 2c4b3cdc1574d4340f56124fc45e06d1f5800dc8
Author: James Lamb <[email protected]>
AuthorDate: Sat Nov 21 19:12:21 2026 +1100
perf(butil): use isb instead of yield for cpu_relax on ARM64 (#3755)
* test(butil): add unit test verifying cpu_relax uses isb on ARM64
Signed-off-by: James Lamb <[email protected]>
* perf(butil): use isb instead of yield for cpu_relax on ARM64
Signed-off-by: James Lamb <[email protected]>
---------
Signed-off-by: James Lamb <[email protected]>
---
src/butil/processor.h | 6 ++++--
test/cpu_unittest.cc | 14 ++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/butil/processor.h b/src/butil/processor.h
index 9219d3163..4d7d491a4 100644
--- a/src/butil/processor.h
+++ b/src/butil/processor.h
@@ -22,8 +22,10 @@
// Pause instruction to prevent excess processor bus usage, only works in GCC
#ifndef cpu_relax
-#if defined(ARCH_CPU_ARM_FAMILY)
-#define cpu_relax() asm volatile("yield\n": : :"memory")
+#if defined(ARCH_CPU_ARM64)
+# define cpu_relax() asm volatile("isb\n": : :"memory")
+#elif defined(ARCH_CPU_ARM_FAMILY)
+# define cpu_relax() asm volatile("yield\n": : :"memory")
#elif defined(ARCH_CPU_RISCV_FAMILY)
// Use the pause hint (Zihintpause extension). Encoding 0x0100000F
// (fence 0, 1) is a HINT on all RISC-V implementations: it never traps
diff --git a/test/cpu_unittest.cc b/test/cpu_unittest.cc
index e7e13abc1..46496d7cc 100644
--- a/test/cpu_unittest.cc
+++ b/test/cpu_unittest.cc
@@ -4,7 +4,10 @@
#include "butil/cpu.h"
#include "butil/build_config.h"
+#include "butil/macros.h"
+#include "butil/processor.h"
+#include <string>
#include <gtest/gtest.h>
// Tests whether we can run extended instructions represented by the CPU
@@ -95,3 +98,14 @@ TEST(CPU, RunExtendedInstructions) {
#endif
#endif
}
+
+#if defined(ARCH_CPU_ARM64)
+TEST(CPU, CpuRelaxArm64UsesIsb) {
+ for (int i = 0; i < 16; ++i) {
+ cpu_relax();
+ }
+ std::string expansion = BAIDU_SYMBOLSTR(cpu_relax());
+ EXPECT_NE(std::string::npos, expansion.find("isb")) << expansion;
+ EXPECT_EQ(std::string::npos, expansion.find("yield")) << expansion;
+}
+#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]