Skip to content

drm/asahi: g17: keep each base fence of a submission's inputs once - #3601

Merged
DjDeveloperr merged 11 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-dedup-inputs
Dec 4, 2026
Merged

DjDeveloperr merged 11 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-dedup-inputs

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What: A G17 submission's inputs went into its list as userspace passed them, so one fence could be held any number of times: a syncobj handle repeated, or several timeline points and fence arrays over the same underlying fences. Each input is now unwrapped into its base fences with collect_coalesced(), the collector the compute source path already uses, and each base fence is kept once across the submission. Of one context's healthy unsignalled fences only the latest stays; a failed fence is never folded away. Stacked on #3600: review the last commit.
Tested: no hardware run at this head 986f3a3 yet; the backport below ran. QEMU arm64 KUnit (asahi kunitconfig) at 986f3a3 (main 33be2ff and #3600's head f35fd09 merged in): Ran 1068 tests: passed: 1067, skipped: 1. A build of drivers/gpu/drm/asahi without KUnit at that head is clean apart from main's own warnings. tools/asahi host tests at 986f3a3: the same failures as on main ade5247, and #3600's g17-command-inputs-tests and its mutations pass. The merge of #3600's partial-coverage change moves this PR's coverage test from Sources::cover() to command_inputs(): a covered container still waits on nothing, and an input the sources leave is the only one waited on. The main merge adapts the dedup to main's Leaves, which now lends its leaves: each kept base fence takes a reference of its own. Before the merges, at 34e83f4: Ran 941 tests: passed: 940, skipped: 1; the new dedup tests fail on #3600's head (red: Ran 941, 4 failed). J616s M4 Pro, backport on test kernel 7.3.0-m4.205 (m4/private-205 = 89a8b725782f with #3600, #3601 and the budget of #3602; not this head): Cyberpunk 2077 benchmark 24.6-25.9 fps, 0 submit errors, 0 lost devices, 0 recoveries; Hearthstone + desktop clean (results). A deep gpubench compute stream crashed the GPU firmware through #3602's order-window EBUSY and a separate teardown bug, not through the input changes.
Risk: two-way door · M4 and M5 (the G17 submit path). Checking base fences is at least as strict as checking their container: an earlier timeline point's error, which a later chain point need not carry, now fails the command too. Coalescing one context's unsignalled points to the latest is what collect_coalesced() already did within one input; an earlier point that later fails while the latest succeeds is not seen.
Not yet: the dEQP-VK synchronization, synchronization2 and timeline-semaphore slices (the next test kernel); a hardware run at this exact head. Not run on M5.

Details

Inputs::new() (from #3600) now:

  • skips an input that has signalled without error, as before;
  • unwraps the rest with collect_coalesced() (dma_fence_unwrap over arrays and chains, plus G17 sync scopes) and keeps each leaf; where collection fails (allocation, an unsupported container, more than 128 leaves) it keeps the input itself, as before;
  • sorts the list by (context, address) and keeps one entry per fence, and of the unsignalled healthy fences of one context (context 0 excepted, it names no timeline) only the latest, which signals after every earlier one. Failed fences keep their own entries.

Compute source coverage is decided on the inputs as passed (Sources::cover, from #3600), since Sources lists the input heads and the list now holds their leaves; a test covers that case.

Evidence
KUnit (QEMU arm64, asahi kunitconfig)
red (#3600 head fbc7bc38d91d + the new tests): Ran 941 tests: passed: 936, failed: 4, skipped: 1
  asahi_g17_inputs.a_repeated_input_is_kept_once
  asahi_g17_inputs.points_of_one_timeline_keep_the_latest
  asahi_g17_inputs.a_container_is_kept_as_its_base_fences
  asahi_g17_inputs.sources_cover_inputs_as_passed_not_their_base_fences
green at 34e83f4d6c28: Ran 941 tests: passed: 940, skipped: 1
also new: a_failed_point_is_never_folded_into_a_later_one (passes before and after)
host tests: 45 FAIL lines, identical set on main 1957bb761912 and on this head

Every command of a submission walked the submission's input syncs and
kept its own list of the fences that had not signalled. Gather that list
once per submission in sync_input::Inputs, after the outputs are
published, and give each command its share through
Inputs::for_command(). A command still holds its own copy, as before;
the next commit shares it.

A command whose compute sources take over the inputs in firmware takes
none of them, as before. Sources covers every input that had not
signalled when it was built (Backend::input_sources), so the per-fence
filter is all or nothing; an input that signalled in between needs no
wait either.

The fences checked on the host before publication are now the
command's own (failures, host waits, publication waits) followed by the
submission's inputs. Only the order of the checks changes: each failed
input still fails the command with PRODUCER_FAILED.

No functional change intended.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Each command of a submission kept its own list of the submission's
unsignalled input fences, and its scheduler job its own dependency on
each, or a merged fence of its own past MERGED_DEPENDENCIES. All of it
stayed allocated while the command was queued. The input count is set
by userspace (in_sync_count has no limit), so one submission of 64
commands behind a stalled fence held 64 copies of every input, and a
queue kept as many of those as it had queued commands.

The commands now share the submission's list (Inputs, behind an Arc),
and past MERGED_DEPENDENCIES inputs one fence merged from all of them
once per submission. A command's scheduler job waits on that fence, or
on each of a few inputs as before, and the command still checks every
input's status before publication.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A submission's inputs went into its list as userspace passed them. The
same fence could be listed any number of times (one syncobj handle
repeated, or several timeline points and fence arrays over the same
underlying fences), and every entry stayed allocated with the queued
commands and was checked before publication.

Unwrap each input into its base fences with collect_coalesced(), the
collector the compute source path already uses, and keep each base
fence once across the submission. Of the unsignalled, healthy fences of
one context only the latest stays: it signals after every earlier one,
as collect_coalesced() already does within one input. A failed fence is
never folded into another, so every input error still fails the
command, and context 0, which names no timeline, is only deduplicated
by identity. Where collection fails (allocation, an unsupported
container, more than 128 leaves) the input itself is kept, as before.

Checking the base fences is at least as strict as checking the
container: a fence array's error is one of its fences', and an earlier
timeline point's error, which a later chain point need not carry, now
fails the command as well.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Hardware results on a backport, not the exact heads. J616s M4 Pro, test kernel 7.3.0-m4.205: m4/private-205 = 89a8b725782f, i.e. #3600 + #3601 + the first two commits of #3602 cherry-picked onto aurora main a851ca0 with the test-kernel set. #3602's order-window commit (1a9a915) was written after these runs and is on no test kernel yet. Each row ran alone on the GPU.

row what ran result
1 Cyberpunk 2077 built-in benchmark, 1920x1200 Low, cold + 7 warm and cold + 2 warm, headless gamescope, read-only tracefs capture of asahi_g17_* submit/schedule/complete/output pass: 24.6-25.9 fps (20.0-21.0 on m4.202, before these changes); busiest queue 549 pending commands until their out-fence (874 on m4.202), so the budget never filled; 0 submit errors, 0 lost devices, 0 GPU recoveries
1b the same benchmark, cold + 1 warm, same capture 0 recoveries, peak 529 per queue, 17.9 / 20.8 fps; the budget probes saw nothing (the charges are inlined), so the exact budget use is still to measure
2 Hearthstone (already running) + desktop, 600 s, with probes on the inlined budget charges pass: busiest queue used 6,912 budget units (2.6% of 262,144)
3 gpubench-vk compute.light at depths 64-16384, then compute.heavy (kind=alu, ~0.5 ms kicks) at depths 64-16384 compute.light pass at every depth, 19 µs per submit at 64 and at 16384. compute.heavy pass at 64 and 1024. At 4096 it failed, and the run crashed the GPU firmware; see below

Row 3, what happened. At depth 4096 one submission failed with EBUSY. It was not from the budget, which only ever sleeps and held about half its units at the time (132k of 262k). It came from the context's submission order window (ORDER_WINDOW = 1024 in g17/context/identity.rs, on main since c510e9d), which refuses a new submission once 1024 are waiting behind the oldest. The budget counts commands, so a client submitting one command per ioctl reached the window first. Borealis reported a lost device, and gpubench went on to its next depth and then exited with work still queued. 0.8 s after the EBUSY:

  • the GPU faulted on an unmapped read at 0x10100 from that client's queue (recovery gen 493, then gen 494);
  • the GPU firmware crashed in the kill that followed (PC 0x18d5c, FAR 0x8, the same signature seen once on m4.202);
  • the desktop compositor lost its GPU, and the machine was rebooted.

The window refusal is fixed in #3602 by its third commit: the window is 4096, asserted above the most submissions the budget lets wait (2048 + 64), so a full queue makes the submitter sleep first. The fault-then-firmware-crash after a lost device is a separate kernel bug, already being looked at elsewhere. Until it is fixed, row 3 at depth ≥ 4096 counts as hang-risk.

Still to run: the Cyberpunk benchmark with probes on the inlined charges (the real budget use), and the dEQP-VK synchronization and synchronization2 slices against the stored baseline, both on the next test kernel.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Results on a backport, not the exact heads. J616s M4 Pro, test kernel 7.3.0-m4.211 (m4/private-211 = f5b29074bf46): #3600, #3601 and #3602's first three commits, including the 4096-submission order window, on aurora main a851ca0 with the test-kernel set. The queue budget was still 262,144 units there. #3602's head is now 5f940654b4e6, which raises it to 2^20 because of row 1c. Each row ran alone on the GPU.

row what ran result
1c Cyberpunk 2077 built-in benchmark, 1920x1200 Low, cold + warm, headless gamescope; kprobes on the budget's two inlined charges in Queue::submit (the new used after each charge), plus the asahi_g17_* tracepoints 23.6 / 25.9 fps, 0 GPU recoveries, 0 client failures. The two busiest queues peaked at 310,982 and 309,291 units, 118% of the 262,144-unit budget, so their submitters slept on it. They held 555 and 522 pending commands: about 71,000 units of command state and about 240,000 of references (publication links, firmware producer fences, scheduler dependencies), about 430 per command
4a dEQP-VK synchronization.* and synchronization2.* (6,213 cases), dq-fast against a stored baseline pass: 6,210 Pass, 3 NotSupported, 0 recoveries. All 431 differences from the baseline are NotSupported → Pass, from a newer Mesa (r11cba886 against the baseline's c356a149)
4b the timeline-semaphore case list (5,753 cases) did not complete. 24 deqp-vk clients lost their device with ETIMEDOUT, all in timeline_semaphore.one_to_n (sync and sync2), with 0 recoveries

On 4b:

  • The ETIMEDOUT came from the runtime side (fail_vm after a publication or pool-release stall), not from the submit ioctl. The budget never returns an error; it only sleeps.
  • No submission failed, and it happened alongside the test kernel's kill/free-list release work. It is being looked at with that work as a suspected kill-gate issue, not the budget or the input changes.

What changed because of 1c:

  • drm/asahi: g17: bound what a queue's pending commands keep allocated #3602 now gives a queue 2^20 units, about 32 MB of references, so Cyberpunk's peak uses about 30% of it.
  • The submission order window grows to 16,384 so the budget still fills before the window could refuse anything.
  • Still to come: a capped-vs-uncapped Cyberpunk A/B on one kernel (budgets 1×, 4× and none) to measure what the throttling costs, and a look at why a Cyberpunk command holds about 430 references.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
has_host_dependencies() decides whether a command may be published from
its submitting ioctl. It looked only at Packet::inputs, but a
submission's own input fences are now in the list its commands share
(shared_inputs), so a command whose only host wait was an unsignalled
submission input could be published early, without waiting for that
input or checking its status. Check every host-checked input, as
has_dependencies() and the dependency checks already do.

The inline cross-engine host test now models the shared list, with a
case where the only host wait is a shared input and a mutation that
looks only at the command's own inputs.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A command whose compute sources take over all of its submission's
inputs in firmware waits on none of them on the host. One whose sources
take over only some of them now shared the submission's whole list, and
so also waited on the host for the inputs its sources already order,
where each command used to skip each covered input on its own.

command_inputs() picks a command's list: the shared one when its
sources take over no input, else a list of its own with the inputs they
leave (none when they leave only signalled ones). That one case pays
for its own list again; every other command keeps sharing. It replaces
Sources::cover(), which only told whether the sources took over all of
them.

A host test compiles command_inputs() and covers the shared, partly
covered and fully covered cases, with mutations that wait on the
covered inputs too or share the list regardless.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review December 4, 2026 05:04
@jgoyvaerts
jgoyvaerts requested review from a team and DjDeveloperr as code owners December 4, 2026 05:04
@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 Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at 986f3a34: ready to merge

Check Detail
CI at head ok 11 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 986f3a34
Conflicts ok none
PR text ok Risk: two-way · M4 and M5 (the G17 submit path). Checking base fences is at least as strict as checking their container: an earlier timeline point's error, which a later chain point need not carry, now fails the command too. Coalescing one context's unsignalled points to the latest is what collectcoalesced() already did within one input; an earlier point that later fails while the latest succeeds is not seen.

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

DjDeveloperr
DjDeveloperr previously approved these changes Dec 4, 2026

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

Approving at 986f3a3. I reviewed the last commit (34e83f4) and the merges on top of #3600.

How I read it: each input is unwrapped with collect_coalesced() into its base fences, and each kept fence takes a reference of its own. dedup() then keeps each base fence once. Within one context it keeps only the latest healthy unsignalled point. A failed or signalled fence is never folded, and context 0 is never folded. If collection fails, the input itself is kept, so nothing is lost. Whether compute sources cover an input is still decided on the inputs as userspace passed them, and the new KUnit case pins that down. The trade-off described under Risk is acceptable to me: an earlier timeline point's error now fails the command, and a later failure of a folded earlier point is not seen. That's what collect_coalesced() already does inside one input.

What I ran on pc:

  • g17 host tests: main + #3600 + #3601 + #3652 414/414 (main 404/404).
  • W=1 of drivers/gpu/drm/asahi: no new warnings against main, with #3600 alone and with this PR on top.
  • dedup() only has KUnit tests, and we don't run arm64 VMs. So I compiled the production dedup() from this head on the host against a model fence and ran it on 20,000 random inputs (duplicates, timelines with failed and signalled points, context 0). It checks that no fence is kept twice, every failed or signalled fence is kept, every context-0 fence is kept, and every healthy point is covered by a kept point of its context at the same or a later seqno. It passes, and five mutations fail it: folding when either side failed (two mutations), keeping the earlier point, skipping the address check, and folding context 0.

Before merge: as for #3600, J714s and J700 rows at the exact head are queued. This lands right after #3600.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 4, 2026
@github-actions github-actions Bot added the ready-to-merge Meets the merge policy: merge it (bot) label Dec 4, 2026
@jgoyvaerts
jgoyvaerts dismissed DjDeveloperr’s stale review December 4, 2026 07:35

The merge-base changed after approval.

@DjDeveloperr
DjDeveloperr merged commit eb9ecd3 into aurora-silicon:main Dec 4, 2026
15 of 16 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged at 986f3a346035 (merge eb9ecd34de1c), right after #3600. The approval at this head was dismissed automatically when #3600 landed, because the diff shrank to this PR's own commit. The head merged is the one that was approved.

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.

2 participants