RISC-V: Execute a PAUSE hint in spin loops

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>
This commit is contained in:
Christoph Müllner 2024-04-18 23:58:58 +02:00 committed by Andreas K. Hüttel
parent 9e06e4a43b
commit 81c7f6193c
No known key found for this signature in database
GPG Key ID: DC2B16215ED5412A

View File

@ -178,4 +178,7 @@
# 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 */