Support waiting in smp_cond_load_relaxed_timeout() via __cmpwait_relaxed(). To ensure that we wake from waiting in WFE periodically and don't block forever if there are no stores to ptr, this path is only used when the event-stream is enabled. Note that when using __cmpwait_relaxed() we ignore the timeout value, allowing an overshoot by up to the event-stream period. And, in the unlikely event that the event-stream is unavailable, fallback to spin-waiting. Define CPU_POLL_RELAX_WAITS to state that we have a waiting implementation. (Non-production environments might not have arch_timer_evtstrm_available() but we don't care about that configuration.) Note that with this we have enough to define ARCH_HAS_CPU_RELAX to indicate that we support an optimized implementation of cpu_poll_relax(). However, defer defining ARCH_HAS_CPU_RELAX as that enables polling based C-state handling, which really needs TIF_POLLING_NRFLAG. Cc: Arnd Bergmann Cc: Will Deacon Cc: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org Suggested-by: Will Deacon Acked-by: Will Deacon Reviewed-by: Catalin Marinas Signed-off-by: Ankur Arora --- Notes: - instead of defining SMP_TIMEOUT_POLL_COUNT to 1, just state that we have a waiting implementation by defining CPU_POLL_RELAX_WAITS. - update comment to that effect. arch/arm64/include/asm/barrier.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h index 9495c4441a46..d186a4558776 100644 --- a/arch/arm64/include/asm/barrier.h +++ b/arch/arm64/include/asm/barrier.h @@ -12,6 +12,7 @@ #include #include +#include #define __nops(n) ".rept " #n "\nnop\n.endr\n" #define nops(n) asm volatile(__nops(n)) @@ -219,6 +220,25 @@ do { \ (typeof(*ptr))VAL; \ }) +/* Re-declared here to avoid include dependency. */ +extern bool arch_timer_evtstrm_available(void); + +/* + * In the common case, cpu_poll_relax() sits waiting in __cmpwait_relaxed() + * for @ptr value to change. + * + * State this by defining CPU_POLL_RELAX_WAITS which enables a time-check + * optimization in smp_cond_load_{relaxed,acquire}_timeout(). + */ +#define CPU_POLL_RELAX_WAITS + +#define cpu_poll_relax(ptr, val, timeout_ns) do { \ + if (arch_timer_evtstrm_available()) \ + __cmpwait_relaxed(ptr, val); \ + else \ + cpu_relax(); \ +} while (0) + #include #endif /* __ASSEMBLER__ */ -- 2.43.7