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 ecfe7670dbfd1443474aaaf58fc6583f5d7534d1
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Tue Nov 10 09:41:04 2026 +0800

    spinlock: add UP_RELAX() arch hook
    
    A busy-wait spin loop hammers the interconnect and the pipeline: it
    keeps polling the lock line although nothing can progress until the
    owner releases, which wastes bus and cache-coherency bandwidth and
    power even though no thread ever sleeps.
    
    Add the UP_RELAX() arch hook with an empty fallback: an optional
    relax hint executed while spinning that reduces pipeline and bus
    contention but does not sleep, so unlocking needs no wake event.  An
    architecture opts in by defining the hook; where it is undefined the
    loop degenerates to a plain busy wait.  Arch implementations follow in
    the next commits.
    
    Evidence: spin-wait loop hints are recommended by the CPU manuals,
    e.g. Intel64 and IA-32 Architectures Software Developer's Manual,
    Volume 2, "PAUSE - Spin Loop Hint": "it is recommended that a PAUSE
    instruction be placed in all spin-wait loops", and the RISC-V
    Instruction Set Manual (Unprivileged ISA), "Zihintpause" extension:
    "It is recommended that a pause instruction generally be included in
    the code sequence for a spin-wait loop".
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 include/nuttx/arch.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 405fa92af6c..7430db32dc6 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -135,6 +135,10 @@
 #  define UP_SEV()
 #endif
 
+#if !defined(UP_RELAX)
+#  define UP_RELAX()
+#endif
+
 #ifdef CONFIG_SMP
 #  define SMP_MB()  UP_DMB()
 #  define SMP_RMB() UP_RMB()

Reply via email to