Skip to content

drm/asahi: g17: arm idle recheck when a direct submission already retired - #3684

Merged
DjDeveloperr merged 2 commits into
mainfrom
fix/g17-idle-recheck-retired
Dec 1, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
fix/g17-idle-recheck-retired

Conversation

@erikwb

@erikwb erikwb commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

What: When a direct submission is submitted and already retired by the time idle_check() runs, idle_check() passed in_flight || submitted (true) to Effort::idle() and idle_hold(), so neither armed its idle recheck. The GPU effort (effort_full) and CLPC's host-GPU vote could then stay asserted until some other event triggered a check. This passes the actual work in flight, so the 16 ms recheck is armed whenever nothing is in flight.
Tested: J716c M5 Max at 591d5febf96d (on main 45d7f828e08a with #3662, which main needs to boot this board), desktop idle: CLPC host_gpu: active reads 0 in 200/200 samples (50 ms apart) in two 10 s windows. On the same base without this PR it read 1 in 131/200 and then 200/200 samples with no CLPC requests, stuck about 16 s. g17 host tests 292/292 (the new check fails on the old code and on the idle-counts-submitted mutation); this change has also run in the J716c daily since 2026-11-27.
Risk: two-way door · every G17 Mac (the idle-check path is shared; on M5 only the effort side runs, since M5 takes no host hold)
Not yet: non-M5 G17 hardware row (the host hold path)

Details

idle_check() notes a new submission (submitted) by comparing port.submissions() with the last value it saw, and calls effort.submit() for it, which already restarts the continuous-idle interval (idle_since). Passing in_flight || submitted to Effort::idle() then made a submission that had already retired look like work in flight, so Effort::idle() returned None instead of Recheck(IDLE_HOLD_NS). Nothing armed IDLE_WORK, and the effort stayed full until the next event that ran a check. idle_hold() had the same argument. Hold::step() checks submissions itself, and M5 returns early from it.

With in_flight: a fresh submission still restarts the 16 ms hold (through effort.submit()), bursts of submissions keep restarting it, and the Clear branch still re-checks port.submissions() for a submission racing the clear. will_clear(now, in_flight || submitted) above it is unchanged; after a fresh submission it answers the same with either argument.

The host test (tools/asahi/g17-m5-effort-tests.py) evaluates the two argument expressions taken from idle_check()'s source against the extracted Effort: a submission that already retired must arm the recheck and later clear, and the hold must see no work in flight; work still in flight must keep both. The idle-counts-submitted mutation puts back in_flight || submitted and fails.

Evidence

J716c (T6050), kernels 7.3.0-ewb415+ (591d5febf96d + #3662) and 7.3.0-ewb413+ (main 45d7f828e08a + #3662, without this PR), same boot loader (aura main with #585), default command line plus watchdog.open_timeout=120, desktop idle on the internal panel, host_gpu: active read from the CLPC debugfs status every 50 ms:

Kernel idle 10 s (1st) idle 10 s (2nd) CLPC requests
without this PR 131/200 active, one run of 131 200/200 active +8, then +0
with this PR 0/200 0/200 +0, +0

After one tiny compute job, both kernels clear within one 50 ms sample in most runs; the stuck state needs the retired-before-check timing, which the desktop's own submissions hit.

python3 tools/asahi/run-host-tests.py --only g17: 292/292 passed.

…ired

When a direct submission starts and finishes before idle_check() runs,
port.submissions() advances (submitted == true) while in_flight is
already false. Passing (in_flight || submitted) into Effort::idle() and
idle_hold() made both return None instead of Recheck(IDLE_HOLD_NS), so
IDLE_WORK was not armed, and effort_full and CLPC host_gpu active could
stay asserted until another event triggered a check.

effort.submit() has already cleared idle_since when submitted is true,
and Hold::step() already checks submissions independently; pass in_flight
so idle_check() arms the 16 ms recheck timer whenever no work remains in
flight.

Signed-off-by: Erik Bourget <[email protected]>
… submission

Evaluate the work-in-flight arguments idle_check() passes to
Effort::idle() and idle_hold() from its source. For a direct submission
that was submitted and already retired before the check, the effort must
arm its idle recheck and later clear, and the hold must see no work in
flight; with work still in flight, both must keep it. The
idle-counts-submitted mutation puts back the old `in_flight || submitted`
and must fail.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team and DjDeveloperr as code owners November 30, 2026 04:14
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merge readiness at 591d5feb: ready to merge

Check Detail
CI at head ok 22 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 591d5feb
Conflicts ok none
PR text ok Risk: two-way · every G17 Mac (the idle-check path is shared; on M5 only the effort side runs, since M5 takes no host hold)

Areas: area:gpu
Merge: gh pr merge 3684 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot 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.

Verdict: HOLD at 591d5feb

Blockers:

  • Hosted CI on 591d5feb is still queued (apple-build, host-tests, and 16 KUnit suites; pr-text and readiness already passed).
  • Non-M5 G17 hardware verification row for the idle_hold() path (which returns early on M5 via self.init.is_m5()), as noted under "Not yet".

Checked:

  • drivers/gpu/drm/asahi/g17/mod.rs (idle_check()) + drivers/gpu/drm/asahi/g17/power.rs (Effort::idle() and Hold::step()):
    • When a direct submission starts and retires before idle_check() runs (submitted == true, in_flight == false), self.effort.submit() already clears idle_since and increments self.effort.submissions(). Passing in_flight instead of in_flight || submitted lets Effort::idle() arm IdleAction::Recheck(IDLE_HOLD_NS) instead of returning None and leaving effort_full / CLPC host_gpu asserted indefinitely.
    • On non-M5 G17, Hold::step() tracks fresh = submissions != self.seen independently: iteration 0 still asserts the hold when !self.active && fresh, and passing in_flight == false lets iteration 1 (or an already-active hold) arm HoldAction::Recheck(hold_ns) instead of stranding the hold active.
    • Active in-flight work (in_flight == true) and submissions racing IdleAction::Clear (self.port.submissions() != submissions) remain unchanged.
  • tools/asahi/g17-m5-effort-tests.py and tools/asahi/run-host-tests.py: extract both idle_check() argument expressions from source, verify retired-submission recheck/clear and in-flight retention, and wire the idle-counts-submitted mutation.
  • Both commits carry human Signed-off-by: trailers, clean PR metadata, and exact-head J716c (M5 Max) A/B verification showing host_gpu: active dropping from 131/200 + 200/200 stuck samples to 0/200 + 0/200.
Evidence
  • Diff audited: 3 files (+51/-4), commits 766fd2aa and 591d5feb.
  • Verified Effort::idle() (drivers/gpu/drm/asahi/g17/power.rs:179-201) and Hold::step() (power.rs:350-381) state transitions for both submitted && !in_flight and in_flight.
  • Status checks at review time: 2 passed (pr-text / pr-text, readiness / readiness), 18 queued (apple-build, host-tests, 16 KUnit suites), 3 skipped.

DjDeveloperr added a commit that referenced this pull request Nov 30, 2026
Resolved idle_check() to #3415's form (its `active` covers #3684's
retired-submission case) and kept #3407's resume_busy_if_inactive()
beside #3415's direct-admission helpers in port.rs.

Signed-off-by: DjDeveloperr <[email protected]>

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

Approved. Passing only the work in flight lets Effort::idle() and idle_hold() arm their recheck when a direct submission retired before the check ran; effort.submit() still restarts the hold for the new submission. The J716c A/B matches: host_gpu stuck at 131/200 and 200/200 before, 0/200 after. The G17P row is in too: a Neo (J700) boot of a candidate carrying this head unchanged. Effort cleared within ~0.3 s of idle, and with idle_off_delay_ms=50 the host hold asserted under work and released right after it, with 0 GPU faults, timeouts or submission errors.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, G17P) row at combined SHA 936d72d0 (wip/ewb-g17-rows-20261130 = main fe9af4b6 + #3684 + #3407 + #3306 + #3415 + #3346)

Kernel: one-shot trial boot 472ed0ed with the dead-man timer and the default command line. Stock Fedora -41 was restored and verified afterwards.

  • Built warm from an existing J700 tree; the source tree was verified to equal 936d72d0 (tree 9da3305d).
  • Image sha256 27185481, aurora.ko sha256 625c14e8, vmlinux build ID a7620fb3.

Results

  • GPU use on the KDE desktop: gpubench 4-queue render (per-queue CRC ok), 2-queue compute, concurrent render + compute, vkcube --c 300 on Wayland. All completed.
  • GPU effort after work: effort_full was true during work (48/49 samples) and cleared within about 0.3 s of idle.
  • Host hold at the default idle_off_delay_ms=2: stayed off.
  • Host hold at idle_off_delay_ms=50: on during work (18 samples), released as soon as the work ended, and stayed off through 5 s of idle.
  • Wi-Fi (wld0) connected and Bluetooth (hci0) powered, before and after the sleep.
  • One test sleep (rtcwake -m mem -s 30, deep): suspended and resumed on the same boot. Afterwards Wi-Fi was up and a GPU render readback was valid. During suspend entry the log had one line, dwc3-apple 40a280000.usb: PM: device_prepare(): genpd_prepare returns -11; the suspend still completed.
  • 0 GPU faults, timeouts or submission errors; 0 WARN, 0 AVC; 0 failed units (stock: 0).
  • Kernel error lines: 11, against 12 on a stock boot, with no new kinds. SMC 0 and PCIe 0, before and after the sleep.

This PR: the idle recheck now runs after a retired direct submission. Effort cleared after every workload in this run.

@aurora-silicon-review aurora-silicon-review Bot 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.

Verdict: MERGE at 591d5febf96d

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - drivers/gpu/drm/asahi/g17/mod.rs (idle_check()) + drivers/gpu/drm/asahi/g17/power.rs (Effort::idle() and Hold::step()):

  • When a direct submission starts and retires before idle_check() runs (submitted == true, in_flight == false), self.effort.submit() already clears idle_since and increments self.effort.submissions(). Passing in_flight instead of in_flight || submitted lets Effort::idle() arm IdleAction::Recheck(IDLE_HOLD_NS) instead of returning None and leaving effort_full / CLPC host_gpu asserted indefinitely.
  • On non-M5 G17, Hold::step() tracks fresh = submissions != self.seen independently: iteration 0 still asserts the hold when !self.active && fresh, and passing in_flight == false lets iteration 1 (or an already-active hold) arm HoldAction::Recheck(hold_ns) instead of stranding the hold active.
  • Active in-flight work (in_flight == true) and submissions racing IdleAction::Clear (self.port.submissions() != submissions) remain unchanged.
  • tools/asahi/g17-m5-effort-tests.py and tools/asahi/run-host-tests.py: extract both idle_check() argument expressions from source, verify retired-submission recheck/clear and in-flight retention, and wire the idle-counts-submitted mutation.
  • Both commits carry human Signed-off-by: trailers, clean PR metadata, and exact-head J716c (M5 Max) A/B verification showing host_gpu: active dropping from 131/200 + 200/200 stuck samples to 0/200 + 0/200.

Follow-ups (not blocking): queued CI; non-M5 G17 idle_hold row

erikwb added a commit that referenced this pull request Dec 1, 2026
Resolve idle_check() in drivers/gpu/drm/asahi/g17/mod.rs against #3684 by keeping DirectIdle::observe() and passing active (in_flight || direct_publishing) into Effort::idle() and idle_hold(), resolve drivers/gpu/drm/asahi/g17/port.rs against #3407 by preserving both the direct-publisher tracking/admission helpers and brief-idle busy-share tracking (resume_busy_if_inactive(), set_effort_full(), clear_effort_and_busy()), and update tools/asahi/g17-m5-effort-tests.py to cover DirectIdle::observe().

Signed-off-by: Erik Bourget <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants