From nobody Fri Jan 30 05:02:57 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4f2P5s6dBrz6QbwC for ; Fri, 30 Jan 2026 05:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f2P5s4r2Xz3pDP for ; Fri, 30 Jan 2026 05:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769749377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N7JrJ6zDRSq6FcQgOoPtv/r02hcXutWjzUT7jH/GO2Y=; b=m2vpIG/vmT7npP84Fyra3DJgLoeovhXaJ4rQ5PEhYKvNNjgSBWO3xKAziG5CitaMnlZw+4 /G17SGlasPQChgtngQUpPi8XK9ZGTZAa1Hn2jDxQcrip8/rYIkFcohJF7pImokQqTeUiaw n47cYhSNvipZuzSiArso5fXa7jgSGLRNn77+/KPlB9TncI9QUoeoKJVOC6oB0eSF8tw6IP 5wMI5LdP/mtig8l1ALZh3eVj93V0FOTPRdwLmoPPLxKa818PWMQZF0xZqJTDLnLjqg07IP JdzZZ3lpMKGUjq/IgBAJG7HK+p3mhZ/FkvNN4Y41Xv9P4U4wk3pne+piCBv3yQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769749377; a=rsa-sha256; cv=none; b=Q5iq71Ef+ShOSYde+KSs5WmMUHdrIzLmaGq3ViS42x17hgXsTkegIIzkUOl7/pcatychJD 5L/B8Xb5lP58jBZbIWc4YLFxUuwTnNHHiiPKEswQshsFxGNs18rgziENNCcHiQSWKYRTpf piV76u5gOh6/5+aZVmW1wH/t2n09c9BU8cFeDQtQ8oJtxJTWeu5MF+ZzngsqggydF94b/7 cOwbCcXSZ7djU2Wi646oSJ3bxnVfhZV9uA9qBeuhbZzd4Qlrh6LLdiOQtfOgOtMWJBkBd8 NUVw/CMJlvLcSQcD8F4yAjzNho8lA55KkeBwZ+ZdPxF/EcaPCII6k2Ep6FvZZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769749377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N7JrJ6zDRSq6FcQgOoPtv/r02hcXutWjzUT7jH/GO2Y=; b=s4ERf5pZemB6apaXgB5sjhO0NgLypDhouKzeUefL9KdiBg3ujPhp3KgfgArVgRCceeXRj+ ERA2UIpqS/4il/e/KFYw0SDdvqQ/KF02HOhqPPNtoTyqO2Wn5ZGSXhCmqeH1odSLwzQS5b Y8ms7CY/mhQV82iluX6+QGN365HhsFiyhmJ/RQ8h6ChHASvjLu7+8opxD8wyuCGSBAR5Lx yST1dxt7QYbApkrUm0/rYVklN13qmpr80AruarjetD8Iqd9bPq+zKeIyKC8onyIn1+gaAl e38o1CDxc4VSmTcsZznL1DnRNnZ/u7iM/DYF5fqwS2hzlftTeOyusBIzg12N3w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f2P5s4Qbwz18RY for ; Fri, 30 Jan 2026 05:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4118e by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Jan 2026 05:02:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Adrian Chadd Subject: git: b30d06409e5f - stable/15 - powerpc: add a best-effort SMP time base sync for G5's that need it List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: adrian X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: b30d06409e5f8851c0505929f4f3999f7bc65b1d Auto-Submitted: auto-generated Date: Fri, 30 Jan 2026 05:02:57 +0000 Message-Id: <697c3b81.4118e.6f074070@gitrepo.freebsd.org> The branch stable/15 has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=b30d06409e5f8851c0505929f4f3999f7bc65b1d commit b30d06409e5f8851c0505929f4f3999f7bc65b1d Author: Adrian Chadd AuthorDate: 2026-01-20 02:38:43 +0000 Commit: Adrian Chadd CommitDate: 2026-01-30 05:02:49 +0000 powerpc: add a best-effort SMP time base sync for G5's that need it There's no timebase freeze platform routine registered on my dual 2.3GHz G5 PPC970FX Apple PowerMac. For platforms without an explicit timebase freeze/unfreeze, we'll have to make do with what we have - which for now is an explicit hand-crafted spinlock/rendezvous method. * For existing platforms, they'll still continue to clock freeze / rendezvous; albeit with some stronger atomic bits now (from jhibbits@.) * Instead of the fallback being "no timesync", implement a best-effort one which does a similar rendezvous barrier between BSP and APs, but instead of freeze/unfreeze the first instruction after the CPUs all register they're ready is to set the timebase. This has resulted in many reboots of my Powermac G5 dual-socket device correctly starting and running in SMP mode. Differential Revision: https://reviews.freebsd.org/D54821 Reviewed by: jhibbits (cherry picked from commit 422c8719eab2b8a01b49f748a88dd372db25f888) --- sys/powerpc/powermac/platform_powermac.c | 99 +++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 9 deletions(-) diff --git a/sys/powerpc/powermac/platform_powermac.c b/sys/powerpc/powermac/platform_powermac.c index c63ef521ca8f..cbb2e212a00d 100644 --- a/sys/powerpc/powermac/platform_powermac.c +++ b/sys/powerpc/powermac/platform_powermac.c @@ -405,21 +405,88 @@ powermac_register_timebase(device_t dev, powermac_tb_disable_t cb) freeze_timebase = cb; } +/** + * @brief Implement a default platform AP/BSP SMP timebase synchronisation + * + * Some powermac platforms don't have a freeze/unfreeze method. + * Here just try our best to force synchronisation. + */ static void -powermac_smp_timebase_sync(platform_t plat, u_long tb, int ap) +powermac_smp_timebase_sync_fallback(platform_t plat, u_long tb, int ap) +{ + static volatile bool tb_ready = false; + static volatile int cpu_done; + + if (bootverbose) + printf("[%d] %s: called, AP tb=0x%lx tb=0x%lx\n", + ap, __func__, tb, mftb()); + + /* Do initial timebase sync */ + mttb(tb); + + if (ap) { + /* + * APs - wait until the BSP signals its ready to sync, + * then wait for all CPUs to be ready. + */ + critical_enter(); + while (!tb_ready) + atomic_thread_fence_seq_cst(); + atomic_add_int(&cpu_done, 1); + do { + atomic_thread_fence_seq_cst(); + } while (cpu_done < mp_ncpus); + mttb(tb); + critical_exit(); + } else { + /* + * BSP - signify that the timebase sync is about to start, + * then wait for other CPUs to be ready. + */ + critical_enter(); + /* Ensure cpu_done is zeroed so we can resync at runtime */ + atomic_store_int(&cpu_done, 0); + tb_ready = true; + atomic_add_int(&cpu_done, 1); + do { + atomic_thread_fence_seq_cst(); + } while (cpu_done < mp_ncpus); + mttb(tb); + /* Reset tb_ready so we can resync at runtime */ + tb_ready = false; + critical_exit(); + } + if (bootverbose) + printf("[%d] %s: finished; AP tb=0x%lx called tb=0x%lx\n", + ap, __func__, tb, mftb()); +} + +/** + * @brief Implement freeze/unfreeze AP/BSP SMP timebase synchronisation + * + * This implements SMP timebase synchronisation for hardware that + * implements freezing a shared timebase clock source. + * + * The BSP will freeze the timebase and signal the APs to program their + * local timebase with the shared timebase value. The BSP will then + * unfreeze the timebase clock, allowing all CPUs to march forward + * from the same base timebase value. + */ +static void +powermac_smp_timebase_sync_freeze(platform_t plat, u_long tb, int ap) { - static volatile bool tb_ready; + static volatile bool tb_ready = false; static volatile int cpu_done; + if (bootverbose) + printf("[%d] %s: called, AP tb=0x%lx tb=0x%lx\n", + ap, __func__, tb, mftb()); + /* - * XXX Temporary fallback for platforms we don't know how to freeze. - * * This needs to be replaced with a cpu-to-cpu software sync * protocol, because this is not a consistent way to sync timebase. */ mttb(tb); - if (freeze_timebase == dummy_timebase) - return; if (ap) { /* APs. Hold off until we get a stable timebase. */ @@ -428,25 +495,39 @@ powermac_smp_timebase_sync(platform_t plat, u_long tb, int ap) atomic_thread_fence_seq_cst(); mttb(tb); atomic_add_int(&cpu_done, 1); - while (cpu_done < mp_ncpus) + do { atomic_thread_fence_seq_cst(); + } while (cpu_done < mp_ncpus); critical_exit(); } else { /* BSP */ critical_enter(); /* Ensure cpu_done is zeroed so we can resync at runtime */ - atomic_set_int(&cpu_done, 0); + atomic_store_int(&cpu_done, 0); freeze_timebase(powermac_tb_dev, true); tb_ready = true; mttb(tb); atomic_add_int(&cpu_done, 1); - while (cpu_done < mp_ncpus) + do { atomic_thread_fence_seq_cst(); + } while (cpu_done < mp_ncpus); freeze_timebase(powermac_tb_dev, false); /* Reset tb_ready so we can resync at runtime */ tb_ready = false; critical_exit(); } + if (bootverbose) + printf("[%d] %s: finished; AP tb=0x%lx called tb=0x%lx\n", + ap, __func__, tb, mftb()); +} + +static void +powermac_smp_timebase_sync(platform_t plat, u_long tb, int ap) +{ + if (freeze_timebase == dummy_timebase) + powermac_smp_timebase_sync_fallback(plat, tb, ap); + else + powermac_smp_timebase_sync_freeze(plat, tb, ap); } /* Fallback freeze. In case no real handler is found in the device tree. */