This will be useful to be put inside loops.

Suggested-by: Andrew Jones <drjo...@redhat.com>
Reviewed-by: Andrew Jones <drjo...@redhat.com>
Signed-off-by: Peter Xu <pet...@redhat.com>
---
 lib/x86/asm/barrier.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/x86/asm/barrier.h b/lib/x86/asm/barrier.h
index 7c108bd..193fb4c 100644
--- a/lib/x86/asm/barrier.h
+++ b/lib/x86/asm/barrier.h
@@ -13,4 +13,15 @@
 #define smp_rmb()      barrier()
 #define smp_wmb()      barrier()
 
+/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
+static inline void rep_nop(void)
+{
+       asm volatile("rep; nop" ::: "memory");
+}
+
+static inline void cpu_relax(void)
+{
+       rep_nop();
+}
+
 #endif
-- 
2.7.4


Reply via email to