Repository navigation
accel/ane: h17: park an idle engine through runtime PM - #1863
Conversation
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).
6eda4a2 to
74eccdd
Compare
|
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. |
74eccdd to
7402a9c
Compare
|
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. 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 |
7402a9c to
d271ab4
Compare
|
Re-reviewed at d271ab4. The earlier point is fixed: Checked the runtime PM paths:
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) |
|
Tested
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) |
|
Ran the H16G regression check on J713 (M4 MacBook Air 13", T8132,
We don't have M1/M2 hardware locally to run that regression check. By inspection, the new Assisted-by: LLM (Gemini) |
|
Thanks, and sorry for the slow reply. These cover what I asked for at d271ab4:
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
left a comment
There was a problem hiding this comment.
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
-
§3 Safety —
ane_fw_ps_off()falls back toapple_sleep_request_deep_once()and returns0during idle runtime suspend (drivers/accel/ane/ane_fw_cold.c:577-580, called viaane_fw_power_down()fromane_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), yetane_fw_ps_off()unconditionally callsapple_sleep_request_deep_once(). Indrivers/soc/apple/sleep.c:1238-1245,apple_sleep_request_deep_once()unconditionally setssleep_deep_requested = trueand returnstruewheneverapple_sleepis 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()returns0instead ofret, skips quarantine, setsb->powered = false/b->parked = true, lets genpd dropANE_SYSunder a stuck child power word, and poisonssleep_deep_requestedfor a later unrelated sleep.- Fix: Gate the
apple_sleep_request_deep_once()fallback inane_fw_ps_off()on!b->in_rpm(orREAD_ONCE(b->in_sleep)).
- Fix: Gate the
-
Concurrency regression —
b->in_sleepTOCTOU inane_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()checkedif (b->in_sleep) return -EAGAIN;underb->lock, serializing cleanly withane_fw_pm_event(PM_SUSPEND_PREPARE)(which writesb->in_sleep = trueat:1397beforeane_fw_sleep_prepare()takesb->lock). This PR dropped theb->in_sleepcheck fromane_fw_unpark()andane_fw_staged_runtime_resume(), leaving only an unlocked check at:1113.- If
PM_SUSPEND_PREPAREruns between:1113andane_fw_unpark()takingb->lock(seeingb->parked == trueand returning0),ane_fw_unpark()will boot the firmware mid-suspend (b->powered = true,b->slept = false) and causeane_fw_staged_suspend()to reject sleep with-EBUSY. - Likewise, a sysfs write to
power/control(on) orpower/autosuspend_delay_ms(-1) betweenPM_SUSPEND_PREPAREandsuspend_freeze_processes()invokesane_fw_staged_runtime_resume()->ane_fw_unpark()whileb->in_sleep == trueand aborts sleep. - Fix: Check
if (READ_ONCE(b->in_sleep))underb->lockinane_fw_unpark()(skip booting and leaveb->parked == true), and inane_fw_session_wake()return-EAGAINafterpm_runtime_put_autosuspend()if still parked due toin_sleep.
- If
-
State-machine race —
ane_fw_staged_runtime_suspend()does not re-checkb->session.quarantinedafterane_h16_session_sleep(&b->session, true)(drivers/accel/ane/ane_fw_cold.c:1153-1176):
Line:1153checksb->session.quarantinedbefore draining in-flight requests (ane_h16_session_sleep(&b->session, true)at:1156), without holdings->lock.ane_h16_session_sleep(true)drains active requests and runsh16_gate_release(s)(ane_h16_program.c:1997); if either fails,h16_fail()setsb->session.quarantined = true(andane_h16_session_sleepreturnsvoid). Without re-checkingb->session.quarantinedafter:1156, runtime suspend can power off and park a quarantined engine (e.g. ifclean_stop=0or STOP still answers), violating the quarantine power-retention invariant and leavingb->parked && b->session.quarantined.- Fix: Re-check
READ_ONCE(b->session.quarantined)afterane_h16_session_sleep(&b->session, true); if set, pin power (ane_fw_quarantine()/pm_runtime_get_noresume()), reopen session, and return-EBUSY.
- Fix: Re-check
-
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 thedevm_pm_runtime_enable()error path (:2776-2782) norane_fw_staged_unbind()(:2801-2812) callspm_runtime_dont_use_autosuspend(dev). If bind fails or unbind runs beforeb->retainedpins the module (e.g., failedprobestage),use_autosuspendstays set on theplatform_device(and leaks the PM-core usage count ifautosuspend_delay_ms < 0).
§1–§6 Checklist Status
- §1 No model gating: Pass (
ane_fw_rpm(b)uses the existingb->soc->macos_sleephardware-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
d271ab4800b3has human author/committer + humanSigned-off-by:only, zero AI trailers in commit; PR body includesAssisted-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 denialsand narrowed to ANE/DART/PMGR errors only; also ran on the pre-Signed-off-bycommit rather thand271ab48. - J813 (T8142): missing
0 SELinux denialsand0 failed systemd units; narrowed to ANE/DART/PMGR errors only. - J713 (T8132 / H16G): missing
0 SELinux denials.
- J700 (T8140): missing
- M2 (H14 —
t6020/t6021/t6022/t8112) shared callback coverage & PR-body correction: The PR body claimspm_runtime_enable()is never called on M2, butane_rtclient_probe_inner()does callpm_runtime_enable(dev)(ane_t6021_rtclient_main.c:3970) andpm_runtime_resume_and_get(dev)(:3971), so M2 boots execute the newane_rtclient_runtime_resume()callback (andane_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 untouchedane_drv.cand does not need a row).
- Full §5 regression tuples (
- §6 Naming: Pass.
Non-blocking polish
- Pair
READ_ONCE(b->powered)readers (:1147,:1413,:2822) withWRITE_ONCE(b->powered, ...)at:603,:644,:1713for KCSAN cleanliness. - In
ane_fw_staged_runtime_suspend(), if an execute raced right at the autosuspend boundary and finished duringane_h16_session_sleep(true)(refreshinglast_busy), checkingpm_runtime_autosuspend_expiration(dev) != 0after draining and returning-EBUSYavoids 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>
d271ab4 to
0ba0b5e
Compare
|
Thanks @DjDeveloperr for the thorough review — every one of those catches was real. Pushed
Verification at
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
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:
- §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 triggersapple_sleep_request_deep_once()or poisonssleep_deep_requestedon a stuck power word; failure now quarantines with power pinned. Resolved. b->in_sleepTOCTOU (ane_fw_unpark/ane_fw_session_wake):ane_fw_unpark()checksREAD_ONCE(b->in_sleep)underb->lock(:1074), andane_fw_session_wake()drops the ref viapm_runtime_put_sync_suspend()and returns-EAGAINif still parked (:1128-1131). Resolved.- Post-drain quarantine race (
ane_fw_staged_runtime_suspend): Re-checksREAD_ONCE(b->session.quarantined)afterane_h16_session_sleep(&b->session, true)(:1167-1171), pinning power viaane_fw_quarantine(), reopening the session, and returning-EBUSY. Resolved. - Autosuspend teardown (
ane_fw_staged_bind/ane_fw_staged_unbind):pm_runtime_dont_use_autosuspend()added on both thedevm_pm_runtime_enable()error path (:2802-2803) and unbind (:2833-2834). Resolved. - Polish & M2 parity:
WRITE_ONCE(b->powered, ...)paired at all 3 write sites (:603, :644, :1737); post-drainpm_runtime_autosuspend_expiration(dev)check added (:1177-1180);ane_t6021_rtclient_main.ccallbacks verified clean (0when!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 in0ba0b5ed9744live 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 on0ba0b5ed9744with 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
0ba0b5ed9744has human author/committer + humanSigned-off-by:only, zero AI trailers in commit; PR body includesAssisted-by:). - §5 Evidence: Incomplete (J713/H16G at
0ba0b5ed9744+ 251/251 KUnit + CIhost-testspassed; waiting on J700 T8140, J813 T8142, and M2 H14 runs at0ba0b5ed9744). - §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)
|
J413 (M2 MacBook Air, T8112 / H14) — no change at
Assisted-by: LLM (Codex) |
|
J700 (T8140 / H17) — runtime PM pass at
Assisted-by: LLM (Codex) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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).
- J700 (T8140 / H17 runtime PM):
All §1–§6 requirements satisfied — approving 0ba0b5ed9744f0974ea74815f4e4846e29e0fa80 for MERGETRAIN-LINUX4.
Assisted-by: LLM (Gemini 4 Neon)
|
For the record, J813 (M5 MacBook Air 13", T8142 / H17) runtime-PM verification at the merged head
Assisted-by: LLM (Gemini) |
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_SYSreference goes to runtime PM, and runtime autosuspend parks it when idle:power/autosuspend_delay_mschanges it, and a negative value keeps the engine up until the next system sleep. There is no module or command-line parameter.last_busywhile 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 viaane_fw_quarantine()and returns-EBUSY.b->in_sleepunderb->lock.ANE_SYSstill 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_sleepproperty): 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 sharingane_t6021behave as before (M1 uses the separate, untouchedane_drv.c).Thanks to Ryan Murray for suggesting runtime PM for this.
Locking
The callbacks take
b->lockonly 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 holdingb->lockdo 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 callspm_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 withpm_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 afterpm_runtime_resume_and_get()and boots it itself (or, ifb->in_sleepprevented unparking, releases withpm_runtime_put_sync_suspend()and returns-EAGAIN).Testing
drivers/accel/ane/,W=1(=y,=m, and!CONFIG_PM) at0ba0b5ed9744drivers/accel/ane/boot.kunitconfigat0ba0b5ed9744host-testsat0ba0b5ed9744checkpatch.pl --strictat0ba0b5ed9744dc7718206cdb+0ba0b5ed9744, NixOS gen 54jplsjyvq,boot_id=08ecc617,ane_t6021.ko) — H16 regression (idle + deep sleep)ane_t6021confirmed carryingane_rtclient_runtime_*/ane_fw_platform_runtime_*in/proc/kallsyms.500000000.aneprobed cleanly (H16 stage program complete; held until reboot),power/runtime_status=unsupported(control=auto) throughout.add128(h16-run.py) passed16384/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-wakeadd128passed16384/16384 fp16 values exactimmediately (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 indmesg -l err..emergrelative to baseline7.3.0-aurora-fleet85+ signedane_t6021+ 4 ANE deps from0ba0b5ed9744, tested by @RyanTheTide) — M2 no-change regressioncontrol=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 errors7.3.0-aurora-fleet85+ signedane_t6021+ 4 ANE deps from0ba0b5ed9744, tested by @RyanTheTide) — runtime PM park/wake/replaypower/control=auto, default 2000 ms autosuspend delay. Oneadd64program 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-1/2000, 3/3 deep sleeps, ABABABAB battery power18.2 ms(1024/1024 exact, 0 ulp, p50127.1 us); parks ~2.4 s (ane_sys off-0, engine + 3 DARTssuspended,DARTs off before ANE_SYS); wakes in15.8 ms;-1/2000verified; 3/3 deep sleeps (suspend_stats/fail=0); 4-pair ABABABAB battery power2171.2 mWparked vs2182.6 mWidle-up (+11.4 mW, SMCPPMC+11.9 mW, 4/4 pairs positive)d271ab48— re-run at0ba0b5ed9744pending) — park, wake, 3-park program replay,-1/2000, 4/4 deep sleeps420000000.ane+ both DARTssuspended,ane_sys off-0); first bring-up16.5 ms(1024/1024 exact); parks ~2.3 s (firmware stopped, status 0x6e,DARTs off before ANE_SYS,ane_sys off-0); wakes in11.0 ms; 3 × 3 s idle program replays exact (18.43 / 22.30 / 21.60 ms);-1/2000verified; 4/4 deep sleeps (suspend_stats/fail=0), all1024/1024 exactpost-wake, 0 ANE/DART/PMGR errorsM1 (
apple,t8103-ane,apple,t6000-ane) binds to the separate, untouchedane_drv.c. M2 (apple,t6020/t6021/t6022/t8112-ane) sharesane_t6021_rtclient_main.c, whereane_rtclient_probe_inner()callspm_runtime_enable()andpm_runtime_resume_and_get()— so M2 boots invokeane_rtclient_runtime_resume(), which returns0whenane_rtclient_is_platform(dev)isfalse(verified on J413 above by @RyanTheTide).Remaining hardware runs at
0ba0b5ed9744J813 (T8142) re-run on
0ba0b5ed9744with 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 at0ba0b5ed9744pending)Assisted-by: LLM (Claude:Opus 5.5, Gemini)