Skip to content

asahi: reuse private syncobjs and share completion with GL fences - #1418

Merged
DjDeveloperr merged 3 commits into
aurora-wipfrom
fix/asahi-share-submit-fence-completion
Nov 30, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-wipfrom
fix/asahi-share-submit-fence-completion

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What

Native Gallium paid for a private syncobj on every submit, then batch retirement and the GL client could each wait on the same GPU work. Cache driver-owned binary handles on the screen and reset returned handles in a single ioctl before reusing them. When a GL fence takes the private output of an accepted submission, link it to that batch so either side can use completion observed by the other.

Tested

MacBook Neo (J700, A18 Pro, G17P B1), stock Fedora 44 kernel 7.3.0-41.fc44.aurora.aarch64, release Mesa base 89ddabbf72c251ff2eaabecb8ebf0ec4755a0269 and head 6e79ebde27138e4e4114e93e6a2953fa4b50a209. Native Gallium and EGL mappings were checksum-verified for each arm. Depth-16 latency fell from 16.687 to 15.540 µs per completed dispatch, a 6.74% paired reduction against a 1.00% same-depth A/A bound.

In three separately instrumented depth-16 runs per arm, binary waits fell from 2.515 per dispatch on base to 1.610 on head. Private-handle reuse alone (53af2b7a006b) still issued 2.588 waits. Both reuse variants issued about one reset per sixteen dispatches and zero creates or destroys in the timed windows. All three arms issued one GPU submit per dispatch.

The checked compute.light FIFO uses the shader from GPUBench a5409150182f9dd0f951ace2d009a832c3d449a1. Each light-gl DEPTH rate invocation used a 300 ms warmup, five 250 ms windows and per-slot result and guard readback. CPU policy bounds were fixed to 2.472 and 1.464 GHz, the application inherited its normal CPU mask, and each qualified block held GPU P10 at 1.470 GHz. Native GL used a private EGL vendor manifest, EGL_PLATFORM=surfaceless, MESA_LOADER_DRIVER_OVERRIDE=asahi and MESA_SHADER_CACHE_DISABLE=true.

Four qualified A/B blocks alternated ABBA and BAAB at each depth, with four matched base/base blocks. Paired latency change is the median of the blockwise ratios. The A/A bound is the largest absolute matched base/base change.

Depth Base µs Head µs Paired latency change A/A bound
1 108.437 107.323 -1.03% 0.71%
2 54.826 55.039 +0.26% 6.58%
4 21.258 20.805 -2.34% 2.75%
8 16.864 16.713 -0.42% 2.30%
16 16.687 15.540 -6.74% 1.00%
32 16.948 15.740 -7.05% 2.58%
64 17.788 16.164 -9.28% 1.27%

The depth-2 increase was within same-depth drift. Fixture source, exact commands, raw FIFO windows, DRM counts and scorer

All 2,360 native GLES31 CTS cases passed on both arms with identical case statuses (195 compute, 104 synchronization, 2,061 SSBO). The cross-context GL server-wait readback also passed on both arms. The head passed all 23 selected Gallium submit, retirement, asynchronous fence, server-wait and memory-barrier host tests. Zero GPU faults, kernel WARNs or AVCs were recorded. The Neo returned to stock with its CPU policies restored.

Risk

Batch retirement still checks asynchronous errors before publishing completion. The batch holds a reference to its exported fence until retirement. Completion sharing applies only to the private output from the same accepted submission. Resetting the recycled handle before reuse preserves the distinction between a newly published fence and a failed submission.

Not yet

A second GPU-generation hardware row is pending before merge.

@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 30, 2026 16:20

@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 6e79ebde

Blockers:

  • Pending second GPU-generation hardware row listed under Not yet before merge.

