Skip to content

drm/asahi: g17: trim direct-submit refcounts, steady QueueConfig rebuilds, and stack copies - #4388

Open
satchlj wants to merge 1 commit into
mainfrom
satchlj/g17-submit-zero-copy
Open

satchlj wants to merge 1 commit into
mainfrom
satchlj/g17-submit-zero-copy

Conversation

@satchlj

@satchlj satchlj commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Profile-guided hot-path cleanup for G17 light compute and render direct submission, based on callee-up perf profiles on G17C (compute.light and render.light at depth 32):

  1. Borrow Backend::direct in place (g17/runtime.rs):
    • compute_direct and compute_readiness previously cloned the entire [Option<Arc<ComputeCell>>; 3] array under self.direct on every compute submission, showing up as ~3.3% total CPU in refcount_inc/refcount_dec_and_test (drop_glue<[Option<Arc<ComputeCell>>; 3]>).
    • Move the rare mixed-engine render_frontier lookup (shared.state.lock()) ahead of self.direct.lock() so self.direct is borrowed directly in place under strict lock order shared.state -> self.direct -> outer_compute -> ComputeCell::queue -> Port::m5_outer. compute_readiness clones only the single claimed ComputeCell on a successful claim, after dropping the lock guard.
  2. Skip steady-state 192-byte QueueConfig rebuilds and stack copies (g17/fw/queue.rs, g17/queue/compute.rs, g17/queue/render.rs, g17/queue/render/publication.rs):
    • Add QueueConfig::matches_steady_compute and QueueConfig::matches_steady_render_identity (covered by new KUnit suite asahi_g17_queue_config_steady) so steady-state compute and render publications check the cached QueueConfig before constructing and copying 192-byte records (~2.0% CPU in compute::Queue::queue_config and ~1.5% CPU in fw::m5::queue::config).
    • Pass Lane::config by reference (Option<&'a QueueConfig>) instead of copying a 200-byte Option<QueueConfig> by value per render stage.
    • Add Graph::record_ref(&T) on the compute graph (contiguous write of 0..size_of::<T>() followed by zeroing only trailing size_of::<T>()..window bytes, avoiding redundant stack staging and double-writes to WC memory) and defer cold non-M5/first-kick locals (ComputeArgs, KickAnnounce, KickPredecessor, oversized m5_dependency_types) off the M5 steady-state stack frame.

Evidence

Tested: M5 Max Mac Studio (J775c / G17C B1) at 2b6d528afa5c0ae062173427fa7dbf8d7c6c4447 passed Vulkan API smoke (8/8 on all four boots), bit-exact scene CRCs, and RTC s2idle on the candidate, with zero new GPU/MMU warnings or faults.

The four-boot ABBA (A1 -> B1 -> B2 -> A2) compared ef8a1bf8ce45 (A) with the PR head (B) using the default command line (MTE enabled), Borealis (aurora-wip c1dd713fd116), and identical .config and LLVM 23 / Rust 1.99 toolchains:

Workload Metric Base (A1, A2) mean PR head (B1, B2) mean Delta
compute.light d=4 us_per_submit 19.14 µs (19.18, 19.10) 18.67 µs (18.53, 18.82) -2.44%
compute.light d=4 submit_cpu_us 11.73 µs (11.71, 11.75) 11.50 µs (11.43, 11.56) -1.98%
compute.light d=8 submit_cpu_us 11.67 µs (11.67, 11.67) 11.40 µs (11.33, 11.48) -2.25%
compute.light d=32 us_per_submit 13.75 µs (13.80, 13.71) 13.98 µs (13.69, 14.28) +1.67% (B2 outlier; submit_cpu -0.44%)
render.light d=1 us_per_submit / submit_cpu_us 131.52 / 12.32 µs 129.73 / 11.16 µs -1.37% / -9.43%
render.light d=4 us_per_submit / submit_cpu_us 26.21 / 12.83 µs 25.67 / 12.44 µs -2.07% / -3.06%
render.light d=8 us_per_submit / submit_cpu_us 23.35 / 14.07 µs 23.09 / 13.55 µs -1.12% / -3.69%
render.light d=32 us_per_submit / submit_cpu_us 22.52 / 14.33 µs 22.33 / 13.83 µs -0.85% / -3.48%
rt.scene light d=2 fps / fps_timed / submit_cpu_us 8,754 / 8,231 / 29.95 µs 8,761 / 8,258 / 29.75 µs +0.08% / +0.33% / -0.68% (CRC d8b92e4d 4/4)
rt.scene medium d=2 fps / fps_timed / submit_cpu_us 887.6 / 919.2 / 47.08 µs 888.4 / 919.8 / 43.33 µs +0.08% / +0.06% / -7.96% (CRC 3d294d0e 4/4)
  • Conformance & regression (all 4 boots): dEQP-VK.api.smoke 8/8 PASS on every boot, rt.scene exact CRCs (d8b92e4d light, 3d294d0e medium), 15 s RTC s2idle PASS on B1 with post-wake dEQP-VK.api.smoke 8/8 PASS and rt.scene light 8,750.7 fps (CRC d8b92e4d), 0 failed systemd units, 0 new kernel GPU/MMU warnings or faults.
  • Host tests & KUnit: 57/57 tools/asahi/g17-*.py PASS (plus legacy-wq-prepub-abort-tests.py PASS); KUnit asahi_g17* 468/468 PASS including new suite asahi_g17_queue_config_steady.
  • Untested on hardware: G17P (A18 Pro), G17G (M5), G17S (M5 Pro), and G17D (M5 Ultra) control rows remain open; non-M5 (G17P) steady-state and J813 paths retain exact wire compatibility and are covered by unit/host tests.

Risk: Two-way door; scoped to G17 direct compute/render submission and steady-state QueueConfig caching in drivers/gpu/drm/asahi/g17/ (no UAPI, ABI, DT, or M1–M4 changes).

…ilds, and stack copies

Profile-guided hot-path cleanup for G17 light compute and render direct
submission:

1. Avoid cloning the 3-slot [Option<Arc<ComputeCell>>; 3] array in
   Backend::compute_direct and Backend::compute_readiness by checking
   any rare cross-engine render frontier before taking self.direct and
   borrowing the locked slice in place (strict lock order
   shared.state -> self.direct -> outer_compute -> ComputeCell::queue ->
   Port::m5_outer).
2. Add QueueConfig::matches_steady_compute and
   matches_steady_render_identity plus Graph::record_ref(&T) so
   steady-state compute and render publications skip rebuilding and
   copying 192-byte QueueConfig descriptors when the cached slot matches,
   pass Lane::config by reference instead of copying 200 bytes per stage,
   and defer cold non-M5/first-kick stack locals (ComputeArgs,
   KickAnnounce, KickPredecessor, oversized m5_dependency_types) off the
   M5 steady-state frame.

Add KUnit coverage (asahi_g17_queue_config_steady).

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners December 5, 2026 03:01

@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 2b6d528
Checked: Mixed-engine frontier lookup releases shared.state before the direct-cache lock, and a successful claim retains its cell before releasing that lock. Compute dependency input stays bounded at 31 barriers plus the parent. The cache match compares dynamic identity and skips reconstruction only with the current epoch and no required transient update. M5 still sends its config when required, and render retains its cold install and J813 paths. The exact author J775c ABBA report and KUnit coverage are recorded on the PR.

@RyanTheTide RyanTheTide 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: MERGE at 2b6d528
Checked: Mixed-engine frontier lookup releases shared.state before the direct-cache lock, and a successful claim retains its cell before releasing that lock. Compute dependency input stays bounded at 31 barriers plus the parent. The cache match compares dynamic identity and skips reconstruction only with the current epoch and no required transient update. M5 still sends its config when required, and render retains its cold install and J813 paths. The exact author J775c ABBA report and KUnit coverage are recorded on the PR.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m4 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) labels Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Merge readiness at 2b6d528a: not ready yet

