Repository navigation
drm/asahi: g17: attach publication links lazily with a single atomic phase - #4020
Conversation
…ic phase Defer predecessor attachment in Publication so in-order command completions avoid locking predecessors during enqueue and avoid draining eager successor lists on the completion worker: - Keep pre-allocated predecessor links on the successor in State::deferred_links with Link::target = None so an unfinished drop never forms an Arc cycle. - Replace separate atomic pending/clean flags with a single AtomicU8 phase (PHASE_PENDING, PHASE_SETTLED_CLEAN, PHASE_FAILING_PENDING, PHASE_FAILED_PENDING, PHASE_FAILING_AFTER_SETTLE, PHASE_FAILED_AFTER_SETTLE) so lockless readers in is_pending(), link_deferred(), and failed_after_release() never see conflicting states. In-order successors skip locking cleanly settled predecessors via one Acquire load on PHASE_SETTLED_CLEAN. - Revoke upstream_released and transition to PHASE_FAILING_* inside claim_locked() before publish(Err) signals the error fence off-lock, so late attachments wait on state.successors until state.published is recorded, queries see is_pending() == true, and probes wait until publish(Err) transitions to PHASE_FAILED_*. - When an out-of-order waiter queues on a deferred timestamp-free publication, subscribe the deferred chain iteratively through State::subscribe_next (no recursion, no allocation, no depth bound), so writer completion alone releases the waiter. - Bound Publication::is_pending() probing (PENDING_PROBE_DEPTH), consume published failures without looping, and release any already-attached successors when a probe settles a clean chain. Based on the lazy publication attachment design from #3443 by DjDeveloperr, split out cleanly from the queue-side clique reduction handled independently in #3681. Add KUnit tests and the g17-publication-lazy-tests.py host test with contract mutations. Signed-off-by: Erik Bourget <erik@ebourget.net>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed 76b855c. Deferred links gain their target after being moved out of the successor. The sentinel covers immediate notifications while the links are attached, and late subscribers wait for publication of a claimed error. The same-engine queue path rechecks completion status before bypassing the host wait. The reported J716c CTS and arm64 KUnit results exercise this head. J700 coverage is pending.
|
Checked Merge. #3681 should land first. After it, this PR conflicts only in Correctness. I ran the real publication and ordering code of main, #3681, this PR and both together against each other on the host (20,000 random command sequences without failures, 60,000 with failures, 118,000 commands accepted while a failure was being published, plus a threaded run):
Cost (host model on x86, so compare the columns, not the numbers). With #3681 a command links only the newest earlier command, so
So on top of #3681 this mostly trades a 19 µs worst completion for a slower submit. Also, after a writer completes with N commands in flight, about N/4 later commands still chain (none on main), because the probe stops four deep and Settling oldest first before the newest-first walk, with a probe depth of 0, removes the extra chaining and cost 29 µs instead of 74 in the 600 case. That is a quick test, not a patch. The A/B on top of #3681 should include submit time ( A behaviour change, not blocking. A writer succeeds, then P fails, then C (waiting for P) succeeds, all accepted before the writer finished: on main C succeeds, here C is cancelled, because C's link to P is still deferred when P fails. It needs a real failure, but it's different from eager settlement unless something probed P in between. Rows. The J716c result ran without #3681, so it doesn't cover the merged head. Owed: J700, and the A/B. No J773g row: T8132 runs |
|
We carry this PR in our unified daily kernel across J716c (M5 Max, T6050), J713 (M4 Air, T8132), and J313 (M1 Air, T8103) alongside Deferring publication predecessor attachment and tracking publication state in a single atomic phase avoids locking settled predecessors on the in-order submit path and eliminates eager successor-list draining on completion, pairing cleanly with Booted and verified on J716c, J713, and J313 (5/5 Vulkan CTS smoke pass on all three Macs, zero GPU errors). |
|
Forward-merged |
Keep main's publication reach tracking alongside the single-atomic phase. Preserve both the reach initializer and the lazy links. Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Forward-merged main
The queued J700 P1/P2 run still measures lazy attachment on its original base. Current main adds #3429's render-prefix path, so the combination still needs a hardware check. Neo has the source comparison. Fresh approval is due at this head. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
I pushed the forward merge at c9ff3ad23af9. The conflict resolution keeps both test registrations. Lazy attachment and #3681's reach and failure counters are intact. The affected host tests passed 353/353, the warm arm64 link passed, and the required hosted checks passed. A maintainer who did not push this head still needs to approve.
Neo's sealed J700 P1/P2 pair runs the earlier GPU base. Keep that result and its scope. Coverage for #4020 together with #3429 still needs a J700 run. J714s can supply shared G17 regression coverage.
There was a problem hiding this comment.
Verdict: MERGE at c9ff3ad
Checked: Deferred links start without a reference to their own publication. Attachment reserves a completion sentinel before operating off-lock, and the iterative subscription walk drains each pending link once. Error publication revokes the clean fast path before the fence signals, and same-engine selection keeps a fence that fails during the pending-publication check. The bundled host harness passed and rejected all nine negative controls. I also checked the arm64 link and 353 host checks recorded for this revision.
Follow-ups: The publication-state rewrite and the queue error-fence check are independently reviewable. A future revision could carry them as separate changes.
|
J616s (16" MacBook Pro,
Correctness (same in A and B)
Timing (µs; per configuration,
How to read this:
Afterwards the Mac went back to its production default (fleet94, Enforcing, 0 failed units). |
|
Merged The exact-head J616s A/B uses the G17P firmware interface and includes both #3681 and #3429 in both arms. All 5,753 timeline CTS cases passed on each arm, along with the checked deep chains. That covers the shared publication path and the interaction the extra J700 row was meant to exercise. The earlier J716c result covers T6050 at Merge tree |
main's aurora-silicon#4020 rewrote the G17 publication links that this branch keeps in one charged block. Links now stay deferred on the successor until its finish(), a waiter that subscribes it, or a probe that finds every predecessor settled, and the phase is one atomic. That conflicts in g17/completion/publication.rs and g17/queue/mod.rs. - publication.rs: main's logic is kept as it is. Only the storage changes back to this branch's: all of a successor's links are one LinkBlock, a KVVec charged with GFP_KERNEL_ACCOUNT, instead of a KVec of (predecessor, KBox<Link>) pairs. A deferred link holds its predecessor, and the deferred links are listed through Link::next, so finish(), subscribe() and the probe take, consume and settle them as main does with its vector. An attached link holds its successor until release(), and State::drop releases the links of a predecessor that is dropped unpublished, as before. - queue/mod.rs: main's firmware_published, kept beside the firmware waits, is a charged KVVec like them. main's skip of producers that were already published inline stays. - The KUnit case that drops an unpublished predecessor now finishes the waiter first, since only then is its link installed in the predecessor. It also checks a successor dropped while its links are still deferred. - tools/asahi/g17-publication-lazy-tests.py and g17-inline-cross-engine-tests.py match source text that moved: add_successor() takes a NonNull<Link>, activate() defers the chained links, link_deferred() skips a settled predecessor in a match guard, the probe unlinks a failed predecessor's link, and the producer and firmware_published pushes use GFP_KERNEL_ACCOUNT. Their models and assertions are unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
What: Defer predecessor link attachment in G17
Publicationso in-order command completions skip predecessor mutex locks at enqueue and avoid draining eager successor lists on the completion worker. Split out from #3443 (based on @DjDeveloperr's lazy-attachment design) as a standalone change independent of #3681's queue-side link reduction and producer failure log.Tested: J716c (16" M5 Max, T6050 / G17C) at exact head
76b855c7237e, SLC enabled (32 planes), default command line, Borealis system Mesa: booted cleanly to desktop, Vulkan CTS 25,017 cases (24,985 Pass, 32 NotSupported, 0 Fail, 0 Crash, 0 DeviceLost), 0 GPU faults or recoveries, 0 new kernel errors. Arm64 Asahi KUnit 579 tests (574 passed, 5 skipped, 0 failed); G17 host suite 343/343 passed (g17-publication-lazy-tests: 10/10 including all 9 contract mutations).Risk: two-way door · G17 Macs (M4, M5, Neo)
Not yet: J700 / M4 hardware rows; combined performance A/B on top of #3681.
Details
drivers/gpu/drm/asahi/g17/completion/publication.rs):Prepared::activate()stores pre-allocated predecessor links on the successor (State::deferred_links,Link::target = Noneso unfinished teardown cannot form anArcself-cycle) instead of locking every predecessor during enqueue.Publication::phase: AtomicU8): Replaces separate atomic flags with a single 6-state phase (PHASE_PENDING,PHASE_SETTLED_CLEAN,PHASE_FAILING_PENDING,PHASE_FAILED_PENDING,PHASE_FAILING_AFTER_SETTLE,PHASE_FAILED_AFTER_SETTLE).Acquireload (PHASE_SETTLED_CLEAN) without taking the predecessor mutex.claim_locked()atomically clearsupstream_releasedand transitions toPHASE_FAILING_*understate.lock()beforepublish(Err)signals the error fence off-lock, so late attachments queue onstate.successorsuntilstate.publishedis recorded and probes wait untilpublish(Err)transitions toPHASE_FAILED_*.predecessor_error.is_none()) transitions toPHASE_FAILED_AFTER_SETTLEonce its error fence has signalled, matching eager settlement (is_pending() == false) even without an intervening probe.Publication::subscribe): When an out-of-order waiter queues on a deferred timestamp-free publication,subscribe()walks an intrusive stack throughState::subscribe_next(no recursion, no allocation, no depth bound) so writer completion alone releases the waiter.Publication::pending_within): Scansdeferred_linksin one pass, stopping at the first predecessor not inPHASE_SETTLED_CLEAN, consuming published failures viaswap_remove, probing timestamp-free predecessors up toPENDING_PROBE_DEPTH, and releasing already-attached successors on clean settlement.drivers/gpu/drm/asahi/g17/queue/mod.rs): Rechecksentry.status() < 0whenpending_publication()returnsNoneso an error signalling between those two reads still entershost_waits.asahi_g17_publication_orderandasahi_g17_cross_engine_timestamps, plus standalone host testtools/asahi/g17-publication-lazy-tests.py(9 behavioral scenarios + 9 contract mutations).Evidence
76b855c7237e7584da4619749f5528443c2efa68(based onmain37a630623169)python3 tools/asahi/run-host-tests.py --only g17):343/343 passedin 7 s (g17-publication-lazy-tests:10/10 passedin 0 s)../tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 --kunitconfig drivers/gpu/drm/asahi):Ran 579 tests: passed: 574, skipped: 5(0 failed).76b855c7237e, default command line,apple-mcc 2220000000.memory-controller: system level cache allocation enabled on 32 planes, Borealis system Mesa,deqp-vk 7ba03cdac7ae(6 workers, shader cache on):synchronization.smoke.*11/11,synchronization.basic.*29/29,synchronization2.op.single_queue.barrier.*_read_image_compute*412/412,query_pool.occlusion_query.copy_*159/159,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 Pass / 4 NotSupported).query_pool.*18,242 Pass / 28 NotSupported,synchronization.timeline_semaphore.*2,880/2,880,synchronization2.timeline_semaphore.*2,873/2,873,pipeline.monolithic.timestamp.*262/262).