Checked:

  • src/gallium/drivers/asahi/agx_fence.c, agx_fence.h, agx_pipe.c, agx_state.h: verified submit_syncobjs front/back partition invariant (ready + returned <= capacity), single-ioctl batch drmSyncobjReset() when returned == capacity (with destroy fallback on reset error), non-overlapping cleanup loop in agx_destroy_screen(), and owns_private_handle gating so externally imported syncobj handles (agx_fence_from_fd) are destroyed rather than recycled.
  • src/gallium/drivers/asahi/agx_batch.c, agx_fence.c: verified batch->syncobj and submit_syncobj share the same accepted submission's output fence, agx_retire_batch() still runs agx_check_batch_fence() before retiring on exported_fence->signaled, release/acquire ordering via p_atomic_set()/p_atomic_read() (__ATOMIC_RELEASE/__ATOMIC_ACQUIRE), last_submit_batch/last_submit_complete handoff across immediate retirement and faulted contexts (ctx->any_faults), and zero recycling of submit_syncobj on failed/split submit error paths.
  • Hardware/test evidence at exact head 6e79ebde: J700 (A18 Pro, G17P B1) paired ABBA/BAAB compute.light FIFO (-6.74% at depth 16, -9.28% at depth 64; binary waits 2.515 -> 1.610/dispatch), 2,360/2,360 native GLES31 CTS, cross-context GL server-wait readback, and 23 Gallium host tests.
Evidence
  • agx_fence_populate() sets f->owns_private_handle = true before util_queue_fence_signal(&f->ready), and batch->exported_fence holds a reference on f until agx_batch_cleanup() on the context thread, avoiding any use-after-free or torn-flag race on threaded-context teardown.
  • agx_destroy_context() drains all submitted batches via agx_sync_all() (dropping batch->exported_fence refs) and destroys any unconsumed ctx->last_submit_fence under screen->destroy_lock.
  • Non-blocking note: agx_poll_batch() and agx_sync_batch() still wait directly on batch->syncobj rather than short-circuiting on batch->exported_fence->signaled; safe as written since agx_cleanup_batches() already takes the fast path.

@DjDeveloperr

Copy link
Copy Markdown
Author

Review at 6e79ebde: the code looks correct. No changes needed.

What I checked:

  • Handle reuse. A pooled handle has one owner at a time. ctx->last_submit_fence owns it until a fence takes it (the field is then set to 0) or the next submit recycles it. After that, the fence owns it until its last reference drops. I found no path that recycles a handle twice, or recycles one that is still in use. Fences from agx_fence_from_fd() keep owns_private_handle false and are destroyed instead of pooled. The driver never exports a pooled handle as a syncobj fd. agx_fence_get_fd() and agx_fence_server_sync() export sync files, which are snapshots, so a later reset of the handle doesn't affect them.
  • Reset before reuse. A returned handle becomes ready only after drmSyncobjReset(), and newly created handles start empty. So agx_wait_failed_submit() still can't mistake an old fence for the output of the failed submit. If the reset fails, the handles are destroyed. ready + returned never exceeds the capacity, and screen destroy frees exactly the two occupied ranges.
  • Shared completion. A fence is linked to a batch only when no server wait is pending. On that path the fence's handle is the submit_syncobj output of the same submit that signals batch->syncobj. So signaled is set only after that submit is seen to complete: by agx_fence_finish(), or by retirement with completed. A batch is retired early only when its fence has seen that same submit complete. agx_sync_batch() passes !ret, so a failed wait marks nothing as signaled. With a pending glWaitSync, in_sync_fd >= 0 skips the link and the existing merge path runs, so the pending server-wait case from asahi: overlap independent GL compute batches on M5 kernels #1372 isn't affected. The any_faults check still runs first, so a fence created after a failed batch is still reported as faulted.
  • Lifetime. The batch holds its own fence reference until agx_batch_cleanup(). The fence never points back at the batch, so the context and the fence can be destroyed in either order. agx_destroy_context() drains everything through agx_sync_all() first. The pool lock never wraps another lock.
  • Host build and tests. The head builds on x86_64 (asahi + zink, debugoptimized), and all 209 tests in the asahi suite pass under the drm-shim. The shim stubs out the syncobj ioctls, so the Neo rows are what cover the fence behaviour.

What's left before merge: a hardware row at this head on a second GPU generation (G15 or G16).

@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 557db281

Blockers:

  • Second GPU-generation hardware row remains pending before merge (Not yet: only MacBook Neo J700 G17P B1 has been run so far).

Checked:

  • Forward merge 557db281 (6e79ebde..557db281): only unrelated src/asahi/compiler/agx_nir_lower_cmat.c and M5 BVH files entered from aurora-wip; zero changes to src/gallium/drivers/asahi/ (agx_fence.{c,h}, agx_pipe.c, agx_state.h, tests/test-fence.cpp, +135/-27).
  • Private syncobj pool partition (ready + returned <= capacity), single-ioctl batch drmSyncobjReset(), owns_private_handle gating of imported handles, and shared batch/GL-fence completion (__ATOMIC_RELEASE/__ATOMIC_ACQUIRE) remain intact.
Evidence
  • Code remains clean with zero defects found at 557db281; ready to approve once the second GPU-generation hardware row is posted.

@DjDeveloperr

Copy link
Copy Markdown
Author

J773g (M4 mini, T8132 G16G) peer row: parity. Native GL d16 at 6e79ebde2713 (this PR's commits) vs base 89ddabbf72c2: −0.27 % paired, inside the 0.32 % A/A drift. Every slot's output, guard words and CRC are verified in every leg.

The PR head is now 557db2812f19. It differs from 6e79ebde only by a merge of aurora-wip (#1419, #1358), which doesn't touch this PR's change.

Row base this PR paired Δ largest A/A Δ qualified blocks
native GL compute row d16 (µs) 37.355 37.321 −0.269 % 0.321 % 4 A/B (ABBA/BAAB), 4 A/A
  • Hardware: J773g (M4 mini, T8132 G16G), saved stock Arch kernel 7.3.0-ARCH-m4mainefed1ae3 with SLC on both planes.
  • Clocks: effective GPU state S10 on every qualified block. CPU clusters fixed at 4,104,000 / 2,892,000 kHz for the run (the highest advertised frequencies), then restored to stock schedutil 912,000–4,464,000 / 900,000–2,892,000 kHz.
  • Stock checks: passed before and after on the same boot: no pending boot entry, 0 failed units, 0 GPU faults, recoveries or hangs. The rows are silent.
  • Kit: Neo lead's second-generation kit (kit.tar.zst 5101a11b), with per-leg verification of the Mesa vendor, the Apple M4/G16G renderer and the loaded library hashes.

GLES31 conformance: 2,360 cases per arm (195 compute, 104 synchronization, 2,061 SSBO). Base and this PR both gave 2,360 Pass, 0 Fail, with identical case-by-case status, and both native server-wait readbacks passed. 0 GPU faults, driver warnings, recoveries or hang kills.

@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 557db281

Blockers: none.

Checked:

  • src/gallium/drivers/asahi/agx_fence.{c,h}, agx_pipe.c, agx_state.h, and tests/test-fence.cpp (+135/-27): private syncobj pool (ready + returned <= capacity) resets returned handles in one drmSyncobjReset() ioctl (with destroy fallback on error), owns_private_handle keeps imported handles out of the pool, agx_destroy_screen() destroys non-overlapping slices, and agx_retire_batch()/agx_check_batch_fence() share completion across submitted batch and exported GL fence with release/acquire atomics and safe TC teardown ordering.
  • Forward merge 557db281 onto aurora-wip: zero conflicts, zero diff vs 6e79ebde in src/gallium/drivers/asahi/.
  • Dual GPU-generation hardware verification complete:
    • MacBook Neo (J700, A18 Pro, G17P B1): -6.74% paired depth-16 latency (16.687 -> 15.540 µs, 1.00% A/A bound), binary waits 2.515 -> 1.610/dispatch, 2,360/2,360 GLES31 CTS pass, cross-context GL server-wait pass, 23 host tests pass, 0 faults.
    • Mac mini M4 (J773g, T8132, G16G): depth-16 parity (37.355 -> 37.321 µs, -0.269% paired inside 0.321% A/A drift across 4 A/B + 4 A/A blocks), 2,360/2,360 GLES31 CTS pass identical to base, both native server-wait readbacks pass, 0 GPU faults/warnings/recoveries/hangs.
Evidence
  • Code independently verified clean; both GPU-generation hardware and GLES31 conformance rows pass with zero faults or regressions. Ready to merge into aurora-wip.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 557db2812f19 from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip 6e153e59 + #1417 #1418 #1425) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@DjDeveloperr
DjDeveloperr merged commit ff06bae into aurora-wip Nov 30, 2026
@DjDeveloperr
DjDeveloperr deleted the fix/asahi-share-submit-fence-completion branch November 30, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants