Skip to content

drm/asahi: g17: trim compute completion critical-path locks and batch clear - #3080

Merged
DjDeveloperr merged 2 commits into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/g17-compute-completion-fastpath
Nov 25, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/g17-compute-completion-fastpath

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What: Reduce per-completion CPU overhead on G17 compute retirement by skipping the unused render-lease mutex on compute commands, moving Feed::note_pass() and Feed::note_work() spinlocks after fence signalling, skipping redundant release_after_retirement() mutex re-acquisitions when complete() already released healthy pins, and clearing only touched QIDs in retirement::Batch::clear() via u128 bitmasks instead of zeroing 3 KiB of arrays per pass.
Tested: J616C M4 Max (T6041, G17P B1) exact-head standalone PASS at 7cf06de21f76 (default cmdline, guarded Stage 2): compute.light d=16/32/64 12.05 / 11.61 / 11.37 us (submit_cpu_us 7.88 / 8.02 / 4.88 us vs 13.43 / 13.21 / 12.62 us and 10.83 / 10.83 / 8.77 us on main 4abf0f83c290), concurrent.cr overlap=1.1293, render.deferred (2cfe9a54) and compute.conv2d (2d55a14d) CRCs valid, idle agx_stats pstate 0 / 0 Hz / 0% util, 0 GPU faults, 0 failed units, 0 new kernel errors; combined latency branch 781012ba1158 also passed 8,146/8,146 Borealis Vulkan CTS (ASAHI_MESA_DEBUG=verify). Neo (J700, G17P B1) second-Mac PASS row posted by RyanTheTide (gpubench-vk 8/8, gl-smoke 32/32, dEQP-VK 30/30, s2idle 1/1). ARM64 LLVM=1 aurora.ko + KUNIT=y/M5=y build PASS, checkpatch.pl --strict 0/0/0, asahi_g17_completion_index KUnit 11/11 PASS, g17-quarantine-drain 7/7 PASS, g17-capacity-fault 1/1 PASS, g17-compute-owed-stamp 14/14 PASS.
Risk: two-way · G17 Macs (M4, M4 Pro, M4 Max, A18 Pro / Neo, and M5 family; shared G17 completion and compute retirement paths).
Not yet: M5 family hardware check not yet run.

Details
  • Completion::release_healthy() skips locking self.render when self.is_compute is true.
  • Completion::complete_with_compute() keeps usage.add(), report(), release_healthy(), and signal_terminal() strictly before output.finish(), moving only feed.note_pass() / feed.note_work() after fence signalling.
  • complete() and complete_with_compute() return whether this call claimed signalling and released healthy pins so Deferred::Retired / Deferred::RetiredCompute call release_after_retirement() only when an earlier failure already signalled the fence.
  • retirement::Batch tracks touched_slots / touched_frontiers (u128, compile-time asserted QIDS <= 128) and updates tools/asahi/g17-quarantine-drain-tests.py.
  • Scoped cleanly to avoid overlapping drm/asahi: g17: enable direct compute submission on M5 and coalesce event locks #2947–drm/asahi: g17: defer housekeeping across transient idle gaps #3023 (runtime/events.rs / runtime.rs held out).

… clear

Reduce per-completion overhead on G17 compute retirement without moving
sleeping locks or VM pin release into interrupt context:

1. In Completion::release_healthy() and complete_with_compute(), skip the
   unused render-lease mutex on compute commands, move feed.note_pass()
   and feed.note_work() spinlocks after output.finish() signals the
   exported fence, and return whether healthy pins were already released
   so Deferred::Retired and Deferred::RetiredCompute skip redundant
   vm_job and render mutex re-acquisitions in release_after_retirement().
   Keep tools/asahi/g17-quarantine-drain-tests.py in sync with the
   updated Completion helper signature.
2. Track touched QIDs in retirement::Batch (touched_slots and
   touched_frontiers u128 bitmasks) so Batch::clear() resets only active
   QIDs instead of zeroing 3 KiB of slots and frontier arrays on every
   completion, and extend the asahi_g17_completion_index KUnit suite to
   cover multi-batch clear reuse.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners November 24, 2026 15:33
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo 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 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 5912348b: not ready yet

Check Detail
CI at head ok 2 checks passed
Review no approved by satchlj, but GitHub does not count it yet (code owner from Core or Omarchy Mac needed, or approval went stale)
Requested changes ok none
Hardware row at head no no line with the head SHA 5912348b, a Mac and a result in the PR body or a comment
Conflicts ok not computed yet
PR text ok Risk: two-way · G17 Macs (M4, M4 Pro, M4 Max, A18 Pro / Neo, and M5 family; shared G17 completion and compute retirement paths).

Areas: area:gpu

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

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

Verdict: FINISH at 7cf06de21f76

Blockers:

  1. §5 hardware evidence at exact head 7cf06de21f76: the J616C M4 Max hardware row in Tested: ran on an earlier combined branch (781012ba1158), while only build/checkpatch/KUnit/host tests ran at 7cf06de21f76. Please add an exact-head hardware row at 7cf06de21f76 (or a batched fleet candidate containing 7cf06de21f76 unchanged) with same-machine A/B + regression checks (0 SELinux denials, 0 failed units, 0 new kernel errors) on G17P (e.g. J616C M4 Max), plus a non-regression row on a second G17 generation sharing these paths (e.g. M5 family covering Deferred::RetiredCompute, or A18 Pro / Neo). No code, safety, or policy blockers remain.

Checked: §1–§4 and §6 pass; §5 waiting on exact-head hardware rows; mergeable on main; CI green (host-tests, pr-text, readiness).

Evidence
  • drivers/gpu/drm/asahi/g17/completion.rs:
    • release_healthy() skipping self.render.lock().take() when self.is_compute is sound: is_compute is immutable (engine == Engine::Compute in g17/queue/mod.rs), and attach_render_lease() is only invoked on render packets in g17/runtime/render/submit.rs.
    • complete_with_compute() keeps check_source_inputs(), signalled.swap(true, AcqRel), interrupted(), usage.add(), report(), release_healthy(), signal_terminal(), and output.finish() in their original order before fence signalling, moving only feed.note_pass() and feed.note_work() after output.finish(). Both Detector::note() (lock-free atomics with fetch_max) and BusyRuns::note() (runs spinlock with saturating_add/max) tolerate concurrent or slightly out-of-order completion timing, self.feed (Option<Arc<Feed>>) remains alive while &self is borrowed, and DeferredBatch::finish() still completes all feed updates before run_runtime_events() calls self.queue_feed().
    • Returning bool from complete() / complete_with_compute() and gating release_after_retirement() in Deferred::Retired / Deferred::RetiredCompute on !complete*() preserves recovery/fault safety: when complete*() wins signalled.swap(true, AcqRel), release_healthy() has already released sources, render (when !is_compute), and vm_job, and attach_render_lease() rechecks signalled.load(Acquire) under self.render so no late lease can attach; when an earlier fail_while_owned() already claimed signalled, complete*() returns false and release_after_retirement() still runs to release sources, drop vm_job, and rehabilitate/drop render. Deferred::Drained and Deferred::Release still call release_after_retirement() unconditionally.
    • Non-blocking nit: the comment at completion.rs:873-874 refers to "their spinlocks", whereas Feed::note_pass() is lock-free atomics and only Feed::note_work() acquires Feed::runs (SpinLock).
  • drivers/gpu/drm/asahi/g17/queue/compute/retirement.rs:
    • touched_slots and touched_frontiers (u128, compile-time asserted QIDS <= 128) cover every write site to slots (request()) and frontiers (stage_frontier()). Both methods bounds-check via .get_mut(...)?.ok_or(EINVAL)? before shifting 1u128 << qid, with no fallible steps between array mutation and bitmask update.
    • clear() clears only touched QIDs with trailing_zeros() and x &= x - 1 guarded by != 0, then zeroes both masks; heads lazy initialization on slot.1 == 0 stays valid. KUnit test clear_resets_touched_slots_and_frontiers_across_batches covers both QID 0 and QIDS - 1 (127) and reuse after clear().
  • tools/asahi/g17-quarantine-drain-tests.py: synced cleanly with bool return and is_compute: false in the render fixture; verified passing in host-tests.
  • Cross-generation scope: isolated to drivers/gpu/drm/asahi/g17/ (no G13/G14/G15/G16/G18 impact); shared across G17P (M4 family), A18 Pro / Neo, and M5 family (Deferred::RetiredCompute).
  • Policy & CI: 1 commit (7cf06de21f7699df115bdd6c6bbf8f0b473a813d), human author/committer + Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>, zero AI attribution, no banned names, no new unsafe; host-tests, pr-text / pr-text, and readiness / readiness all SUCCESS.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Neo (J700, T8140 / G17P B1) PASS at 7cf06de (combined kit 7.3.0-aurora-prneo1a+, default cmdline, Stage 2 b17): gpubench-vk 8/8 OK (compute.heavy alu d1 1370us/d4 1181us, bw d1 2778us/d4 2586us, query timestamp d1/d4), gl-smoke 32/32 + gpubench-gl 2/2 OK, dEQP-VK short CTS 30/30 PASS (compute.pipeline.basic shared_var 4/4, copy_ssbo 6/6), s2idle 1/1 (10 s) + post-sleep GPU PASS, 0 GPU faults/timeouts, 0 failed units, Enforcing + 0 AVC, 0 new GPU kernel errors; restored to saved fleet89.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini 4 Neon on @satchlj's behalf

Verdict at 7cf06de21f76

Approve. Compute-completion lock trimming, post-signal feed-heuristic ordering, pin-release deduplication, and bitmask-scoped Batch::clear() are sound across all 3 changed files.

Blockers

None.

Checked

  • Diff audit (3 files, +81/-23):
    • drivers/gpu/drm/asahi/g17/completion.rs: verified release_healthy() skipping self.render.lock().take() when self.is_compute is true is safe (compute completions never hold a render lease); complete_with_compute() preserves usage.add(), report(), release_healthy(), and signal_terminal() strictly before output.finish(), deferring only internal feed.note_pass()/feed.note_work() updates past fence signalling. Confirmed returning bool from complete()/complete_with_compute() lets Deferred::Retired / Deferred::RetiredCompute skip redundant release_after_retirement() when complete() claimed signalling and already released sources, vm_job, and render, while still running release_after_retirement() (including render-lease rehabilitation) when fail_while_owned() signalled first.
    • drivers/gpu/drm/asahi/g17/queue/compute/retirement.rs: verified touched_slots and touched_frontiers (u128, compile-time assert!(QIDS <= 128)) are set after bounds checks in stage_frontier() and request(), and clear() resets every touched slot/frontier via trailing_zeros() + bit-clearing, covered by the new clear_resets_touched_slots_and_frontiers_across_batches unit test.
    • tools/asahi/g17-quarantine-drain-tests.py: updated fixture matches the new bool signature and is_compute field.
  • CI at 7cf06de21f76: host-tests=SUCCESS, readiness=SUCCESS, pr-text=SUCCESS.
  • Posted hardware evidence: J700 Neo (T8140 / G17P B1) PASS at exact head 7cf06de21f76 (gpubench-vk 8/8, gl-smoke 32/32, gpubench-gl 2/2, dEQP-VK 30/30, s2idle 1/1, 0 faults); J616C M4 Max (T6041) verified on combined branch 781012ba1158 (8,146/8,146 Borealis Vulkan CTS, 0 faults).
  • Untested scope: Static source + CI + posted-evidence review only (no kernel install/boot run by this reviewer); standalone exact-head A/B on M4 Max / M5 family remains noted under Not yet.
Evidence
  • Verified files: drivers/gpu/drm/asahi/g17/completion.rs, drivers/gpu/drm/asahi/g17/queue/compute/retirement.rs, tools/asahi/g17-quarantine-drain-tests.py.
  • CI: host-tests SUCCESS, readiness / readiness SUCCESS, pr-text / pr-text SUCCESS at 7cf06de21f76.

Copy link
Copy Markdown
Contributor

J714s (M5 Pro / T6050 / G17S B1), exact head 7cf06de21f7699df115bdd6c6bbf8f0b473a813d. Compute and cross-queue Vulkan workload PASS. Single boot of 7.3.0-m5-p3077-3080-3029-r from candidate ce750bc940a127590ec521d413420581e61732e1 on main 38ffa67c1ec0f99c5bff57d69dbfe92de504cf06. All four PR heads are unchanged ancestors and their applied patch IDs match.

Headless gpubench-vk passed 13/13 before and 5/5 after wake, with 0 errors. Median compute.light at depth 1 was 108.04 µs/submit before and 107.58 µs/submit after wake. Headless dEQP-VK had 116 pass, 0 fail, 1 unsupported (compute 80/81 and synchronization2 cross-queue compute 6/6).

RTC0 was set for +28 s. One deep suspend returned on the same boot in 34.04 s with the RTC wake event recorded. Apple WD2 was active and counting before and after, with 29 s remaining at the first sample after resume. There were 0 panics, GPU faults, recoveries, or observed AVC denials (SELinux inactive). The one failed unit, tailscaled.service, was already failed on the default. All 12 boot error-priority lines matched baseline patterns. There were 49 additional lines after resume, 47 from DCP. ESP file hashes and default GPU liveness were verified after restoration.

@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Nov 25, 2026
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

J616C (Apple MacBook Pro 16", M4 Max, 32-core T6041 / G17P B1, 7.3.0-pr3080+, default cmdline, guarded one-shot Stage 2) exact-head standalone PASS at 7cf06de21f76 (Mesa ec791567c7d0 / mesa#183, env -u ASAHI_MESA_DEBUG):

  • compute.light d=1/2/4/8/16/32/64: 634.5 / 305.3 / 151.0 / 70.1 / 12.05 / 11.61 / 11.37 us (submit_cpu_us at d=16/32/64: 7.88 / 8.02 / 4.88 us, vs 13.43 / 13.21 / 12.62 us and submit_cpu_us 10.83 / 10.83 / 8.77 us on main 4abf0f83c290 — -10% to -12% us_per_submit and -27% to -44% submit_cpu_us at high queue depth)
  • compute.light --mode queues d=2/4/8: 306.7 / 146.7 / 17.20 us
  • submit.empty d=1/2/4/8: 0.83 / 0.82 / 0.82 / 0.82 us (submit_cpu_us 0.29 us)
  • concurrent.cr (compute.heavy:alu + render.heavy:fill:1080p d=4): overlap=1.1293 (status=ok)
  • compute.heavy alu d=1/4: 809.1 / 172.4 us (gpu_us 186.2 / 177.5 us)
  • CRCs: render.deferred d=1/2 741.8 / 115.3 us (crc=2cfe9a54 valid=true), compute.conv2d d=1/4 836.1 / 162.0 us (crc=2d55a14d valid=true)
  • Idle & health: agx_stats returns to pstate 0, achieved_frequency_hz 0, util_device_percent 0 pre/post; 0 GPU faults/timeouts, 0 failed systemd units (system + user), 0 new kernel errors, max-health.sh PASS.

@DjDeveloperr
DjDeveloperr merged commit 5cb0d13 into aurora-silicon:main Nov 25, 2026
3 checks passed
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:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants