Skip to content

drm/asahi: g17: lockless fence status, published-source coalescing, and G17P direct compute sources - #3392

Merged
RyanTheTide merged 4 commits into
mainfrom
perf/g17-fence-sync-direct
Dec 1, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
perf/g17-fence-sync-direct

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What:
Cut kernel-side CPU and global device-mutex overhead on cross-queue GPU fence handoffs (gpubench-vk sync.signal and multi-queue compute pipelines) across G17P and M5 without any chip allowlists or new parameters:

  • Lockless fence status (asahi_g17_fence_status): check dma_fence_is_signaled(), pair with smp_rmb(), and read READ_ONCE(fence->error) instead of taking fence->lock with IRQs off via dma_fence_get_status() on every input fence, scope node, and collected leaf. Also skip redundant job::fence_status() in Queue::enqueue() when sources.contains_input() already matched, and back sync_input::collect_coalesced() with a 4-leaf inline stack buffer to eliminate per-submit heap allocations on the common path.
  • Published-source coalescing with retained error dependencies (sync_input::coalesce_source / Sources::coalesced_errors): ExportFence keeps an independent dma_fence context so early/out-of-order failures never violate core dma_fence monotonicity; collect_coalesced() preserves all distinct-context ExportFence leaves, and Backend::input_sources() records packed (qid, published_seq) atomically on Submission alongside published_epoch to collapse healthy unsignalled published compute ExportFences sharing (epoch, qid) to the latest publication ordinal in Sources::sources while retaining every superseded earlier Submission in Sources::coalesced_errors. Sources::check() checks both sources and coalesced_errors lock-free before publication, at retirement, in DeferredBatch::finish(), and before signalling the consumer fence, so firmware emits at most one barrier/NativeWait per QID while any independent late failure on an earlier coalesced export still fails the consumer with PRODUCER_FAILED even if the retained later export completes cleanly (leaving failed, unpublished, retired, cross-epoch, and cross-QID leaves uncoalesced).
  • G17P direct compute sources (compute_direct & compute_readiness): carry immutable stamp_va and monotonic exec_share identity on PublishedSource so G17P resolves same-VM compute sources lock-free onto the primary channel without the device mutex (kick barriers for M5 and shared-execution-context G17P sources, NativeWait completion-wait records via queue.publish_with_native_waits() for cross-context G17P sources, and implicit-parent skip for same-QID sources).

Tested:

  • J714s MacBook Pro M5 Pro (T6050, G17S B1) at exact head 871fe9798f34 (7.3.0-m5-pr3392v2, built on the M5, origin/main DTB), one trial boot, default 7.3.0-m5-cdirect16 restored with 253/253 ESP hashes verified: PASS, 0 GPU faults, 0 kernel WARNs, GPU online with 0 crashed and 0 quarantined
    • Vulkan CTS (deqp-vk 1.4.7.1), 0 failed: synchronization.smoke.* 12/12, synchronization2.op.single_queue.barrier.*_read_image_compute* 412/412, synchronization.basic.* 29/29, synchronization.internally_synchronized_objects.* 2/2 (Mesa kit inst-A), synchronization.timeline_semaphore.one_to_n.* 955/955 (M5 system Mesa vk-aac82bea8e)
    • gpubench-vk (3x500 ms): sync.signal host d1 124.9 us, queue d2 16.96 us/hop; the same session's main-based kernel (main 9e38a276dcb4 + drm/asahi: g17: allow compute_direct() on mixed render/compute contexts #3429 + perf/g17-publication-direct-lazy) gave 127.3 us and 17.59 us/hop, so this PR is not slower than a main-based kernel. compute.cull_mdi CRC 07f6c861 valid (d1 1043.8 us, d2 888.1 us per submit)
  • J700 MacBook Neo (A18 Pro T8140, G17P B1) at exact head 871fe9798f34008da22802e2548a5dc4f3bd59ad (7.3.0-neo-g17fs2), one-shot boot, default 7.3.0-41 untouched, STOCK_DIFF=0, 0 GPU faults, 0 kernel WARNs, 0 SELinux AVCs: PASS
    • sync.signal timeline d2: P0 15.924 us/hop, unpinned 15.430 us/hop; binary d2: P0 15.643 us/hop, unpinned 15.383 us/hop (status=ok)
    • Targeted Vulkan CTS (deqp-vk): 9,584/9,584 executed passed, 0 failed (synchronization.timeline_semaphore.* 2880/2880, synchronization2.timeline_semaphore.* 2873/2873, synchronization.basic.binary_semaphore.* 5/5, synchronization2.basic.binary_semaphore.* 6/6, all 4 signal_order.shared_{timeline,binary}_semaphore.* suites 955/2865 passed, 1910 not supported, 0 failed)
  • J700 MacBook Neo (A18 Pro T8140, G17P B1) at 10f3766eb5044 (7.3.0-neo-g17fs) vs origin/main 88ddea8bae4ae (7.3.0-neo-g17base), 4-boot BAAB (cand, base, base, cand), default cmdline, STOCK_DIFF=0, 0 GPU faults, 0 kernel WARNs, 0 SELinux AVCs:
    • sync.signal timeline d2: P0 16.685 -> 15.651 us/hop (-6.20%), E1 30.331 -> 27.502 us/hop (-9.33%), unpinned 16.147 -> 15.235 us/hop (-5.65%)
    • sync.signal timeline d4: P0 17.039 -> 15.809 us/hop (-7.22%), unpinned 15.684 -> 15.280 us/hop (-2.57%)
    • sync.signal binary d2: P0 17.246 -> 15.933 us/hop (-7.61%), E1 30.965 -> 28.844 us/hop (-6.85%), unpinned 16.583 -> 15.635 us/hop (-5.72%); binary d4 unpinned 16.395 -> 15.362 us/hop (-6.30%)
    • Controls unchanged: sync.signal host d1 +0.34%, compute.light d1 +0.10% / d4 -0.08%, compute.heavy alu d2 -0.60%, concurrent.cr d4 -0.54%, render.light d1/d4 +0.35%, render.deferred 0.00% (CRC 2cfe9a54 exact match), render.postfx 0.00% (CRC 4707efa8 exact match)
    • perf on candidate confirms both dma_fence_get_status and Firmware::publish_compute_raw disappeared from the sync.signal timeline profile
  • ARM64 QEMU KUnit (asahi*) at 871fe9798f340: 462/465 passed (3 skipped, 0 failed), including published_export_coalesce_key_tracks_epoch_qid_and_invalidation (verifying both arrival orders and consumer PRODUCER_FAILED outcome when an earlier coalesced export fails after collection while the retained later export completes cleanly) and lockless_fence_status_tracks_unsignaled_success_and_error
  • Host tests & mutations at 871fe9798f340: tools/asahi/run-host-tests.py --only g17- 233/233 passed (including drop-coalesced-error and skip-coalesced-error-check mutations asserting consumer late-error failure), tools/asahi/run-host-tests.py --only asahi-m4 1/1 passed; scripts/checkpatch.pl --git HEAD~1..HEAD: 0 errors, 0 warnings

Risk:
two-way · G17P (J700 MacBook Neo) and M5 (J714s / J813 / J815) — a plain revert restores the previous locked status checks and device-mutex G17P compute input path.

Not yet:

…nd G17P direct compute sources

Cut kernel CPU and device-mutex overhead on cross-queue GPU fence handoffs
across G17P and M5:

1. Lockless fence status (asahi_g17_fence_status): query
   dma_fence_is_signaled() followed by smp_rmb() and READ_ONCE(fence->error)
   instead of taking fence->lock with IRQs disabled via dma_fence_get_status()
   on every input fence, scope node, and collected leaf. Also check
   sources.contains_input() before re-querying fence_status() in
   Queue::enqueue(), and back collect_coalesced() with a 4-leaf inline stack
   buffer to avoid per-submit heap allocations on the common path.
2. Published-source coalescing: ExportFence intentionally keeps an independent
   dma_fence context so out-of-order early failures cannot violate core
   dma_fence monotonicity. Record the packed (qid, published_seq) atomically
   on Submission alongside published_epoch and coalesce healthy unsignalled
   published ExportFences sharing (epoch, qid) in both collect_leaf() and
   Backend::input_sources() to the latest publication ordinal, leaving
   failed, unpublished, cross-epoch, and cross-QID leaves intact.
3. G17P direct compute submission with input sources: record immutable
   stamp_va and monotonic exec_share identity on PublishedSource so
   resolve_direct_sources(), compute_direct(), and compute_readiness() handle
   same-VM compute sources without taking the device mutex on G17P as well as
   M5 (using kick barriers for same-execution-context G17P sources and
   NativeWait records via publish_with_native_waits() for cross-context
   sources, while skipping duplicate self-QID barriers).

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 14:13

@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: Changes requested at 10f3766eb504.

The coalescer drops an earlier unsignalled export in favor of the latest publication on the same epoch and QID. Checking that both are healthy at collection does not establish that a later fence reports an independent failure of the earlier export. The new unit test marks the earlier source failed only after checking that it was discarded, and then checks the key rather than the consumer result. Please prove that later publication subsumes the earlier fence outcome, or retain the earlier error dependency separately. Add a consumer-side test where an earlier initially healthy export fails after collection while the later export completes. The current J700 results are substantial; the M5 row remains open.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro M5 Pro, T6050 / G17S B1, second generation) at exact head 10f3766eb5044ae80b630a18ab987fa99aa67d9c: PASS, 0 faults / 0 failures.

  • Setup:
    • Single trial boot (7.3.0-m5-pr3392, built on J714s with stock config + LOCALVERSION=-m5-pr3392, origin/main DTB / MCC SLC off, Borealis Mesa inst-A).
    • Default ESP reinstated immediately after boot (253/253 hashes verified after restore to 7.3.0-m5-cdirect16, test modules removed, LIVE vulkaninfo=1 dispatch=1 kernel=ok).
  • gpubench-vk (3×500 ms runs):
    • sync.signal (work=compute.light, d1): status=ok, latency_us median 129.57 µs (p5 121.99 µs, p95 134.80 µs, n=4518).
    • compute.cull_mdi (objs=16384, visible=75, d1/d2): status=ok, d1 1041.67 µs/submit, d2 888.10 µs/submit (gpu_gap_us 0.375 µs), CRC 07f6c861 valid.
  • VK sync CTS (1,381/1,381 PASS, 0 Fail, 0 NotSupported):
    • dEQP-VK.synchronization.smoke.*: 12/12
    • dEQP-VK.synchronization2.op.single_queue.barrier.*_read_image_compute*: 412/412
    • dEQP-VK.synchronization.timeline_semaphore.one_to_n.*: 955/955
    • dEQP-VK.synchronization.internally_synchronized_objects.*: 2/2
  • Health: online=1, crashed=0, quarantined=0, fw_inputs converted=4221 published=4221, 0 capacity refusals, 0 GPU faults/WARNs/BUGs/errors in dmesg.

drivers/gpu/drm/asahi/g17/sync_input.c now queries fence status locklessly
via asahi_g17_fence_status() (using dma_fence_is_signaled(), smp_rmb(),
and READ_ONCE(fence->error)) and coalesces published ExportFences via
asahi_g17_export_coalesce_key().

Update the standalone C host-test shim in test-fence-signalling.py that
includes sync_input.c directly so it models signaled + error fields on
struct dma_fence, provides dma_fence_is_signaled(), smp_rmb(), READ_ONCE(),
and asahi_g17_export_coalesce_key(), and covers lockless fence status and
published-source coalescing.

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

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

The new fixture verifies same-(epoch,QID) collection selects the newest unsignalled fence and releases references. It does not exercise the pending error case from the previous review: an earlier unsignalled export discarded by coalescing can fail after collection while the retained export succeeds. The runtime selection is unchanged. Please retain the earlier error dependency or demonstrate the production invariant that the later completion synthesizes that earlier failure. Add a consumer outcome assertion for the late-error case. The reported prior-head M5 row helps cover the unchanged runtime.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (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) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at 871fe979: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 871fe979
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · G17P (J700 MacBook Neo) and M5 (J714s / J813 / J815) — a plain revert restores the previous locked status checks and device-mutex G17P compute input path.

Areas: area:gpu

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

@gig3m

gig3m commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

M5 hardware row, J813 (MacBook Air 13" M5, G17G) at 100b51f792b7: boots, runs GL and Vulkan compute load with no GPU faults, and light-submit speed is unchanged against main.

Kernel: main cec0503a5a02 plus our local XRGB8888 primary-plane patch for Hyprland, LLVM, GPU firmware 26B123. A/B on the same kernel, one boot per arm: aurora.ko with this PR's two commits applied (they apply cleanly; drivers/gpu/drm/asahi between this PR's base 88ddea8bae4a and cec0503a5a02 differs by 12 small files), and aurora.ko from main.

Check This PR main
Boot Initialized aurora, Hyprland desktop, 0 failed units same
GL: glmark2-es2-drm --off-screen at 2560x1664, 2 full runs 1234, 1246 1244, 1229
GL: 3 runs of terrain/refract/jellyfish/shadow/build at 15 s each 709, 714, 692 707, 706, 703
Light Vulkan compute, queue depth 8 (µs per submit, 3 runs) 25.39 / 25.62 / 25.50 24.96 / 25.52 / 25.26
Light Vulkan compute, queue depth 32 (µs per submit, 3 runs) 24.07 / 24.04 / 23.91 23.82 / 24.02 / 23.54
GPU fault, timeout or recovery lines in the kernel log 0 0

The light-compute program is the one from #3389's J813 row: a ring of N fences, each submit one 1×1×1 atomicAdd dispatch, with 20,000 timed submits per depth. The final counter matched on every run. The same program showed #3389's −23 % at depth 8 on this Mac today, so a change of that size would show here.

tools/asahi/g17-m5-cross-qid-direct-tests.py and tools/asahi/g17-m5-sibling-gate-tests.py pass at this head. I did not run their --mutation variants.

Not run: dEQP-VK, a multi-client or multi-queue stress test, or a workload with cross-queue dependencies.

Assisted-by: LLM (Claude:Opus 5.5)

…rces

Coalescing healthy unsignalled published compute ExportFences on the same
(epoch, physical QID) in sync_input.c discarded the earlier ExportFence
reference before Backend::input_sources() could record it. Because an
earlier submission on the same QID can still fail independently after
collection (for example via its own producer error, cancellation, or
recovery interrupt) while a later publication on that QID completes
cleanly, dropping the earlier reference could hide a late failure from a
consumer waiting on the coalesced set.

Remove cross-context ExportFence coalescing from sync_input.c so
collect_coalesced() returns all distinct-context ExportFence leaves, and
perform same-(epoch, QID) firmware-wait coalescing in
sync_input::coalesce_source() / Backend::input_sources() while retaining
every superseded earlier Submission in Sources::coalesced_errors.
Sources::check() checks both wait sources and coalesced_errors lock-free
(before publication, at retirement, in DeferredBatch::finish(), and before
signalling the consumer fence), so firmware still emits at most one
barrier/NativeWait per QID while any late error on an earlier coalesced
source fails the consumer with PRODUCER_FAILED.

Add KUnit and host mutation tests (drop-coalesced-error and
skip-coalesced-error-check) asserting the consumer outcome when an earlier
initially healthy coalesced export fails after collection while the
retained later export completes cleanly.

Signed-off-by: DjDeveloperr <[email protected]>
@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 27, 2026

@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 for exact-head hosted checks and final-stack G17P/M5 rows. The new head addresses the late-error finding.

Checked: Collection now preserves distinct-context export leaves. Firmware wait coalescing keeps the latest publication for a physical queue and retains the earlier Submission in a separate error list. The common status check includes that list, including the new pre-publication check after native waits are assembled. The added fixture covers an earlier export that fails after collection while the later export completes. The posted J813 row predates this delta.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 27, 2026
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 30, 2026
Conflict in drivers/gpu/drm/asahi/g17/fence.rs: main and this branch each
added code next to the same lines; all of main's code is kept and this
branch's additions sit beside it (nothing of main's removed). drm/asahi
builds with the Apple config.
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merged main in at 204c2b6b1e81 (no change to this PR's own code). One conflict in g17/fence.rs: both sides added code next to the same lines; all of main's code is kept and this PR's additions sit beside it. drm/asahi builds with the Apple config; the next merge train runs the asahi KUnit on it. The earlier row still covers this PR's files.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 204c2b6b1e81 (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot] at 871fe97 (this head only merges main in: maintainer merge-up). Row: the hardware row at 871fe97 (same PR files; this head only merges main in). CI: linux train L5 = main + #3218 #3488 #2763 #3419 #3647 #2213 #2432 #3392: Apple driver compile pass, Apple DTBs W=1 pass, planned KUnit clpc/dcp-fabric/dcp-topology/dcp-display/macsmc/jpeg/asahi/sep pass, host tests apple-dcp + g14-v27-2 (25/25) pass. Hosted CI is queued behind the backlog. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 01458dc into main Dec 1, 2026
4 of 9 checks passed
@RyanTheTide
RyanTheTide deleted the perf/g17-fence-sync-direct branch December 1, 2026 10:05
muness pushed a commit to muness/linux that referenced this pull request Dec 1, 2026
The two harnesses copy driver code next to stand-ins. Code that landed
on main 12-01 calls stand-ins they did not have, so both fail to compile:
- g17-output-fence-tests: fence.rs (aurora-silicon#3392) calls KickDependency::qid().
- g17-render-owed-stamp-tests (aurora-silicon#3229): backend.rs calls
  Packet::note_first_excuse()/first_excuse() and Queues::forfeit_blocker()
  (compute allowance forfeit), and recovery::note_retired() now takes the
  retired command number.
The render cases have no compute command, so the new stand-ins record no
excuse and forfeit nothing. All g17 host tests pass (329 jobs).
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) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (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.

3 participants