From nobody Fri Jan 30 05:06:36 2026 X-Original-To: dev-commits-src-all@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 4f2PB51Fkvz6Qc0j for ; Fri, 30 Jan 2026 05:06:37 +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 4f2PB45hdYz3q12 for ; Fri, 30 Jan 2026 05:06:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769749596; 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=/MLpRH1xZaC0HTMh6CaSEuZZ5MDxk3BR9sJo/FvN0Fc=; b=b4XhFhZYuxFQxqnGieL/zZ9E515CL8OyC0E+1/Wwl90yu7ek9fZwb0dBp0geMa6O2CGw3+ tyMnmFADamjSu4LA/u60CY6G8A6E+zrIkPSHgr5FU7oh8yZWRp+c5JfEXfBIX8yTq1ov+T D1PJ+7zmp4r0WPBbTeyfCayAOI3X44KjIC8JAIxcFISmcOnsOoH1AlhCuVqOKdmCxQgoDQ vgMkb/r9+s3fBSCXnEO6LJlpI7Yc5O6vCtoadLBaEDnCl8+Msu55/dNr9fqQVP9zGgKHKT MO7mJ01B5u4VYIWI7Ce0QnPCBSBJMJgc0d4W3hXg8aDM192o4/uSRncacL+rig== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769749596; a=rsa-sha256; cv=none; b=fQrgpY3ok03pjVXhJN2q8rIFLi72pwuqzG1AB7mACsg8obhVEtGnHtgvtN6VtHBN959S/p BHmAXbIJN4JD0yi/iDYPVXZQsRiZWomp1NwxTvdUyxeql3HDQdTvlfyrSJsQ4xoQi5n8CH E1D09WTtQiQ36b3gL7oNQswIdc+0aO/KHGNXq16dlLQHgDAm3mac7fjHqXV3xK8iKZXwKB 9KjfCSopZcRzPEzo3UEWrXGyw2ansH9RW5NmX8ROYYvm44o6H5rqFKFQRff7BHPYZ0ixzH zAREdAWuiX5uEvMEHlHSLW+TNTkXROahhnlhIz+iDZWldD1n7L1ULGn57+MtNA== 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=1769749596; 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=/MLpRH1xZaC0HTMh6CaSEuZZ5MDxk3BR9sJo/FvN0Fc=; b=pg3CsOcVQQ2MkG6u/pzwO5L62QLpBXEsl9Tq4qlKTVr0SpjqMzxqBFa2sV+Ko9ZWDh5sAj jHCCvMd4lapHpggSAGI7qmxv3ORLp2eniJTvwAa21H9ZKaH0jwk0MrcA9aPwyfHjZHAUvY 0Qg5FAQ3f4+ZM6akf10Z6hT4kesNE8AWZVGbozA6YjN53cb30Xw9BxPsxSmNEre1CcwV6R Upr2Lxz7LTwmE2G7Jn9xmDoJibTGc2xU2VgjY0QceZE+6kLpGi+h/KL4af3Mfsk5Nn+tCY fcQHZowkgqNuUT/+OcFXO2ETswYQ7xJ+kzedgTackRmMzhpO2Qksw2hhcYzw7A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f2PB43zXjz18gj for ; Fri, 30 Jan 2026 05:06:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 41a08 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Jan 2026 05:06:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Adrian Chadd Subject: git: f7358bc0363f - stable/14 - powerpc: add a best-effort SMP time base sync for G5's that need it List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/14 X-Git-Reftype: branch X-Git-Commit: f7358bc0363fc1860cea64da972e590c9053919d Auto-Submitted: auto-generated Date: Fri, 30 Jan 2026 05:06:36 +0000 Message-Id: <697c3c5c.41a08.66c799d0@gitrepo.freebsd.org> The branch stable/14 has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=f7358bc0363fc1860cea64da972e590c9053919d commit f7358bc0363fc1860cea64da972e590c9053919d Author: Adrian Chadd AuthorDate: 2026-01-20 02:38:43 +0000 Commit: Adrian Chadd CommitDate: 2026-01-30 05:06:18 +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 191d9ae64abe..a34b7c9c83cb 100644 --- a/sys/powerpc/powermac/platform_powermac.c +++ b/sys/powerpc/powermac/platform_powermac.c @@ -406,21 +406,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. */ @@ -429,25 +496,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. */