Skip to content

drm/asahi: g17: replace sorted dma_fence_array merge with inline-drained barrier - #3324

Open
oreater wants to merge 2 commits into
aurora-silicon:mainfrom
oreater:pr/g17-inline-dep-barrier
Open

oreater wants to merge 2 commits into
aurora-silicon:mainfrom
oreater:pr/g17-inline-dep-barrier

Conversation

@oreater

@oreater oreater commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What: Replace __dma_fence_unwrap_merge() / dma_fence_array in asahi_g17_merge_fences() with a single-pass O(N) stack-buffered merge and a compact asahi_g17_barrier fence that joins sync_scope's per-CPU active_scopes inline drain pass instead of queueing irq_work on every barrier completion.

Tested: J716c (MacBook Pro 16" M5 Max) host build + tests at 22d1339fe02a (make LLVM=1 ARCH=arm64 drivers/gpu/drm/asahi/ clean with 0 warnings in touched files; tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py passing including new asahi_g17_merge_fences tests; run-host-tests.py --only asahi-m4 1/1, --only cross-qid-direct 11/11, --only capacity-fault 1/1). Equivalent barrier path previously boot- and Vulkan-stress-tested on J716c (7.3.0-40).

Risk: two-way · G17 Macs (M4/M5) when a submission has >8 scheduler dependencies (MERGED_DEPENDENCIES).

Not yet: Bare-metal boot and GPU stress run at this exact rebased main commit (22d1339fe02a).

Design details and test evidence
  • Generalizes asahi_g17_scope's ready / work fields into struct asahi_g17_deferred so asahi_g17_signal_fence() drains both ready scopes and ready barriers inline on the same CPU (respecting SCOPE_ATOMIC_BATCH and falling back to irq_work only for foreign fence signalers).
  • Adds asahi_g17_barrier_create() in drivers/gpu/drm/asahi/g17/sync_scope.c using a single flexible-array allocation, constructor guard, barrier_drop_children() child release after signalling, lock-safe batched set_deadline, and negative error propagation.
  • Updates sync_input::merge() and asahi_g17_merge_fences() to use stack buffers up to 64 fences (heap-allocating only above 64), skip already-signalled non-error fences, deduplicate identical pointers and same-context fences (keeping the latest seqno) for small active sets (<= 16), preserve already-signalled error fences, and bypass barrier allocation when 0 or 1 fences remain.
  • Extends tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py to test all-signalled stub return, same-context deduplication without barrier allocation, error-fence preservation alone and alongside unsignalled fences, and the >64 heap path.

…ned barrier

When a G17 submission carries more than MERGED_DEPENDENCIES (8) scheduler
dependencies, sync_input::merge() previously allocated a cursor array and
delegated to __dma_fence_unwrap_merge(), which walks every input twice,
heap-allocates and sorts a second pointer array, and wraps the result in a
dma_fence_array. Every dma_fence_array completion also queues an irq_work
(IPI) even when its final child signals inside asahi_g17_signal_fence().

Generalize sync_scope's per-CPU active_scopes deferred-completion node and
add asahi_g17_barrier, a compact single-allocation variable-fan-in barrier
that joins the same inline drain pass when triggered from
asahi_g17_signal_fence() (falling back to irq_work only for foreign
signalers or when SCOPE_ATOMIC_BATCH is reached).

Update asahi_g17_merge_fences() and sync_input::merge() to:
- use stack scratch buffers up to 64 fences (heap-allocating only above 64),
- skip already-signalled non-error fences in a single pass,
- deduplicate identical pointers and same-context fences (keeping the
  latest seqno) for small active sets while keeping large merges O(N),
- preserve already-signalled error fences instead of dropping their status,
- return the stub or single remaining fence directly without allocating a
  barrier when 0 or 1 fences remain.

Extend tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py
to cover asahi_g17_merge_fences() fast paths, same-context deduplication,
error-fence preservation, and the >64 heap path.

Signed-off-by: oreater <[email protected]>
@oreater
oreater marked this pull request as ready for review November 26, 2026 22:34
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 26, 2026 22:34
@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 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 06a530fe: not ready yet

Check Detail
CI at head no failing: host-tests
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 06a530fe, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · G17 Macs (M4/M5) when a submission has >8 scheduler dependencies (MERGEDDEPENDENCIES).

Areas: area:gpu

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

@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: FINISH, then merge at 22d1339fe02a15d90074e230d4c1a161c4247428

Blocker: The new host merge tests mock asahi_g17_barrier_create(), so they only test selection of inputs. At this head there is also no hardware run of the production barrier. Please exercise the new callback/refcount path, including a child already complete during registration, the last child completing in the inline drain and from a foreign signaler, and a negative child status. Show one barrier completion and balanced child refs. The exact-head J716c stress and peer rows remain due.

Checked: Reviewed the collector, reference ownership, constructor guard, deadline snapshotting, and the bounded inline drain. The test cases for deduplication, error inputs and large inputs do not enter the production barrier. No DT, board gating, private material, or attribution changes.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks @oreater. The review is waiting on tests that exercise the real barrier: a child already signalled at registration, the last child in the inline drain and from a foreign signaler, and a negative status. It also needs before/after numbers for the >8-dependency case and an exact-head J716c stress row. Can you add these within 24 h? If not, we park it and pick it up when there is room (maintainer edits are on).

@erikwb erikwb 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, then merge at 22d1339fe02a

Blockers: the J716c row at this head is missing.

Checked: Traced callback registration, the constructor guard, callback and drain references, error publication, and deadline snapshots. No new hardware gates, runtime parameters or safety limits. The readiness checks passed and the branch has no conflicts. The equivalent-path boot predates this head. Exact-head J716c and peer rows are still due.

Evidence

Question, not blocking until measured: drivers/gpu/drm/asahi/g17/sync_input.c:161 keeps timeline chain wrappers as barrier children. That may cost the signalling path this change optimizes. Take a render submit with eight other pending inputs and a two-point chain whose leaves have distinct contexts. Let the newest leaf complete first and the predecessor complete last, after the first chain work has rearmed the callback and the other inputs have completed. The old merge unwraps the chain and queues one array completion. The new merge queues chain work for each leaf, then queues barrier work because the chain signals outside the driver's inline drain. Keep the flat fast path and retain the existing unwrap path for container inputs, or preserve the old leaf-level waiting in the new merge. A count of deferred work items per signal on that case, against main, would settle it.

drivers/dma-buf/dma-fence-chain.c:122 rearms via irq_work and signals with plain dma_fence_signal(). The render path in g17/queue/mod.rs:257 does not fold external inputs into firmware waits. The host merge tests replace the real barrier with a mock. Exercise the production callback path and show one barrier completion with balanced refs when a child completes during construction, the last callback runs on the inline path or a foreign path, and a child reports a negative status.

@erikwb

erikwb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

J716c (16-inch M5 Max) at 22d1339fe02a: boots, and Vulkan synchronization, memory and compute CTS show no regression against the same kernel without this PR.

Evidence

Built into batched kernel 7.3.0-ewb350+ (main 9d7918bc6316 plus open #3389 #3411 #3415 #3390 #3392 #3330 #3443 #3153 #3324 #3325 #3406 #3429), which contains this head unchanged. Control 7.3.0-ewb355+ is the same tree with the #3324 merge reverted. Borealis aurora-wip 437b0b52151, deqp-runner with 4 jobs. One-shot trial boots on the default command line plus watchdog.open_timeout=120 (a recovery watchdog for test boots only).

CTS with #3324 (ewb350) without (ewb355)
synchronization mixed list (5354 cases), run 1 4423 pass, 17 fail, 149 flaky 4426 pass, 163 flaky
same list, run 2 4337 pass, 252 flaky 4398 pass, 39 fail, 152 flaky
synchronization2.op.multi_queue.timeline_semaphore alone (4269) 4266 pass, 3 skip 4266 pass, 3 skip
memory.mapping (4466) 4466 pass not run
compute sample (1250) 490 pass, 760 skip not run
kernel errors during the runs none from the GPU driver; one burst of apple_pmp 284500000.pmp: RTKit: refused auxiliary buffer request at about 30 min uptime none

Every fail and flaky case on both kernels is in synchronization2.op.multi_queue.timeline_semaphore while it runs beside the rest of the synchronization list; run on its own the family passes on both.

… tests

The merge tests replace asahi_g17_barrier_create() with a mock, so the
new barrier's callback and reference path had no coverage. Compile the
production g17/sync_scope.c unchanged against a single-CPU dma_fence,
llist, per-CPU and irq_work model (ASan/UBSan on) and check, for
children already signalled at registration, the last child signalled in
the asahi_g17_signal_fence() drain or by a foreign signaler (irq_work
fallback), a negative child status, a barrier waiting on a barrier and
more ready barriers than SCOPE_ATOMIC_BATCH: one barrier completion,
the expected inline or irq_work path, balanced child references and the
barrier's release.

Dropping the callback's barrier put, the inline drain, the error
propagation, the child release on completion or the constructor guard
each fails the test.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks @oreater. I pushed 06a530f on top of your commit (test-only, no driver change) to answer the App finding. test-fence-signalling.py now builds the unchanged production g17/sync_scope.c against a single-CPU dma_fence/llist/irq_work model (ASan/UBSan on) and runs the real asahi_g17_barrier_create() path. Cases: children already signalled at registration, the last child signalled in the asahi_g17_signal_fence() drain and by a foreign signaler (irq_work fallback), negative child status, a barrier waiting on a barrier, and more ready barriers than SCOPE_ATOMIC_BATCH. Each case checks one completion, balanced child refs and the barrier release.
Tests: the whole script passes. Removing the callback's put, the inline drain, error propagation, the child release or the constructor guard each makes it fail.
Still open: App re-review at the new head, CI approval, the before/after numbers for the >8-dependency case (including the chain-leaf deferred-work question from the other review), and exact-head J716c stress + M4 rows.

@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 06a530fe for hosted CI and the J716c hardware row.

Checked: This delta compiles production sync_scope.c and exercises children already signalled at registration, inline and foreign completion, negative child status, nested barriers, early caller put, and the bounded drain handoff. The cases assert one completion and balanced references, addressing the host-coverage finding. The test models one CPU, so keep the current-head J716c stress and peer validation for the real IRQ path.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) ci-failing A check failed at the PR head (bot) labels Nov 30, 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: MERGE at 06a530fe1cfb

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: This delta compiles production sync_scope.c and exercises children already signalled at registration, inline and foreign completion, negative child status, nested barriers, early caller put, and the bounded drain handoff. The cases assert one completion and balanced references, addressing the host-coverage finding. The test models one CPU, so keep the current-head J716c stress and peer validation for the real IRQ path.

Follow-ups (not blocking): hosted CI; J716c IRQ-path stress row

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:m4 Macs affected, from Merge risk (bot) blast:m5 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) 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.

3 participants