Repository navigation
drm/asahi: g17: cut the references a pending command holds - #3681
Conversation
…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 <jonathan.goyvaerts@gmail.com>
|
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
|
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 <jonathan.goyvaerts@gmail.com>
602ea2f to
4d9cb2f
Compare
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
J700 (Neo, G17P) boot row at head Kernel: one trial boot (boot
Results
Not covered:
This row covers the success path and multi-queue progress only. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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.
|
Recorded inherited publication errors before signalling the producer’s public fence in c1fae1d. |
|
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.
This is a backport, so the PR stays a draft until the row passes at its own head. |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Tested exact head
Note: This was a single-pass benchmark check on J716c rather than a full CTS/reboot regression row, and the kernel image booted with a post- |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: the code is right. Land it once the J714s and J700 rows below pass at this head. I found nothing that has to change first. There is one thing worth fixing in a follow-up (an extra cancel after a failure) and two small notes.
Reviewed at c1fae1db7ecc, merged into main 5fe340acef00 (clean, tree 634cfeb3de00). It is also clean on 37a630623169; nothing under drivers/gpu/drm/asahi changed between the two. I pushed nothing.
What I checked
Link cut. A kept predecessor really does stand for everything below its reach:
- Covered commands are always accepted before the command that covers them (
priorcan't pass the base, and an ioctl's commands are enqueued in order), andpendingonly goes from true to false. So anything still linkable now was linkable when the kept one was accepted. - A rule that links nothing (query-access compute,
host_producer_waits) records no reach of its own. - The first candidate is always kept, so the terminal fence, the timestamp window and the host/firmware waits are decided exactly as on main.
Failure log.
sinceis read after the prunes and beforebuild(). Failures are entered before the first fence signals, and an entry stays open until the public fence has signalled. Trimming never drops an open entry.- The mutex is a leaf: nothing is allocated under it with a blocking flag, and it is taken in process context only (device mutex → log, queue lock → log).
- Every failing path goes through
signal_resultor the inherited error inOutput::publish. That covers retirement, unpublished cancels, failed-while-owned, recovery and teardown. - The log holds no references, so there is no cycle with the queue.
c1fae1dbis needed. Without it (entry closed at the raw failure, or no entry for an inherited error) the check below misses failures that the old fences caught.
What I ran on the merge tree
| Check | Result |
|---|---|
run-host-tests.py --only g17, CI image (rust 1.96) |
333/333 passed (the runner is byte-identical to main's) |
g15-input-error, m3-packet, m5-client-handoff, legacy-wq (read the changed files or their neighbours) |
3/3, 2/2, 2/2, 10/10 |
make ARCH=arm64 LLVM=1 W=1 drivers/gpu/drm/asahi/, stock aurora config (G15, G16, G18 and M5 on) |
rc 0; asahi_core.o and aurora.o rebuilt |
The same with CONFIG_KUNIT=y (compiles the new cases; not run here) |
rc 0 |
| W=1 warnings in the six changed driver files | one, on main's fetch_update in begin_replay |
checkpatch --strict per commit |
0 errors; 6 warnings (test lines over 100 columns) / clean / 1 warning (c1fae1db has no description) |
| Random comparison of main and this head, described below | no difference, no missed failure |
The comparison compiles the real publication.rs, EnqueueOrdering::build, Outstanding, Output and FailureLog source from main and from the merge on the host. It feeds both the same random commands, barriers and failures. In 400,000 sequences (11.2 million commands):
- every command got the same host, firmware and inherited timestamp waits, and every public fence, terminal fence and pending flag was the same after every step;
- links fell from 18.0 to 6.7 million;
- of 56 million producer checks, the log missed none that a fence would have caught;
- 300,000 (consumer, producer) pairs with failures signalled from other threads during acceptance: none missed.
I also broke the code on purpose: reach without its rule, keep-newest-only, reach off by one, no entry for inherited errors, entry closed early, trim of needed entries, and since past open entries. The comparison caught all seven.
Follow-up, not blocking: an open failure can cancel a command that main would run. Since c1fae1db an entry stays open while its public fence waits for an older publication, and since stays below it all that time. Take Y (failed, finished and pruned) and X (a newer, failed command whose public fence is still waiting). A command accepted now that covers Y but not X gets a since below Y's entry and fails with ECANCELED. On main it runs, unless Y still holds its VM pin. Between the two commits the log didn't do this, and the second commit's text ("failed and retired before the command was accepted: not counted") no longer holds here. It only errs towards cancelling, only after a real failure, and only for a barrier that stops short of the newest failure. It was 4,983 of 14 million checks, in sequences that fail on purpose.
A fix that is exact in the same comparison (0 of 14 million, still no misses): count when an entry closes instead of when it opens.
since()returns the number of closed entries.end()increments that number, stores it in the entry, and moves the entry to the end of the closed ones.failed()counts entries that are open or closed aftersince.trim()then still needs only one pass.- Please add the case that has no KUnit test yet: a raw failure behind a pending predecessor, checked between its terminal and its public fence.
I didn't push this because the head has rows and a comparison on it now.
Notes
firmware_waitsstill collects each producer's completed fence, and nothing reads it any more. It can become a list of scheduled fences.- The earlier approval here came from the account that pushed
c1fae1db, so it doesn't count for the last-push rule. It missed the point above. The 12-01 J700 row is the success path only, withaurora.kobuilt out of tree on another main plus #3705. The readiness table's "hardware row ok" is also early: the body's J616s runs are backports. The J716c result at this exact head (38.5 → 57.3 fps, 0 faults) is the best evidence so far.
Land order. #3985 and #3342 share no file with this; any order. #3991 (on hold) merges cleanly either way; I didn't build it together with this one. #3411 and #3390 each merge into main but conflict with this in queue/mod.rs, so whichever lands second needs a forward merge. For #3411 it is one field in Queue::new. For #3390 it is the producer loop, plus its host test, which expects firmware.push(completed.clone()). #3443 conflicts in publication.rs, job.rs and queue/mod.rs and cuts the same clique, so it should be reworked on top of this one. Its deferred attaching has to keep the rule this relies on: a kept predecessor can't fire before its ancestors. I'd land this first, then #3390/#3411, then #3443, then #3602.
Rows owed: J714s, J700, J616s (J773g not needed)
Kernels. head = this head merged into the current main. base = that main. Same .config, DTB and Mesa. Image and modules from the same build, not an out-of-tree module. Record the main, merge and tree SHAs and both build IDs.
Link and failure counters, both arms (as root; stock config has KPROBE_EVENTS and HIST_TRIGGERS):
cd /sys/kernel/tracing
L=$(awk '$3 ~ /publication.*8Prepared8activate$/{print $3; exit}' /proc/kallsyms)
F=$(awk '$3 ~ /dependency.*10FailureLog5begin$/{print $3; exit}' /proc/kallsyms)
echo "p:g17row/links $L n=+24(%x0):u64" >> kprobe_events
[ -n "$F" ] && echo "p:g17row/failed $F seq=%x1:u64" >> kprobe_events
echo 'hist:keys=n' > events/g17row/links/trigger
[ -n "$F" ] && echo 'hist:keys=seq' > events/g17row/failed/trigger
# after each workload
cat events/g17row/links/hist; [ -n "$F" ] && cat events/g17row/failed/hist
+24 is the length of Prepared::links. I read it from the disassembly of my build (rustc 1.100.1); check that activate in the row's aurora.ko loads the length from [x0, #0x18]. FailureLog::begin exists only on head.
J714s (M5 Pro, T6050 G17S): base, head, head, base, then one lockdep boot of head. SLC on (16 planes), headless only.
gpubench-vk, CRCs verified:compute.cull_mdi(objs=16384 visible=75, depths 1, 2, 8, timestamps on, CRC07f6c861),render.light(kind=tri, depths 1, 8, 32, 64),render.postfx(1, 2),compute.light(1, 8),compute.heavy(kind=alu, 1, 4). Plusgpubench-rt-vk rt.scenemedium.- CTS:
synchronization.smoke.*,synchronization2.op.single_queue.*,query_pool.concurrent_queries.*,query_pool.occlusion_query.copy_*,multiview.queries.*,pipeline.monolithic.timestamp.*. - Stress for the cut references: GTA V at native resolution, 3 minutes in the open world, with the link histogram. Cyberpunk 2077 with separate D3D12 queues also works. These keep hundreds of commands pending behind timestamp writers.
- Failure path:
gpubench-stress-vk --test cr.concurrent,xq.order,xq.chain,sync.dense,queue.depth,compute.long,life.churn,life.fault --duration 240 --seed 3681 --kernel-log. - Lockdep boot (
PROVE_LOCKING,DEBUG_LOCK_ALLOC): items 2 and 4 once.
Pass:
- every CRC right, CTS results identical case by case with 0 Fail, stress exits 0;
- no primary metric more than 5% worse in both halves of the ABBA;
- GTA V links per command on head at or below base at p50 and p99 (J616s went from about 310 to 1.4), and no lower fps;
failedhas entries afterlife.faultif it reportsfaults_device_lostabove 0;- 0
WARNING:,BUG:,possible circular locking dependency,possible recursive locking,G17: refused a submission; G17: recovery gen,asahi: recovery: GPU MMU faultandthe client sees a lost deviceonly duringlife.faultand only for its faulting client. The checked client reports no error.
J700 (T8140 G17P): one head boot, plus base if any number looks off. Items 1 (render.light to depth 32) and 4, the 12-01 multi-queue CTS lists (then: 16,680 Pass / 7,080 NotSupported and 12,798 Pass / 9 NotSupported, 0 Fail), the two-client close test (kernel_resident back to its start), three s2idle cycles with item 1's compute.cull_mdi after each. The same pass lines. This one replaces the 12-01 row.
J773g: not needed. T8132 runs g16/ with its own jobs, fences and graph. From g17/ it uses only sync_input, sync_output and status, which this doesn't touch.
J616s (author), at this exact head merged into main, without the test-kernel set: Cyberpunk 2077 cold and warm with the same kprobes (links about 1.4, other references about 16 per command, 0 submit failures, 0 recoveries), dEQP synchronization.* and synchronization2.* (6,213 cases), and life.fault from item 4, which is the failure path none of the runs has had. T604x has no Mac in our lab, so this is the only T604x coverage. Please put the result in the body with the full SHA.
Not covered by any row: a command cancelled because a same-queue producer on the other engine failed while its public fence was still waiting. The KUnit cases and the comparison cover it.
|
We carry this PR in our unified daily kernel across J716c (M5 Max, T6050), J713 (M4 Air, T8132), and J313 (M1 Air, T8103) alongside Pruning transitively reached publications and checking cross-engine producer failures through the per-engine failure log eliminates the O(N^2) producer fence/publication clique on deep mixed render/compute queues, cutting submission overhead and unlocking smooth async compute on J716c (contributing to 60.14 FPS in Cyberpunk 2077 2.5 T2 with zero GPU faults). Booted and verified on J716c, J713, and J313 (5/5 Vulkan CTS smoke pass on all three Macs, zero GPU errors). |
|
J714s (M5 Pro, G17S B1, SLC ON 16 planes) #3681 |
J700 (MacBook Neo, T8140, G17P) at
|
| Check | Result |
|---|---|
| Item 1, item 4: GPUBench, every case checked | PASS. cull_mdi d1/d2/d8 CRC 07f6c861 each, also after each sleep. render.light d1/8/32, render.postfx d1/2, compute.light d1/8, compute.heavy d1/4 and rt.scene medium all valid |
| Two-client close | PASS. kernel_resident 236 → 222 MiB, at most +16 MiB allowed, both rounds (6 and 7 s after the close) |
| The 12-01 CTS lists, absolute | 23,760 of 23,760 and 12,807 of 12,807 recorded, 0 cases that are not Pass, NotSupported, QualityWarning or CompatibilityWarning. No failing case, so nothing to re-run on stock |
| Stress (240 s budget, seed 3681) | all 8 tests pass, 0 errors: cr.concurrent, xq.order, xq.chain, sync.dense, queue.depth, compute.long, life.churn, life.fault |
life.fault |
The client stores through an unmapped address over and over. 92 stores were ignored and 0 devices were lost: the GPU dropped them, with no failure and no recovery. Deviation (stated): this client never reports device lost here. The checked client had 0 errors, 0 GPU lines in its window, and a fresh device worked afterwards (cull_mdi d1/d2/d8 in a new process, CRC 07f6c861) |
s2idle × 3, each followed by cull_mdi |
PASS. Success 0 → 3, fail 0, panel, 6 CPUs and the GPU back, 0 failed units |
| Kernel log | 0 WARN, BUG, Oops or lockup lines, 0 GPU fault, recovery or lost-device lines, 0 G17: refused a submission, 0 boot hits. Firmware online, not crashed in all 9 capacity samples |
| Watchdog | armed throughout |
Not measured
- fps against a base: there is no base arm on the J700, so this row is about correctness and hangs. The times are recorded, not judged.
- CTS case-identity: also no base arm. The case counts differ from the 12-01 row (now 4,266 Pass and 19,494 NotSupported of 23,760; then 16,680 and 7,080). The 1,378 messages that the run printed say "Concurrent requires more than 1 queue family": stock Mesa 26.3.0-30 here exposes one, and the 12-01 row used another ICD. The same stock pre-check on the stock kernel gave 5 Pass and 25 NotSupported of 30. I did not trace every NotSupported case.
- Links per command: stock
aurora_defconfigrefuses a kprobe onaurora.ko's Rust functions (they have no ftrace location, andKPROBE_EVENTS_ON_NOTRACEis off), so the review's link and failure counters could not be armed. - Not covered: the failure path where a same-queue producer fails while its public fence still waits, and the case that a
life.faultclient loses its device.
How it ran: the first two attempts stopped before any check of the PR (kit bugs: the kprobes, then a GPUBench multi-queue command without --verify that crashes in the test tool). Dead-man-only recovery, 30-minute dead-men.
Stock restored: boot-ctxr.bin byte-identical to before, no trial marker left, stock 7.3.0-41, PMU boot-error count 00.
|
J714s |
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 the current head c1fae1d: Ran 958 tests: passed: 957, skipped: 1. At 4d9cb2f, my last commit: Ran 958 tests: passed: 957, skipped: 1. Each of my commits' new cases fails 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 at c1fae1d: failures only in files this doesn't touch (apple-dcp, g15-pb-growth, g15-retention mutations, g15-stats-drain, sep-suspend-errors: environment). g15-input-error, the one host test reading dependency.rs, passes. J616s M4 Pro, only on backports in test kernels, never at this head, both with #3602's budget: (1) the first commit on 7.3.0-m4.213: 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). (2) both of my commits on 7.3.0-m4.219: Cyberpunk 34.2 / 35.7 fps; other references per command 189 → 16 (the producer fences are gone); busiest queue at 33.6% of the budget; 0 recoveries, 0 submit failures (result). The current head adds DjDeveloperr's c1fae1d, which was not run on the J616s. With it, a failure's log entry stays open until a deferred public fence is published.
Risk: two-way door · M4 and M5 (G17 publication chaining in
EnqueueOrdering::build, the producer status checks ofPacket, and every command's failure path, which now enters a failure log before its fences signal). A wrong reach or a wrongsincecould 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 at this head (the backports above lack c1fae1d). 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: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):
Order::newrefuses 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.predecessor_erroralong the path to K. That blocks K's upstream release and turns its result into PRODUCER_FAILED, and the command inherits it from K.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:(count, seq, done), entered inCompletion::signal_resultbefore the terminal or output fence signals, and marked done after both;since()is the count just below the oldest entry still in flight;sinceright beforeEnqueueOrdering::buildreads their statuses, and keepsProducers { log, since, prefix }instead of a fence per producer;Why it matches the fences exactly. For any other-engine command X within the prefix:
sincewas read:build()finds X failed and waits for it on the host, as before, and the log doesn't count it again.sinceand counts.FailureRecordstopped on purpose.Bound.
sinceand covers it. In-flight entries stay.GFP_NOWAITpush fails) holdssincebelow it while in flight, like an entry, and conservatively fails every command whosesinceis below the latest such failure.New cases (asahi_g17_dependency):
The quarantine-drain host test's
Completionstand-in getssignal_result.Evidence
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.