Skip to content

drm/asahi: g17: cut the references a pending command holds - #3681

Draft
jgoyvaerts wants to merge 3 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-reach-links
Draft

jgoyvaerts wants to merge 3 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-reach-links

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: A pending G17 command kept references that grow with the queue's depth: one publication link per covered pending publication, and one completed fence per unfinished producer of the other engine it waits for in firmware. Behind a stalled job a queue of n pending commands held about n² of them (#2858). Cyberpunk 2077 filled #3602's queue budget with them (about 310 links and 170 producer fences per command on an M4 Pro). Two commits cut both at the source, with publication order and errors unchanged: (1) a publication records how far its ancestors reach, and a command skips a candidate a kept predecessor already reaches, so a chain that waits for all earlier commands takes one link per command; (2) each queue keeps a failure log per engine, and a command checks its producers through it (one reference and two numbers) instead of keeping a fence for each.
Tested: QEMU arm64 KUnit (asahi kunitconfig) at 4d9cb2f: Ran 958 tests: passed: 957, skipped: 1. Each commit's new cases fail on the code before it (link cut disabled: the link-count case fails, Ran 954; failure check stubbed: the 3 failure-log cases fail, Ran 957; lost failures tracked as first-only and not in flight: the lost case fails, Ran 958). tools/asahi host tests: the same failure set as on main 45d7f82 (at 602ea2f; the amend touches only FailureLog, and g15-input-error, the one host test reading dependency.rs, passes at this head). J616s M4 Pro, backport of the first commit on test kernel 7.3.0-m4.213 (not this head): Cyberpunk 2077 benchmark 33.3 / 35.4 fps, 1.4 links per command (was ~310), busiest queue at 84.8% of the budget, 0 recoveries, 0 submit failures (result). The second commit is not on hardware yet.
Risk: two-way door · M4 and M5 (G17 publication chaining in EnqueueOrdering::build, the producer status checks of Packet, and every command's failure path, which now enters a failure log before its fences signal). A wrong reach or a wrong since could let a command publish before an older publication it covers, or miss a producer's failure. The write-ups, with file:line references, cover ordering, error propagation, coverage, the in-flight race and the log's bound; the tests cover each. The many-to-many pattern (independent producers covered together) keeps one link each; #3602's budget still bounds it.
Not yet: a hardware run of the second commit (expected: Cyberpunk's producer references from ~190 per command to none, and the busiest queue well under the budget). Not run on M5.

Details

Reach. Publication::reach[e], set once before activation under the queue's lock (set_reach), is the largest s such that every publication of engine e up to seq s, which a later command could still link to (unfinished, publication pending) when this one was accepted, is an ancestor of this one. EnqueueOrdering::build:

  • walks each engine's covered candidates newest first (the frontier's prefix iterator now runs backwards; no extra allocation);
  • keeps a candidate unless its sequence ≤ what kept predecessors already reach on its engine;
  • sets the command's reach to the covered prefix of each engine its rules link (same_chain, cross_chain), or what its kept predecessors reach, whichever is further.

Timestamp waits are still collected from every candidate.

Why it is sound (full write-up with file:line references: ordering, error propagation, coverage):

  • Ordering: a skipped X is at most a kept K's reach. X is pending now, so it was pending when K was accepted, and a covered command is always accepted before its consumer (Order::new refuses a prior past the base). So X is an ancestor of K. A publication fires only once every predecessor has (remaining == 0), and so does upstream release. So K, and this command, fire after X.
  • Errors: X's error sets predecessor_error along the path to K. That blocks K's upstream release and turns its result into PRODUCER_FAILED, and the command inherits it from K.
  • Coverage: reach records only what a command actually linked. A query-accessing compute's host waits, a host-wait queue, or a command whose barriers skip an engine reach nothing there. So "link only the newest" counterexamples keep their link.

Not changed: host waits, firmware producer waits and scheduler dependencies.

Builds on the analysis in #2858 (its option 2a, reach-based reduction) and bounds what #3602's budget has to hold.

Second commit: producer failures through a log

dependency::FailureLog, one per queue and engine:

  • entries (count, seq, done), entered in Completion::signal_result before the terminal or output fence signals, and marked done after both;
  • since() is the count just below the oldest entry still in flight;
  • a command that waits for the other engine's producers in firmware reads since right before EnqueueOrdering::build reads their statuses, and keeps Producers { log, since, prefix } instead of a fence per producer;
  • it fails iff an entry has count > since and a sequence within its prefix.

Why it matches the fences exactly. For any other-engine command X within the prefix:

  • finished ok before: X never fails, and is never entered.
  • X's failure signalled before since was read: build() finds X failed and waits for it on the host, as before, and the log doesn't count it again.
  • X fails after, or is still being signalled: its entry is past since and counts.
  • X failed and retired before the command was accepted: not counted. A plain "lowest failed sequence" would keep failing every later command covering it, which FailureRecord stopped on purpose.

Bound.

  • Trimmed at every enqueue: a done entry stays only while an unfinished command of the other engine has a smaller since and covers it. In-flight entries stay.
  • Each kept entry stands for one (consumer, producer) pair that used to hold a completed fence. So the log never holds more than those fences did, and normally only recent failures.
  • A failure that cannot be entered (its GFP_NOWAIT push fails) holds since below it while in flight, like an entry, and conservatively fails every command whose since is below the latest such failure.

New cases (asahi_g17_dependency):

  • a_producer_failing_after_acceptance_fails_its_consumer (including the in-flight case);
  • a_failure_before_acceptance_does_not_fail_a_later_consumer;
  • trimming_keeps_only_what_an_unfinished_consumer_can_check.

The quarantine-drain host test's Completion stand-in gets signal_result.

Evidence
KUnit (QEMU arm64, asahi kunitconfig)
red (cut disabled: every candidate kept): Ran 954 tests: passed: 952, failed: 1, skipped: 1
  asahi_g17_cross_engine_timestamps.a_chain_behind_a_stalled_head_takes_one_link_per_command
green at 087a904aa7df: Ran 954 tests: passed: 953, skipped: 1
new cases (asahi_g17_cross_engine_timestamps):
  a_chain_behind_a_stalled_head_takes_one_link_per_command   (32 renders: 32 links, was 528)
  a_reduced_chain_still_publishes_after_its_stalled_head     (ordering, no early upstream release)
  a_reduced_chain_still_fails_when_its_head_fails            (error propagation)
  a_newest_predecessor_that_does_not_reach_keeps_the_older_link   (2858 problem 1)
  independent_producers_keep_one_link_each                   (2858 problem 2, m x n kept)
  a_rule_that_links_nothing_reaches_nothing                  (mixed per-command rules)
host tests: 29 FAIL lines, identical set on main 45d7f828e08a and on d5c52de7a062 (comments differ from this head)

Measured motivation (before this change, m4.211, budget probes on the inlined charges): Cyberpunk's busiest queue, 680k commands. Per command: links mean 302-319 (64%), producer fences ~170 (35%), scheduler dependencies ~6 (1%). Peak 311,000 units against the 262,144-unit budget.

…reach

A command chains its host publication behind every covered pending
publication, one link each. Behind one stalled timestamp writer every
later covered command joins the chain, so a queue of n pending
commands held n(n-1)/2 links. On an M4 Pro,
Cyberpunk 2077's busiest queue averaged about 310 links per pending
command, 64% of what its pending commands hold, and filled the queue
budget.

A publication now records how far its ancestors reach on each engine:
every publication of that engine up to that sequence which a later
command could still link to (unfinished, publication pending) when it
was accepted is one of its ancestors. A new command takes its
candidates newest first and skips one whose sequence a kept
predecessor already reaches. Its own reach is the covered prefix of
each engine its rules link, or what its kept predecessors reach.

Publication order and errors are unchanged:
- a skipped publication is an ancestor of a kept one, so it fires
  first: a publication fires only once every predecessor has, and
  upstream release needs that too;
- its error reaches the kept one, and through it this command, as
  PRODUCER_FAILED.

Reach records only what a command actually linked, so per-command
prefixes, a query-accessing compute's host waits instead of links, and
host-wait queues reach nothing they did not link (the "newest only"
counterexample keeps its link). Independent producers covered together
(m x n) keep every link; the queue budget still bounds that.
Timestamp waits are still collected from every candidate.

A chain that waits for all earlier commands now takes one link per
command.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Hardware result on a backport, not the exact head. J616s M4 Pro, test kernel 7.3.0-m4.213 (m4/private-213, on m4/private-212): #3681's link cut (cherry-pick of 087a904), #3600, #3601 and #3602's first two commits, with main's 2048-submission order window. #3602's budget was 262,144 units per queue.

Cyberpunk 2077 built-in benchmark, 1920x1200 Low, cold + warm, headless gamescope, alone on the GPU. Kprobes on the budget's two inlined charges read the new used after each one, beside the asahi_g17_* tracepoints. 0 trace overruns.

m4.211 (before the link cut) m4.213 (with it)
fps cold / warm 23.6 / 25.9 33.3 / 35.4
links per command, mean (p50 / p99) 302-319 (358 / 415) 1.4 (1 / 3)
producer fences + host waits per command, mean 167-176 183-189
scheduler dependencies per command, mean 5.7-6.0 2.1
busiest queue's budget peak 310,982 units (118.6%: submitter slept) 222,180 units (84.8%)
second queue 309,291 (118.0%) 208,241 (79.4%)
peak pending commands per queue 555 607
submit failures, GPU recoveries 0, 0 0, 0
  • The link cut does what the proof says. A command now holds 1.4 links on average, against ~310. Most of the fps difference against m4.211 comes from other changes in the test kernel (memory limits, queue lending, storm fixes) and is not attributed to this.
  • The budget no longer fills, but sits at ~85%. What remains is the producer fences, now 98% of the references (about 190 per command): one completed fence per covered unfinished producer of the other engine, kept for error propagation.
  • Replacing those with a per-engine failure log is written up but not implemented. The owner decides it from this number.

@jgoyvaerts jgoyvaerts changed the title drm/asahi: g17: link a command only to publications its others don't reach drm/asahi: g17: cut the references a pending command holds Nov 30, 2026
A command kept one completed fence for every unfinished command of the
other engine it waited for in firmware, only to fail when one of them
failed. Behind a deep queue these were most of what its pending
commands held. On an M4 Pro, once publication links had been cut,
Cyberpunk 2077's commands held about 190 such references each, 98% of
the references its busiest queue's budget counted, and that queue
peaked at 85% of the budget.

Each queue now keeps a failure log per engine. A failed command is
entered before its terminal and output fences signal and marked done
after both. A command that waits for the other engine's producers in
firmware keeps that engine's log and two numbers instead:
- since: the log count below its oldest failure still in flight, read
  before the command reads its producers' statuses;
- its prefix of that engine.
It fails if a failure past since is within the prefix.

This fails a command exactly when one of its fences did:
- a producer whose failure is at or below since had signalled it
  before the statuses were read, so it is found failed there and waited
  for on the host, as before;
- a producer that fails later, or is still being signalled, is past
  since;
- a producer that finished, or failed and retired before the command
  was accepted, never counts. A plain lowest failed sequence would have
  kept failing every later command covering it, which FailureRecord
  deliberately stopped.

The log keeps a done failure only while an unfinished command of the
other engine has a smaller since and covers it; it is trimmed at every
enqueue. Each kept failure then stands for one (consumer, producer) pair
that used to hold a completed fence, so the log never holds more than
those fences did, and normally only recent failures. A failure that
cannot be entered (the GFP_NOWAIT push fails) holds since below it
while in flight, like an entry, and fails, conservatively, every
command whose since is below the latest such failure.

The scheduler still waits for the producers' latest scheduled fence.
The quarantine-drain host test's Completion stand-in gets the new
signal_result.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-reach-links branch from 602ea2f to 4d9cb2f Compare November 30, 2026 16:42
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, G17P) boot row at head c1fae1db

