Skip to content

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

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

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

After its first request the H17 ANE 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, as macOS keeps it whenever it has no client.

This parks it after idle_park_ms without a request (default 5000, 0 turns it off), with the sequence a system sleep already uses:

  • An execute cancels the timer and its end rearms it. A successful wake or first bring-up also arms it.
  • The park takes the backend lock and does nothing if the engine is already parked, a system sleep is under way, it isn't at the program stage, it's quarantined, or the SoC doesn't use the macOS sleep (or uses the warm one).
  • It closes the session with ane_h16_session_sleep(true), which waits only for requests in flight (s->active), not open programs. If a ring still has something pending, it reopens and rearms.
  • Otherwise it stops the firmware (clean_stop), powers the engine down, and marks it parked as after a wake. The next request takes the existing ane_fw_session_wake() path: cold boot from the preload and replay of every open program.
  • The session stays closed while parked, as after a wake from system sleep, and requests that waited out the park are woken so they wake the engine. A program closed while parked is deferred: the wake reopens the session after the cold boot, and the close then finds its program lost to the new firmware and only frees its memory, with no firmware traffic. The first version reopened the session with the engine off. A close then sent TERMINATE to the powered-off engine, got -EBUSY, and quarantined the session for good, because recovery skips a parked engine. camera-denoise hit this when a client kept its program loaded through an idle gap and then switched formats.
  • PM_SUSPEND_PREPARE cancels a pending park (cancel_delayed_work_sync), and the sleep then parks the engine itself.
  • Lock order is the same as ane_fw_sleep_prepare() (backend lock, then session lock). None of the session callbacks that run under the session lock take the backend lock.
  • Outside a system sleep there is no deep path to fall back on, so a firmware stop that fails quarantines the engine, as a failed sleep does without one.

Testing

J700 (MacBook Neo, T8140), Aura 1.0.0b9, integration 1d2ef21 plus this commit, ANE built in. The program is an H17 elementwise add (1024 fp16 lanes) from mil-hwx-compiler, run through tools/testing/selftests/drivers/ane/ane-run.py. The loaded-program test used a local copy with a pause between runs.

Test Result
5 runs, then idle All exact. 5 s later: firmware stopped (status 0x6e), powered down, "idle 5000 ms: parked until the next request". ane_sys, engine and DARTs off.
Run on the parked engine "up for a request", 5 runs exact
One loaded program, 4 runs 8 s apart 3 parks. Each wake logs "H17 program replayed" and the output is exact. About 18 ms per run after a park (cold boot and replay) against about 0.13 ms warm.
Deep sleep while parked "10 coprocessors up and stopped", still parked after the wake
Deep sleep within 5 s of use The sleep stopped and powered the engine down itself, with no idle park in between. "resume ok: parked until the next request"
idle_park_ms=0, then 5000 Stays on, then parks 5 s after the next request

The session-closed-while-parked change was folded in afterwards. KUnit passes (246/246), and so does a W=1 build of drivers/accel/ane/ with the Neo config, but KUnit doesn't build the park path. On 2026-11-19 it ran on the J700. That kernel had this PR's change (same patch-id as this head) on top of #1768 (hang recovery), a local non-contiguous allocation change and the address-space fix in #2240.

Test Result
Load, 3 runs, keep the program open 12 s (parks at 5 s), close All exact. The close is deferred with no quarantine. The old version logged "program quarantine" and "session quarantined (-16)" here.
Next load right after "program lost across sleep, released", then "up for a request". The closed program isn't replayed, and the runs are exact.
camera-denoise networks: 640x360 kept open through a park, closed, then 320x240 Both exact, with no quarantine
Close racing the wake of another client's load (offsets 7.9 to 13 s) Both orders happened: replayed then closed live, or close deferred and released at the wake. All 20-run clients exact, no quarantine.
One loaded program, 4 runs 8 s apart 3 parks, each followed by a replay, all exact
Two programs open and parked, RTC-woken deep sleep Both replayed after the wake, runs exact. A program closed while parked was released at the next wake.
Deliberate hang (with #1768) Recovered in 141 ms, and runs afterwards were exact

No new kernel errors.

Open questions

  • ane_fw_ps_off() falls back to apple_sleep_request_deep_once() when a power word stays BUSY after the unlatch. Outside a system sleep that flags the next sleep as deep and returns success, so an idle park would report success with a stuck word, and the next request's power-up would fail into quarantine. That fails safe, but I haven't hit it: the words read clear since 992923c. Should the idle path treat a stuck word as a failure instead?
  • 5 s is a guess, set against an ~18 ms cold boot and replay. I don't know what macOS uses.
  • accel/ane: h17: recover a hung engine and retry a failed boot #1768 also changes the parked and recovery state in ane_fw_cold.c. I'm happy to rebase onto it.
  • ane_fw_power_down() still logs "powered down for system sleep" on an idle park; the next line says it was an idle park.

The commit has Assisted-by: LLM and no Signed-off-by yet. niteria will add the sign-off before this leaves draft.

🤖 Generated with Claude Code

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).
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. macOS keeps the ANE off whenever it
has no client.

After idle_park_ms (5 s by default, 0 disables it) with no request,
take the way down a system sleep takes: close the session and wait for
requests in flight, stop the firmware and power the engine off, then
mark it parked as after a wake. The next request boots it from the
preload and replays every open program, the path a wake already uses.
An execute cancels the timer and its end rearms it; a system sleep
cancels a pending park and parks the engine itself.

Leave the session closed while parked, as a wake from system sleep
does, and wake the requests that waited out the park so they wake the
engine. A program closed while parked is then deferred: the wake
reopens the session after the cold boot, and the deferred close finds
its program lost to the new firmware and only releases its memory,
with no firmware traffic. Reopening the session with the engine off
would let a close send TERMINATE to it: the transport fails that with
-EBUSY and the session is quarantined for good, since the hung-request
recovery does not touch a parked engine.

Outside a system sleep there is no deep path to fall back on, so a
firmware stop that fails quarantines the engine, as a failed sleep
does without one.

Assisted-by: LLM
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.

1 participant