Check Detail
CI at head running running: apple-build, host-tests, KUnit plan
Review ok approved by RyanTheTide, aurora-silicon-review
Requested changes ok none
Hardware row at head ok the PR body at 2b6d528a
Conflicts ok none
PR text ok Risk: two-way · scoped to G17 direct compute/render submission and steady-state QueueConfig caching in drivers/gpu/drm/asahi/g17/ (no UAPI, ABI, DT, or M1–M4 changes).

Areas: area:gpu

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor

The clean integration of 2b6d528afa5c onto d0684a0604a0 is tree 7f4b4cbeabf10d667d357e75bc25b27d5cfb1332. The three other PR blobs match the head. In g17/runtime.rs and g17/queue/compute.rs, the merge retains #3242's constructor change and firmware-only completion-state mapping alongside the direct-submit and steady-queue changes here.

On that tree, git diff --check and python3 -I tools/asahi/g17-compute-constructor-tests.py passed. The fixture passed all eight constructor wait cases and caught both negative controls.

The upcoming J700 matched row will carry #3242 in both arms and check mixed engine submission, work completion and VM churn.

@DjDeveloperr

DjDeveloperr commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Additional Host Tests passed on the integration of 2b6d528afa5c with d0684a0604a0, tree 7f4b4cbeabf10d667d357e75bc25b27d5cfb1332.

Ran git diff --check d0684a0604a0 7f4b4cbeabf10 and the following fixtures with python3 -I on the exact tree:

  • g17-direct-compute-render-prefix-tests.py
  • g17-inline-cross-engine-tests.py
  • g17-publication-lazy-tests.py
  • g17-render-direct-recovery-tests.py
  • g17-render-template-tests.py (2 passed)

Two more host fixtures passed on the same tree with python3 -I:

  • g17-direct-stage-prefixes-tests.py covered the render and compute prefixes and sibling guard.
  • g17-m5-multiqueue-contention-tests.py covered the shared credit ring under concurrent submissions.

The staged J700 mixed-engine and VM-churn row is still pending.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 5, 2026

This branch has not been deployed

No deployments
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:m1 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants