Skip to content

accel/ane: h17: park an idle engine through runtime PM - #1863

Open
niteria wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
niteria:ane/h17-idle-park
Open

niteria wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
niteria:ane/h17-idle-park

Conversation

@niteria

@niteria niteria commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

After its first request, the H17 Neural Engine stays powered until the next system sleep. On a J700, ane_sys, the engine and its three DARTs were still on 10 minutes after the last request. Between boot and the first request, and after each wake, the engine is already parked: firmware stopped, power off.

Change

Once the engine serves programs, its ANE_SYS reference goes to runtime PM, and runtime autosuspend parks it when idle:

  • The bound device uses autosuspend with a 2 s delay. power/autosuspend_delay_ms changes it, and a negative value keeps the engine up until the next system sleep. There is no module or command-line parameter.
  • Runtime suspend parks the engine, the way a system sleep takes it down: close the session and wait for requests in flight, stop the firmware, power the engine off, and leave the session closed until the next request. A ring with something still pending returns -EBUSY with a fresh last-busy, so autosuspend tries again later.
  • Runtime resume boots it. A request for a parked engine resumes the device. The resume callback boots it from the preload and replays every open program, the path a wake already uses.
  • Executes hold the device; the end of an execute restarts the delay. A system sleep holds the device across its own shutdown, then suspends it at once, so ANE_SYS still goes off before the sleep. A quarantined engine keeps its power.

The 2 s default comes from the measured cost of a wake: a request that found the engine parked took ~18 ms end to end on a J700, against ~0.13 ms warm, and the H16 driver logs a cold boot from the preload at 9–11 ms. At 2 s the wake costs under 1% of any pause long enough to trigger it, and the engine cycles its power at most once every 2 s.

