Skip to content

drm/asahi: g17: avoid publication contagion and host drains on timestamp overlap - #3139

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/g17-timestamp-publication-overlap
Nov 25, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/g17-timestamp-publication-overlap

Conversation

@erikwb

@erikwb erikwb commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What: Stop timestamp-free G17 Publication chains from staying permanently pending after their timestamped ancestors publish cleanly, and let timestamp-writing renders (with their firmware fragment-end timestamp window disabled when chained) and NO_QUERY_ACCESS computes overlap pending publications in firmware instead of draining both engines to zero on the host.
Tested: J716c M5 Max (ewb-m5) on identical runtime code (7.3.0-ewb311+ vs clean main 42d693c46cb9 7.3.0-ewb308+, same .config): Cyberpunk 2077 T2 2560x1600 with Borealis rose from 45.46 to 49.90 FPS (+9.78%, compute utilization 81% -> 96%) on driver 8f88e781 and 45.00 to 49.24 FPS (+9.42%, 80% -> 96%) on driver b044001f; Vulkan CTS query_pool.* and synchronization* passed 27,984 cases with 0 failures and 0 GPU errors or recoveries (aurora-peripherals.service failed as on baseline). At head 8677cbde1ddc: arm64 QEMU KUnit asahi_* 388 passed / 3 skipped / 0 failed, G17 host tests 93/93 passed, checkpatch.pl 0 errors / 0 warnings.
Risk: two-way door · G17 queues (M4, M4 Pro, M4 Max, M5, M5 Pro, M5 Max, M5 Ultra)
Not yet: M4 / M4 Pro / M4 Max / M5 Pro / M5 Ultra hardware runs (no local G17 hardware beyond J716c; ewb-m4 J713 uses G16G).

Details

Commit 086a909dc8c6 (drm/asahi: overlap cross-engine commands with timestamped producers on G17) exposed Publication on every overlapping timestamp-free command (job.rs) and forced host completion waits for timestamp-writing renders and NO_QUERY_ACCESS computes behind any covered publication.

On workloads that emit per-frame render timestamps (such as Cyberpunk 2077 under vkd3d-proton and Borealis), ftrace (asahi_g17_*) showed two serializing effects that drained both engines to inflight_R=0, inflight_C=0 over 100 times per second:

  1. Contagious Publication chains: A timestamp-free Publication never cleared its pending state after all predecessors published Ok(()). Every subsequent overlapping command in the frame chained behind it and kept fences.publication populated long after the original timestamped command completed, disabling firmware_source / input_sources() cross-queue barriers and turning every subsequent query_access compute or timestamped render into a full-frontier host drain.
  2. Unnecessary host drains for host-written timestamps: Once a render chained behind pending host predecessors disables its firmware fragment-end timestamp window (Destinations::disable_window()), both renders and NO_QUERY_ACCESS computes perform all timestamp writes on the host inside ordered Publication::publish(). Only query-accessing compute commands (query_access == true, e.g. query resets/copies that touch query memory on the GPU) need host completion waits.

Changes:

  • drivers/gpu/drm/asahi/g17/completion/publication.rs: track has_outputs and an atomic pending flag on Publication. When a timestamp-free Publication's predecessors all publish Ok(()) before its own GPU retirement, clear pending (Release) and immediately release downstream Publication successors under the same state lock. Publications that fail before settling (or carry outputs) keep pending set so deferred errors continue to propagate; a settled timestamp-free publication whose own GPU work fails later relies on retirement-time producer checks and VM failure state, matching commands without a publication.
  • drivers/gpu/drm/asahi/g17/completion.rs: add Destinations::disable_window() and invoke it in Completion::new() whenever host_predecessors is true, keeping handed false so all timestamps are written on the host in publication order.
  • drivers/gpu/drm/asahi/g17/queue/mod.rs: filter has_pending_publication(), input_sources(), and EnqueueOrdering::build() by Publication::is_pending(), restrict host completion waits to query-accessing compute commands (plus already-signalled status < 0 same-engine entries that failed after prune_frontier()), and chain ordered publication for renders and NO_QUERY_ACCESS computes.
Evidence

Cyberpunk 2077 T2 (2560x1600, J716c M5 Max ewb-m5, same .config, default kernel command line, fans max, performance governor)

Kernel Borealis build Avg FPS Min FPS p99 V / F / C (busy%) GPU errors
main 42d693c46cb9 (7.3.0-ewb308+) 8f88e781 45.46 — — 2.12 / 7.31 / 17.76 ms (81%) 0
This PR (7.3.0-ewb311+, run 1) 8f88e781 49.96 42.11 25.7 ms 2.11 / 6.90 / 19.13 ms (96%) 0
This PR (7.3.0-ewb311+, run 2) 8f88e781 49.84 42.31 25.5 ms 2.11 / 6.88 / 19.17 ms (96%) 0
main 42d693c46cb9 (7.3.0-ewb308+) b044001f 45.00 — — 1.96 / 7.31 / 17.75 ms (80%) 0
This PR (7.3.0-ewb311+, run 1) b044001f 49.35 42.03 25.5 ms 1.94 / 6.98 / 19.38 ms (96%) 0
This PR (7.3.0-ewb311+, run 2) b044001f 49.13 41.28 26.1 ms 1.94 / 7.01 / 19.45 ms (96%) 0

Vulkan CTS on J716c M5 Max (7.3.0-ewb311+, Borealis b044001f)

  • dEQP-VK.query_pool.*: 18,230 Pass / 40 NotSupported / 0 Fail
  • dEQP-VK.synchronization.smoke.*: 11 Pass / 0 Fail
  • dEQP-VK.synchronization.op.single_queue.binary_semaphore.*: 1,422 Pass / 1 NotSupported / 0 Fail
  • dEQP-VK.synchronization.op.single_queue.fence.*: 1,422 Pass / 1 NotSupported / 0 Fail
  • dEQP-VK.synchronization.op.multi_queue.binary_semaphore.*: 4,266 Pass / 3 NotSupported / 0 Fail
  • dEQP-VK.synchronization2.op.single_queue.binary_semaphore.*: 2,633 Pass / 1 NotSupported / 0 Fail

Unit tests & style at head 8677cbde1ddc

  • Arm64 QEMU KUnit (asahi_*): 391 ran, 388 passed, 3 skipped, 0 failed (including asahi_g17_timestamp_window, asahi_g17_publication_order, and asahi_g17_cross_engine_timestamps)
  • tools/asahi/run-host-tests.py --only g17: 93/93 passed
  • scripts/checkpatch.pl --no-tree -g HEAD: 0 errors, 0 warnings

…amp overlap

Commit 086a909 ("drm/asahi: overlap cross-engine commands with
timestamped producers on G17") exposed ordered host publications on every
overlapping timestamp-free command and forced timestamp-writing renders and
NO_QUERY_ACCESS computes to wait on the host for any covered publication.

Two effects serialized pipelined workloads that emit per-frame timestamps:
1. A timestamp-free Publication never cleared its pending state after all
   predecessors published cleanly, so every later command in the frame
   chained behind it and kept fences.publication populated even long after
   the original timestamped command completed. Any subsequent
   query-accessing compute or timestamp-writing render then added host
   completion waits on the entire frontier and drained both engines to
   zero in flight.
2. Timestamp-writing renders and NO_QUERY_ACCESS computes perform all
   host-ordered timestamp writes inside Publication::publish() once a
   chained render's firmware fragment-end timestamp window is disabled, so
   stalling them on the host behind covered publications was unnecessary.

Fix both while preserving ordered timestamp publication and deferred
producer error propagation:
- Track has_outputs and an atomic pending flag on Publication. When a
  timestamp-free Publication's predecessors all publish Ok(()), clear
  pending and immediately release any downstream Publication successors
  without waiting for its own GPU retirement. Publications that fail
  before settling (or carry outputs) keep pending set so deferred errors
  continue to propagate; a settled timestamp-free publication whose own
  GPU work fails later relies on retirement-time producer checks and VM
  failure state, matching commands without a publication.
- Add Destinations::disable_window() and disable the firmware fragment-end
  timestamp window on any render chained behind pending host predecessors,
  so its timestamps are written strictly on the host in publication order.
- Restrict host completion waits in EnqueueOrdering::build() to
  query-accessing compute commands, while still adding already-signalled
  error fences (status < 0) on both same-engine paths when a covered entry
  failed between frontier pruning and ordering. Renders and
  NO_QUERY_ACCESS computes overlap pending publications in firmware and
  chain ordered publication.
- Check Publication::is_pending() in has_pending_publication() and
  input_sources() so settled timestamp-free commands do not block
  cross-queue firmware barriers.
- Extend asahi_g17_timestamp_window, asahi_g17_publication_order, and
  asahi_g17_cross_engine_timestamps KUnit tests to cover window disabling,
  clean upstream settlement, settled-then-failed propagation, chained
  timestamped overlap in both directions, and query-access host waits.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team and DjDeveloperr as code owners November 25, 2026 08:29
@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) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 8677cbde: ready to merge

