From nobody Tue Jan 27 04:39:46 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 4f0Xkc0WmTz6QC2r for ; Tue, 27 Jan 2026 04:39:52 +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 4f0Xkb2XQ3z46NK for ; Tue, 27 Jan 2026 04:39:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769488791; 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=N64cJ7ozmfoW15J6iZvgSEMgV5/J7LkrtfJTmpEQBBw=; b=mwRCUNTRjwWAKeUnTYPBddx40TFAYkicvpIRO4uT6xNpAXk2HxDPPewiq6QTtCfmUSw6zb LyGxFsAhfYLMhcNL3hywVC7rY/nAobgrsEVbsQk/Nz0vDNnw0GnKQhMUBG8J97ZtEz82MF SWIszbCvUNFK3DM3QmcBRX6ORjxw2y2nULXA6XIurgOLWtQ5R0u1POw4VEtioyWC4IHZ1Z huLPgsMZ9zHALfaanQ6MxVbP0DzehdeJ9i2cDWdd1JynAcrWccqbK7inq8H51vyyNRtKf7 UJVyF9dsZaPJPFnIDjD2Y20r/i4ggPeURYcNebO6x11WYgCMOj6BgMJc8DlKEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769488791; 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=N64cJ7ozmfoW15J6iZvgSEMgV5/J7LkrtfJTmpEQBBw=; b=ojYFckxf+i6o56bvfCfa57cqt/0o2cDXTIkAuOxnnLcmUD2mDlov82ISd7bEvypUhbGnv1 45Q9bgF7+CNoGCp9H/oeSXzu5BDeX+gyt6J00QdZfj85+CkGO/1wBXVFqn5A/NF+cVpBNQ asylr485LjPzzsrf0svkSM+66ETlhiJ308EiC7KtF42F2x9h4ZaUhKak3Na58GAzp+Vb7D 7zkR5XMbNyKiHT0ryiy1RWtfL1iHg0xIKIMl4HqI/19JFH8xhCuKuRme5WVnvDwL36n1UB P98Htj4Bzc53T4wgKEpBF/YGYFFHX2ByqK21bEdvEtPrdgGWbvZ1t4nBOAWm/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769488791; a=rsa-sha256; cv=none; b=A7pA8YDNV4ErnTmZ1Itm4uJVHK4RvEeIWVObTA449EWeHKQK6MNi1fDW4Qb/BDCepymCac meyspnm0gaS626l2QMkkE/Uu/6QbJZqlciJB3+4hSofVN1UsOZxWaXqeJLKYY8cFNcDz1C XF76b0CL38u4N3L73X7T1jefMWSVwgxwGPEAkm8oJodE+0wqLg4zlzl3F0Inhxt9R8emlZ jgk4kojs5GNs3cOjn8/Ig1uHP5z2TrTiO5sc5W50lXC304Of6relzGaNcpTQgO0kDxhCbj 6z0s8yIycCxXCHsjMX15pM1NtsteEM753fi+M4VXPujzKVvmLul9TDo+s642Hg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f0Xkb18vbzsPp for ; Tue, 27 Jan 2026 04:39:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3b74c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 27 Jan 2026 04:39:46 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Adrian Chadd Subject: git: 422c8719eab2 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 422c8719eab2b8a01b49f748a88dd372db25f888 Auto-Submitted: auto-generated Date: Tue, 27 Jan 2026 04:39:46 +0000 Message-Id: <69784192.3b74c.645fa4cf@gitrepo.freebsd.org> The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=422c8719eab2b8a01b49f748a88dd372db25f888 commit 422c8719eab2b8a01b49f748a88dd372db25f888 Author: Adrian Chadd AuthorDate: 2026-01-20 02:38:43 +0000 Commit: Adrian Chadd CommitDate: 2026-01-27 04:38:23 +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 --- 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. */