From 556f12ba7a96b720fbee4b4c4234518c38bf07e9 Mon Sep 17 00:00:00 2001 From: nwhitehorn Date: Fri, 9 Feb 2018 20:09:32 +0000 Subject: [PATCH] Fix PowerMac G5 thermal management, plus likely other bugs, introduced in r328113 and affecting SMP systems. The way the time is set on PowerMacs is racy and relies on all the CPUs in the system setting a register simultaneously in a rendezvous. A few-cycle delay can result in out-of-sync times, which can break the scheduler and result in calls like mtx_sleep() and pause() never timing out if the thread is migrated while sleeping. r328113 added a call to a no-op function between the beginning of the rendezvous and setting the time that was only called on APs and added enough cycles to cause a problematic offset. For some reason, the fan-management code was the first place this appeared. Clue from: andreast Reported by: many --- sys/powerpc/powerpc/mp_machdep.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/powerpc/powerpc/mp_machdep.c b/sys/powerpc/powerpc/mp_machdep.c index 642b3b8f75d0..560336befb36 100644 --- a/sys/powerpc/powerpc/mp_machdep.c +++ b/sys/powerpc/powerpc/mp_machdep.c @@ -81,11 +81,20 @@ machdep_ap_bootstrap(void) __asm __volatile("or 27,27,27"); __asm __volatile("or 6,6,6"); - /* Give platform code a chance to do anything necessary */ + /* + * Set timebase as soon as possible to meet an implicit rendezvous + * from cpu_mp_unleash(), which sets ap_letgo and then immediately + * sets timebase. + * + * Note that this is instrinsically racy and is only relevant on + * platforms that do not support better mechanisms. + */ + platform_smp_timebase_sync(ap_timebase, 1); + + /* Give platform code a chance to do anything else necessary */ platform_smp_ap_init(); - /* Initialize DEC and TB, sync with the BSP values */ - platform_smp_timebase_sync(ap_timebase, 1); + /* Initialize decrementer */ decr_ap_init(); /* Serialize console output and AP count increment */