2 * Count register synchronisation.
4 * All CPUs will have their count registers synchronised to the CPU0 expirelo
5 * value. This can cause a small timewarp for CPU0. All other CPU's should
6 * not have done anything significant (but they may have had interrupts
7 * enabled briefly - prom_smp_finish() should not be responsible for enabling
10 * FIXME: broken for SMTC
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/irqflags.h>
16 #include <linux/r4k-timer.h>
18 #include <asm/atomic.h>
19 #include <asm/barrier.h>
20 #include <asm/cpumask.h>
21 #include <asm/mipsregs.h>
23 static atomic_t __initdata count_start_flag
= ATOMIC_INIT(0);
24 static atomic_t __initdata count_count_start
= ATOMIC_INIT(0);
25 static atomic_t __initdata count_count_stop
= ATOMIC_INIT(0);
30 void __init
synchronise_count_master(void)
34 unsigned int initcount
;
37 #ifdef CONFIG_MIPS_MT_SMTC
39 * SMTC needs to synchronise per VPE, not per CPU
45 pr_info("Checking COUNT synchronization across %u CPUs: ",
48 local_irq_save(flags
);
51 * Notify the slaves that it's time to start
53 atomic_set(&count_start_flag
, 1);
56 /* Count will be initialised to expirelo for all CPU's */
60 * We loop a few times to get a primed instruction cache,
61 * then the last pass is more or less synchronised and
62 * the master and slaves each set their cycle counters to a known
63 * value all at once. This reduces the chance of having random offsets
64 * between the processors, and guarantees that the maximum
65 * delay between the cycle counters is never bigger than
66 * the latency of information-passing (cachelines) between
70 nslaves
= num_online_cpus()-1;
71 for (i
= 0; i
< NR_LOOPS
; i
++) {
72 /* slaves loop on '!= ncpus' */
73 while (atomic_read(&count_count_start
) != nslaves
)
75 atomic_set(&count_count_stop
, 0);
78 /* this lets the slaves write their count register */
79 atomic_inc(&count_count_start
);
82 * Everyone initialises count in the last loop:
85 write_c0_count(initcount
);
88 * Wait for all slaves to leave the synchronization point:
90 while (atomic_read(&count_count_stop
) != nslaves
)
92 atomic_set(&count_count_start
, 0);
94 atomic_inc(&count_count_stop
);
96 /* Arrange for an interrupt in a short while */
97 write_c0_compare(read_c0_count() + COUNTON
);
99 local_irq_restore(flags
);
102 * i386 code reported the skew here, but the
103 * count registers were almost certainly out of sync
104 * so no point in alarming people
109 void __init
synchronise_count_slave(void)
113 unsigned int initcount
;
116 #ifdef CONFIG_MIPS_MT_SMTC
118 * SMTC needs to synchronise per VPE, not per CPU
124 local_irq_save(flags
);
127 * Not every cpu is online at the time this gets called,
128 * so we first wait for the master to say everyone is ready
131 while (!atomic_read(&count_start_flag
))
134 /* Count will be initialised to expirelo for all CPU's */
135 initcount
= expirelo
;
137 ncpus
= num_online_cpus();
138 for (i
= 0; i
< NR_LOOPS
; i
++) {
139 atomic_inc(&count_count_start
);
140 while (atomic_read(&count_count_start
) != ncpus
)
144 * Everyone initialises count in the last loop:
147 write_c0_count(initcount
);
149 atomic_inc(&count_count_stop
);
150 while (atomic_read(&count_count_stop
) != ncpus
)
153 /* Arrange for an interrupt in a short while */
154 write_c0_compare(read_c0_count() + COUNTON
);
156 local_irq_restore(flags
);