Skip to content

Commit

Permalink
MIPS: Synchronize MIPS count one CPU at a time
Browse files Browse the repository at this point in the history
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 a08489c "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>
  • Loading branch information
Jayachandran C authored and Ralf Baechle committed Aug 17, 2012
1 parent 5a67044 commit cf9bfe5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
8 changes: 4 additions & 4 deletions arch/mips/include/asm/r4k-timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

#ifdef CONFIG_SYNC_R4K

extern void synchronise_count_master(void);
extern void synchronise_count_slave(void);
extern void synchronise_count_master(int cpu);
extern void synchronise_count_slave(int cpu);

#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)
{
}

Expand Down
4 changes: 2 additions & 2 deletions arch/mips/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ asmlinkage __cpuinit void start_secondary(void)

cpu_set(cpu, cpu_callin_map);

synchronise_count_slave();
synchronise_count_slave(cpu);

/*
* irq will be enabled in ->smp_finish(), enabling it too early
Expand Down Expand Up @@ -173,7 +173,6 @@ void smp_send_stop(void)
void __init smp_cpus_done(unsigned int max_cpus)
{
mp_ops->cpus_done();
synchronise_count_master();
}

/* called from main before smp_init() */
Expand Down Expand Up @@ -206,6 +205,7 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle)
while (!cpu_isset(cpu, cpu_callin_map))
udelay(100);

synchronise_count_master(cpu);
return 0;
}

Expand Down
26 changes: 11 additions & 15 deletions arch/mips/kernel/sync-r4k.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ static atomic_t __cpuinitdata count_reference = ATOMIC_INIT(0);
#define COUNTON 100
#define NR_LOOPS 5

void __cpuinit synchronise_count_master(void)
void __cpuinit synchronise_count_master(int cpu)
{
int i;
unsigned long flags;
unsigned int initcount;
int nslaves;

#ifdef CONFIG_MIPS_MT_SMTC
/*
Expand All @@ -43,16 +42,15 @@ void __cpuinit synchronise_count_master(void)
return;
#endif

printk(KERN_INFO "Synchronize counters across %u CPUs: ",
num_online_cpus());
printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu);

local_irq_save(flags);

/*
* Notify the slaves that it's time to start
*/
atomic_set(&count_reference, read_c0_count());
atomic_set(&count_start_flag, 1);
atomic_set(&count_start_flag, cpu);
smp_wmb();

/* Count will be initialised to current timer for all CPU's */
Expand All @@ -69,10 +67,9 @@ void __cpuinit synchronise_count_master(void)
* two CPUs.
*/

nslaves = num_online_cpus()-1;
for (i = 0; i < NR_LOOPS; i++) {
/* slaves loop on '!= ncpus' */
while (atomic_read(&count_count_start) != nslaves)
/* slaves loop on '!= 2' */
while (atomic_read(&count_count_start) != 1)
mb();
atomic_set(&count_count_stop, 0);
smp_wmb();
Expand All @@ -89,14 +86,15 @@ void __cpuinit synchronise_count_master(void)
/*
* Wait for all slaves to leave the synchronization point:
*/
while (atomic_read(&count_count_stop) != nslaves)
while (atomic_read(&count_count_stop) != 1)
mb();
atomic_set(&count_count_start, 0);
smp_wmb();
atomic_inc(&count_count_stop);
}
/* Arrange for an interrupt in a short while */
write_c0_compare(read_c0_count() + COUNTON);
atomic_set(&count_start_flag, 0);

local_irq_restore(flags);

Expand All @@ -108,11 +106,10 @@ void __cpuinit synchronise_count_master(void)
printk("done.\n");
}

void __cpuinit synchronise_count_slave(void)
void __cpuinit synchronise_count_slave(int cpu)
{
int i;
unsigned int initcount;
int ncpus;

#ifdef CONFIG_MIPS_MT_SMTC
/*
Expand All @@ -127,16 +124,15 @@ void __cpuinit synchronise_count_slave(void)
* 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();

/* Count will be initialised to next expire for all CPU's */
initcount = atomic_read(&count_reference);

ncpus = num_online_cpus();
for (i = 0; i < NR_LOOPS; i++) {
atomic_inc(&count_count_start);
while (atomic_read(&count_count_start) != ncpus)
while (atomic_read(&count_count_start) != 2)
mb();

/*
Expand All @@ -146,7 +142,7 @@ void __cpuinit synchronise_count_slave(void)
write_c0_count(initcount);

atomic_inc(&count_count_stop);
while (atomic_read(&count_count_stop) != ncpus)
while (atomic_read(&count_count_stop) != 2)
mb();
}
/* Arrange for an interrupt in a short while */
Expand Down

0 comments on commit cf9bfe5

Please sign in to comment.