Skip to content

soc: apple: clpc: hold the M4 (T8132) memory, fabric and P-cluster floors for ANE work - #2671

Closed
RyanTheTide wants to merge 8 commits into
integration/aurorafrom
ane/t8132-clpc-floor
Closed

RyanTheTide wants to merge 8 commits into
integration/aurorafrom
ane/t8132-clpc-floor

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Make the T8132 CLPC an ANE provider.
  • Hold its one qualified busy floor (M5/F3, the state the GPU already gets while it has work in flight) while ANE work is in flight. It is released 32 ms (HOLD_MS) after the last request ends, as on the other SoCs.
  • As on the M4 Pro, the engine runs at a speed set by one CPU cluster's frequency, here the P cluster. Hold that cluster at 2.616 GHz while ANE work is in flight, through the existing cluster floor. That's where the firmware time reaches its plateau: 0.44 ms 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.
  • The cluster and the floor come from the device tree, not from a SoC table or a machine check. The CLPC node's new apple,ane-cpu-opp names an OPP; the cluster is the one whose CPUs use that OPP's table, and the floor is its opp-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.
  • Fix the CLPC KUnit config, which did not link: it was missing the SMC driver.

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:

kernel EXECUTE p50 firmware time top-1
#2630 only 0.918 ms 0.697 ms 16/16
+ M5/F3 floor (commit 1) 0.682 ms 0.445 ms 16/16
+ P-cluster floor (commit 2) 0.457 ms 0.315 ms 16/16
#2630 only, every CPU busy 0.348 ms 0.310 ms 16/16
  • The add-128 program output is unchanged (sha256 a001d87e...a839, the same as on the M4 Pro), 0 WARN, oops, DART faults or AVCs.
  • With commit 1 only: E cluster busy gives 0.579 ms (firmware 0.476), P cluster busy gives 0.430 ms (firmware 0.287). That's what pointed at the P cluster.
  • KUnit (drivers/soc/apple/clpc.kunitconfig, arm64 qemu): 12 pass, 1 skip.
  • Head 9736f57 (device-tree floor): tools/asahi/clpc-ane-cpu-opp-tests.py runs the production parser over a fake tree. It covers the CPU from the OPP's table, kHz from opp-hz, refusals for an OPP no CPU uses or one with no usable frequency, CPUs without a node, and balanced node refs. The any-cpu, hz and leak mutants are killed. Full host suite 454/455; the one failure is the known pmp-floor-tests --mutant class-twice failure, 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_check adds nothing on t8132-j713/j773g, and dt_binding_check passes for apple,pmc.yaml.

Still to run.

  • A J713 row at 9736f57 with a Stage 2 DTB built from this tree: the 2.616 GHz floor held during MobileNetV1 and released after, the same EXECUTE times as the table version (0.457 ms p50). A boot whose device tree lacks the property shows no cluster floor and nothing else changes.
  • Idle power with the floors released after ANE work, and package power while the floors are held under a sustained ANE load.

Assisted-by: LLM (Claude:Opus 5.5)

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>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1.

I reviewed the two clpc commits. The first two commits are #2630, which has its own review.

  1. drivers/soc/apple/clpc.c:1584-1586 and 1404-1405: the ANE cluster floor is chosen by a per-SoC table entry (cluster 1, 2616000 kHz) plus a machine-compatible check, .ane_cluster_machine = "apple,t8132".
    • The machine check adds nothing. apple_clpc_hw_t8132 is only reachable through the apple,t8132-clpc match at clpc.c:2067, so of_machine_is_compatible("apple,t8132") is always true wherever this table applies. Drop it.
    • More importantly, both values are machine facts the devicetree already holds: the P cluster is a cpu-map node, and the floor is an existing OPP (opp-2616000000, arch/arm64/boot/dts/apple/t8132.dtsi:303). Have the CLPC node point at them, for example a phandle to the cluster and one to the OPP, and read the floor from there. Keep this table entry only as the fallback while the DTs catch up. That also lets the next SoC with the same coupling get a floor without another table entry.

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)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1.

  1. clpc.c:1583-1586 with 1404-1405: the ANE cluster floor is still chosen from a per-SoC table entry (cluster 1, 2616000 kHz) plus of_machine_is_compatible("apple,t8132"). The machine check is always true wherever this table applies, since apple_clpc_hw_t8132 is reachable only through the apple,t8132-clpc match at clpc.c:2067. Both values are already in the devicetree: the P cluster is cpu-map cluster1, and the floor is opp-2616000000 in t8132.dtsi:303. Please have the CLPC node reference the cluster and the OPP, read them in probe, apply no cluster floor when they are absent, and drop the machine string. Head d08c13b predates the earlier review, so this is still open.
    Smaller: .ane repeats the table's top .map state (5/3) and could be derived from it, and the new T8132 KUnit expectations sit under a T6040 comment. Rows still owed: a 10-minute sustained MobileNet run on the J713 with PHPC, P-cluster frequency and temperatures, idle power 60 s after the last request compared with accel/ane: run the T8132 (M4) Neural Engine on macOS 27.2 firmware #2630 alone, and a J773g boot with ANE work, since the floor applies to every M4.

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>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Pushed d08c13b..9736f57 (fast-forward) for the open blocker (the ANE cluster floor came from a per-SoC table entry plus of_machine_is_compatible("apple,t8132")):

  • 207078c adds apple,ane-cpu-opp to the CLPC node binding: an OPP of the CPU cluster whose frequency sets the ANE's speed.
  • e39f180 points the T8132 CLPC at the P cluster's opp-2616000000.
  • 9736f57 makes probe read it. The cluster is a CPU whose operating-points-v2 is that OPP's table, and the floor is the OPP's opp-hz. The T8132 table fields and the machine string are gone. Without the property there is no cluster floor. T6040 keeps its table entry (property absent -> table) until its tree carries the property; that move needs a J616s Stage 2 DTB refresh, so it's a follow-up.

