Repository navigation
soc: apple: clpc: hold the M4 (T8132) memory, fabric and P-cluster floors for ANE work - #2671
RyanTheTide wants to merge 8 commits into
Conversation
On macOS 27.2 (26B123) iBoot preloads a T8132 ANE image with a different TEXT/DATA split than 26.6.2: TEXT 0xbc000 and DATA 0x2b0000, DATA at DVA 0x100_000b_c000 (as on T6050 and T8142 at 27.2). The T8132 platform pins the 25G83 sizes, so preflight refuses the hand-off with -EINVAL and the engine stays off on every M4 Mac that runs 27.2 firmware. - Let the H16 path pick the loader's build through next_build, as the H17 staged path already does: preflight and probe use the build whose preload sizes and IOVAs match the hand-off. - Let a preload rule carry the TEXT and DATA sizes it was made for (0 keeps the 26.5-27.0 sizes), and check the snapshots against them. - Add the T8132 27.2 build and its J713 profile. Its DATA has the 26A428 patchbay records and rewritten range 0x10 bytes earlier; GKTS and ECAP change on every boot, as on 25G83. The boot values are the T8132 25G83 ones. KUnit covers both T8132 builds (each admits only its own layout) and a rule that refuses snapshots of another size. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
program_add128_slots_test checks that a program without a scratch segment gets no scratch binding, but it passes NULL for the binding and then reads its own uninitialized one. With the stack pattern-filled the check fails (scratch.index 0xfefefefe). Pass the zeroed binding to ane_h16_process_bindings() so the check tests what it says. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The M4 (T8132) CLPC takes no ANE input, so Neural Engine work runs with the memory controller and fabric at whatever the CPUs ask for. On an idle J713 MobileNetV1 takes 0.92 ms an EXECUTE (firmware 0.70 ms). With every CPU busy, which makes the CLPC hold its M5/F3 busy floor, the same program takes 0.35 ms (firmware 0.34 ms). The M4 Pro, whose CLPC holds an ANE floor, takes 0.27 ms. Make the T8132 CLPC an ANE provider and hold that one qualified busy floor, M5/F3 (the state the GPU gets while it has work in flight), while ANE work is in flight. Also add the SMC dependency the CLPC KUnit config was missing (the test kernel did not link without it). Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
As on the M4 Pro, the M4's Neural Engine runs at a speed set by the frequency of one CPU cluster, whatever runs on it: here the P cluster (cpu-map cluster1). With the M5/F3 floor held, MobileNetV1 on a J713 spends 0.44 ms in the firmware with the P cluster at or below 1.512 GHz, 0.32 ms at 2.616 GHz and 0.29-0.31 ms from there up to 4.104 GHz. Hold the P cluster at 2.616 GHz, the start of that plateau, while ANE work is in flight, through the existing cluster floor. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Blockers: 1. I reviewed the two clpc commits. The first two commits are #2630, which has its own review.
HW row: J713, this head on the default cmdline. Run MobileNetV1 continuously for 10 minutes and record package power (PHPC), the P-cluster frequency and die temperatures while the floors are held. Then record idle package power 60 s after the last request, against #2630 alone. Pass if the P-cluster floor drops within the 32 ms hold, idle power matches #2630, thermal throttling still lowers the P cluster under the sustained load (the frequency QoS maximum wins over the minimum), and the regression run shows 0 AVC denials, 0 failed units and 0 new kernel errors. Assisted-by: LLM (Claude:Opus 5.5) |
|
Blockers: 1.
|
The Neural Engine on M4-generation SoCs runs at a speed set by the frequency of one CPU cluster, whatever runs on it. Let the CLPC node name an OPP of that cluster's table: while ANE work is in flight the cluster is held at or above that OPP's frequency. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
On a J713, MobileNetV1 spends 0.44 ms in the ANE firmware with the P cluster at or below 1.512 GHz, 0.32 ms at 2.616 GHz and 0.29-0.31 ms from there up to 4.104 GHz. Point the CLPC's apple,ane-cpu-opp at the P cluster's 2.616 GHz OPP, the start of that plateau. The property goes in t8132.dtsi, not in t8132-memory.dtsi with the rest of the CLPC node: the T8132 platform-data adapter shares that file without the CPU OPP tables, so a boot that takes its nodes from the adapter gets no ANE cluster floor. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T8132 ANE cluster floor came from the CLPC's hardware table (cluster 1, 2616000 kHz) and was applied only on machines compatible with "apple,t8132". Both are already in the device tree: the cluster is the one whose CPUs use the OPP table, and the floor is an OPP in it. Read the CLPC node's apple,ane-cpu-opp at probe: the cluster is a CPU whose operating-points-v2 is the OPP's table, the floor is its opp-hz. Without the property there is no cluster floor on T8132. T6040 keeps its table entry until its tree carries the property. tools/asahi/clpc-ane-cpu-opp-tests.py runs the production parser over a fake tree: the CPU comes from the OPP's table and the floor from its opp-hz, an OPP no CPU uses or without a usable frequency is refused, a CPU without a node is skipped, and every node it gets is put. Taking any CPU, reporting hertz or leaking the OPP node each fail it. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Pushed d08c13b..9736f57 (fast-forward) for the open blocker (the ANE cluster floor came from a per-SoC table entry plus
The property sits in t8132.dtsi as a The smaller points: the T8132 expectations now sit under their own comment. Tests: a new host test runs the production parser over a fake tree, with 3 mutants killed. Full host suite 454/455 (the one failure is the known Still owed: the J713 row with a Stage 2 DTB from this tree, and the rows from the earlier review (10-minute sustained MobileNet with PHPC/frequency/temperatures, idle power after release, J773g boot). |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial review at head 9736f576081153bd70c2642045111262a81fe143 against pre-pr-checklist.md.
Verdict: Request changes (2 code hardening fixes + owed hardware/thermal rows + open stacked PR #2630).
Resolved since prior review
- No model gating (Rule 1): The per-SoC T8132 cluster-floor table entry and redundant
of_machine_is_compatible("apple,t8132")gate are gone.Documentation/devicetree/bindings/power/apple,pmc.yamldocumentsapple,ane-cpu-opp,arch/arm64/boot/dts/apple/t8132.dtsisetsapple,ane-cpu-opp = <&donan_p_opp_2616>on&clpc(correctly keepingt8132-memory.dtsiandt8132-platform-data.dtsfree of CPU OPP references), andapple_clpc_ane_cpu_opp()derives both cluster CPU and floor kHz from DT. - Regression safety on other SoCs: When
apple,ane-cpu-oppis absent (-ENOENT), T6040 preserves its existing table fallback; T8140 hasane_cluster_khz == 0; T8142/T8152/T6050 haveclpc->ane == NULL. No other SoC changes behavior. - CI & Attribution (Rule 4): All 8/8 CI checks pass (
dt-checks,host-testsincludingclpc-ane-cpu-opp-tests.py+ 3 mutants,source,rust-build,kunit, 3×DWC3/ATC). All 7 commits carry human identity (Ryan Murray <ryan@aurorasilicon.org>) and humanSigned-off-byonly; PR body ends withAssisted-by: LLM (Claude:Opus 5.5).
Code findings to address
- Error-path UAF on
clpc->policy_nbinapple_clpc_probe()(drivers/soc/apple/clpc.c:1455-1546):
cpufreq_register_notifier(&clpc->policy_nb, CPUFREQ_POLICY_NOTIFIER)runs at lines 1457–1459, beforedevm_add_action_or_reset(dev, apple_clpc_stop, clpc)is installed at line 1544. Any error return between lines 1460 and 1544 (missing/badapple,gpu-power-state, missing PMC parent, missingreg, invalid rail count, or allocation failure) unwindsdevm_kzallocand freesclpcwhile&clpc->policy_nbremains registered on the globalcpufreq_policy_notifier_list. This was pre-existing on T6040 and is now also reachable on T8132 wheneverapple,ane-cpu-oppis present. Please register the notifier via a dedicateddevm_add_action_or_resetunregister helper (or afterapple_clpc_stopis registered). opp-hzupper bound exceedsfreq_qossigneds32range (drivers/soc/apple/clpc.c:1270-1271):
apple_clpc_ane_cpu_opp()rejectsdiv_u64(hz, 1000) > UINT_MAX, butfreq_qos_update_request()takess32(S32_MAX/INT_MAX=FREQ_QOS_MAX_DEFAULT_VALUE). A malformed DTopp-hzin(S32_MAX * 1000, UINT_MAX * 1000]passes the check and then passes a negatives32tofreq_qos_update_request(), trippingclpc->update_errorson every sample. Please bound againstS32_MAX(orINT_MAX) and cover it inclpc-ane-cpu-opp-tests.py.
Blocking hardware, safety & stacking items (Rules 1, 3, 5)
- Zero hardware runs at
9736f576: The DTapple,ane-cpu-opppath has not been booted on hardware yet. Needed on J713 (default cmdline, rebuilt Stage 2 DTB from this tree): confirm 2.616 GHz floor held during MobileNetV1 (~0.457 ms p50) and released withinHOLD_MS, plus a boot with a DTB lackingapple,ane-cpu-oppconfirming clean no-floor behavior. - Sustained thermal/power safety row (Rules 3 & 5): Still owed on J713 — 10-minute sustained MobileNetV1 run recording package power (PHPC), P-cluster frequency, and die temperatures, confirming thermal throttling (
FREQ_QOS_MAX) still overrides theFREQ_QOS_MINfloor, plus idle package power 60 s after release compared with#2630alone and a full regression check (0 AVC denials, 0 failed units, 0 new kernel errors). - Second T8132 board row (Rule 1): J773g (or another T8132 Mac) boot with ANE work, since
t8132.dtsienables this across all T8132 boards. - Stacked dependency: Commits
3dd4610dand8f2af6f0belong to open PR#2630(still awaiting its T8132 26.6.2 stub row);#2671should not merge ahead of#2630.
Minor non-blocking nits
drivers/soc/apple/clpc.c:1281-1282:of_node_put(cpu_table)runs beforeif (cpu_table == table); comparing beforeof_node_put()avoids comparing a released pointer.drivers/soc/apple/clpc.c:1540:ane_cluster_khzdebugfs is created wheneverclpc->ane && clpc->ane_cpu >= 0, even ifcpufreq_register_notifier()failed (!clpc->policy_nb_added). Gating onclpc->policy_nb_addedavoids armingane_qoswithout a removal notifier.drivers/soc/apple/clpc.c:1940-1942: theapple_clpc_hw_t8132.aneKUnit checks still sit under the/* T6040 ... */comment.tools/asahi/clpc-ane-cpu-opp-tests.py: consider adding edge cases forparent == NULLandhz == 1000.
Assisted-by: LLM (Google:Gemini 4 Neon)
|
J713 row at 9736f57, run on the J713 default kernel (7.3.0-bj713t6+, which carries this head and a DTB with
Still to run: the DTB-without-property boot and the 10-minute sustained row. The Assisted-by: LLM (Claude:Opus 5.5) |
|
J713 10-minute sustained row at 9736f57, run on the J713 default kernel (7.3.0-bj713t6+ with a DTB that has
Idle power 60 s after the release is not usable from this run. The internal panel came on at full brightness around the end of the loop (3.5 W before the load with the panel dark, 9.1-9.3 W after with it lit), so I'm not quoting an idle number. Still to run: the boot with a DTB that lacks Assisted-by: LLM (Claude:Opus 5.5) |
|
#2630 has landed and the J713 floor and 10-minute sustained rows are in. Still needed: the two probe fixes from review (a probe error must not leave the policy notifier registered after the CLPC data is freed, and opp-hz must be bounded by S32_MAX), a boot with a DTB that lacks apple,ane-cpu-opp, a J773g boot with ANE work, and an idle power reading 60 s after release with the panel dark, against #2630 alone. |
Probe registered the cpufreq policy notifier for the ANE cluster floor before apple_clpc_stop() was installed as a devres action. Any probe error in between (a bad apple,gpu-power-state, no PMC parent, no reg, a bad rail count, an allocation failure) freed the CLPC data with its notifier still on the global policy chain, and the notifier would also have taken sample_lock before mutex_init(). Register it from one helper, used by the ANE floor and by the platform profile, only once apple_clpc_stop() is in place to unregister it. The ANE floor and its ane_cluster_khz debugfs file now exist only when the notifier is registered. apple,ane-cpu-opp accepted any opp-hz up to UINT_MAX kHz, but the floor is a frequency QoS request, which is an s32: a value above S32_MAX kHz turned into a negative request that failed on every sample. Refuse it, compare the CPU's OPP table before putting it, and cover both bounds (1 kHz, S32_MAX kHz), an OPP outside a table and a CPU without a table in clpc-ane-cpu-opp-tests.py, with mutants for the bound and the missing parent check. Also put the T8132 ANE KUnit expectations under their own comment. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Pushed 9736f57..a0dcf61 (fast-forward, one commit) for the two code findings and the nits.
Tests: Still to run on the J713, on this head with the default cmdline:
A J773g boot with ANE work is also still needed. Assisted-by: LLM (Claude:Opus 5.5) |
Problem. On the M4 (T8132) the CLPC takes no Neural Engine input, so ANE work runs with the memory controller and fabric wherever the CPUs leave them. On an idle M4 Air (J713) MobileNetV1 takes 0.92 ms an EXECUTE. With every CPU busy, which makes the CLPC hold its M5/F3 busy floor, the same program takes 0.35 ms. The M4 Pro, whose CLPC already holds an ANE floor, takes 0.27 ms.
Change.
apple,ane-cpu-oppnames an OPP; the cluster is the one whose CPUs use that OPP's table, and the floor is itsopp-hz. t8132.dtsi points it at the P cluster's 2.616 GHz OPP. Without the property there is no cluster floor. T6040 keeps its existing table entry until its tree carries the property.Stacked on #2630 (which makes the T8132 ANE run on 27.2 firmware).
Testing.
All on a J713 (M4 Air), macOS 27.2 firmware, lab kernels on the stock cmdline, MobileNetV1 H16G, 2000 timed runs with the CPUs idle:
drivers/soc/apple/clpc.kunitconfig, arm64 qemu): 12 pass, 1 skip.tools/asahi/clpc-ane-cpu-opp-tests.pyruns the production parser over a fake tree. It covers the CPU from the OPP's table, kHz fromopp-hz, refusals for an OPP no CPU uses or one with no usable frequency, CPUs without a node, and balanced node refs. Theany-cpu,hzandleakmutants are killed. Full host suite 454/455; the one failure is the knownpmp-floor-tests --mutant class-twicefailure, which also fails on the tip. KUnit apple-clpc 10/10 (arm64 qemu). W=1 clean on clpc.o, t8132-platform-handoff.o and t8132-platform-data.dtb.o.dtbs_checkadds nothing on t8132-j713/j773g, anddt_binding_checkpasses for apple,pmc.yaml.Still to run.
Assisted-by: LLM (Claude:Opus 5.5)