Commit 6460b4cc authored by Paul Mackerras's avatar Paul Mackerras Committed by Linus Torvalds

[PATCH] ppc32: improve timebase sync for SMP

Currently the procedure in the ppc32 kernel that synchronizes the timebase
registers across an SMP powermac system does so by setting both timebases
to zero.  That is OK at boot but causes problems if done later.  So that we
can do hotplug CPU on these machines, this patch changes the code so it
reads the timebase from one CPU and transfers the value to the other CPU. 
(Hotplug CPU is needed for sleep (aka suspend to RAM) to work.)
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 35b535d9
No related merge requests found
...@@ -116,6 +116,8 @@ static unsigned int core99_tb_gpio; ...@@ -116,6 +116,8 @@ static unsigned int core99_tb_gpio;
/* Sync flag for HW tb sync */ /* Sync flag for HW tb sync */
static volatile int sec_tb_reset = 0; static volatile int sec_tb_reset = 0;
static unsigned int pri_tb_hi, pri_tb_lo;
static unsigned int pri_tb_stamp;
static void __init core99_init_caches(int cpu) static void __init core99_init_caches(int cpu)
{ {
...@@ -453,7 +455,7 @@ static int __init smp_core99_probe(void) ...@@ -453,7 +455,7 @@ static int __init smp_core99_probe(void)
#endif #endif
struct device_node *cpus, *firstcpu; struct device_node *cpus, *firstcpu;
int i, ncpus = 0, boot_cpu = -1; int i, ncpus = 0, boot_cpu = -1;
u32 *tbprop; u32 *tbprop = NULL;
if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345); if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
cpus = firstcpu = find_type_devices("cpu"); cpus = firstcpu = find_type_devices("cpu");
...@@ -576,46 +578,74 @@ static void __init smp_core99_setup_cpu(int cpu_nr) ...@@ -576,46 +578,74 @@ static void __init smp_core99_setup_cpu(int cpu_nr)
} }
} }
void __init smp_core99_take_timebase(void) /* not __init, called in sleep/wakeup code */
void smp_core99_take_timebase(void)
{ {
/* Secondary processor "takes" the timebase by freezing unsigned long flags;
* it, resetting its local TB and telling CPU 0 to go on
*/ /* tell the primary we're here */
pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 4); sec_tb_reset = 1;
pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
mb(); mb();
set_dec(tb_ticks_per_jiffy); /* wait for the primary to set pri_tb_hi/lo */
set_tb(0, 0); while (sec_tb_reset < 2)
last_jiffy_stamp(smp_processor_id()) = 0; mb();
/* set our stuff the same as the primary */
local_irq_save(flags);
set_dec(1);
set_tb(pri_tb_hi, pri_tb_lo);
last_jiffy_stamp(smp_processor_id()) = pri_tb_stamp;
mb();
/* tell the primary we're done */
sec_tb_reset = 0;
mb(); mb();
sec_tb_reset = 1; local_irq_restore(flags);
} }
void __init smp_core99_give_timebase(void) /* not __init, called in sleep/wakeup code */
void smp_core99_give_timebase(void)
{ {
unsigned long flags;
unsigned int t; unsigned int t;
/* Primary processor waits for secondary to have frozen /* wait for the secondary to be in take_timebase */
* the timebase, resets local TB, and kick timebase again for (t = 100000; t > 0 && !sec_tb_reset; --t)
*/ udelay(10);
/* wait for the secondary to have reset its TB before proceeding */ if (!sec_tb_reset) {
for (t = 1000; t > 0 && !sec_tb_reset; --t)
udelay(1000);
if (t == 0)
printk(KERN_WARNING "Timeout waiting sync on second CPU\n"); printk(KERN_WARNING "Timeout waiting sync on second CPU\n");
return;
}
set_dec(tb_ticks_per_jiffy); /* freeze the timebase and read it */
set_tb(0, 0); /* disable interrupts so the timebase is disabled for the
last_jiffy_stamp(smp_processor_id()) = 0; shortest possible time */
local_irq_save(flags);
pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 4);
pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
mb();
pri_tb_hi = get_tbu();
pri_tb_lo = get_tbl();
pri_tb_stamp = last_jiffy_stamp(smp_processor_id());
mb(); mb();
/* tell the secondary we're ready */
sec_tb_reset = 2;
mb();
/* wait for the secondary to have taken it */
for (t = 100000; t > 0 && sec_tb_reset; --t)
udelay(10);
if (sec_tb_reset)
printk(KERN_WARNING "Timeout waiting sync(2) on second CPU\n");
else
smp_tb_synchronized = 1;
/* Now, restart the timebase by leaving the GPIO to an open collector */ /* Now, restart the timebase by leaving the GPIO to an open collector */
pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 0); pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 0);
pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0); pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
local_irq_restore(flags);
smp_tb_synchronized = 1;
} }
......
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