Commit db0dbd57 authored by Huacai Chen's avatar Huacai Chen Committed by Ralf Baechle

MIPS: sync-r4k: reduce skew while synchronization

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 cf9bfe55 (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: default avatarHuacai 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: default avatarRalf Baechle <ralf@linux-mips.org>
parent 5610b125
...@@ -17,34 +17,22 @@ ...@@ -17,34 +17,22 @@
#include <asm/barrier.h> #include <asm/barrier.h>
#include <asm/mipsregs.h> #include <asm/mipsregs.h>
static atomic_t count_start_flag = ATOMIC_INIT(0); static unsigned int initcount = 0;
static atomic_t count_count_start = ATOMIC_INIT(0); static atomic_t count_count_start = ATOMIC_INIT(0);
static atomic_t count_count_stop = ATOMIC_INIT(0); static atomic_t count_count_stop = ATOMIC_INIT(0);
static atomic_t count_reference = ATOMIC_INIT(0);
#define COUNTON 100 #define COUNTON 100
#define NR_LOOPS 5 #define NR_LOOPS 3
void synchronise_count_master(int cpu) void synchronise_count_master(int cpu)
{ {
int i; int i;
unsigned long flags; unsigned long flags;
unsigned int initcount;
printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu); printk(KERN_INFO "Synchronize counters for CPU %u: ", cpu);
local_irq_save(flags); 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, cpu);
smp_wmb();
/* Count will be initialised to current timer for all CPU's */
initcount = read_c0_count();
/* /*
* We loop a few times to get a primed instruction cache, * We loop a few times to get a primed instruction cache,
* then the last pass is more or less synchronised and * then the last pass is more or less synchronised and
...@@ -63,9 +51,13 @@ void synchronise_count_master(int cpu) ...@@ -63,9 +51,13 @@ void synchronise_count_master(int cpu)
atomic_set(&count_count_stop, 0); atomic_set(&count_count_stop, 0);
smp_wmb(); smp_wmb();
/* this lets the slaves write their count register */ /* Let the slave writes its count register */
atomic_inc(&count_count_start); 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: * Everyone initialises count in the last loop:
*/ */
...@@ -73,7 +65,7 @@ void synchronise_count_master(int cpu) ...@@ -73,7 +65,7 @@ void synchronise_count_master(int cpu)
write_c0_count(initcount); write_c0_count(initcount);
/* /*
* Wait for all slaves to leave the synchronization point: * Wait for slave to leave the synchronization point:
*/ */
while (atomic_read(&count_count_stop) != 1) while (atomic_read(&count_count_stop) != 1)
mb(); mb();
...@@ -83,7 +75,6 @@ void synchronise_count_master(int cpu) ...@@ -83,7 +75,6 @@ void synchronise_count_master(int cpu)
} }
/* 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);
...@@ -98,19 +89,12 @@ void synchronise_count_master(int cpu) ...@@ -98,19 +89,12 @@ void synchronise_count_master(int cpu)
void synchronise_count_slave(int cpu) void synchronise_count_slave(int cpu)
{ {
int i; int i;
unsigned int initcount;
/* /*
* Not every cpu is online at the time this gets called, * Not every cpu is online at the time this gets called,
* 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) != cpu)
mb();
/* Count will be initialised to next expire for all CPU's */
initcount = atomic_read(&count_reference);
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) != 2) while (atomic_read(&count_count_start) != 2)
......
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