Skip to content

accel/ane: hold performance-domains CPU cluster while requests run - #3006

Closed
satchlj wants to merge 3 commits into
integration/aurorafrom
satchlj/ane-cluster-hold
Closed

satchlj wants to merge 3 commits into
integration/aurorafrom
satchlj/ane-cluster-hold

Conversation

@satchlj

@satchlj satchlj commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Hold up the CPU cluster named by an ANE node's performance-domains DT property while EXECUTE requests are in flight (plus a 100 ms idle hold), using freq_qos (FREQ_QOS_MIN at policy max) and dev_pm_qos (DEV_PM_QOS_RESUME_LATENCY = 0).

  1. dt-bindings: npu: apple,ane: describe performance-domains — documents optional performance-domains on apple,ane pointing to the CPU cluster performance domain held up while requests run.
  2. accel/ane: hold up the performance-domains CPU cluster while requests run — adds drivers/accel/ane/ane_cluster_hold.{c,h} and wires it into the H16/H17 (ane_h16_backend.c, ane_fw_cold.c) execution path:
    • Strictly DT-driven: keys solely on performance-domains matching a CPU cluster's performance-domains phandle + specifier args (#performance-domain-cells 0-cell and multi-cell safe). Nodes without performance-domains, or pointing to a domain without CPUs, are a no-op; no SoC or board checks.
    • Lockless fast-path check in ane_cluster_hold_busy() paired with WRITE_ONCE/READ_ONCE; all freq_qos / dev_pm_qos mutations run in work items (kick / release), never in the request path.
    • Policy max limits (including thermal caps) still take precedence (FREQ_QOS_MIN cannot override FREQ_QOS_MAX).
    • Releases and cancels pending work (cancel_work_sync) on PM_SUSPEND_PREPARE / PM_HIBERNATION_PREPARE, and ane_cluster_hold_fini() is a safe no-op (if (!h->ready) return;) on zero-initialized holds before ane_cluster_hold_init().
  3. arm64: dts: apple: t6050-j775c: link the ANE to its CPU cluster — links ane0 to &cpufreq_pc on J775c.

Verification

Static & build checks (on exact PR tree 5d911e8fe25b)

  • scripts/checkpatch.pl --git origin/integration/aurora..HEAD: 0 errors (only expected MAINTAINERS notice for new files under drivers/accel/ane/, covered by F: drivers/accel/ane/).
  • make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/npu/apple,ane.yaml: PASS (0 warnings, 0 errors).
  • make dtbs_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/npu/apple,ane.yaml apple/t6050-j775c.dtb: PASS (0 warnings, 0 errors).
  • W=1 arm64 compile with CONFIG_DRM_ACCEL_ANE=y: PASS (0 warnings, 0 errors).
  • W=1 arm64 compile with CONFIG_DRM_ACCEL_ANE=m: PASS (0 warnings, 0 errors).
  • W=1 arm64 compile with CONFIG_CPU_FREQ=n + CONFIG_DRM_ACCEL_ANE=y: PASS (0 warnings, 0 errors).

Hardware test on J775c (Mac Studio M5 Max, T6050) — final driver code

  • Kernel stack: cand-16b + #3003 + #3004 (c8d987803624, boot-default .ane = { 6, 2 }, no debugfs override) + exact final #3006 driver (ane_cluster_hold.c sha256:eac0efce..., ane_cluster_hold.h sha256:e88ae278...) with ane@508000000 performance-domains = <&cpufreq_pc0> in the carry DTB.
  • Boot & artifacts: 7.3.0-lobata-cand+ #3 SMP PREEMPT Mon Nov 23 14:38:22 EST 2026, build-id: 44ecd8f1a0edae7c7ecda9d2f9189c1fbbcac2c5, boot_id: d34470f0-1857-40c5-aef5-13df4d3dc646, Image.gz sha256:1f1f0880301a414a5bca7e8c523e12b15972c4013394257fc6ffb51b0b093d28, t6050-j775c.dtb sha256:0442bec28ef4c650d4e3395589f7001808c7e5b4a3bdd4971fc466d68f9de0ed.
  • DT resolution & verbatim dmesg attach:
    • /proc/device-tree/soc/ane@508000000/performance-domains = 0x00000008 resolved to policy12 (CPUs 12-17, min=300000, max=4608000, gov=schedutil).
    • [ 11.611878] ane_t6021 508000000.ane: CPUs 12-17 (cpufreq policy12) held up while requests run
  • Functional readback (policy12 scaling_cur_freq / scaling_min_freq & cpuidle):
    • Before EXECUTE: cur=300000 min=300000.
    • Run 1 (unet-320 200 runs, p50 2658.2 µs, p90 2675.5 µs, p99 2686.1 µs, mean 2641.6 µs; add64 p50 170.9 µs):
      • During EXECUTE (20 samples @ 40 ms): 15× (4608000, 4608000), 3× (300000, 300000), 1× (1620000, 300000), 1× (2292000, 300000).
      • cpuidle deltas across CPUs 12–17 (WFI-only states, latency=1us): state0 +usage=309 +time=3800238us, state1 +usage=343 +time=1038263us.
      • 1 s after release: cur=300000 min=300000.
    • Run 2 (unet-320 200 runs, p50 2498.3 µs, p90 2520.3 µs, p99 2540.0 µs, mean 2499.3 µs; add64 p50 175.0 µs):
      • During EXECUTE (20 samples @ 40 ms): 14× (4608000, 4608000), 5× (300000, 300000), 1× (2880000, 300000).
      • cpuidle deltas across CPUs 12–17: state0 +usage=8186 +time=3560433us, state1 +usage=130 +time=538813us.
      • 1 s after release: cur=300000 min=300000.
    • Reference accuracy on both runs: finite True, max|ref| 2.512, max abs err 0.0035, mean abs err 0.00042, rel 0.0014.
    • Median unet-320 latency on the tip stack is unchanged around ~2.5–2.65 ms; in a separate baseline-kernel measurement with an earlier cluster-hold implementation where per-inference latency was sub-millisecond, holding the cluster reduced unet-320 median from 912.7 µs to 550.7 µs.
  • §5 Regression health: 0 ANE errors, 0 CLPC/PMC errors, 0 SELinux AVC denials, 0 failed systemd units, 0 new kernel errors (same 3 pre-existing cand-16b lines in journalctl -b -k -p err: 1 snd-soc-macaudio safety-disable + 2 apple-dcp lines). Clean warm handback to known-good default kernel verified (f463db85-87c5-4e1e-b21a-fba02ad1d72f, marker: spent, both ESPs clean).

Not tested

  • Not yet tested on non-J775c Apple Silicon Macs (non-J775c nodes omit performance-domains, so the driver takes the no-op path; =y/=m/!CONFIG_CPU_FREQ compile paths verified).
  • The J775c trial ran on cand-16b + #3003 + #3004 + this series because integration/aurora tip does not yet carry the full J775c boot stack standalone (patch 3 t6050-j775c.dts is verified by dtbs_check; the carry DTB uses the same performance-domains link on ane@508000000).
  • System sleep (PM_SUSPEND_PREPARE release path) was not exercised on J775c in this row (S2R is not yet enabled on J775c).
  • Deep cpuidle power-down states were not present on J775c (CPUs 12–17 expose only WFI state0/state1 with latency=1us), so DEV_PM_QOS_RESUME_LATENCY = 0 suppression of deep power-down states is not observable on this board.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)
Assisted-by: LLM (Google:Gemini 4 Neon)

An ANE node may name the CPU cluster performance domain that the driver
holds up while requests run.

Signed-off-by: Satya Benson <satya@benson.earth>
… run

The H16/H17 backends raise the CLPC's DRAM and fabric floors while an
EXECUTE is in flight, but leave the CPU clusters to the governor. When
the node names a CPU cluster in performance-domains, hold that cluster
up from the first EXECUTE until 100 ms after the last one ends: a
minimum-frequency request at the policy's maximum, and a resume latency
of 0 on its CPUs so that cpuidle keeps them out of power-down. A policy
maximum such as a thermal limit still wins.