Check Detail
CI at head ok 18 checks passed
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at 8677cbde
Conflicts ok none
PR text ok Risk: two-way · G17 queues (M4, M4 Pro, M4 Max, M5, M5 Pro, M5 Max, M5 Ultra)

Areas: area:gpu
Merge: gh pr merge 3139 --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.

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

Verdict: MERGE at 8677cbde1ddc

Blockers: none

Checked: Full G17 publication settlement, firmware timestamp window disablement, cross-engine and same-engine ordering logic, KUnit tests, J716c verification evidence, and live CI status.

Evidence
  • drivers/gpu/drm/asahi/g17/completion.rs: replaces Destinations::render with allow_window and invokes disable_window() in Completion::new() whenever host_predecessors is true, keeping handed false so renders chained behind pending host predecessors cannot race deferred writes or bypass inherited errors via the firmware fragment-end timestamp window.
  • drivers/gpu/drm/asahi/g17/completion/publication.rs: tracks has_outputs, atomic pending (Release/Acquire), and upstream_released under state. Clears pending on successful publish() or when a timestamp-free (!has_outputs) publication has all predecessors complete cleanly (remaining == 0, no predecessor_error), releasing downstream successors without signalling its own fence early; failed publications remain pending so deferred errors still propagate, and late successors after a subsequent own-GPU failure still observe state.published.
  • drivers/gpu/drm/asahi/g17/queue/mod.rs: filters has_pending_publication(), input_sources(), and EnqueueOrdering::build() by pending_publication(), narrows host completion waits to Engine::Compute && query_access (retaining already-signalled status < 0 same-engine error fences that failed after prune_frontier()), and chains ordered publication for renders and NO_QUERY_ACCESS computes.
  • Live CI at 8677cbde1ddc: 19/19 checks passed (0 active, 0 failed), including readiness and KUnit asahi tests, with exact-head J716c M5 Max hardware verification and Vulkan CTS query_pool / synchronization* pass rows in the PR description.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) ready-to-merge Meets the merge policy: merge it (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

8677cbd J616s (MacBook Pro 16" M4 Pro, T6040, Apple M4 Pro (G16S B1) g17, guarded one-shot default cmdline 7.3.0-aurora-pr3170+, verbatim fleet89 config combining disjoint exact heads #3170 3025a8dcbf66 + #3139 8677cbde1ddc + #3160 b5cc5906a955, all #3139 files 0-line diff vs 8677cbde1ddc) PASS:

  • Vulkan CTS: dEQP-VK.query_pool.statistics_query.* 18,770/18,775 Pass / 0 Fail / 5 NS; dEQP-VK.query_pool.concurrent_queries.* 2/2 Pass / 0 Fail; dEQP-VK.synchronization2.op.multi_queue.{binary,timeline}_semaphore.* 2,844 Pass / 0 Fail / 7,047 NS across 9,891 cases. (Note: dEQP-VK.pipeline.monolithic.timestamp.advanced_graphics_tests.draw_indirect_stage_in_render_pass aborts with identical pre-existing DeviceLost on unmodified stock 7.3.0-aurora-fleet89 on this machine, 0 regressions.)
  • 8-way concurrent compute+render stress 8/8 ok; Borealis gpubench-vk (render.light 122.55 us, compute.light 99.55 us) + gpubench-gl (render.postfx 1080p 1665 fps, crc=2133faaa valid=true) ok; rtc1 s2idle 1/1 (success=1 fail=0), post-wake VK (126.71/113.13 us) + GL (1635 fps, crc=2133faaa valid=true) ok; 0 AVC, 0 failed units, Enforcing; restored 7.3.0-aurora-fleet89 verified.

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

3 participants