powerpc: use spin loop primitives in some functions
authorNicholas Piggin <npiggin@gmail.com>
Tue, 6 Jun 2017 13:08:32 +0000 (23:08 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 2 Jul 2017 10:40:24 +0000 (20:40 +1000)
Use the different spin loop primitives in some simple powerpc
spin loops, including those which will spin as a common case.

This will help to test the spin loop primitives before more
conversions are done.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Add some includes of <linux/processor.h>]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/delay.h
arch/powerpc/kernel/smp.c
arch/powerpc/kernel/time.c
arch/powerpc/mm/hash_native_64.c

index 52e4d54da2a9845d16db0773ca81310178707723..3df4417dd9c8361fe95ff952c1491ad4c1b0a8ca 100644 (file)
@@ -2,6 +2,7 @@
 #define _ASM_POWERPC_DELAY_H
 #ifdef __KERNEL__
 
+#include <linux/processor.h>
 #include <asm/time.h>
 
 /*
@@ -58,11 +59,18 @@ extern void udelay(unsigned long usecs);
        typeof(condition) __ret;                                               \
        unsigned long __loops = tb_ticks_per_usec * timeout;                   \
        unsigned long __start = get_tbl();                                     \
-       while (!(__ret = (condition)) && (tb_ticks_since(__start) <= __loops)) \
-               if (delay)                                                     \
+                                                                               \
+       if (delay) {                                                           \
+               while (!(__ret = (condition)) &&                               \
+                               (tb_ticks_since(__start) <= __loops))          \
                        udelay(delay);                                         \
-               else                                                           \
-                       cpu_relax();                                           \
+       } else {                                                               \
+               spin_begin();                                                  \
+               while (!(__ret = (condition)) &&                               \
+                               (tb_ticks_since(__start) <= __loops))          \
+                       spin_cpu_relax();                                      \
+               spin_end();                                                    \
+       }                                                                      \
        if (!__ret)                                                            \
                __ret = (condition);                                           \
        __ret;                                                                 \
index 418019728efa23788bd85c25ce94380e7c8c5e29..a975ddf772001974a3299a90772370a71965a804 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/notifier.h>
 #include <linux/topology.h>
 #include <linux/profile.h>
+#include <linux/processor.h>
 
 #include <asm/ptrace.h>
 #include <linux/atomic.h>
@@ -767,8 +768,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
                smp_ops->give_timebase();
 
        /* Wait until cpu puts itself in the online & active maps */
-       while (!cpu_online(cpu))
-               cpu_relax();
+       spin_until_cond(cpu_online(cpu));
 
        return 0;
 }
index 0cc0dad905d57e33c1b119cf3e629362a0c83cc2..fe6f3a28545578524045a6f8583e691b233f3738 100644 (file)
 #include <linux/suspend.h>
 #include <linux/rtc.h>
 #include <linux/sched/cputime.h>
+#include <linux/processor.h>
 #include <asm/trace.h>
 
 #include <asm/io.h>
-#include <asm/processor.h>
 #include <asm/nvram.h>
 #include <asm/cache.h>
 #include <asm/machdep.h>
@@ -442,6 +442,7 @@ void __delay(unsigned long loops)
        unsigned long start;
        int diff;
 
+       spin_begin();
        if (__USE_RTC()) {
                start = get_rtcl();
                do {
@@ -449,13 +450,14 @@ void __delay(unsigned long loops)
                        diff = get_rtcl() - start;
                        if (diff < 0)
                                diff += 1000000000;
+                       spin_cpu_relax();
                } while (diff < loops);
        } else {
                start = get_tbl();
                while (get_tbl() - start < loops)
-                       HMT_low();
-               HMT_medium();
+                       spin_cpu_relax();
        }
+       spin_end();
 }
 EXPORT_SYMBOL(__delay);
 
index bdaac28193f7d4374e73b69e1361e96e0ef770f9..fbd1acc3b8d91f88006c09c233402f5151f90866 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/spinlock.h>
 #include <linux/bitops.h>
 #include <linux/of.h>
+#include <linux/processor.h>
 #include <linux/threads.h>
 #include <linux/smp.h>
 
@@ -184,8 +185,10 @@ static inline void native_lock_hpte(struct hash_pte *hptep)
        while (1) {
                if (!test_and_set_bit_lock(HPTE_LOCK_BIT, word))
                        break;
+               spin_begin();
                while(test_bit(HPTE_LOCK_BIT, word))
-                       cpu_relax();
+                       spin_cpu_relax();
+               spin_end();
        }
 }