Nodes without performance-domains, or naming a domain without CPUs,
hold nothing; there is no SoC or board check. The requests are changed
from work items, never in the request path, attach once the cluster's
cpufreq policy exists, and are dropped before system sleep.

Tested on J775c (Mac Studio M5 Max, T6050) on cand-16b + #3003 + #3004
with this final driver code (boot_id d34470f0-1857-40c5-aef5-13df4d3dc646):
on the first EXECUTE the driver logged
"ane_t6021 508000000.ane: CPUs 12-17 (cpufreq policy12) held up while
requests run", policy12 scaling_min_freq/scaling_cur_freq rose from
300000 kHz before EXECUTE to 4608000 kHz during EXECUTE and returned to
300000 kHz after idle release, with 0 ANE errors, 0 CLPC/PMC errors,
0 SELinux denials, 0 failed units, and 0 new kernel errors. Median
unet-320 latency on the tip stack is unchanged around ~2.5-2.65 ms;
in a separate baseline-kernel measurement with an earlier cluster-hold
implementation where per-inference latency was sub-millisecond, holding
the cluster reduced unet-320 median from 912.7 us to 550.7 us.

Signed-off-by: Satya Benson <satya@benson.earth>
Name the cpufreq_pc cluster in the ANE node's performance-domains, so
the driver holds it up while requests run.

Signed-off-by: Satya Benson <satya@benson.earth>

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

Formal §1–§6 pre-PR checklist review at a1c9e7bfcbff9561ace139eb0db107c2eeb301ca (REQUEST_CHANGES).

What passes

  • Buildability & DT schema: W=1 arm64 builds (CONFIG_DRM_ACCEL_ANE=y, =m, and CONFIG_CPU_FREQ=n) verified by author; live CI dt-checks and host-tests are green; OF node refcounting in ane_cluster_hold_attach() (of_parse_phandle_with_args, of_cpu_device_node_get) and init/fini error unwinds in ane_fw_cold.c and ane_h16_backend.c are clean; non-J775c nodes without performance-domains take the no-op path.
  • §4 & §6 (Clean-room, attribution, naming): All 3 commits (d9087e4df56a, 8cd431751654, a1c9e7bfcbff) carry human author/committer (Satya Benson <satya@benson.earth>) and human Signed-off-by: only (zero AI trailers); PR body carries Assisted-by:; clean naming.

