Skip to content

drm/asahi: g17: link publications directly to timestamp writers and attach lazily - #3443

Open
DjDeveloperr wants to merge 6 commits into
mainfrom
perf/g17-publication-direct-lazy
Open

DjDeveloperr wants to merge 6 commits into
mainfrom
perf/g17-publication-direct-lazy

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What:
Stop building an all-pairs Publication dependency clique per frame on G17, and stop draining successor lists eagerly in the completion worker.

  • queue/mod.rs, job.rs: Fences::timestamp_publications carries only the pending timestamp writers (has_outputs()) through timestamp-free commands, the same way timestamp waits are already inherited. Each command links directly to the pending timestamp writers instead of to every timestamp-free command in between, so a deeply pipelined GTA V frame drops from about 15,000-18,700 KBox<Link> edges to one per real predecessor.
  • Timestamp-free commands still carry failures: PublicationChain links each command to the newest uncovered timestamp-free entry that is still pending (Fences::covers records how far a command's waits already reach), kept separate from the inherited writers. An earlier entry that fails before or after enqueue reaches every later command as PRODUCER_FAILED.
  • completion/publication.rs: predecessor links are allocated up front and kept on the successor (deferred_links, target = None, so an unfinished drop leaves no Arc cycle). A predecessor that settled cleanly is recognised by an AtomicBool read with Acquire before its lock is taken; publish(Err) clears it, so late failures still reach successors. DeferredBatch::finish() attaches only predecessors that are still pending or failed, and the probe ends on the first failed predecessor (Probe::Consumed) or releases a queued successor once its predecessor settles (Probe::Settled), so it never loops.
  • When a waiter queues on a deferred publication, the whole deferred chain behind it is subscribed iteratively (an explicit stack, no depth limit), so a successor is always released when its last predecessor finishes, however long the chain.
  • KUnit: in_order_writer_finish_drains_zero_deferred_links, deep_timestamp_free_chain_links_directly_to_writer_not_clique, timestamp_free_entry_failed_before_enqueue_fails_covering_successor, timestamp_free_entry_failing_after_enqueue_fails_covering_successor. Host test tools/asahi/g17-publication-direct-lazy-tests.py: 13 scenarios (failure before/after enqueue and after release, deep chains of 4-6 timestamp-free entries, queued-successor release) and 11 contract mutations, each caught (clique regression, failed-status propagation, eager attachment, unfinished-drop Arc leak, late-error flag clearing, lockless clean-predecessor path, dropped chain link, retrying a failed predecessor, kept attached successors, missing and depth-bounded subscription).

Tested:

Risk: two-way · G17 Macs (M5 Pro, Neo)

Not yet:

  • SLC-on GTA V A/B. Earlier GTA V numbers for this change were measured with SLC off and are withdrawn.

…ttach lazily

Avoid O(N^2) Publication link cliques and multi-millisecond event-worker stalls when deep timestamp-free chains queue behind pending timestamp writers:

1. Direct timestamp-writer linking (queue/mod.rs, job.rs): track inherited pending timestamp-writer publications in Fences::timestamp_publications and collect only actual timestamp writers (has_outputs()) or failed entries (status < 0) in EnqueueOrdering::build(), collapsing ~18,000 clique links per deeply pipelined frame to O(N).
2. Lazy successor attachment (completion/publication.rs): retain pre-allocated predecessor links on each successor with Link::target = None until finish() runs (preventing Arc self-cycles on unfinished teardown), fast-pathing cleanly settled predecessors via an Acquire load on settled_clean without locking them or draining eager successor lists on the event worker.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 21:44
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo 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 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at 1213e012: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at 1213e012
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · G17 Macs (M5 Pro, Neo)

Areas: area:gpu

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

… chain

Linking a command straight to the timestamp writers of the pending
timestamp-free entries it covers dropped those entries from the chain.
Such an entry can fail while its writer is still pending (its fence
then still reads 0, so it is not linked as failed), or fail after the
covering command was enqueued. Either way the covering command signalled
success when the writer did, instead of inheriting the failure.

Link the newest pending timestamp-free entry of each covered prefix that
no newer linked entry covers. Each command records the prefix of its own
engine it covers, and a linked entry reaches the entries it covers
through its own links, so in-order submission adds one link per engine
and no clique. These chain links are kept apart from the inherited
writers, so later commands still flatten only to writers.

Linked entries that have not retired keep their predecessors deferred,
so bound how deep Publication::is_pending() follows them; a probe that
stops early reports pending, which only links more.

License the publication host test GPL-2.0-only, and test both failure
orders and a chain-dropping mutation in KUnit and on the host.

Signed-off-by: DjDeveloperr <[email protected]>
Publication::is_pending() settles a deferred timestamp-free publication
once its predecessors are clean. Two cases were missing:

A predecessor that released its successors early and then failed has
pending and settled_clean both clear. The probe asked it, got "not
pending", found it still unsettled and asked again, forever. Consume
that link as terminal instead and keep PRODUCER_FAILED for finish(),
so the probe ends and the failure is still published.

Settling through the probe dropped the predecessor links but left
successors that had already attached queued, so a successor that
finished before the settlement waited for this command's own
completion. Release them off-lock, as predecessors_done_ok() does.

Add host tests for both cases.

Signed-off-by: DjDeveloperr <[email protected]>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict — hold at 22a4e9c88267. The follow-ups fix the intermediate failure lost at 8442bb05b047, the retry loop after a late failure, and the host test license. One fence-progress blocker remains.

drivers/gpu/drm/asahi/g17/completion/publication.rs:348 attaches a finished successor S to timestamp-free B without subscribing B to its still-pending writer A. When A publishes successfully, S’s fence stays unsignalled until another caller probes or finishes B. The new host test (case 10) explicitly observes S’s zero fence status after A succeeds, then calls b.is_pending() to make the fence signal. A fence waiter does not perform that queue probe. On the previous eager path, A completing released B’s attached successors immediately. When the first successor actually waits on B, arrange notification from B’s pending predecessors. Test that S signals when A completes with no subsequent submission, probe, or B completion.

I checked the direct writer and error links, attachment and Arc ownership, terminal-error handling, and release ordering. The J714s candidate contains the original head. Both J714s and J700 need rows covering the revised runtime code.

… on it

A timestamp-free publication links itself to its predecessors only at
its own finish(), or when a probe settles it. A successor that finished
first and queued on it therefore stayed unsignalled after the
predecessors published, until that command retired or something
probed it; a fence waiter never probes.

When a waiter queues on an unfinished deferred timestamp-free
publication, subscribe it to its predecessors right away, holding a
sentinel as finish() does, so their completion settles it and releases
the waiter. Subscriptions this starts in turn are bounded by the probe
depth; a publication past the bound links at its own finish(), or when
a probe settles it and releases what queued on it.

Require in the host test that the waiter signals on the writer's
completion alone, and cover the bounded chain.

Signed-off-by: DjDeveloperr <[email protected]>
Subscribing a deferred publication when a waiter queues on it stopped
four publications deep. Past that the intermediaries stayed deferred, so
the writer's completion did not signal the waiter, and an intermediary
failing later made that same waiter report the error.

Subscribe iteratively instead: add_successor() only queues the link and
reports whether the publication needs subscribing, and subscribe() walks
a stack threaded through State::subscribe_next, linking each queued
publication and pushing the deferred ones it reaches in turn. It neither
recurses nor allocates, and each publication is queued at most once.

Require in the host test that the writer's completion alone signals the
waiter through 4, 5 and 6 deferred intermediaries, and that a later
intermediary failure leaves it unchanged; both fail with the old depth
limit.

Signed-off-by: DjDeveloperr <[email protected]>
satchlj
satchlj previously approved these changes Nov 28, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and host-tested at exact HEAD 69fd36afe7c4:

  • Code review: forwarding only pending timestamp writers (Fences::timestamp_publications + collect_publication_predecessors()) removes the O(N^2) clique across timestamp-free commands while preserving failed-entry propagation. Lazy attachment (deferred_links, settled_clean fast path, and the intrusive non-recursive subscribe_next stack) avoids Arc cycles and stack/heap growth on deep pipelines, and pending_within() cleanly handles failed_after_release() and drops links off-lock.
  • run-host-tests.py --only g17: 254/254 passed in 4 s.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor

Code review note at 22a4e9c88267 on fences.covers in drivers/gpu/drm/asahi/g17/queue/mod.rs:

fences.covers = order.wait_through[index] is stored unconditionally even when same_chain == false, which happens for Engine::Compute when query_access == true (same_engine_wait_completed(Compute, true) is true, so same_chain is false).

Trace:

  1. Render R1 (has_outputs = true) is pending.
  2. Compute C1 (seq 1, query_access = false, has_outputs = false) chains behind R1 and is pushed to publishers[COMPUTE] with ready != completed.
  3. Compute C2 (seq 2, query_access = true, has_outputs = true, wait_through[COMPUTE] = Some(1)): because same_chain == false, C2 does not run the PublicationChain link loop over same_covered, and its same_wait path only collects R1.completed via collect_timestamp_waits(C1) (since C1 is timestamp-free with status == 0). Yet C2 still records fences.covers = Some(1).
  4. A subsequent C3 or R2 passing [(1, None, pub_C1), (2, Some(1), pub_C2)] to PublicationChain::link() sees C2.covers == Some(1) and skips pub_C1 even though C2 never linked pub_C1. If C1 fails on the GPU while R1 is still pending, C1's error never reaches C3/R2.

Gating fences.covers on same_chain (e.g. same_chain.then_some(order.wait_through[index]).flatten(), or the actual same_covered high-water mark linked by PublicationChain) closes this.

The kernel prelude brings pin_init::Init::chain into scope, so
`.iter().chain(...)` on the predecessor and chain link slices is
ambiguous (E0034). Name Iterator::chain.

Signed-off-by: DjDeveloperr <[email protected]>
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Nov 28, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro M5 Pro, T6050 / G17S B1) exact-head correctness row at 1213e012b40c0d12b5662ebd6cd724a05fa55ef2: PASS, 0 failures, 0 GPU faults, 0 recoveries.

  • Kernel 7.3.0-m5-pr3443, built on the M5 from the exact head tree (5f6926667569) with the default's config. One trial boot; the default 7.3.0-m5-cdirect16 was restored afterwards with all 253 ESP files byte-identical.
  • SLC on: the boot used this tree's own t6050-j714s.dtb with only the MCC node's status set to okay. The kernel log showed apple-mcc ... system level cache allocation enabled on 16 planes.
  • Vulkan CTS (deqp-vk 1.4.7.1, Mesa kit inst-A), 0 failed:
    • synchronization.smoke.* 12/12, synchronization.basic.* 29/29
    • synchronization2.op.single_queue.barrier.*_read_image_compute* 412/412
    • query_pool.occlusion_query.copy_* 152 passed, 7 not supported; query_pool.concurrent_queries.* 2/2
    • multiview.queries.* 16/16, pipeline.monolithic.timestamp.basic_graphics_tests.* 80/80
    • api.copy_and_blit.core.image_to_image.simple_tests.* 19 passed, 4 not supported
  • gpubench-vk (ae90a40, 3x500 ms): compute.cull_mdi CRC 07f6c861 valid at d1 and d2; chainbench_diag ran clean.
  • GPU health before and after: online, 0 crashed, 0 quarantined, drained render pairs 0 failures / 0 recovered, no render kills, no GPU fault or recovery lines in the kernel log.
  • Correctness only; the PR body's GTA V numbers predate this head and were measured with SLC off.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, Apple A18 Pro T8140 / G17P B1) exact-head kernel verification row at 1213e012b40c0d12b5662ebd6cd724a05fa55ef2: PASS. SLC was on for both boots, every gpubench CRC matched stock, CTS had 0 Fail, and there were 0 GPU faults or recoveries.

  • Host tests: python3 tools/asahi/run-host-tests.py --only g17- passed 254/254 (13 s) at exact head.
  • Build and boot:
    • Built 7.3.0-neo-pr3443 from exact head with the stock 7.3.0-41 config plus LOCALVERSION=-neo-pr3443 (0 build errors, 2,002 modules).
    • Booted once with grub2-reboot and a 10-minute fallback timer; the default entry stayed 7.3.0-41.fc44.aurora.aarch64. System Mesa, and the kernel command line was identical to stock (0-byte diff).
    • On the trial boot (55df6342), the kernel build ID was 60ea4ab1d73efcfd5051781252afdf2a5f75c9ca (MATCH) and the aurora.ko build ID was 4e88e8b6ea54e8e4a8c5fb6ecc2d3d18cfeceb97 (MATCH).
  • SLC (apple-mcc) check, the same on both boots:
    • Stock 7.3.0-41 (boot 0eed3efa) and 7.3.0-neo-pr3443 (boot 55df6342) both logged: apple-mcc 220000000.memory-controller: system level cache allocation enabled on 4 planes
    • /proc/device-tree/soc/memory-controller@220000000/status read okay on both boots.
  • VK CTS (6 jobs, 37,886 cases in 185 s): 31,611 Pass, 6,275 NotSupported, 0 Fail, 0 recoveries, 0 left. This is the same case list as the linux#3328 row:
    • dEQP-VK.synchronization{,2}.* (basic, smoke, single-queue, timeline semaphore, implicit, none_set_reset, internally synchronized objects, and all synchronization2.*_read_image_compute*): 31,242 Pass, 6,178 NotSupported, 0 Fail. The *_read_image_compute* cases were 5,100 Pass, 5,806 NotSupported.
    • dEQP-VK.compute.pipeline.basic.*: 79 Pass, 2 NotSupported.
    • dEQP-VK.api.command_buffers.*: 65 Pass, 66 NotSupported.
    • dEQP-VK.renderpass{,2}.suballocation.subpass_dependencies.*: 73 Pass, 22 NotSupported.
    • dEQP-VK.query_pool.occlusion_query.copy_*: 152 Pass, 7 NotSupported.
  • gpubench-vk (fdf4dd6, system Mesa): 22/22 rows ok, and every CRC matched the stock 7.3.0-41 baseline run in the same slot. Per-submit times are stock -> PR:
    • render.light d1/d8/d32: 124.3/29.3/27.5 -> 128.6/31.1/29.7 µs.
    • render.deferred tile msaa=4 1080p d1/d2: CRC 5e4130ce on both; 11111.1/10714.3 -> 10714.3/10714.3 µs.
    • render.postfx msaa=4 1080p d1/d2: CRC 668d6f0a on both; 759.5/556.6 -> 775.2/575.8 µs.
    • render.pass_chain all_bar / oq_bar d1/d4: CRC 93411763 on all; all_bar 520.8/454.5 -> 551.5/370.8 µs, oq_bar 781.2/857.1 -> 854.7/949.4 µs.
    • render.mdi draws=1024 bindless=1024 d1/d4: CRC 3ba813b3 on both; 463.0/130.6 -> 509.3/149.4 µs.
    • compute.light d1/d8: 104.0/16.1 -> 108.0/16.9 µs. compute.heavy alu d1/d4: 1382.5/1181.1 -> 1351.4/1181.1 µs.
    • compute.cull_mdi d1/d2/d4: CRC 57276de2 on all three; 5357.1/1973.7/1875.0 -> 9677.4/1973.7/1960.8 µs.
    • concurrent.cr (compute.heavy alu + render.heavy fill 1080p) overlap: 0.977 -> 0.963.
    • sync.signal (compute.light d1) latency p5/median/p95: 141.0/145.8/152.1 -> 133.1/150.0/163.6 µs.
    • These times come from a short correctness run, not a perf A/B. Stock 7.3.0-41 is older than the PR base, so the cull_mdi d1 difference should not be read as a regression from this change. The linux#3328 row on this Mac showed the same cull_mdi d1 number (9677.4 µs).
  • Kernel health and restore:
    • 0 GPU faults or recoveries and 0 MMU faults. 0 WARN/BUG/Oops/stack-overflow/KASAN/lockup/RCU-stall/timeout lines and 0 new kernel error lines. 0 AVC denials, 0 failed units, 0 core dumps.
    • Restored cleanly to stock 7.3.0-41.fc44.aurora.aarch64 (boot 227cff1d, PMU f701/f702 = 30 00). The trial files in /boot and /lib/modules, the BLS entry and the fallback timer were removed, and stock.sh before vs after differs by 0 bytes.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE-CLEAR at 1213e012b40c0d12b5662ebd6cd724a05fa55ef2. Writer completion now signals waiters across deep timestamp-free chains. I checked concurrent subscriptions, error propagation and teardown. No blocking findings.

