Skip to content

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

Merged
niteria merged 1 commit into
aurora-silicon:integration/aurorafrom
niteria:ane/h17-idle-park
Nov 23, 2026
Merged

niteria merged 1 commit into
aurora-silicon:integration/aurorafrom
niteria:ane/h17-idle-park

Conversation

@niteria

@niteria niteria commented Nov 13, 2026 •

Copy link
Copy Markdown

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 (or an execute that refreshed last_busy while draining) returns -EBUSY, so autosuspend tries again later. Outside a system sleep there is no deep-sleep fallback: a stuck power word or a session that quarantines while draining keeps power pinned via ane_fw_quarantine() and returns -EBUSY.
  • 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, serialized against b->in_sleep under b->lock.
  • 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 M2 devices sharing ane_t6021 behave as before (M1 uses the separate, untouched ane_drv.c).

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 (or, if b->in_sleep prevented unparking, releases with pm_runtime_put_sync_suspend() and returns -EAGAIN).

Testing

What Result
arm64 build of drivers/accel/ane/, W=1 (=y, =m, and !CONFIG_PM) at 0ba0b5ed9744 No new warnings
KUnit under arm64 QEMU, drivers/accel/ane/boot.kunitconfig at 0ba0b5ed9744 251/251 passed
CI host-tests at 0ba0b5ed9744 Passed
checkpatch.pl --strict at 0ba0b5ed9744 Clean (0 errors, 0 warnings, 0 checks)
J713 (T8132 / H16G, M4 MacBook Air 13", dc7718206cdb + 0ba0b5ed9744, NixOS gen 54 jplsjyvq, boot_id=08ecc617, ane_t6021.ko) — H16 regression (idle + deep sleep) Loaded ane_t6021 confirmed carrying ane_rtclient_runtime_* / ane_fw_platform_runtime_* in /proc/kallsyms. 500000000.ane probed cleanly (H16 stage program complete; held until reboot), power/runtime_status=unsupported (control=auto) throughout. add128 (h16-run.py) passed 16384/16384 fp16 values exact (2/2 runs) before and after 3.5 s idle. 1/1 deep sleep (rtcwake -d rtc1 -m mem -s 15, suspend_stats success=1 fail=0): H16 ANE: resume ok: cold, firmware ready 11 ms, post-wake add128 passed 16384/16384 fp16 values exact immediately (2/2) and after 2.5 s idle (2/2). Regression: 0 SELinux denials (SELinux disabled on NixOS, lsm=lockdown,capability), 0 failed systemd units, 0 new kernel errors in dmesg -l err..emerg relative to baseline
J413 (T8112 / H14, M2 MacBook Air, 7.3.0-aurora-fleet85 + signed ane_t6021 + 4 ANE deps from 0ba0b5ed9744, tested by @RyanTheTide) — M2 no-change regression Both runtime PM callbacks verified in loaded module; control=auto, runtime_status=active, no readable autosuspend delay (identical to stock fleet85). Depthwise conv + MobileNetV1 passed 200/200 before idle and 200/200 after 3.5 s idle (800/800 candidate executions matching stock digests). Regression (SELinux Enforcing): 0 AVCs, 0 failed units, 0 new kernel errors
J700 (T8140 / H17, 7.3.0-aurora-fleet85 + signed ane_t6021 + 4 ANE deps from 0ba0b5ed9744, tested by @RyanTheTide) — runtime PM park/wake/replay power/control=auto, default 2000 ms autosuspend delay. One add64 program stayed loaded across 3/3 idle parks (ANE_SYS off-0, ANE + all 3 DARTs suspended) and runtime resumes (3 program replays), parked again after close. First + all 3 post-resume inferences matched CPU reference 4096/4096 FP16 exact, 0 ULP. Regression (SELinux Enforcing): 0 AVCs, 0 failed units, 0 new kernel errors
J700 (T8140, Aura 1.0.0b9, prior revision) — -1/2000, 3/3 deep sleeps, ABABABAB battery power First bring-up 18.2 ms (1024/1024 exact, 0 ulp, p50 127.1 us); parks ~2.4 s (ane_sys off-0, engine + 3 DARTs suspended, DARTs off before ANE_SYS); wakes in 15.8 ms; -1 / 2000 verified; 3/3 deep sleeps (suspend_stats/fail=0); 4-pair ABABABAB battery power 2171.2 mW parked vs 2182.6 mW idle-up (+11.4 mW, SMC PPMC +11.9 mW, 4/4 pairs positive)
J813 (T8142, M5 MacBook Air 13", prior revision d271ab48 — re-run at 0ba0b5ed9744 pending) — park, wake, 3-park program replay, -1/2000, 4/4 deep sleeps Boots parked (420000000.ane + both DARTs suspended, ane_sys off-0); first bring-up 16.5 ms (1024/1024 exact); parks ~2.3 s (firmware stopped, status 0x6e, DARTs off before ANE_SYS, ane_sys off-0); wakes in 11.0 ms; 3 × 3 s idle program replays exact (18.43 / 22.30 / 21.60 ms); -1 / 2000 verified; 4/4 deep sleeps (suspend_stats/fail=0), all 1024/1024 exact post-wake, 0 ANE/DART/PMGR errors

M1 (apple,t8103-ane, apple,t6000-ane) binds to the separate, untouched ane_drv.c. M2 (apple,t6020/t6021/t6022/t8112-ane) shares ane_t6021_rtclient_main.c, where ane_rtclient_probe_inner() calls pm_runtime_enable() and pm_runtime_resume_and_get() — so M2 boots invoke ane_rtclient_runtime_resume(), which returns 0 when ane_rtclient_is_platform(dev) is false (verified on J413 above by @RyanTheTide).

Remaining hardware runs at 0ba0b5ed9744

  • J813 (T8142) re-run on 0ba0b5ed9744 with full §5 regression tuple.

  • 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 at 0ba0b5ed9744; no regression (J413/H14, J713/H16G, and J700/H17 done; J813/T8142 re-run at 0ba0b5ed9744 pending)

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

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

Copy link
Copy Markdown

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
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
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)

@RyanTheTide

Copy link
Copy Markdown

Thanks, and sorry for the slow reply. These cover what I asked for at d271ab4:

  • On the J813 (H17): it boots parked, wakes in 11 ms with exact results, re-parks, and holds a program loaded across three parks.
  • On the J713 (H16G): no spurious runtime PM, exact add128 before and after a 3.5 s idle, and a clean deep sleep and resume.

Approved from my side. If you want the M1/M2 (H13/H14) no-change row as well, we can run it on our M1 Pro and M2 at this head.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

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

Overall the runtime PM architecture is clean: idle_park_ms is gone, autosuspend uses standard power/autosuspend_delay_ms with a measured 2 s default, CONFIG_PM / !CONFIG_PM / =m / =y build cleanly without unused-function warnings, and locking/refcounting on the happy paths is well-reasoned. However, three real error/concurrency bugs in ane_fw_cold.c, one runtime-PM teardown leak, and §5 evidence gaps remain before MERGETRAIN-LINUX4.

Code & Safety Blockers

  1. §3 Safety — ane_fw_ps_off() falls back to apple_sleep_request_deep_once() and returns 0 during idle runtime suspend (drivers/accel/ane/ane_fw_cold.c:577-580, called via ane_fw_power_down() from ane_fw_staged_runtime_suspend():1168):
    ane_fw_staged_runtime_suspend() correctly notes that "Outside a system sleep there is no deep path to fall back on" (:1137), yet ane_fw_ps_off() unconditionally calls apple_sleep_request_deep_once(). In drivers/soc/apple/sleep.c:1238-1245, apple_sleep_request_deep_once() unconditionally sets sleep_deep_requested = true and returns true whenever apple_sleep is registered (true on J700 and J813). If the CPU or subblock power word sticks during an idle park (b->in_rpm == true), ane_fw_ps_off() returns 0 instead of ret, skips quarantine, sets b->powered = false / b->parked = true, lets genpd drop ANE_SYS under a stuck child power word, and poisons sleep_deep_requested for a later unrelated sleep.

    • Fix: Gate the apple_sleep_request_deep_once() fallback in ane_fw_ps_off() on !b->in_rpm (or READ_ONCE(b->in_sleep)).
  2. Concurrency regression — b->in_sleep TOCTOU in ane_fw_unpark() / ane_fw_staged_runtime_resume() (drivers/accel/ane/ane_fw_cold.c:1069-1088, 1113-1125, 1185-1197):
    Prior to this PR, ane_fw_session_wake() checked if (b->in_sleep) return -EAGAIN; under b->lock, serializing cleanly with ane_fw_pm_event(PM_SUSPEND_PREPARE) (which writes b->in_sleep = true at :1397 before ane_fw_sleep_prepare() takes b->lock). This PR dropped the b->in_sleep check from ane_fw_unpark() and ane_fw_staged_runtime_resume(), leaving only an unlocked check at :1113.

    • If PM_SUSPEND_PREPARE runs between :1113 and ane_fw_unpark() taking b->lock (seeing b->parked == true and returning 0), ane_fw_unpark() will boot the firmware mid-suspend (b->powered = true, b->slept = false) and cause ane_fw_staged_suspend() to reject sleep with -EBUSY.
    • Likewise, a sysfs write to power/control (on) or power/autosuspend_delay_ms (-1) between PM_SUSPEND_PREPARE and suspend_freeze_processes() invokes ane_fw_staged_runtime_resume() -> ane_fw_unpark() while b->in_sleep == true and aborts sleep.
    • Fix: Check if (READ_ONCE(b->in_sleep)) under b->lock in ane_fw_unpark() (skip booting and leave b->parked == true), and in ane_fw_session_wake() return -EAGAIN after pm_runtime_put_autosuspend() if still parked due to in_sleep.
  3. State-machine race — ane_fw_staged_runtime_suspend() does not re-check b->session.quarantined after ane_h16_session_sleep(&b->session, true) (drivers/accel/ane/ane_fw_cold.c:1153-1176):
    Line :1153 checks b->session.quarantined before draining in-flight requests (ane_h16_session_sleep(&b->session, true) at :1156), without holding s->lock. ane_h16_session_sleep(true) drains active requests and runs h16_gate_release(s) (ane_h16_program.c:1997); if either fails, h16_fail() sets b->session.quarantined = true (and ane_h16_session_sleep returns void). Without re-checking b->session.quarantined after :1156, runtime suspend can power off and park a quarantined engine (e.g. if clean_stop=0 or STOP still answers), violating the quarantine power-retention invariant and leaving b->parked && b->session.quarantined.

    • Fix: Re-check READ_ONCE(b->session.quarantined) after ane_h16_session_sleep(&b->session, true); if set, pin power (ane_fw_quarantine() / pm_runtime_get_noresume()), reopen session, and return -EBUSY.
  4. Runtime PM teardown — missing pm_runtime_dont_use_autosuspend() (drivers/accel/ane/ane_fw_cold.c:2770-2783, 2801-2812):
    ane_fw_staged_bind() enables autosuspend (pm_runtime_use_autosuspend(dev) at :2772), but neither the devm_pm_runtime_enable() error path (:2776-2782) nor ane_fw_staged_unbind() (:2801-2812) calls pm_runtime_dont_use_autosuspend(dev). If bind fails or unbind runs before b->retained pins the module (e.g., failed probe stage), use_autosuspend stays set on the platform_device (and leaks the PM-core usage count if autosuspend_delay_ms < 0).

§1–§6 Checklist Status

  • §1 No model gating: Pass (ane_fw_rpm(b) uses the existing b->soc->macos_sleep hardware-behavior property).
  • §2 Production-ready, no hacks: Pass (default cmdline, no new module/cmdline params, 2 s autosuspend delay justified by measured ~16–20 ms cold wake+replay cost).
  • §3 Safety: Fail (Blocker #1 above).
  • §4 Clean-room & attribution: Pass (commit d271ab4800b3 has human author/committer + human Signed-off-by: only, zero AI trailers in commit; PR body includes Assisted-by:).
  • §5 Evidence: Incomplete (will also need updated runs on the fixed head SHA):
    • Full §5 regression tuples (0 SELinux denials, 0 failed units, 0 new kernel errors) are missing fields across all three posted hardware rows:
      • J700 (T8140): missing 0 SELinux denials and narrowed to ANE/DART/PMGR errors only; also ran on the pre-Signed-off-by commit rather than d271ab48.
      • J813 (T8142): missing 0 SELinux denials and 0 failed systemd units; narrowed to ANE/DART/PMGR errors only.
      • J713 (T8132 / H16G): missing 0 SELinux denials.
    • M2 (H14 — t6020/t6021/t6022/t8112) shared callback coverage & PR-body correction: The PR body claims pm_runtime_enable() is never called on M2, but ane_rtclient_probe_inner() does call pm_runtime_enable(dev) (ane_t6021_rtclient_main.c:3970) and pm_runtime_resume_and_get(dev) (:3971), so M2 boots execute the new ane_rtclient_runtime_resume() callback (and ane_rtclient_runtime_suspend() on unwind). Please fix the PR body note and add an M2 (H14) no-change regression row on the final head SHA (M1 uses untouched ane_drv.c and does not need a row).
  • §6 Naming: Pass.

Non-blocking polish

  • Pair READ_ONCE(b->powered) readers (:1147, :1413, :2822) with WRITE_ONCE(b->powered, ...) at :603, :644, :1713 for KCSAN cleanliness.
  • In ane_fw_staged_runtime_suspend(), if an execute raced right at the autosuspend boundary and finished during ane_h16_session_sleep(true) (refreshing last_busy), checking pm_runtime_autosuspend_expiration(dev) != 0 after draining and returning -EBUSY avoids an immediate back-to-back park right after an execute.

Assisted-by: LLM (Gemini 4 Neon)

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

niteria commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @DjDeveloperr for the thorough review — every one of those catches was real. Pushed 0ba0b5ed9744 addressing all 4 blockers and both non-blocking polish items:

  1. §3 Safety (ane_fw_ps_off): gated apple_sleep_request_deep_once() on !b->in_rpm, so a stuck power word during idle park returns ret, quarantines with power pinned, and never poisons sleep_deep_requested.
  2. b->in_sleep TOCTOU (ane_fw_unpark / ane_fw_session_wake): checked READ_ONCE(b->in_sleep) under b->lock in ane_fw_unpark() (covering both ane_fw_staged_runtime_resume() and the fallback unpark path). In ane_fw_session_wake(), if still parked afterwards, drop the ref with pm_runtime_put_sync_suspend() and return -EAGAIN.
  3. Quarantine race (ane_fw_staged_runtime_suspend): checked READ_ONCE(b->session.quarantined) both before and after ane_h16_session_sleep(&b->session, true); if set, call ane_fw_quarantine(b, b->session.error ?: -EIO) to pin power, reopen the session if closed, and return -EBUSY.
  4. Autosuspend teardown (ane_fw_staged_bind / ane_fw_staged_unbind): added pm_runtime_dont_use_autosuspend(dev) on devm_pm_runtime_enable() failure and unbind.
  5. Polish: paired READ_ONCE(b->powered) readers with WRITE_ONCE(b->powered, ...) at all 3 write sites, and added a post-drain pm_runtime_autosuspend_expiration(dev) check in ane_fw_staged_runtime_suspend() to reopen and return -EBUSY if an execute refreshed last_busy while draining.

Verification at 0ba0b5ed9744 so far

  • checkpatch.pl --strict: clean (0 errors, 0 warnings, 0 checks).
  • arm64 W=1 builds of drivers/accel/ane/: clean (0 new warnings) for =y, =m, and !CONFIG_PM.
  • arm64 QEMU KUnit (drivers/accel/ane/boot.kunitconfig): 251/251 passed.
  • CI host-tests: passed.
  • J713 (T8132 / H16G, M4 MacBook Air 13", dc7718206cdb + 0ba0b5ed9744, NixOS gen 54 jplsjyvq, boot_id=08ecc617, ane_t6021.ko):
    • Confirmed ane_rtclient_runtime_* / ane_fw_platform_runtime_* in /proc/kallsyms; 500000000.ane probed cleanly (H16 stage program complete; held until reboot), power/runtime_status=unsupported (control=auto) throughout.
    • add128 (h16-run.py): 16384/16384 fp16 values exact (2/2) before idle and again after 3.5 s idle.
    • Deep sleep (rtcwake -d rtc1 -m mem -s 15): 1/1 succeeded (suspend_stats success=1 fail=0, H16 ANE: resume ok: cold, firmware ready 11 ms, runtime_status=unsupported); post-wake add128 passed 16384/16384 fp16 values exact immediately (2/2) and after 2.5 s idle (2/2).
    • §5 regression: 0 SELinux denials (SELinux disabled on NixOS, lsm=lockdown,capability), 0 failed systemd units, 0 new kernel errors in dmesg -l err..emerg relative to baseline.

Also corrected the M2 note in the PR description (ane_rtclient_probe_inner() does call pm_runtime_enable() + pm_runtime_resume_and_get() on M2, invoking ane_rtclient_runtime_resume() which returns 0 for non-platform devices).

We'll re-run J700 (T8140) and J813 (T8142) at 0ba0b5ed9744 with full §5 regression tuples next. @RyanTheTide, if your offer for an M2 (H14) no-change check still stands, a run at 0ba0b5ed9744 would be much appreciated!

Assisted-by: LLM (Gemini)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

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 re-review at 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80.

Wave 80C Blockers — All Code & Safety Items Resolved

Verified every code blocker and polish item from d271ab4800b3:

  1. §3 Safety (ane_fw_ps_off): if (b->in_rpm || !apple_sleep_request_deep_once()) return ret; (drivers/accel/ane/ane_fw_cold.c:577) — idle runtime suspend no longer triggers apple_sleep_request_deep_once() or poisons sleep_deep_requested on a stuck power word; failure now quarantines with power pinned. Resolved.
  2. b->in_sleep TOCTOU (ane_fw_unpark / ane_fw_session_wake): ane_fw_unpark() checks READ_ONCE(b->in_sleep) under b->lock (:1074), and ane_fw_session_wake() drops the ref via pm_runtime_put_sync_suspend() and returns -EAGAIN if still parked (:1128-1131). Resolved.
  3. Post-drain quarantine race (ane_fw_staged_runtime_suspend): Re-checks READ_ONCE(b->session.quarantined) after ane_h16_session_sleep(&b->session, true) (:1167-1171), pinning power via ane_fw_quarantine(), reopening the session, and returning -EBUSY. Resolved.
  4. Autosuspend teardown (ane_fw_staged_bind / ane_fw_staged_unbind): pm_runtime_dont_use_autosuspend() added on both the devm_pm_runtime_enable() error path (:2802-2803) and unbind (:2833-2834). Resolved.
  5. Polish & M2 parity: WRITE_ONCE(b->powered, ...) paired at all 3 write sites (:603, :644, :1737); post-drain pm_runtime_autosuspend_expiration(dev) check added (:1177-1180); ane_t6021_rtclient_main.c callbacks verified clean (0 when !ane_rtclient_is_platform(dev)) and PR-body M2 note corrected. Resolved.

Remaining Blocker (Evidence Only)

  • §5 Live-HW verification at 0ba0b5ed9744: All four code fixes in 0ba0b5ed9744 live exclusively in the H17 (ane_fw_rpm(b)) runtime PM paths, which are not exercised on J713 (H16G). As noted in the PR body's unchecked box, the primary H17 hardware rows — J700 (T8140) and J813 (T8142) — are still from prior revisions (pre-0ba0b5ed9744) and still need re-runs on 0ba0b5ed9744 with full §5 regression tuples (0 SELinux denials, 0 failed units, 0 new kernel errors), along with the pending M2 (H14) no-change row.

§1–§6 Checklist

  • §1 No model gating: Pass.
  • §2 Production-ready, no hacks: Pass.
  • §3 Safety: Pass (code blocker #1 fixed).
  • §4 Clean-room & attribution: Pass (commit 0ba0b5ed9744 has human author/committer + human Signed-off-by: only, zero AI trailers in commit; PR body includes Assisted-by:).
  • §5 Evidence: Incomplete (J713/H16G at 0ba0b5ed9744 + 251/251 KUnit + CI host-tests passed; waiting on J700 T8140, J813 T8142, and M2 H14 runs at 0ba0b5ed9744).
  • §6 Naming: Pass.

Code is clean and ready for immediate approval once the H17 (and M2) hardware re-runs at 0ba0b5ed9744 are posted.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown

J413 (M2 MacBook Air, T8112 / H14) — no change at 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80. Ran the signed ane_t6021 module and its four ANE dependencies built from that commit on 7.3.0-aurora-fleet85, using a Linux one-shot. Both runtime PM callbacks were present in the loaded module.

  • Depthwise convolution and MobileNetV1 each passed 200/200 before idle and 200/200 after 3.5 s idle. All four candidate output digests matched the corresponding stock fleet85 digests (800/800 candidate executions).
  • The H14 device stayed control=auto, runtime_status=active, with no readable autosuspend delay, on both builds.
  • Regression tuple with SELinux Enforcing — 0 failed units, 0 AVCs, 0 new kernel errors from module load through the workload. Production fleet85 was restored and verified.

Assisted-by: LLM (Codex)

@RyanTheTide

Copy link
Copy Markdown

J700 (T8140 / H17) — runtime PM pass at 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80. Ran the signed ane_t6021 module and its four ANE dependencies built from that commit on 7.3.0-aurora-fleet85, using a Linux one-shot.

  • The ANE used power/control=auto and the default 2,000 ms autosuspend delay. One add64 program stayed loaded across 3/3 idle parks and runtime resumes. Each park showed ANE_SYS off-0 with the ANE and all three DARTs suspended. The kernel logged three program replays. The ANE parked again after close.
  • The first inference and all three post-resume inferences each matched the CPU reference on 4,096/4,096 FP16 values, 0 ULP.
  • Regression tuple with SELinux Enforcing — 0 failed units, 0 AVCs, 0 new kernel errors from module load through the workload. Production fleet85 was restored and verified.

Assisted-by: LLM (Codex)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

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 re-review at 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80:

  • All prior code, locking, and §3 safety blockers were already verified resolved on 0ba0b5ed9744.
  • Both owed exact-head §5 hardware rows are now posted and green (with 0 failed units, 0 AVCs, 0 new kernel errors, SELinux Enforcing):
    • J700 (T8140 / H17 runtime PM): power/control=auto, 2,000 ms autosuspend, 3/3 idle parks (ANE_SYS off-0, ANE + all 3 DARTs suspended) + 3 replays, 4,096/4,096 FP16 0 ULP.
    • J413 (T8112 / H14 no-change): 800/800 inferences before/after 3.5 s idle matching stock digests, runtime_status=active.
    • Alongside existing exact-head J713 (H16G) verification, 251/251 KUnit, and green CI (host-tests).

All §1–§6 requirements satisfied — approving 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80 for MERGETRAIN-LINUX4.

Assisted-by: LLM (Gemini 4 Neon)

@niteria
niteria merged commit 0f111a0 into aurora-silicon:integration/aurora Nov 23, 2026
1 check passed
@niteria

niteria commented Nov 23, 2026

Copy link
Copy Markdown
Author

For the record, J813 (M5 MacBook Air 13", T8142 / H17) runtime-PM verification at the merged head 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80 (7.3.0-air-m5-eb6d9ec180e8 + 0ba0b5ed9744, NixOS gen 15, boot_id=87c9e15a-c772-4ff0-bcfe-f8998a631ad9) also passed cleanly:

  • Boot-parked: 420000000.ane and all three ANE DARTs (421800000.iommu, 421820000.iommu, 421840000.iommu) booted suspended, ane_sys off-0, power/control=auto, power/autosuspend_delay_ms=2000, DARTs off before ANE_SYS: streams were 0x1 0x1 0x1, PMGR 0x23ff.
  • Wake & idle park: add1024 loaded in 9.7 ms, 5/5 runs 1024/1024 exact, max 0 ulp (p50 114.4 us), re-parked after 3.2 s idle (ane + all 3 DARTs suspended, ane_sys off-0).
  • Held program across 3 × 3.2 s idle parks: loaded in 11.6 ms, cycle 0 0.32 ms, then parked to ane_sys off-0 + all 3 DARTs suspended between each submit; replayed (H17 program replayed 0 0) and executed in 18.73 ms, 23.94 ms, 20.26 ms, 1024/1024 exact, 0 ulp on every cycle; parked cleanly after close.
  • Autosuspends disable/re-enable: power/autosuspend_delay_ms=-1 woke the engine (ane_sys on) and held it active past 3.2 s; restoring 2000 re-parked (ane_sys off-0, DARTs off before ANE_SYS: streams were 0x0 0x0 0x0, PMGR 0x23ff), and a subsequent add1024 run passed (1024/1024 exact, 0 ulp) and re-parked.
  • §5 regression tuple: 0 SELinux denials (SELinux disabled on NixOS, lsm=lockdown,capability), 0 failed systemd units, 0 new kernel errors in dmesg -l err,crit,alert,emerg vs the gen-14 baseline.

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.

3 participants