Blockers

  1. Suspend race / stuck cluster hold & PM QoS (ane_fw_pm_event() & ane_h16_pm_event()):
    • Both ane_fw_pm_event() (ane_fw_cold.c) and ane_h16_pm_event() (ane_h16_backend.c) call ane_cluster_hold_drop(&...->hold) before ane_fw_sleep_prepare() / ane_h16_sleep_prepare() calls ane_h16_session_sleep(..., true) to quiesce in-flight and incoming EXECUTE requests.
    • ane_cluster_hold_drop()'s own contract requires "with requests stopped" (and it clears h->want = false without clearing h->busy). Because requests are NOT stopped yet, an in-flight EXECUTE finishing or a new EXECUTE starting on an unparked engine between ane_cluster_hold_drop() and ane_h16_session_sleep(..., true) will call ane_cluster_hold_busy() and re-queue apply / release, allowing the system to enter sleep with FREQ_QOS_MIN pinned at max_freq and DEV_PM_QOS_RESUME_LATENCY = 0 active.
    • In addition, ane_h16_pm_event() drops the hold even on platforms without a sleep path (!sleep_warm && !sleep_cold) right before refusing suspend while requests may still run; and despite the PR body claiming PM_HIBERNATION_PREPARE handling, neither notifier calls ane_cluster_hold_drop() on PM_HIBERNATION_PREPARE.
  2. Missing CPUFREQ_REMOVE_POLICY handling & silent freq_qos error state drift (ane_cluster_hold.c):
    • ane_cluster_hold_attach() takes policy = cpufreq_cpu_get(cpu), stores it permanently in h->policy, and adds freq_qos_add_request(&policy->constraints, &h->freq, ...) without registering a CPUFREQ_POLICY_NOTIFIER for CPUFREQ_REMOVE_POLICY. Compare apple_clpc_policy_notify() in drivers/soc/apple/clpc.c: if the cpufreq driver module unloads or a cluster policy is torn down, h->freq is never withdrawn and h->policy stays pinned/stale until reboot (since pinned ANE backends never run fini).
    • In ane_cluster_hold_apply(), if freq_qos_update_request() returns < 0, WRITE_ONCE(h->held, want) still flips unconditionally, leaving h->held out of sync with the actual QoS request (so a failed drop would never be retried).
  3. Architectural duplication & policy conflict with drivers/soc/apple/clpc.c (#3009 / #2856):
    • apple-clpc already implements the ANE CPU cluster frequency floor (apple_clpc_ane_cluster(), active on T6040 in tree, extended to T8142 in #3009, and being made DT-driven via apple,ane-cpu-opp in #2856) driven by the same apple_clpc_ane_set_active() hook.
    • #3006 introduces a second, parallel freq_qos mechanism and a competing DT binding (performance-domains on apple,ane) that unconditionally pins FREQ_QOS_MIN at policy->cpuinfo.max_freq rather than a measured knee OPP (for example, on T8142 #3009 measured 4176 MHz / 4.49 W as the knee vs 4464 MHz / 5.31 W with no speedup; on T8132 #2856 measured 2616 MHz vs 4.1 GHz). If both CLPC and #3006 are ever active on the same SoC, #3006's max_freq vote silently overrides CLPC's power-optimal knee OPP and adds mismatched hold windows (32 ms vs 100 ms).
    • Please converge on a single mechanism/DT binding (e.g. extending CLPC's DT-driven apple,ane-cpu-opp from #2856 to T6050) rather than carrying two parallel ANE cluster-hold implementations, unless hardware A/B proves DEV_PM_QOS_RESUME_LATENCY = 0 is strictly necessary on a board with deep cpuidle states.
  4. §1 Single-board DT gating (Patch 3):
    • Patch 3 adds performance-domains = <&cpufreq_pc> only to arch/arm64/boot/dts/apple/t6050-j775c.dts instead of the shared T6050 DTSI (t6050-peripherals.dtsi / t6050-max.dtsi), even though cpufreq_pc and ane0 are common across T6050 boards (j714s, j716c, j775c, etc.).
  5. §5 Evidence & test gaps:
    • On the tested PR stack (boot_id: d34470f0-1857-40c5-aef5-13df4d3dc646), unet-320 latency was unchanged (~2.50–2.66 ms vs #3004 alone 2.55 ms; the 912.7 -> 550.7 us figure is from a separate older kernel/implementation).
    • DEV_PM_QOS_RESUME_LATENCY = 0 could not be observed/verified on J775c (WFI-only latency=1us states), and PM_SUSPEND_PREPARE was untested.
    • ane_cluster_hold.c adds ~290 lines of concurrency/lifecycle state machine without KUnit tests. (Also note PR body cites 5d911e8fe25b for static checks rather than live head a1c9e7bfcbff.)

Assisted-by: LLM (Gemini 4 Neon)

@satchlj

satchlj commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Gemini 4 Neon on @satchlj's behalf.

Closing this PR to converge on apple-clpc's single ANE CPU cluster floor mechanism (#3009 merged, #2856 DT-driven apple,ane-cpu-opp) rather than carrying a parallel freq_qos + performance-domains path that pins max_freq and showed no unet-320 latency improvement on J775c over #3004. If T6050 needs an ANE CPU cluster floor beyond #3004, we will extend CLPC's knee-OPP binding instead.

@satchlj satchlj closed this Nov 23, 2026
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