Kernel: one trial boot (boot b0f8a86e). Stock Fedora -41 was restored and verified afterwards.

Results

  • Mixed render/compute with checked output:
    • q4 render triangle 42.3 µs, per-queue CRC ok
    • compute.light d1, per-slot CRC ok
    • concurrent render + compute on separate queues, and interleaved on one queue
    • 4-queue and 4-process compute; 4-queue render
    • cross-queue timeline and binary semaphore chains; host signal
    • queue churn (CRC ok)
  • Multi-queue CTS: sync2 16,680 Pass / 7,080 NotSupported / 0 Fail; sync 12,798 Pass / 9 NotSupported / 0 Fail. Identical case for case to the other boots on this Image.
  • Two clients in separate cgroups: kernel_resident 308 → 452 MB while running, 297 MB six seconds after close; user_resident back to its starting value at the end.
  • Health: 0 WARN, 0 GPU faults, 0 AVC, 0 failed units. The only flagged line is the out-of-tree taint from building the module with M=.

Not covered:

  • link or reference counts per command: the J700 has no counter for them, and this run did not trace them;
  • the deferred-error path for delayed publication;
  • a lost-device or failure injection.

This row covers the success path and multi-queue progress only.

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

Reviewed c1fae1d. Raw failure is logged before terminal signalling. A deferred predecessor failure is also recorded before the public fence signals, and the model observed that failure through the consumer's log. The 291 driver checks passed. The mixed-engine hardware row is still open.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Recorded inherited publication errors before signalling the producer’s public fence in c1fae1d.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Hardware result for the second commit, on a backport, not the exact head. J616s M4 Pro, test kernel 7.3.0-m4.219: the failure log as a cherry-pick of 4d9cb2f, on top of the link cut and #3600/#3601/#3602's budget (262,144 units per queue). The test kernel also has a local change that lets a command queued behind already-published producers be published from its ioctl. That change lowers scheduler dependencies but not the references counted here.

Cyberpunk 2077 built-in benchmark, 1920x1200 Low, cold + warm, headless gamescope, alone on the GPU. The same kprobes as before sit on the budget's two inlined charges. 0 trace overruns.

m4.213 (link cut only) m4.219 (link cut + failure log)
fps cold / warm 33.3 / 35.4 34.2 / 35.7
links per command, mean (p50 / p99) 1.4 (1 / 3) 1.4 (1 / 3)
other references per command, mean (p50 / p99) 189 (205 / 297) 16.2 (18 / 28)
scheduler dependencies per command, mean 2.1 2.1
busiest queue's budget peak 222,180 units (84.8%) 88,048 units (33.6%)
second queue 208,241 (79.4%) 84,354 (32.2%)
submit failures, GPU recoveries 0, 0 0, 0
  • The producer fences are gone. Packet no longer keeps a completed fence per producer, and the other references per command fell from 189 to 16.
    • The remaining 16 are checked inputs and the inherited host-timestamp waits. The charge counts both, and this trace doesn't separate them.
  • The busiest queue now peaks at a third of the budget (was 85%).
  • No GPU fault happened during the run, so it did not exercise the failure path itself. The KUnit cases cover that path.

This is a backport, so the PR stays a draft until the row passes at its own head.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants