From 38fa36952d36a2db5fdc03f4f4a00bc64da763ba Mon Sep 17 00:00:00 2001 From: XieJiSS Date: Tue, 24 Oct 2023 11:03:43 +0800 Subject: [PATCH 1/2] Implement pause support for RISC-V see-also: https://github.com/torvalds/linux/blob/84186fcb834ecc55604efaf383e17e6b5e9baa50/arch/riscv/include/asm/vdso/processor.h#L9 --- include/boost/atomic/detail/pause.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/boost/atomic/detail/pause.hpp b/include/boost/atomic/detail/pause.hpp index efdfb62b..c82ea7a3 100644 --- a/include/boost/atomic/detail/pause.hpp +++ b/include/boost/atomic/detail/pause.hpp @@ -48,6 +48,16 @@ BOOST_FORCEINLINE void pause() BOOST_NOEXCEPT __asm__ __volatile__("pause;" : : : "memory"); #elif (defined(__ARM_ARCH) && __ARM_ARCH >= 8) || defined(__ARM_ARCH_8A__) || defined(__aarch64__) __asm__ __volatile__("yield;" : : : "memory"); +#elif defined(__riscv) && __riscv_xlen == 64 +#if defined(__riscv_zihintpause) + __asm__ __volatile__("pause" : : : "memory"); +#elif defined(__riscv_muldiv) + /* In lieu of a halt instruction, induce a long-latency stall. */ + __asm__ __volatile__("div %0, %0, zero" : "=r" (dummy)); +#else + /* Encoding of the pause instruction */ + __asm__ __volatile__ (".4byte 0x100000F"); +#endif #endif #endif } From ce34f076a00afd726273bef45421ba1136b43fd9 Mon Sep 17 00:00:00 2001 From: XieJiSS Date: Mon, 15 Jan 2024 13:41:29 +0800 Subject: [PATCH 2/2] fix: remove rocket-specific code introduced from the kernel --- include/boost/atomic/detail/pause.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/boost/atomic/detail/pause.hpp b/include/boost/atomic/detail/pause.hpp index c82ea7a3..0d47c927 100644 --- a/include/boost/atomic/detail/pause.hpp +++ b/include/boost/atomic/detail/pause.hpp @@ -51,9 +51,6 @@ BOOST_FORCEINLINE void pause() BOOST_NOEXCEPT #elif defined(__riscv) && __riscv_xlen == 64 #if defined(__riscv_zihintpause) __asm__ __volatile__("pause" : : : "memory"); -#elif defined(__riscv_muldiv) - /* In lieu of a halt instruction, induce a long-latency stall. */ - __asm__ __volatile__("div %0, %0, zero" : "=r" (dummy)); #else /* Encoding of the pause instruction */ __asm__ __volatile__ (".4byte 0x100000F");