Commit cf9bfe55 authored by Jayachandran C's avatar Jayachandran C Committed by Ralf Baechle

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 a08489c5 "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: default avatarJayachandran C <jchandra@broadcom.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/4216/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 5a670445
...@@ -12,16 +12,16 @@ ...@@ -12,16 +12,16 @@
#ifdef CONFIG_SYNC_R4K #ifdef CONFIG_SYNC_R4K
extern void synchronise_count_master(void); extern void synchronise_count_master(int cpu);
extern void synchronise_count_slave(void); extern void synchronise_count_slave(int cpu);
#else #else
static inline void synchronise_count_master(void) static inline void synchronise_count_master(int cpu)
{ {
} }
static inline void synchronise_count_slave(void) static inline void synchronise_count_slave(int cpu)
{ {
} }
......
...@@ -130,7 +130,7 @@ asmlinkage __cpuinit void start_secondary(void) ...@@ -130,7 +130,7 @@ asmlinkage __cpuinit void start_secondary(void)
cpu_set(cpu, cpu_callin_map); cpu_set(cpu, cpu_callin_map);
synchronise_count_slave(); synchronise_count_slave(cpu);
/* /*
* irq will be enabled in ->smp_finish(), enabling it too early * irq will be enabled in ->smp_finish(), enabling it too early
...@@ -173,7 +173,6 @@ void smp_send_stop(void) ...@@ -173,7 +173,6 @@ void smp_send_stop(void)
void __init smp_cpus_done(unsigned int max_cpus) void __init smp_cpus_done(unsigned int max_cpus)
{ {
mp_ops->cpus_done(); mp_ops->cpus_done();
synchronise_count_master();
} }
/* called from main before smp_init() */ /* called from main before smp_init() */
...@@ -206,6 +205,7 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle) ...@@ -206,6 +205,7 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle)
while (!cpu_isset(cpu, cpu_callin_map)) while (!cpu_isset(cpu, cpu_callin_map))
udelay(100); udelay(100);
synchronise_count_master(cpu);
return 0; return 0;
} }
......
...@@ -28,12 +28,11 @@ static atomic_t __cpuinitdata count_reference = ATOMIC_INIT(0); ...@@ -28,12 +28,11 @@ static atomic_t __cpuinitdata count_reference = ATOMIC_INIT(0);
#define COUNTON 100 #define COUNTON 100
#define NR_LOOPS 5 #define NR_LOOPS 5
void __cpuinit synchronise_count_master(void) void __cpuinit synchronise_count_master(int cpu)
{ {
int i; int i;
unsigned long flags; unsigned long flags;
unsigned int initcount; unsigned int initcount;
int nslaves;
#ifdef CONFIG_MIPS_MT_SMTC #ifdef CONFIG_MIPS_MT_SMTC
/* /*
...@@ -43,8 +42,7 @@ void __cpuinit synchronise_count_master(void) ...@@ -43,8 +42,7 @@ void __cpuinit synchronise_count_master(void)
return; return;
#endif #endif
printk(KERN_INFO "Synchronize counters across %u CPUs: ", printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu);
num_online_cpus());
local_irq_save(flags); local_irq_save(flags);
...@@ -52,7 +50,7 @@ void __cpuinit synchronise_count_master(void) ...@@ -52,7 +50,7 @@ void __cpuinit synchronise_count_master(void)
* Notify the slaves that it's time to start * Notify the slaves that it's time to start
*/ */
atomic_set(&count_reference, read_c0_count()); atomic_set(&count_reference, read_c0_count());
atomic_set(&count_start_flag, 1); atomic_set(&count_start_flag, cpu);
smp_wmb(); smp_wmb();
/* Count will be initialised to current timer for all CPU's */ /* Count will be initialised to current timer for all CPU's */
...@@ -69,10 +67,9 @@ void __cpuinit synchronise_count_master(void) ...@@ -69,10 +67,9 @@ void __cpuinit synchronise_count_master(void)
* two CPUs. * two CPUs.
*/ */
nslaves = num_online_cpus()-1;
for (i = 0; i < NR_LOOPS; i++) { for (i = 0; i < NR_LOOPS; i++) {
/* slaves loop on '!= ncpus' */ /* slaves loop on '!= 2' */
while (atomic_read(&count_count_start) != nslaves) while (atomic_read(&count_count_start) != 1)
mb(); mb();
atomic_set(&count_count_stop, 0); atomic_set(&count_count_stop, 0);
smp_wmb(); smp_wmb();
...@@ -89,7 +86,7 @@ void __cpuinit synchronise_count_master(void) ...@@ -89,7 +86,7 @@ void __cpuinit synchronise_count_master(void)
/* /*
* Wait for all slaves to leave the synchronization point: * Wait for all slaves to leave the synchronization point:
*/ */
while (atomic_read(&count_count_stop) != nslaves) while (atomic_read(&count_count_stop) != 1)
mb(); mb();
atomic_set(&count_count_start, 0); atomic_set(&count_count_start, 0);
smp_wmb(); smp_wmb();
...@@ -97,6 +94,7 @@ void __cpuinit synchronise_count_master(void) ...@@ -97,6 +94,7 @@ void __cpuinit synchronise_count_master(void)
} }
/* Arrange for an interrupt in a short while */ /* Arrange for an interrupt in a short while */
write_c0_compare(read_c0_count() + COUNTON); write_c0_compare(read_c0_count() + COUNTON);
atomic_set(&count_start_flag, 0);
local_irq_restore(flags); local_irq_restore(flags);
...@@ -108,11 +106,10 @@ void __cpuinit synchronise_count_master(void) ...@@ -108,11 +106,10 @@ void __cpuinit synchronise_count_master(void)
printk("done.\n"); printk("done.\n");
} }
void __cpuinit synchronise_count_slave(void) void __cpuinit synchronise_count_slave(int cpu)
{ {
int i; int i;
unsigned int initcount; unsigned int initcount;
int ncpus;
#ifdef CONFIG_MIPS_MT_SMTC #ifdef CONFIG_MIPS_MT_SMTC
/* /*
...@@ -127,16 +124,15 @@ void __cpuinit synchronise_count_slave(void) ...@@ -127,16 +124,15 @@ void __cpuinit synchronise_count_slave(void)
* so we first wait for the master to say everyone is ready * so we first wait for the master to say everyone is ready
*/ */
while (!atomic_read(&count_start_flag)) while (atomic_read(&count_start_flag) != cpu)
mb(); mb();
/* Count will be initialised to next expire for all CPU's */ /* Count will be initialised to next expire for all CPU's */
initcount = atomic_read(&count_reference); initcount = atomic_read(&count_reference);
ncpus = num_online_cpus();
for (i = 0; i < NR_LOOPS; i++) { for (i = 0; i < NR_LOOPS; i++) {
atomic_inc(&count_count_start); atomic_inc(&count_count_start);
while (atomic_read(&count_count_start) != ncpus) while (atomic_read(&count_count_start) != 2)
mb(); mb();
/* /*
...@@ -146,7 +142,7 @@ void __cpuinit synchronise_count_slave(void) ...@@ -146,7 +142,7 @@ void __cpuinit synchronise_count_slave(void)
write_c0_count(initcount); write_c0_count(initcount);
atomic_inc(&count_count_stop); atomic_inc(&count_count_stop);
while (atomic_read(&count_count_stop) != ncpus) while (atomic_read(&count_count_stop) != 2)
mb(); mb();
} }
/* Arrange for an interrupt in a short while */ /* Arrange for an interrupt in a short while */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment