2008-04-29 00:14:26 +08:00
|
|
|
/*
|
|
|
|
* Count register synchronisation.
|
|
|
|
*
|
2009-06-18 07:40:34 +08:00
|
|
|
* All CPUs will have their count registers synchronised to the CPU0 next time
|
2008-04-29 00:14:26 +08:00
|
|
|
* value. This can cause a small timewarp for CPU0. All other CPU's should
|
|
|
|
* not have done anything significant (but they may have had interrupts
|
|
|
|
* enabled briefly - prom_smp_finish() should not be responsible for enabling
|
|
|
|
* interrupts...)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/irqflags.h>
|
2009-06-18 07:40:34 +08:00
|
|
|
#include <linux/cpumask.h>
|
2008-04-29 00:14:26 +08:00
|
|
|
|
2009-06-18 07:40:34 +08:00
|
|
|
#include <asm/r4k-timer.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2008-04-29 00:14:26 +08:00
|
|
|
#include <asm/barrier.h>
|
|
|
|
#include <asm/mipsregs.h>
|
|
|
|
|
2016-01-21 21:09:51 +08:00
|
|
|
static unsigned int initcount = 0;
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 21:38:59 +08:00
|
|
|
static atomic_t count_count_start = ATOMIC_INIT(0);
|
|
|
|
static atomic_t count_count_stop = ATOMIC_INIT(0);
|
2008-04-29 00:14:26 +08:00
|
|
|
|
2013-01-22 19:59:30 +08:00
|
|
|
#define COUNTON 100
|
2016-01-21 21:09:51 +08:00
|
|
|
#define NR_LOOPS 3
|
2008-04-29 00:14:26 +08:00
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 21:38:59 +08:00
|
|
|
void synchronise_count_master(int cpu)
|
2008-04-29 00:14:26 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-08-14 21:26:13 +08:00
|
|
|
printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu);
|
2008-04-29 00:14:26 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We loop a few times to get a primed instruction cache,
|
|
|
|
* then the last pass is more or less synchronised and
|
|
|
|
* the master and slaves each set their cycle counters to a known
|
|
|
|
* value all at once. This reduces the chance of having random offsets
|
|
|
|
* between the processors, and guarantees that the maximum
|
|
|
|
* delay between the cycle counters is never bigger than
|
|
|
|
* the latency of information-passing (cachelines) between
|
|
|
|
* two CPUs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NR_LOOPS; i++) {
|
2012-08-14 21:26:13 +08:00
|
|
|
/* slaves loop on '!= 2' */
|
|
|
|
while (atomic_read(&count_count_start) != 1)
|
2008-04-29 00:14:26 +08:00
|
|
|
mb();
|
|
|
|
atomic_set(&count_count_stop, 0);
|
|
|
|
smp_wmb();
|
|
|
|
|
2016-01-21 21:09:51 +08:00
|
|
|
/* Let the slave writes its count register */
|
2008-04-29 00:14:26 +08:00
|
|
|
atomic_inc(&count_count_start);
|
|
|
|
|
2016-01-21 21:09:51 +08:00
|
|
|
/* Count will be initialised to current timer */
|
|
|
|
if (i == 1)
|
|
|
|
initcount = read_c0_count();
|
|
|
|
|
2008-04-29 00:14:26 +08:00
|
|
|
/*
|
|
|
|
* Everyone initialises count in the last loop:
|
|
|
|
*/
|
|
|
|
if (i == NR_LOOPS-1)
|
|
|
|
write_c0_count(initcount);
|
|
|
|
|
|
|
|
/*
|
2016-01-21 21:09:51 +08:00
|
|
|
* Wait for slave to leave the synchronization point:
|
2008-04-29 00:14:26 +08:00
|
|
|
*/
|
2012-08-14 21:26:13 +08:00
|
|
|
while (atomic_read(&count_count_stop) != 1)
|
2008-04-29 00:14:26 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* i386 code reported the skew here, but the
|
|
|
|
* count registers were almost certainly out of sync
|
|
|
|
* so no point in alarming people
|
|
|
|
*/
|
|
|
|
printk("done.\n");
|
|
|
|
}
|
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 21:38:59 +08:00
|
|
|
void synchronise_count_slave(int cpu)
|
2008-04-29 00:14:26 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not every cpu is online at the time this gets called,
|
|
|
|
* so we first wait for the master to say everyone is ready
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NR_LOOPS; i++) {
|
|
|
|
atomic_inc(&count_count_start);
|
2012-08-14 21:26:13 +08:00
|
|
|
while (atomic_read(&count_count_start) != 2)
|
2008-04-29 00:14:26 +08:00
|
|
|
mb();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Everyone initialises count in the last loop:
|
|
|
|
*/
|
|
|
|
if (i == NR_LOOPS-1)
|
|
|
|
write_c0_count(initcount);
|
|
|
|
|
|
|
|
atomic_inc(&count_count_stop);
|
2012-08-14 21:26:13 +08:00
|
|
|
while (atomic_read(&count_count_stop) != 2)
|
2008-04-29 00:14:26 +08:00
|
|
|
mb();
|
|
|
|
}
|
|
|
|
/* Arrange for an interrupt in a short while */
|
|
|
|
write_c0_compare(read_c0_count() + COUNTON);
|
|
|
|
}
|
|
|
|
#undef NR_LOOPS
|