Repository navigation
M4 PMP: fan-based rail budget and self-described 27.2 PMP path - #2533
DjDeveloperr wants to merge 9 commits into
Conversation
|
Hardware row from a J713 (M4 Air) on the 27.2 (26B123) stub. The name lookup works there, but on its own it does not lift the CPU caps on an Air. Records: with this PR the J713 logs Still capped: with the records found, an idle J713 keeps all six sensors invalid much longer than the 2 s Proposed addition (patch below): hold the last cool reading for up to 30 s, but only while the SMC's measured P+E+GPU rails total under 500 mW. The rail reading must be from the last 1.5 s, and an all-zero read doesn't count. A dark cluster is powered down, and the rails show independently that nothing is drawing. The 2 s hold and every other limit are unchanged. With this PR plus the patch: 0 Not covered by this row: the sleep-segment commit, because I ran no suspend. Numbers and method
Patch: thermal: apple-pmp: ride out long dark spans while the SoC is idle drivers/thermal/apple-pmp-thermal.c | 31 +++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/apple-pmp-thermal.c b/drivers/thermal/apple-pmp-thermal.c
index 9eba514e1feda..29c8bc2b46040 100644
--- a/drivers/thermal/apple-pmp-thermal.c
+++ b/drivers/thermal/apple-pmp-thermal.c
@@ -43,6 +43,16 @@
/* Inside the cooling slope window (50-250 ms); used while cool and idle. */
#define APPLE_PMP_SLOW_POLL_MS 100
#define APPLE_PMP_GOVERNOR_NS 100000000ULL
+/*
+ * On the 27.2 firmware a cool, idle J713 keeps every sensor dark much longer than
+ * APPLE_PMP_GATED_HOLD_NS (13.3 s the longest of 53 spans in 120 s sampled at
+ * 100 ms, 86% of samples dark). Dark clusters are powered down, so ride a span out
+ * this long as well, but only while the SMC's measured CPU and GPU rails, read no
+ * longer ago than the stale limit, add up to less than an idle SoC draws.
+ */
+#define APPLE_PMP_GATED_IDLE_HOLD_NS 30000000000ULL
+#define APPLE_PMP_IDLE_RAILS_MW 500
+#define APPLE_PMP_IDLE_RAILS_STALE_NS 1500000000ULL
struct apple_pmp_cluster {
struct cpufreq_policy *policy;
@@ -61,6 +71,9 @@ static struct {
struct delayed_work power_work;
struct device *power_hwmon;
unsigned int rail_mw[3];
+ /* The last successful SMC rail read, whatever the sensors said, and when. */
+ unsigned int idle_rail_mw;
+ u64 idle_rail_ns;
int power_error;
u64 gpu_epoch;
bool power_polling;
@@ -226,6 +239,10 @@ static void apple_pmp_power_work(struct work_struct *work)
*/
mutex_lock(&pmp_thermal.lock);
now = ktime_get_ns();
+ if (!ret) {
+ pmp_thermal.idle_rail_mw = mw[0] + mw[1] + mw[2];
+ pmp_thermal.idle_rail_ns = now;
+ }
if (!ret && (!pmp_thermal.enabled || pmp_thermal.cached_error ||
now - pmp_thermal.cooling.last_ns > 500000000ULL))
ret = -EAGAIN;
@@ -397,6 +414,14 @@ static int apple_pmp_guard(unsigned int level)
return err;
}
+/* Called with the lock held: did the SMC just see an idle SoC? */
+static bool apple_pmp_rails_idle(u64 now)
+{
+ return pmp_thermal.idle_rail_ns && now >= pmp_thermal.idle_rail_ns &&
+ now - pmp_thermal.idle_rail_ns < APPLE_PMP_IDLE_RAILS_STALE_NS &&
+ pmp_thermal.idle_rail_mw < APPLE_PMP_IDLE_RAILS_MW;
+}
+
static int apple_pmp_sample(void)
{
struct apple_pmp_snapshot snapshot;
@@ -415,8 +440,10 @@ static int apple_pmp_sample(void)
pmp_thermal.valid_ns = snapshot.finished_ns;
pmp_thermal.valid_mc = value;
} else if (ret == -ENODATA && pmp_thermal.valid_ns &&
- snapshot.finished_ns - pmp_thermal.valid_ns < APPLE_PMP_GATED_HOLD_NS &&
- pmp_thermal.valid_mc < APPLE_PMP_GATED_HOLD_MC) {
+ pmp_thermal.valid_mc < APPLE_PMP_GATED_HOLD_MC &&
+ (snapshot.finished_ns - pmp_thermal.valid_ns < APPLE_PMP_GATED_HOLD_NS ||
+ (snapshot.finished_ns - pmp_thermal.valid_ns < APPLE_PMP_GATED_IDLE_HOLD_NS &&
+ apple_pmp_rails_idle(snapshot.finished_ns)))) {
value = pmp_thermal.valid_mc;
ret = 0;
}Assisted-by: LLM (Claude:Opus 5.5) |
|
apple_pmp_thermal_setup() sets pmp_thermal.power_budget = !of_machine_is_compatible("apple,j773g"), and the new power_budget module parameter (0644) can override it at run time. The budget is the policy for machines without a fan, so it should follow the hardware description rather than a board name: for example, disable it when the device tree describes fans/an active cooling device, or with a property on the PMP thermal node. The runtime override should go away with that; it changes thermal behaviour outside the driver's control. Until then this should stay a draft. |
|
Hardware data for the 27.2 PMP layout half of this PR: on the 13-inch M4 MacBook Air (J713, firmware 27.2) a kernel without it (integration/aurora b4cd7b3 plus unrelated merges) boots cleanly, but the PMP die sensor read fails and With this whole PR (plus one local commit) in the lab kernel, the same Air runs at 3.9 GHz sustained under thermal control, so the sensor path works there; which of the two halves the sensor read needs is not separated yet. If it is the layout change, as the error suggests, splitting the 27.2 PMP layout into its own PR would let it land now, while the budget selection moves to a hardware description (my earlier comment). |
|
Follow-up from the M4 Air (J713) on 27.2, after a day on kernels that carry this PR plus the dark-span hold from my earlier comment (#2533 (comment)):
Could you fold the hold into this PR (or tell me to open it as a separate PR on top)? The J713 default kernel carries both today, and getting them merged takes the J713 one step closer to running the plain integration tip. Assisted-by: LLM (Claude:Opus 5.5) |
|
Blockers: 5.
|
422bc70 to
12aea2b
Compare
|
Rebased onto
Also folded in the version-free 27.2 PMP start ( Checks on Assisted-by: LLM (Gemini:4 Neon) |
|
Thanks for the rework: the fan-based budget selection is what the hardware description supports. One remaining point: two new checks still select the path by the root SoC compatible, For the hardware side: on the J713 a kernel without this series boots with the PMP die sensor returning -EIO and the CPUs held at their minimum caps (912/900 MHz), so a J713 row of this head that shows the sensor reading and the clocks released is the result that matters. |
|
Hardware row on a J713 (M4 Air, macOS 27.2 stub) for the current head 12aea2b, built exactly as the PR branch (on integration/aurora a84637d) and booted with the shared fleet cmdline. The sensor part works: the records are found by name ( At idle the CPUs still stay on the minimum caps. In 150 s I counted 462 So for the J713 this head is not mergeable as is. It needs the idle hold back, either in this PR or as a PR on top. I can open that PR if you prefer. Numbers and method
Assisted-by: LLM (Claude:Opus 5.5) |
12aea2b to
d3a8923
Compare
|
Updated to
Assisted-by: LLM (Gemini:4 Neon) |
d3a8923 to
f5610a1
Compare
|
Rebased cleanly onto
Assisted-by: LLM (Gemini:4 Neon) |
|
Re-checked at f5610a1. Everything from my earlier comments is taken: the budget follows the SMC fan nodes (apple-pmp-thermal.c:104-115, 762), the New since 12aea2b:
Rows still missing for this head: a full-image boot on the J773g; a J713 27.2 row on the rebased budget path; suspend and resume on 25G83 and 26B123; and a PMP start plus registry-update row on a T8140 (A18 Pro), a T6041 (M4 Pro) and a T6000 (M1 Pro) for the RTKit and CONFIRM_IOREG changes. Assisted-by: LLM (Claude:Opus 5.5) |
The T8132 thermal driver restricts the CPU clusters and the G16 GPU through a shared budget on the measured CPU and GPU rails: 8 W sustained, a 600 J burst, and a slow climb toward a die temperature target. That is the fanless MacBook Airs' policy, and fan-cooled T8132 machines (Mac mini J773g, MacBook Pro J604, iMac J623/J624) currently inherit it too. On the M4 Mac mini (J773g), under gpubench render.heavy fill at 1080p, macOS 27.2 (26B123) holds its GPU at the top state (1578 MHz) at 100% active with 8.1-9.6 W of GPU power for the whole run. On Linux the fanless budget switched the same load between S10 and S9 every one to two seconds at a 58-61 C die, and earlier runs sat at S8. Decide whether to apply the shared rail power budget from the device tree rather than a board check: disable it when an available apple,smc-hwmon node describes one or more available fan-* children, and keep it on fanless machines. On fan-cooled Macs the rails are still read and reported through hwmon (with their own report timestamp and live rail sum, so long dark sensor spans do not make hwmon go stale), but restrict nothing; die protection (cooling from 106 C), the thermal governor and critical shutdown are unchanged. A missing or slow SMC rail reading no longer restricts anything on fan-cooled boards either: the GPU's level is published before the read. Signed-off-by: Diljit Singh <hey@djdev.me>
The T8132 PMP telemetry reads six die temperature records at fixed SRAM offsets (0x68624..0x68958, stride 0xa4) observed on the 26.6.2 (25G83) firmware. On 27.2 (26B123), runtime SRAM scans find the same six named records 0x1140 bytes later (0x69764..0x69a98, same 0xa4 stride), while the RTKit header word at 0x234 (matching ADT segment-ranges) moves from 0x3c000 to 0x3d000. Each record starts with its NUL-terminated name. After registering, run a freezable delayed worker that checks apple_pmp_telemetry_online() (including the ASC run bit) before touching SRAM: try the 25G83 offsets first, and otherwise scan from the offset read at header word 0x234 for each record name. A candidate must have a validity word of 0 or 1; a name found more than once is taken only in step with a unique first record at the 0xa4 stride, or refused. Until the records are found, and if they never are, reads behave as before. The firmware populates the records after it starts, so the worker retries every second for a minute and logs the offsets it settles on. The host selftest covers moved records, implausible and duplicate copies, ambiguity and range bounds. Signed-off-by: Diljit Singh <hey@djdev.me>
Over a system sleep Linux keeps and restores the T8132 PMP's second ADT segment in SRAM: 0x3c000..0xa4000 (0x68000 bytes) on 26.6.2 (25G83). On 27.2 (26B123), ADT segment-ranges and the RTKit header word at 0x234 place that segment at 0x3d000..0xa5000 (still 0x68000 bytes). Keeping the fixed 0x3c000 range would overwrite the preceding 4 KiB page on wake and drop the final 4 KiB page of the segment. Prefer the DT apple,sram-keep property (offset and size supplied by the boot loader from ADT segment-ranges) whenever it is present. When apple,sram-keep is absent on T8132, take the offset from header word 0x234 with the 0x68000 fallback size, refusing any offset that is not 4 KiB-aligned or falls outside SRAM. Signed-off-by: Diljit Singh <hey@djdev.me>
…ing it Some firmware reports in by itself once its CPU runs and then acknowledges IOP power on by itself. The T8132 PMP image of macOS 27.2 does: on the M4 Mac mini (J773g), about 0.13 ms after it reports in. After that it answers no IOP power request, so a wake, which clears the acknowledgment and asks again, waits for nothing: apple_pmp 380500000.pmp: RTKit: IOP power acknowledgment failed: -62 macOS 27.2 sends that firmware no IOP power request at all: once it has started the endpoints, the firmware acknowledges IOP power on, and macOS sets the AP on. Other firmware waits to be asked. Add apple_rtkit_boot_or_wake(). It gives the firmware a bounded time to report in (its endpoint map, and CoreAnalytics where the ops need it) and again to acknowledge IOP power on. If both happen, it finishes the boot without a request, as apple_rtkit_boot() does. Otherwise it asks as apple_rtkit_wake() does. A firmware that does not report in by itself therefore gets the request no later than the given time after its CPU starts. Add its Rust wrapper, RtKit::boot_or_wake(). Signed-off-by: Diljit Singh <hey@djdev.me>
…start The PMP's start wakes the firmware: it asks for IOP power and waits for the acknowledgment. The T8132 PMP image of macOS 27.2 acknowledges IOP power on by itself once it has reported in, and answers no request after that, so on the M4 Mac mini (J773g) on 27.2 the start fails: apple_pmp 380500000.pmp: RTKit: IOP power acknowledgment failed: -62 macOS sends that image no IOP power request. Gate this on PmpHwConfig::self_ack_start (enabled only on T8132) and start such SoCs with apple_rtkit_boot_or_wake(): take the firmware's own acknowledgment if it comes, and ask as before if it doesn't. Other SoCs keep calling rtk.wake() directly with no behavior change or extra wait. On 27.2 the J773g's whole RTKit start takes 1.3 ms from its CPU starting, so the firmware gets 20 ms for each step. Signed-off-by: Diljit Singh <hey@djdev.me>
…d length The PMP firmware sends UPDATE_IOREG (endpoint 0x20, type 0x36) for some of the registry entries it registered, naming each by its own index, and waits for CONFIRM_IOREG (0x37) before it publishes their reports. The driver confirms with a zero value. On the M4 Mac mini (J773g) on macOS 27.2, the PMP image updates four entries at its start (indices 0x17c, 0x17f, 0x182 and 0x18a). macOS answers each with CONFIRM_IOREG 8 (A2I 0x0037000000000008, hv22/hv23 traces). 8 is the length the firmware registered for those entries; the index is word 0x48 of each entry's REGISTER_IOREG buffer. Keep the firmware's index with each registered entry, and gate answering UPDATE_IOREG with that entry's registered length on PmpHwConfig::confirm_ioreg_len (enabled only on T8132). Other SoCs keep the existing zero payload with no behavior change, and on T8132 an index that names no registered entry keeps the old zero with a warning. Signed-off-by: Diljit Singh <hey@djdev.me>
A system sleep keeps the T8132 PMP firmware's data segment, at the offset the image's own RTKit header gives (word 0x234). The check that the header names a page-aligned segment inside the SRAM ran only when a sleep began, so a firmware image that doesn't describe itself that way ran until its first sleep, which then failed. Check it at probe, and refuse such an image there with a message. The driver then runs only a T8132 image that describes its own layout, and the M4 PMP pieces can rely on that instead of on the OS firmware's version. An offset of 0 is refused too. Signed-off-by: Diljit Singh <hey@djdev.me>
…tible
The M4 PMP session's pieces — its power-vote bridge, its telemetry and
thermal policy, and the PMP report's readiness — previously ran only on
the Airs and on macOS 26.6.2 firmware because apple_t8132_firmware_path()
compares the boot loader's os-fw-version with "26.6.2". On the M4 Mac
mini (J773g) on macOS 27.2 there is then no thermal zone, no telemetry,
and no vote bridge, so the G16 driver's apple_pmp_j713_gpu_prepare()
refuses the PMP session and the GPU cannot come up.
None of these pieces depends on the OS firmware's version or the root
SoC compatible any more. Each takes what it needs from the PMP firmware
itself:
- the data segment from the image's header, which the PMP driver now
checks at probe;
- the temperature records by name;
- the IOP power handshake the firmware starts;
- each registry entry's length as the firmware registered it.
The vote bridge still checks its soc-device record in the firmware's
tunables.
Key each piece on the PMP node's own compatible ("apple,t8132-pmp-v2")
rather than the OS firmware version gate or a root SoC compatible check:
- pmp-report.c checks supplier->of_node directly (dropping the unused
apple_t8132_firmware_path stubs from the t6030-pmp host test harnesses);
- apple-pmp-thermal.c checks sensors->dev->of_node;
- pmp-display.h and pmp-telemetry.c check for an available
apple,t8132-pmp-v2 node.
apple_t8132_firmware_path() stays for the display, DART, and other paths
that this series does not touch.
Signed-off-by: Diljit Singh <hey@djdev.me>
…ode compatible t8132_platform_handoff() previously returned early unless the boot loader reported macOS 26.6.2 firmware or the Mac was an Air. On other firmware, macOS 27.2 among them, it applied neither of its two parts: - The PMGR ownership policy. Without it Linux owns every power domain in the board tree, with auto-PM written to each one at probe, including domains that stay firmware-owned (AIC, GPIO, display) or out of Linux's reach. On the M4 Mac mini (J773g) on 27.2 that ends in an SError when the PCIe controller probes. - The memory nodes (MCC, PMC and CLPC) for a loader tree that lacks them. They depend on the PMP path, which now self-describes from the firmware image header. Key the handoff on the presence of an "apple,t8132-pmp-v2" node rather than the root SoC compatible or OS firmware version string, and reuse that node reference when populating the missing platform nodes. Signed-off-by: Diljit Singh <hey@djdev.me>
f5610a1 to
0b5979c
Compare
|
@RyanTheTide Thanks for the thorough review! Updated and force-pushed (
Verification on
Assisted-by: LLM (Gemini:4 Neon) |
M4 (T8132) PMP session support on macOS 27.2 firmware (26B123), with no OS-version or board-name gate.
Why
On
integration/aurora, the M4 PMP pieces (power-vote bridge, telemetry, thermal policy, and PMP report readiness) run only on the Airs or when the boot loader'sos-fw-versionis"26.6.2". On the M4 Mac mini (J773g) running 27.2 firmware, that leaves no thermal zone, telemetry, or vote bridge, so the G16 driver'sapple_pmp_j713_gpu_prepare()refuses the PMP session.Observed runtime differences on 27.2 compared to 26.6.2:
segment-rangesdata offset and the SRAM RTKit header word at0x234move from0x3c000to0x3d000, and runtime SRAM scans locate the six named die temperature records0x1140bytes later (0x69764..0x69a98, same0xa4stride);-62);UPDATE_IOREGmessages with each entry's registered length (8).What
apple,smc-hwmonnodes for availablefan-*children (covering J773g, J604, J623/J624, and future fan-cooled T8132 boards while keeping the budget on fanless Airs). Rails remain read and reported through hwmon; die cooling from 106 C, thermal governor, and critical shutdown are unchanged.0x234for each named temperature record (0xa4stride for duplicates, plausibility check on the validity word). Runs onsystem_freezable_wqand checksapple_pmp_telemetry_online()(including the ASC run bit) before and after scanning.apple,sram-keep(exact offset and size from ADTsegment-ranges) when provided by the boot loader; otherwise takes the offset from header word0x234(4 KiB-aligned) with the0x68000fallback size.apple_rtkit_boot_or_wake(). Gives a co-processor a bounded window (20 ms, 15x the 1.3 ms observed J773g start) to report in and acknowledge IOP power on by itself before falling back toapple_rtkit_wake().boot_or_wake(). Matches the observed macOS 27.2 handshake on J773g without sending an unanswered IOP power request.UPDATE_IOREGwith the entry's registered length (word0x48of itsREGISTER_IOREGbuffer;8for the four entries updated on J773g 27.2; unknown indices keep0with a warning).apple_t8132_pmp_path(). Replaces the26.6.2version gate for the PMP session pieces (vote bridge, telemetry, thermal, PMP report).apple_t8132_firmware_path()stays unchanged for display, DART, PMGR, and boot-handoff paths.The earlier J713 dark-span hold commit (
422bc70b) has been dropped from this PR to avoid hardcoded idle thresholds and to stay clear of #2699.Testing
12aea2b043f2onintegration/auroraa84637dca209):asahiprofileImage+modulesbuilt cleanly (rc=0, 0 warnings on all modified files).scripts/checkpatch.pl --git origin/integration/aurora..HEADclean (0 errors, 0 warnings across all 9 commits).tools/testing/selftests/drivers/gpu/asahi-m4/test-thermal-sensor.pypassed (75,414 frozen oracle rows + moved-record, ambiguity, and range-bounds checks).7.3.0-ARCH-m4drv8(two boots, module-equivalentapple-pmp.ko+apple-pmp-thermal.ko):PMP firmware acknowledged IOP power on by itself,PMP firmware and endpoint ready), 0-62timeouts, 0 unregisteredUPDATE_IOREGentries.0x69764 0x69808 0x698ac 0x69950 0x699f4 0x69a98 (data from 0x3d000).apple-pmp-thermalprobed cleanly withrail power reported, no power budget, die thermal zone (apple-pmp-die52.75–56.0 C), 6apple_pmp+ 4apple_pmp_powerhwmon inputs, vote bridge ready, and full GPU/display bring-up with 0 backstop trips across compute/render rows.12aea2b043f2) on J773g 27.2.rtkitstart andCONFIRM_IOREGtouch every PMP SoC).Assisted-by: LLM (Gemini:4 Neon)