powerpc/64: implement spin loop primitives
authorNicholas Piggin <npiggin@gmail.com>
Tue, 6 Jun 2017 13:08:31 +0000 (23:08 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 2 Jul 2017 10:40:17 +0000 (20:40 +1000)
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/processor.h

index c49165a7439c592e921d8b091e2d11bbfca9d3d4..832775771bd3e9c050ae43b9eb5ad545ddffcce9 100644 (file)
@@ -428,6 +428,26 @@ static inline unsigned long __pack_fe01(unsigned int fpmode)
 
 #ifdef CONFIG_PPC64
 #define cpu_relax()    do { HMT_low(); HMT_medium(); barrier(); } while (0)
+
+#define spin_begin()   HMT_low()
+
+#define spin_cpu_relax()       barrier()
+
+#define spin_cpu_yield()       spin_cpu_relax()
+
+#define spin_end()     HMT_medium()
+
+#define spin_until_cond(cond)                                  \
+do {                                                           \
+       if (unlikely(!(cond))) {                                \
+               spin_begin();                                   \
+               do {                                            \
+                       spin_cpu_relax();                       \
+               } while (!(cond));                              \
+               spin_end();                                     \
+       }                                                       \
+} while (0)
+
 #else
 #define cpu_relax()    barrier()
 #endif