]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
RISC-V: Execute a PAUSE hint in spin loops
authorChristoph Müllner <christoph.muellner@vrull.eu>
Thu, 18 Apr 2024 21:58:58 +0000 (23:58 +0200)
committerAndreas K. Hüttel <dilfridge@gentoo.org>
Mon, 24 Jun 2024 19:36:49 +0000 (21:36 +0200)
The atomic_spin_nop() macro can be used to run arch-specific
code in the body of a spin loop to potentially improve efficiency.
RISC-V's Zihintpause extension includes a PAUSE instruction for
this use-case, which is encoded as a HINT, which means that it
behaves like a NOP on systems that don't implement Zihintpause.

Binutils supports Zihintpause since 2.36, so this patch uses
the ".insn" directive to keep the code compatible with older
toolchains.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
sysdeps/unix/sysv/linux/riscv/atomic-machine.h

index c1c9d949a080a56871fadae81d7c011b852f6ed1..90283d9746aae3630d0f5ecfc1977a820be9c89d 100644 (file)
 # error "ISAs that do not subsume the A extension are not supported"
 #endif /* !__riscv_atomic */
 
+/* Execute a PAUSE hint when spinning.  */
+#define atomic_spin_nop() __asm(".insn i 0x0f, 0, x0, x0, 0x010")
+
 #endif /* bits/atomic.h */