Repository navigation
soc: apple: clpc: hold the M4 (T8132) memory, fabric and P-cluster floors for ANE work - #2856
RyanTheTide wants to merge 6 commits into
Conversation
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>
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>
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>
|
Review at a3ff203. The DT shape for the cluster floor is the right direction, but the series still carries a SoC gate, the floor value comes from a benchmark, and the head mechanism has not run on hardware.
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial pre-PR checklist review (§1–§6) at a3ff20338afe6fd8190de3151a6569a468c20b96 (REQUEST_CHANGES).
Checklist Summary
- §1 (No model gating): Pass — at head
a3ff2033, T8132's ANE cluster floor is driven purely from the DT propertyapple,ane-cpu-opp = <&donan_p_opp_2616>inarch/arm64/boot/dts/apple/t8132.dtsi(documented inDocumentation/devicetree/bindings/power/apple,pmc.yaml), withapple_clpc_hw_t8132.ane_cluster_khz = 0and.ane_cluster_machine = NULL. T6040 retains its existing table entry only as a fallback whenapple,ane-cpu-oppis absent (-ENOENT), per §1 chicken-and-egg rules. - §2 (Production-ready / default cmdline): Pass — works on default command line with no module parameters or hacks.
- §3 (Safety & concurrency): Pass (with one pre-existing non-blocking concurrency note below) —
apple_clpc_ane_cpu_opp()validatesopp-hzin[1 kHz, S32_MAX kHz](preventing negatives32PM QoS requests), comparescpu_table == tablebeforeof_node_put(), and balances all OF node references (verified byclpc-ane-cpu-opp-tests.py+ 5 mutations). Movingapple_clpc_policy_nb_register()afterdevm_add_action_or_reset(dev, apple_clpc_stop, clpc)andmutex_init(&clpc->sample_lock)closes the probe-error UAF / uninitialized-mutex race and prevents double registration when bothane_cpu >= 0andlow_power_khzare set.clpc->anekref +apple_clpc_ane_detach()remain safe across removal. - §4 (Clean-room & attribution): Pass — all 6 commits carry human author/committer and human
Signed-off-by:only; PR body includesAssisted-by:. - §5 (Evidence): Blocked — see Blocker below.
- §6 (Naming): Pass — clean Aurora/Linux naming throughout.
Blocker
- §5 (Evidence) — No J713 hardware run or arm64 KUnit run at head
a3ff2033(and CI still running):- The J713 MobileNetV1 table in the PR body was collected on the earlier table-based commits (prior to
apple,ane-cpu-oppDT parsing, theapple_clpc_policy_nb_register()/apple_clpc_stop()reordering, and the rebase onto#2816). - As listed under
**Still to run.**, please post the heada3ff2033evidence:- arm64 QEMU KUnit (
drivers/soc/apple/clpc.kunitconfig) ona3ff2033. - J713 run on
a3ff2033with a Stage 2 DTB built from this tree: 2.616 GHz P-cluster floor held during MobileNetV1 and released after, matching EXECUTE latency, plus a boot withoutapple,ane-cpu-oppshowing no cluster floor and no regressions. - On the same J713 boot:
#2816low-power/performanceplatform profiles still behave as before, thermal/scaling_max_freqcap below 2.616 GHz still wins over the ANE floor, idle/sustained package power, and regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).
- arm64 QEMU KUnit (
- Also wait for CI
dt-checksandkunitto finish green (currentlyIN_PROGRESS;host-tests,source,rust-build, and DWC3/ATC builds are green).
- The J713 MobileNetV1 table in the PR body was collected on the earlier table-based commits (prior to
Non-blocking Technical Notes
- Pre-existing lock race between
apple_clpc_halt()andapple_clpc_policy_notify()(drivers/soc/apple/clpc.c:1196-1199, 1221-1230, 1252-1262):apple_clpc_halt()readsclpc->ane_qos_khzand callsfreq_qos_update_request(&clpc->ane_qos, FREQ_QOS_MIN_DEFAULT_VALUE)without holdingclpc->sample_lock, and inapple_clpc_stop()it runs beforecpufreq_unregister_notifier(). A concurrentCPUFREQ_REMOVE_POLICYcallback (which takessample_lockand callsfreq_qos_remove_request(&clpc->ane_qos)) can race withapple_clpc_halt()on suspend or unbind. Wrapping theane_qosupdate inapple_clpc_halt()withsample_lock(and checkingfreq_qos_request_active(&clpc->ane_qos)) would close this cleanly. apple_clpc_ane_cpu_opp()missing-vs-invalid phandle (clpc.c:1288-1290): Ifapple,ane-cpu-oppis present in DT with a broken phandle,of_parse_phandle()returnsNULLand the helper returns-ENOENT, which on a fallback-capable SoC (like T6040) would silently fall back to the table instead of returning-EINVAL. Checkingof_property_present()first would distinguish absent from malformed.- Intermediate commit gating: Commit 2 (
2b4248d1523b) temporarily adds.ane_cluster_machine = "apple,t8132"before commit 5 (60dd04604a66) replaces it withapple,ane-cpu-opp. Net state ata3ff2033is clean.
Assisted-by: LLM (Gemini 4 Neon)
|
Review at a3ff203: BLOCKERS:
The two code findings from the #2671 review are fixed at this head, and I found no new code defect. The blockers above are the hardware rows that review asked for, which are still owed. Full reviewCode findings from the #2671 review (9736f57), checked at a3ff203:
Replay onto #2816: the only conflict, Other Macs: when the property is absent, Lifetime/refcount: the DT/binding: Mechanics: every commit in integration/aurora..a3ff203 carries only Run here at a3ff203:
Assisted-by: LLM (Claude:Opus 5.5) |
|
arm64 KUnit at a3ff203 (§5 item 1): |
|
J713 rows at a3ff203 (13-inch M4 Air, 27.2), for item 3 of the review. The kernel is integration/aurora 95a13cf plus open heads, including this PR at a3ff203, booted as a one-shot on the default command line. The ANE load is MobileNetV1 looped on the H16G. policy0 is the P cluster (CPUs 0, 7, 8, 9). Values were sampled every 50 ms.
Still to run: the boot with a DTB that lacks Assisted-by: LLM (Claude:Opus 5.5) |
This supersedes #2671. It carries the same six commits, rebased onto integration/aurora after #2816 (low-power ceiling from
apple,low-power-frequency-max-mhz, High Power mode fromapple,high-power-mode). #2671 no longer merged and its branch can't be rewritten without a force push, so this is a new branch. The only conflict was inapple_clpc_probe(), and the range-diff is below.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, which must be at most S32_MAX kHz so that a frequency QoS request can hold it. 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.apple_clpc_policy_nb_register()) only after theapple_clpc_stopdevm action is in place, so a probe error can't leave a freedclpcon the notifier chain. Both users go through the helper: the ANE cluster floor and the low-power profile ceiling, which since soc: apple: clpc: Take the Low Power mode ceiling from the DT (rebased on #2784) #2816 comes from the DT and may now sit next to the "apple-smc" (High Power mode only) profile.#2630 (which makes the T8132 ANE run on 27.2 firmware) is merged and is part of the base.
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. 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.drivers/soc/apple/clpc.o, W=1, LLVM, arm64 fleet config: 0 warnings.run-host-tests.py --only clpc: 9/9. That includes theclpc-ane-cpu-opp-tests.pycases for anopp-hzof (S32_MAX + 1) kHz (refused), S32_MAX kHz and 1 kHz (held) and an OPP with no parent table (refused), with all five mutants killed (any-cpu,hz,leak,u32,no-parent).clpc-high-power-cleanup-testsfrom soc: apple: clpc: Take the Low Power mode ceiling from the DT (rebased on #2784) #2816 passes too.run-host-tests.py --only pmp: 22/22.checkpatch.pl --strict: 0 errors and 0 checks on all six commits. The one warning is the usual "does MAINTAINERS need updating?" for the new host test file.Still to run.
scaling_max_freqcap below 2.616 GHz still wins over the ANE floor.range-diff against #2671 (a0dcf61)
git range-diff integration/aurora..a0dcf61c 95a13cf6..a3ff2033:The registration still runs after
devm_add_action_or_reset(dev, apple_clpc_stop, clpc), and both callers go through the helper, so the notifier is registered at most once.Assisted-by: LLM (Claude:Opus 5.5)