diff options
author | Jayachandran C <jchandra@broadcom.com> | 2012-08-14 09:26:13 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2012-08-17 04:57:28 -0400 |
commit | cf9bfe55f24973a8f40e2c922a7e82cf09e486fd (patch) | |
tree | 86d7da54a921d0545e396a1d6da229b15d3e44e9 /arch | |
parent | 5a6704454a68ab6e27e4fc5b82818a8c5733bf29 (diff) |
MIPS: Synchronize MIPS count one CPU at a time
The current implementation of synchronise_count_{master,slave} blocks
slave CPUs in early boot until all of them come up. This no longer
works because blocking a CPU with interrupts off after notifying the
CPU to be online causes problems with the current kernel.
Specifically, after the workqueue changes
(commit a08489c569dc1 "Pull workqueue changes from Tejun Heo")
the CPU_ONLINE notification callback workqueue_cpu_up_callback()
will hang on wait_for_completion(&idle_rebind.done), if the slave
CPUs are blocked for synchronize_count_slave().
The changes are to update synchronize_count_{master,slave}() to handle
one CPU at a time and to call synchronise_count_master() in __cpu_up()
so that the CPU_ONLINE notification goes out only after the COP0 COUNT
register is synchronized.
[ralf@linux-mips.org: This matter only to those few platforms which are
using the cp0 counter as their clocksource which are XLP, XLR and MIPS'
CMP solution.]
Signed-off-by: Jayachandran C <jchandra@broadcom.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/4216/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/mips/include/asm/r4k-timer.h | 8 | ||||
-rw-r--r-- | arch/mips/kernel/smp.c | 4 | ||||
-rw-r--r-- | arch/mips/kernel/sync-r4k.c | 26 |
3 files changed, 17 insertions, 21 deletions
diff --git a/arch/mips/include/asm/r4k-timer.h b/arch/mips/include/asm/r4k-timer.h index a37d12b3b61c..afe9e0e03fe9 100644 --- a/arch/mips/include/asm/r4k-timer.h +++ b/arch/mips/include/asm/r4k-timer.h | |||
@@ -12,16 +12,16 @@ | |||
12 | 12 | ||
13 | #ifdef CONFIG_SYNC_R4K | 13 | #ifdef CONFIG_SYNC_R4K |
14 | 14 | ||
15 | extern void synchronise_count_master(void); | 15 | extern void synchronise_count_master(int cpu); |
16 | extern void synchronise_count_slave(void); | 16 | extern void synchronise_count_slave(int cpu); |
17 | 17 | ||
18 | #else | 18 | #else |
19 | 19 | ||
20 | static inline void synchronise_count_master(void) | 20 | static inline void synchronise_count_master(int cpu) |
21 | { | 21 | { |
22 | } | 22 | } |
23 | 23 | ||
24 | static inline void synchronise_count_slave(void) | 24 | static inline void synchronise_count_slave(int cpu) |
25 | { | 25 | { |
26 | } | 26 | } |
27 | 27 | ||
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index 31637d8c8738..9005bf9fb859 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c | |||
@@ -130,7 +130,7 @@ asmlinkage __cpuinit void start_secondary(void) | |||
130 | 130 | ||
131 | cpu_set(cpu, cpu_callin_map); | 131 | cpu_set(cpu, cpu_callin_map); |
132 | 132 | ||
133 | synchronise_count_slave(); | 133 | synchronise_count_slave(cpu); |
134 | 134 | ||
135 | /* | 135 | /* |
136 | * irq will be enabled in ->smp_finish(), enabling it too early | 136 | * irq will be enabled in ->smp_finish(), enabling it too early |
@@ -173,7 +173,6 @@ void smp_send_stop(void) | |||
173 | void __init smp_cpus_done(unsigned int max_cpus) | 173 | void __init smp_cpus_done(unsigned int max_cpus) |
174 | { | 174 | { |
175 | mp_ops->cpus_done(); | 175 | mp_ops->cpus_done(); |
176 | synchronise_count_master(); | ||
177 | } | 176 | } |
178 | 177 | ||
179 | /* called from main before smp_init() */ | 178 | /* called from main before smp_init() */ |
@@ -206,6 +205,7 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle) | |||
206 | while (!cpu_isset(cpu, cpu_callin_map)) | 205 | while (!cpu_isset(cpu, cpu_callin_map)) |
207 | udelay(100); | 206 | udelay(100); |
208 | 207 | ||
208 | synchronise_count_master(cpu); | ||
209 | return 0; | 209 | return 0; |
210 | } | 210 | } |
211 | 211 | ||
diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c index 842d55e411fd..7f1eca3858de 100644 --- a/arch/mips/kernel/sync-r4k.c +++ b/arch/mips/kernel/sync-r4k.c | |||
@@ -28,12 +28,11 @@ static atomic_t __cpuinitdata count_reference = ATOMIC_INIT(0); | |||
28 | #define COUNTON 100 | 28 | #define COUNTON 100 |
29 | #define NR_LOOPS 5 | 29 | #define NR_LOOPS 5 |
30 | 30 | ||
31 | void __cpuinit synchronise_count_master(void) | 31 | void __cpuinit synchronise_count_master(int cpu) |
32 | { | 32 | { |
33 | int i; | 33 | int i; |
34 | unsigned long flags; | 34 | unsigned long flags; |
35 | unsigned int initcount; | 35 | unsigned int initcount; |
36 | int nslaves; | ||
37 | 36 | ||
38 | #ifdef CONFIG_MIPS_MT_SMTC | 37 | #ifdef CONFIG_MIPS_MT_SMTC |
39 | /* | 38 | /* |
@@ -43,8 +42,7 @@ void __cpuinit synchronise_count_master(void) | |||
43 | return; | 42 | return; |
44 | #endif | 43 | #endif |
45 | 44 | ||
46 | printk(KERN_INFO "Synchronize counters across %u CPUs: ", | 45 | printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu); |
47 | num_online_cpus()); | ||
48 | 46 | ||
49 | local_irq_save(flags); | 47 | local_irq_save(flags); |
50 | 48 | ||
@@ -52,7 +50,7 @@ void __cpuinit synchronise_count_master(void) | |||
52 | * Notify the slaves that it's time to start | 50 | * Notify the slaves that it's time to start |
53 | */ | 51 | */ |
54 | atomic_set(&count_reference, read_c0_count()); | 52 | atomic_set(&count_reference, read_c0_count()); |
55 | atomic_set(&count_start_flag, 1); | 53 | atomic_set(&count_start_flag, cpu); |
56 | smp_wmb(); | 54 | smp_wmb(); |
57 | 55 | ||
58 | /* Count will be initialised to current timer for all CPU's */ | 56 | /* Count will be initialised to current timer for all CPU's */ |
@@ -69,10 +67,9 @@ void __cpuinit synchronise_count_master(void) | |||
69 | * two CPUs. | 67 | * two CPUs. |
70 | */ | 68 | */ |
71 | 69 | ||
72 | nslaves = num_online_cpus()-1; | ||
73 | for (i = 0; i < NR_LOOPS; i++) { | 70 | for (i = 0; i < NR_LOOPS; i++) { |
74 | /* slaves loop on '!= ncpus' */ | 71 | /* slaves loop on '!= 2' */ |
75 | while (atomic_read(&count_count_start) != nslaves) | 72 | while (atomic_read(&count_count_start) != 1) |
76 | mb(); | 73 | mb(); |
77 | atomic_set(&count_count_stop, 0); | 74 | atomic_set(&count_count_stop, 0); |
78 | smp_wmb(); | 75 | smp_wmb(); |
@@ -89,7 +86,7 @@ void __cpuinit synchronise_count_master(void) | |||
89 | /* | 86 | /* |
90 | * Wait for all slaves to leave the synchronization point: | 87 | * Wait for all slaves to leave the synchronization point: |
91 | */ | 88 | */ |
92 | while (atomic_read(&count_count_stop) != nslaves) | 89 | while (atomic_read(&count_count_stop) != 1) |
93 | mb(); | 90 | mb(); |
94 | atomic_set(&count_count_start, 0); | 91 | atomic_set(&count_count_start, 0); |
95 | smp_wmb(); | 92 | smp_wmb(); |
@@ -97,6 +94,7 @@ void __cpuinit synchronise_count_master(void) | |||
97 | } | 94 | } |
98 | /* Arrange for an interrupt in a short while */ | 95 | /* Arrange for an interrupt in a short while */ |
99 | write_c0_compare(read_c0_count() + COUNTON); | 96 | write_c0_compare(read_c0_count() + COUNTON); |
97 | atomic_set(&count_start_flag, 0); | ||
100 | 98 | ||
101 | local_irq_restore(flags); | 99 | local_irq_restore(flags); |
102 | 100 | ||
@@ -108,11 +106,10 @@ void __cpuinit synchronise_count_master(void) | |||
108 | printk("done.\n"); | 106 | printk("done.\n"); |
109 | } | 107 | } |
110 | 108 | ||
111 | void __cpuinit synchronise_count_slave(void) | 109 | void __cpuinit synchronise_count_slave(int cpu) |
112 | { | 110 | { |
113 | int i; | 111 | int i; |
114 | unsigned int initcount; | 112 | unsigned int initcount; |
115 | int ncpus; | ||
116 | 113 | ||
117 | #ifdef CONFIG_MIPS_MT_SMTC | 114 | #ifdef CONFIG_MIPS_MT_SMTC |
118 | /* | 115 | /* |
@@ -127,16 +124,15 @@ void __cpuinit synchronise_count_slave(void) | |||
127 | * so we first wait for the master to say everyone is ready | 124 | * so we first wait for the master to say everyone is ready |
128 | */ | 125 | */ |
129 | 126 | ||
130 | while (!atomic_read(&count_start_flag)) | 127 | while (atomic_read(&count_start_flag) != cpu) |
131 | mb(); | 128 | mb(); |
132 | 129 | ||
133 | /* Count will be initialised to next expire for all CPU's */ | 130 | /* Count will be initialised to next expire for all CPU's */ |
134 | initcount = atomic_read(&count_reference); | 131 | initcount = atomic_read(&count_reference); |
135 | 132 | ||
136 | ncpus = num_online_cpus(); | ||
137 | for (i = 0; i < NR_LOOPS; i++) { | 133 | for (i = 0; i < NR_LOOPS; i++) { |
138 | atomic_inc(&count_count_start); | 134 | atomic_inc(&count_count_start); |
139 | while (atomic_read(&count_count_start) != ncpus) | 135 | while (atomic_read(&count_count_start) != 2) |
140 | mb(); | 136 | mb(); |
141 | 137 | ||
142 | /* | 138 | /* |
@@ -146,7 +142,7 @@ void __cpuinit synchronise_count_slave(void) | |||
146 | write_c0_count(initcount); | 142 | write_c0_count(initcount); |
147 | 143 | ||
148 | atomic_inc(&count_count_stop); | 144 | atomic_inc(&count_count_stop); |
149 | while (atomic_read(&count_count_stop) != ncpus) | 145 | while (atomic_read(&count_count_stop) != 2) |
150 | mb(); | 146 | mb(); |
151 | } | 147 | } |
152 | /* Arrange for an interrupt in a short while */ | 148 | /* Arrange for an interrupt in a short while */ |