It applies to every engine whose firmware parks the macOS way (the backend's existing macos_sleep property): T8140 (J700) and T8142 (M5) today. The ANE platform driver gains runtime PM callbacks. They return 0 for every device that isn't the bound H17 engine, which is what the PM core does when a driver has none, so H16 and the M1/M2 devices behave as before.

Thanks to Ryan Murray for suggesting runtime PM for this.

Locking

The callbacks take b->lock only when they have work to do: a powered engine to park, or a parked engine at the program stage to boot. The paths that call into runtime PM while holding b->lock do so only with the engine already powered off (power-down, quarantine) or before it serves programs (the first bring-up). Neither can wait for a callback that needs the lock. The session wake calls pm_runtime_resume_and_get() without any lock held. The execute hooks run under the session lock and only take a no-resume reference or drop one with pm_runtime_put_autosuspend().

If runtime suspend is forbidden (power/control = on) or the delay is negative, a system sleep can park the engine while the device stays active. The wake then finds the engine still parked after pm_runtime_resume_and_get() and boots it itself.

Testing

What Result
arm64 build of drivers/accel/ane/, W=1, J700 config with the ANE built in No new warnings
KUnit under UML, boot.kunitconfig (KASAN, UBSAN) All suites pass except ane-h16-hwx, which crashes the same way on integration/aurora (15 pass, 2 crashed)
KUnit, pm.kunitconfig 16/16
tools/asahi/run-host-tests.py 450/451, the same as integration/aurora: the one failure, pmp-floor-tests --mutant class-twice, fails on both
checkpatch.pl --strict Clean
J700 (T8140, Aura 1.0.0b9, b8c5bb03 + this commit + J700 encoder-0 DT / ALS sleep fix) — park & wake First bring-up 18.2 ms (1024/1024 exact, 0 ulp, p50 127.1 us); parks ~2.4 s after last request (ane_sys off-0, engine + 3 DARTs suspended, DARTs off before ANE_SYS); wakes in 15.8 ms (1024/1024 exact, 0 ulp, p50 126.2 us)
J700 — program kept loaded across 3 parks Program held open across 3 × 3 s idle pauses; parked (ane_sys off-0) each time, replayed on wake (16.8 / 19.5 / 20.0 ms wake+replay+exec), 1024/1024 exact, 0 ulp on every run
J700 — power/autosuspend_delay_ms -1 and back -1 wakes and keeps ane_sys on past 5 s idle; restoring 2000 parks immediately; next request wakes in 15.5 ms (1024/1024 exact)
J700 — deep sleeps (rtcwake -m mem) 3/3 succeeded (suspend_stats/fail=0): parked, ~40 ms after use while active (stops firmware and drops ane_sys before sleep), and with autosuspend_delay_ms=-1 (fallback unpark path on next request); all 1024/1024 exact post-wake
J700 — battery power (4-pair ABABABAB, 25 s windows, fixed backlight 31/525) Total System Power 2171.2 mW parked vs 2182.6 mW idle-up (+11.4 mW, paired [+15.5, +6.7, +5.6, +18.0] mW); SMC PPMC 649.9 vs 661.8 mW (+11.9 mW, 4/4 pairs positive)
J700 — regression 0 failed systemd units, 0 ANE/DART/PMGR kernel errors or warnings
J813 (T8142, M5 MacBook Air 13", ab9352c6 + #2325 + #2747 + d271ab48, ANE as module ane_t6021.ko) — park & wake At boot 420000000.ane + both DARTs (421800000.iommu, 421840000.iommu) suspended, ane_sys off-0. First bring-up 16.5 ms (1024/1024 exact, 0 ulp, p50 125.2 us); parks ~2.3 s after UNLOAD (firmware stopped, status 0x6e, powered down, idle: parked until the next request, DARTs off before ANE_SYS, ane_sys off-0); wakes in 11.0 ms (1024/1024 exact, 0 ulp, p50 146.5 us)
J813 — program kept loaded across 3 parks Loaded once (10.94 ms), 3 × 3 s idle pauses; parked (ane_sys off-0, both DARTs suspended) each time, replayed on wake (18.43 / 22.30 / 21.60 ms wake+replay+exec), 1024/1024 exact, 0 ulp every cycle; close → re-parked cleanly
J813 — power/autosuspend_delay_ms -1 and back -1 wakes (ane_sys on), warm load 0.6 ms, stays active past 4.5 s idle; restoring 2000 parks immediately (ane_sys off-0), wake run 18.9 ms (1024/1024 exact), re-parked
J813 — deep sleeps (apple_sleep, t8142_wake_s=20) 4/4 succeeded (suspend_stats/fail=0): parked (ane_sys off-0), ~31 ms after UNLOAD while active (firmware stopped, status 0x6e, powered down, DARTs off before ANE_SYS, 10 coprocessors up and stopped, resume ok: parked until the next request), and with autosuspend_delay_ms=-1 (fallback unpark path in 11.2 ms); all 1024/1024 exact post-wake, 0 ANE/DART/PMGR errors
J713 (T8132 / H16G, M4 MacBook Air 13", dc771820 + d271ab48, ANE as module ane_t6021.ko) — H16 regression (idle + deep sleep) Loaded ane_t6021 confirmed carrying ane_rtclient_runtime_* / ane_fw_platform_runtime_*. 500000000.ane probed unchanged, power/runtime_status=unsupported throughout. add128 (16384/16384 exact, 0 ulp) passed before (0.6 ms load, p50 137.8 us) and after 3.5 s idle (0.4 ms load, p50 115.4 us). 1/1 deep sleep (rtcwake -d rtc1 -m mem -s 15, suspend_stats/fail=0): H16 ANE: resume ok: cold, firmware ready 11 ms, post-wake add128 passed immediately (0.4 ms load, p50 113.0 us) and again after 2.5 s idle (0.6 ms load, p50 206.9 us). 0 failed units, 0 ANE/DART/PMGR errors or warnings

Still to run

  • M1/M2 regression run: we do not have M1/M2 hardware locally. The new runtime PM callbacks in ane_t6021_rtclient_main.c return 0 without touching hardware for every device that isn't the bound H17 engine, so M1/M2 behavior is unchanged by inspection; happy for someone with an M1/M2 to run a check if desired.

  • Clean-room: no Apple code, strings, firmware, RE output or tuning values

  • No chip/board/firmware-version gate where a hardware property can decide

  • Works on the default kernel command line; no hacks, delays or lab-only paths

  • Safety limits come from the machine, not from constants in code

  • Hardware safety rules followed for every test boot

  • Third-party commits unchanged; reporters and testers credited

  • Commits: human Signed-off-by only; no agent trailers of any kind

  • Tested on the affected hardware; no regression (J700, J813/M5, and J713/H16G done; no M1/M2 hardware locally)

Assisted-by: LLM (Claude:Opus 5.5, Gemini)

m0d16l14n1 added a commit to m0d16l14n1/linux that referenced this pull request Nov 15, 2026
RyanTheTide: accel/ane: h17: recover a hung engine and retry a failed boot

With aurora-silicon#1863 (idle park) kept: the idle park leaves the engine alone while a
hung-request recovery is queued or running. aurora-silicon#1303 is not taken (aurora-silicon#1768 carries
its retry).
@RyanTheTide

Copy link
Copy Markdown
Contributor

idle_park_ms in ane_fw_cold.c adds a private module parameter for the idle park delay, and its 5000 ms default has no measurement behind it. This is what runtime PM autosuspend does: pm_runtime_set_autosuspend_delay() with a default based on the measured cold start, and the standard power/autosuspend_delay_ms attribute for anyone who needs a different value. Please move the park onto runtime PM and drop the parameter. Until then this should stay a draft.

@niteria niteria changed the title accel/ane: h17: park an idle engine accel/ane: h17: park an idle engine through runtime PM Nov 21, 2026
@niteria

niteria commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Moved onto runtime PM: the bound device uses autosuspend, the runtime suspend callback parks the engine, and the resume callback boots it for the next request. idle_park_ms is gone; power/autosuspend_delay_ms adjusts the delay, and a negative value keeps the engine up.

The default is 2 s, from the measured wake cost: a request on a parked engine took ~16–20 ms end to end on the J700 (cold boot + replay), and the H16 driver logs a cold boot from the preload at 9–11 ms. At 2 s the wake costs under 1% of any pause long enough to trigger it, and the engine cycles its power at most once every 2 s.

Rebased onto integration/aurora (b8c5bb03) and tested on J700 (park/wake, loaded program across 3 parks, deep sleeps parked/active/-1, autosuspend_delay_ms=-1 and back, plus an ABABABAB battery power check showing ~11 mW saved while parked). Build, KUnit, host-test, and J700 results are in the description; T8142 (M5) and H16/M1–M2 regression runs remain under "Still to run" while this stays in draft (and Signed-off-by will be added before leaving draft).

@niteria
niteria marked this pull request as ready for review November 21, 2026 23:54
The H17 engine stays off until its first request and is parked again
after each system sleep, but once a request has brought it up it stays
powered for the rest of the boot: ANE_SYS, the engine and its DARTs keep
drawing power until the next sleep.

Hand the engine's ANE_SYS reference to runtime PM once it serves
programs, and park it through runtime autosuspend:

- The bound device uses autosuspend with a 2 s delay. A request that
  finds the engine parked waits for a cold boot from the preload and the
  replay of its programs, ~18 ms on a J700; 2 s keeps that under 1% of a
  longer pause and the engine's power cycles at most one per 2 s. The
  standard power/autosuspend_delay_ms changes it, and a negative value
  keeps the engine up until the next system sleep.
- The runtime suspend callback takes the way down a system sleep takes:
  close the session and wait for requests in flight, stop the firmware,
  power the engine off and leave it parked, with the session closed, as
  after a wake. A ring with something still pending refuses with -EBUSY
  and autosuspend tries again later.
- A request for a parked engine resumes the device; the resume callback
  boots it from the preload and replays every open program, the path a
  wake already uses. If runtime PM never suspended the device (runtime
  PM forbidden) while a system sleep parked the engine, the request
  boots it itself.
- An execute holds the device and its end restarts the delay.
- A system sleep holds the device across its own way down and then
  suspends it at once, so ANE_SYS still goes off before the sleep.
- A quarantined engine keeps its power: the quarantine pins the device.

This applies to every engine whose firmware parks the macOS way
(macos_sleep), T8140 and T8142 today.

The callbacks take b->lock only when they have work to do (a powered
engine to park, a parked engine at the program stage to boot), and the
paths that call into runtime PM under b->lock do so only with the engine
already powered off or before it serves programs, so neither waits for
a callback that needs the lock.

Suggested-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: Bartosz Nitka <niteria@gmail.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-reviewed at d271ab4. The earlier point is fixed: idle_park_ms is gone, the park is the runtime suspend callback, the delay is the standard power/autosuspend_delay_ms with a 2 s default derived from the measured ~18 ms wake, and a negative delay keeps the engine up. Signed-off-by is present.

Checked the runtime PM paths:

  • A pending ring returns -EBUSY after pm_runtime_mark_last_busy(), so rpm_suspend() reschedules the autosuspend instead of leaving the engine up for good. The other -EBUSY returns (bring-up, quarantine, system sleep) leave it up on purpose and each has a later put that retries.
  • ane_fw_program_busy() holds a usage count for the whole time a program runs, and the suspend callback closes admission and drains before stopping the firmware, so a park can't land under a running program.
  • PM_SUSPEND_PREPARE takes a no-resume reference before the system sleep parks the engine itself, then drops it synchronously when the engine is off, so genpd can still turn ANE_SYS off for the sleep as before.
  • The rtclient change from pm_sleep_ptr() to pm_ptr() adds runtime callbacks that return 0 for non-platform devices, which is what runtime PM did for them without callbacks, so nothing changes there.

No blocker. The PR is no longer a draft, but the description still lists the T8142 (M5) row and the H16/M1–M2 regression runs under "Still to run". Those need to land before merge: on H16 at least one request after a 2 s idle (park + wake in the log, result unchanged) and one deep sleep with the engine parked.

Assisted-by: LLM (Claude:Opus 5.5)

@niteria

niteria commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Tested d271ab48 on J813 (M5 MacBook Air 13", T8142, ab9352c6 + #2325 + #2747 + d271ab48, with ane_t6021 built as a module):

  • Park & wake: boots parked (420000000.ane and both DARTs 421800000.iommu / 421840000.iommu suspended, ane_sys off-0, autosuspend_delay_ms=2000). First bring-up (add1024, 20 runs) in 16.5 ms (1024/1024 exact, 0 ulp, p50 125.2 us); parks ~2.3 s after UNLOAD (firmware stopped, status 0x6e, powered down, idle: parked until the next request, DARTs off before ANE_SYS: streams were 0x0 0x0 0x0, PMGR 0x23ff, ane_sys off-0); wakes in 11.0 ms (1024/1024 exact, 0 ulp) and re-parks cleanly.
  • Program held loaded across 3 parks: loaded once (10.94 ms), 3 × 3 s pauses verified parked (ane_sys off-0, both DARTs suspended) and replayed (H17 program replayed 0 0, 1st exec 18.43 / 22.30 / 21.60 ms, 5/5 1024/1024 exact, 0 ulp each cycle); close() → TERMINATE and UNLOAD → parked cleanly.
  • power/autosuspend_delay_ms -1 and back: -1 wakes (ane_sys on), warm load 0.6 ms, stays active past 4.5 s idle; restoring 2000 parks immediately (ane_sys off-0), wake run 18.9 ms (1024/1024 exact), re-parks cleanly.
  • Deep sleeps (apple_sleep, 4/4 succeeded, suspend_stats/fail=0): parked (ane_sys off-0), ~31 ms after UNLOAD while active (stops firmware, drops DARTs + ANE_SYS before 10 coprocessors up and stopped, resumes parked until the next request), and with autosuspend_delay_ms=-1 (takes fallback unpark path on next request in 11.2 ms); all 1024/1024 exact post-wake, 0 ANE/DART/PMGR kernel errors.

Updated the PR description with the J813/T8142 rows. The H16 and M1/M2 regression runs remain under "Still to run".

Assisted-by: LLM (Gemini)

@niteria

niteria commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Ran the H16G regression check on J713 (M4 MacBook Air 13", T8132, dc771820 + d271ab48 cherry-picked identically across all 5 files, ane_t6021.ko module with ane_rtclient_runtime_* / ane_fw_platform_runtime_* verified in /proc/kallsyms):

  • Probe & >2 s idle: 500000000.ane probed identically (H16 stage program complete; held until reboot), power/runtime_status stayed unsupported (control=auto) with no spurious runtime PM activity. add128 passed 16384/16384 exact, max 0 ulp before (loaded in 0.6 ms, p50 137.8 us) and after 3.5 s idle (loaded in 0.4 ms, p50 115.4 us).
  • Deep sleep (rtcwake -d rtc1 -m mem -s 15): 1/1 succeeded (suspend_stats: success=1, fail=0; H16 ANE: booted again from the preload after system sleep, H16 ANE: resume ok: cold, firmware ready 11 ms, runtime_status=unsupported). Post-wake add128 passed 16384/16384 exact, max 0 ulp immediately (loaded in 0.4 ms, p50 113.0 us) and again after 2.5 s idle (loaded in 0.6 ms, p50 206.9 us).
  • Regression: 0 failed systemd units, 0 ANE/DART/PMGR errors or warnings.

We don't have M1/M2 hardware locally to run that regression check. By inspection, the new ane_t6021_rtclient_main.c runtime PM callbacks return 0 without touching hardware for non-H17 devices (ane_rtclient_is_platform(dev) is false on M1/M2), so M1/M2 behavior is unchanged. Updated the PR description with the J713 results and M1/M2 note.

Assisted-by: LLM (Gemini)

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