mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-16 09:26:47 +07:00
db0dbd57d5
While synchronization, count register will go backwards for the master.
If synchronise_count_master() runs before synchronise_count_slave(),
skew becomes even more. The skew is very harmful for CPU hotplug (CPU0
do synchronization with CPU1, then CPU0 do synchronization with CPU2
and CPU0's count goes backwards, so it will be out of sync with CPU1).
After the commit cf9bfe55f2
(MIPS: Synchronize MIPS count one
CPU at a time), we needn't evaluate count_reference at the beginning of
synchronise_count_master() any more. Thus, we evaluate the initcount (It
seems like count_reference is redundant) in the 2nd loop. Since we write
the count register in the last loop, we don't need additional barriers
(the existing memory barriers are enough).
Moreover, I think we loop 3 times is enough to get a primed instruction
cache, this can also get less skew than looping 5 times.
Comments are also updated in this patch.
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Steven J. Hill <Steven.Hill@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: Fuxin Zhang <zhangfx@lemote.com>
Cc: Zhangjin Wu <wuzhangjin@gmail.com>
Patchwork: https://patchwork.linux-mips.org/patch/12163/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
117 lines
2.9 KiB
C
117 lines
2.9 KiB
C
/*
|
|
* Count register synchronisation.
|
|
*
|
|
* All CPUs will have their count registers synchronised to the CPU0 next time
|
|
* 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>
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <asm/r4k-timer.h>
|
|
#include <linux/atomic.h>
|
|
#include <asm/barrier.h>
|
|
#include <asm/mipsregs.h>
|
|
|
|
static unsigned int initcount = 0;
|
|
static atomic_t count_count_start = ATOMIC_INIT(0);
|
|
static atomic_t count_count_stop = ATOMIC_INIT(0);
|
|
|
|
#define COUNTON 100
|
|
#define NR_LOOPS 3
|
|
|
|
void synchronise_count_master(int cpu)
|
|
{
|
|
int i;
|
|
unsigned long flags;
|
|
|
|
printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu);
|
|
|
|
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++) {
|
|
/* slaves loop on '!= 2' */
|
|
while (atomic_read(&count_count_start) != 1)
|
|
mb();
|
|
atomic_set(&count_count_stop, 0);
|
|
smp_wmb();
|
|
|
|
/* Let the slave writes its count register */
|
|
atomic_inc(&count_count_start);
|
|
|
|
/* Count will be initialised to current timer */
|
|
if (i == 1)
|
|
initcount = read_c0_count();
|
|
|
|
/*
|
|
* Everyone initialises count in the last loop:
|
|
*/
|
|
if (i == NR_LOOPS-1)
|
|
write_c0_count(initcount);
|
|
|
|
/*
|
|
* Wait for slave to leave the synchronization point:
|
|
*/
|
|
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);
|
|
|
|
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");
|
|
}
|
|
|
|
void synchronise_count_slave(int cpu)
|
|
{
|
|
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);
|
|
while (atomic_read(&count_count_start) != 2)
|
|
mb();
|
|
|
|
/*
|
|
* Everyone initialises count in the last loop:
|
|
*/
|
|
if (i == NR_LOOPS-1)
|
|
write_c0_count(initcount);
|
|
|
|
atomic_inc(&count_count_stop);
|
|
while (atomic_read(&count_count_stop) != 2)
|
|
mb();
|
|
}
|
|
/* Arrange for an interrupt in a short while */
|
|
write_c0_compare(read_c0_count() + COUNTON);
|
|
}
|
|
#undef NR_LOOPS
|