Both exact-head runs passed with SLC enabled and reported zero CTS failures, GPU faults or recoveries. J714s passed the timestamp and synchronization cases. J700 passed 254/254 G17 host checks and 31,611 CTS cases, with all 22 benchmark rows passing and every CRC matching stock. J714s results · J700 results

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 1213e012b40c: the follow-up commit is a clean 3-line explicit Iterator::chain disambiguation in drivers/gpu/drm/asahi/g17/queue/mod.rs, preserving the verified deferred-subscription fixes, CODE-CLEAR review, and exact-head J714s + J700 hardware rows.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) merge-conflict Conflicts with the base branch (bot) labels Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@DjDeveloperr this one doesn't merge mechanically any more. #3319 (merged 11-26) replaced the same timestamp-free chaining on main with a fence model: Fences::timestamp_waits, collect_timestamp_waits() and push_unique_fence(). This branch links Publications instead (timestamp_publications, covers). The two touch the same fields in job.rs and queue/mod.rs. Can you either port the direct-link change onto #3319's fences, or close this one if #3319 already covers the O(N^2) case? @AxxzyWasTaken's fences.covers note (stored even when same_chain == false) still needs an answer on the ported version. Once it's ported, the J714s and J700 rows can be redone on one combined build.

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:m5 Macs affected, from Merge risk (bot) blast:neo 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) merge-conflict Conflicts with the base branch (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants