This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 318f4d4eee076c27ea84ac561075b02e4605a1ee
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Tue Nov 10 09:41:05 2026 +0800

    arch/x86_64: define UP_RELAX() as PAUSE
    
    Busy-wait spin loops on x86_64 fall back to the empty UP_RELAX()
    hint, so a contended lock hammers the interconnect and the pipeline:
    the polling loop keeps issuing loads against the lock line although
    nothing can progress until the owner releases.
    
    Define UP_RELAX() as the PAUSE instruction, replacing the
    UP_WFE() alias that was previously mapped to the same instruction.
    PAUSE hints that the code sequence is a spin-wait loop; the processor
    uses this to avoid the memory order violation penalty on loop exit and
    to reduce the power consumed while spinning.  It does not sleep, so
    unlocking needs no wake event.
    
    Evidence: Intel64 and IA-32 Architectures Software Developer's
    Manual, Volume 2, "PAUSE - Spin Loop Hint": "The PAUSE instruction
    provides a hint to the processor that the code sequence is a spin-wait
    loop", "it is recommended that a PAUSE instruction be placed in all
    spin-wait loops" and "An additional function of the PAUSE instruction
    is to reduce the power consumed by a processor while executing a spin
    loop."  Linux uses the same hint in cpu_relax()
    (arch/x86/include/asm/vdso/processor.h).
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 arch/x86_64/include/barriers.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/x86_64/include/barriers.h b/arch/x86_64/include/barriers.h
index ec634564fc3..b155ff8c420 100644
--- a/arch/x86_64/include/barriers.h
+++ b/arch/x86_64/include/barriers.h
@@ -29,6 +29,12 @@
 #define UP_DMB() __asm__ __volatile__ ("mfence" ::: "memory")
 #define UP_RMB() __asm__ __volatile__ ("lfence" ::: "memory")
 #define UP_WMB() __asm__ __volatile__ ("sfence" ::: "memory")
-#define UP_WFE() __asm__ __volatile__ ("pause")
+
+/* Relax hint for spin waiting: PAUSE reduces bus and cache-coherency
+ * contention while polling the lock.  It does not sleep and needs no
+ * wake event.
+ */
+
+#define UP_RELAX() __asm__ __volatile__ ("pause")
 
 #endif /* __ARCH_X86_64_INCLUDE_BARRIERS_H */

Reply via email to