The property sits in t8132.dtsi as a &clpc override, not in t8132-memory.dtsi. The T8132 platform-data adapter (drivers/soc/apple/t8132-platform-data.dts) includes t8132-memory.dtsi without the OPP tables, and a reference there broke its build; an independent review caught it before the push. A boot that takes its CLPC node from that adapter therefore gets no ANE cluster floor. That costs performance only.

The smaller points: the T8132 expectations now sit under their own comment. .ane still repeats the top .map state; I left that as is, to keep this change to the blocker.

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 pmp-floor-tests class-twice failure, which also fails on the tip). KUnit apple-clpc 10/10. W=1 clean, plus dtbs_check and dt_binding_check.

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 DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yaml documents apple,ane-cpu-opp, arch/arm64/boot/dts/apple/t8132.dtsi sets apple,ane-cpu-opp = <&donan_p_opp_2616> on &clpc (correctly keeping t8132-memory.dtsi and t8132-platform-data.dts free of CPU OPP references), and apple_clpc_ane_cpu_opp() derives both cluster CPU and floor kHz from DT.
  • Regression safety on other SoCs: When apple,ane-cpu-opp is absent (-ENOENT), T6040 preserves its existing table fallback; T8140 has ane_cluster_khz == 0; T8142/T8152/T6050 have clpc->ane == NULL. No other SoC changes behavior.
  • CI & Attribution (Rule 4): All 8/8 CI checks pass (dt-checks, host-tests including clpc-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 human Signed-off-by only; PR body ends with Assisted-by: LLM (Claude:Opus 5.5).

Code findings to address

  1. Error-path UAF on clpc->policy_nb in apple_clpc_probe() (drivers/soc/apple/clpc.c:1455-1546):
    cpufreq_register_notifier(&clpc->policy_nb, CPUFREQ_POLICY_NOTIFIER) runs at lines 1457–1459, before devm_add_action_or_reset(dev, apple_clpc_stop, clpc) is installed at line 1544. Any error return between lines 1460 and 1544 (missing/bad apple,gpu-power-state, missing PMC parent, missing reg, invalid rail count, or allocation failure) unwinds devm_kzalloc and frees clpc while &clpc->policy_nb remains registered on the global cpufreq_policy_notifier_list. This was pre-existing on T6040 and is now also reachable on T8132 whenever apple,ane-cpu-opp is present. Please register the notifier via a dedicated devm_add_action_or_reset unregister helper (or after apple_clpc_stop is registered).
  2. opp-hz upper bound exceeds freq_qos signed s32 range (drivers/soc/apple/clpc.c:1270-1271):
    apple_clpc_ane_cpu_opp() rejects div_u64(hz, 1000) > UINT_MAX, but freq_qos_update_request() takes s32 (S32_MAX / INT_MAX = FREQ_QOS_MAX_DEFAULT_VALUE). A malformed DT opp-hz in (S32_MAX * 1000, UINT_MAX * 1000] passes the check and then passes a negative s32 to freq_qos_update_request(), tripping clpc->update_errors on every sample. Please bound against S32_MAX (or INT_MAX) and cover it in clpc-ane-cpu-opp-tests.py.

Blocking hardware, safety & stacking items (Rules 1, 3, 5)

  1. Zero hardware runs at 9736f576: The DT apple,ane-cpu-opp path 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 within HOLD_MS, plus a boot with a DTB lacking apple,ane-cpu-opp confirming clean no-floor behavior.
  2. 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 the FREQ_QOS_MIN floor, plus idle package power 60 s after release compared with #2630 alone and a full regression check (0 AVC denials, 0 failed units, 0 new kernel errors).
  3. Second T8132 board row (Rule 1): J773g (or another T8132 Mac) boot with ANE work, since t8132.dtsi enables this across all T8132 boards.
  4. Stacked dependency: Commits 3dd4610d and 8f2af6f0 belong to open PR #2630 (still awaiting its T8132 26.6.2 stub row); #2671 should not merge ahead of #2630.

Minor non-blocking nits

  • drivers/soc/apple/clpc.c:1281-1282: of_node_put(cpu_table) runs before if (cpu_table == table); comparing before of_node_put() avoids comparing a released pointer.
  • drivers/soc/apple/clpc.c:1540: ane_cluster_khz debugfs is created whenever clpc->ane && clpc->ane_cpu >= 0, even if cpufreq_register_notifier() failed (!clpc->policy_nb_added). Gating on clpc->policy_nb_added avoids arming ane_qos without a removal notifier.
  • drivers/soc/apple/clpc.c:1940-1942: the apple_clpc_hw_t8132.ane KUnit checks still sit under the /* T6040 ... */ comment.
  • tools/asahi/clpc-ane-cpu-opp-tests.py: consider adding edge cases for parent == NULL and hz == 1000.

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J713 row at 9736f57, run on the J713 default kernel (7.3.0-bj713t6+, which carries this head and a DTB with apple,ane-cpu-opp; default cmdline; 27.2). I sampled every policy's scaling_min_freq at 50 ms through 3 s of idle, then MobileNetV1 for 30000 runs, then 3 s after.

  • The P policy minimum went from 912000 to 2616000 0.10 s after MobileNet started, held for the whole run, and was back at 912000 within one 50 ms sample of the end. That fits APPLE_CLPC_HOLD_MS = 32.
  • MobileNet passed, with p50 0.443 ms. The E policy was untouched.

Still to run: the DTB-without-property boot and the 10-minute sustained row. The S32_MAX code fix is also still outstanding.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J713 10-minute sustained row at 9736f57, run on the J713 default kernel (7.3.0-bj713t6+ with a DTB that has apple,ane-cpu-opp; default cmdline; 27.2; on AC). MobileNetV1 ran in a loop for 600 s (43 passes, all PASS, last p50 0.540 ms), followed by 90 s idle, sampled at 1 Hz.

  • The P floor held: scaling_min_freq was 2616000 in 539 of 540 samples between 60 and 600 s. P ran at 2.616 GHz and the E policy was untouched.
  • Total system power was 6.7-7.0 W during the steady load. Die temperature peaked at 76.0 C, with no thermal action.
  • Release worked: after the loop the floor was off in all 65 samples (P minimum 912000, P at 1.26 GHz).

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 apple,ane-cpu-opp. The S32_MAX code fix is also still outstanding.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

#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>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Pushed 9736f57..a0dcf61 (fast-forward, one commit) for the two code findings and the nits.

  • Probe error left the policy notifier registered after clpc was freed (clpc.c 1455-1546). The notifier is now registered from a single helper, apple_clpc_policy_nb_register() (clpc.c:1254). Probe only calls it once the apple_clpc_stop devres action is installed: for the ANE floor at clpc.c:1551 and for the platform profile at clpc.c:1572. Probe now only works out the ANE CPU and floor early. Any error before the stop action therefore frees clpc with nothing on the chain, and the notifier can no longer run before sample_lock is initialised. ane_cluster_khz is set, and its debugfs file created, only when the notifier is registered (clpc.c:1552-1556), so ane_qos is never armed without its removal notifier.
  • opp-hz is now bounded by S32_MAX kHz, not UINT_MAX (clpc.c:1281). clpc-ane-cpu-opp-tests.py adds cases for (S32_MAX + 1) kHz (refused) and S32_MAX kHz and 1 kHz (both held), plus an OPP with no parent table. It also adds two mutants: u32 brings back the old bound, and no-parent drops the parent check.
  • Nits: the CPU's OPP table is compared before of_node_put() (clpc.c:1292). The T8132 KUnit expectations now sit under their own comment, with the T6040 ones under theirs.

Tests: drivers/soc/apple/clpc.o builds with W=1 (arm64, LLVM) with no new warnings; the one kernel-doc warning, about pmp_agent, was already there at 9736f57. run-host-tests.py --only clpc: 9/9 pass, and all 5 mutants of the ANE OPP parser are killed. checkpatch --strict is clean. The KUnit suite (apple-clpc*) has not been run on this head yet.

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)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #2856: the same commits rebased onto integration/aurora after #2816 (conflict in apple_clpc_probe() only; range-diff in the new PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants