Repository navigation
drm/asahi: g17: single-lock render completion fast path and doorbell lock release - #3024
Conversation
On M5 (G17S/G17C/G17D), compute_direct() returned None unconditionally because M5 compute shares the per-priority outer work ring with render and issues host-port gating and submission-history updates. As a result, every steady-state M5 compute submission fell back to the global device mutex (shared.state), serializing concurrent compute queues against each other and against the event worker. Add a dedicated port-level M5 outer-ring mutex (Port::m5_outer) ordered after the compute queue cell and render publication lock (device mutex -> compute cell -> port.render -> port.m5_outer -> port.qos/mailbox), and expose non-interfering direct credit consumption on OuterCredits (is_scoped() / consume_direct()) plus direct port views for M5's shared outer ring and submission-history table. Guard device-mutex M5 compute and render outer-ring publications with m5_outer_lock(), reset the cached history geometry on recovery restart, and allow steady-state M5 compute submissions to publish through compute_direct() without taking shared.state. Add a KUnit test covering direct credit consumption alongside OuterScope. Signed-off-by: Diljit Singh <[email protected]>
Each completion pass in run_runtime_events() / runtime_event_turn() previously took the global device mutex (shared.state) up to five times and ran M5 firmware.drain_reports() (trace/statistics rings plus GPU power register reads) on every completion interrupt, even during tight compute loops where no render mask was pending. Coalesce the worker_deferred take and empty-batch restore into the existing device-mutex holds, avoid dropping and immediately re-acquiring shared.state around a no-op observe_renders() when render masks are zero, and throttle M5 post-signal report draining (drain_post_signal_reports()) to the HOUSEKEEPING_NS (1 ms) cadence while work remains in flight. On recovery passes, drain post-signal reports before service_runtime_recovery() resets firmware rings (matching the unthrottled post-signal ordering and #2909) without double-draining in housekeeping. Add host tests (g17-m5-direct-compute-tests.py) covering mixed render/compute ring wrap, generation-change queued-claim handling, concurrent direct/scoped credit safety, and post-signal/pre-recovery report ordering. Signed-off-by: Diljit Singh <[email protected]>
On M5 (G17S/G17C/G17D), render_direct() returned None unconditionally, forcing every steady-state TA/3D render pass through the global device mutex (shared.state) across prepare_render() and publish_render(), serializing multi-pass graphics and multi-queue render submissions against each other and the event worker. Extend Port and OuterCredits so steady-state M5 render pairs can reserve two slots on M5's shared outer ring under the existing lock order (render publication lock -> m5_outer -> admission, QoS, mailbox), write both Compute-master WorkSlots, issue the HardwareSubmission::advance_pair host-port write, expose the retained pair while consuming two direct credits, and record submission history and the pipe-2 doorbell (pipe 0 on J813) without holding shared.state across preparation or publication. Bind M5 PB tokens via acquire_owner_bound() in lend_render(), track the submitting CPU in render_direct(), and extend the asahi_g17_outer_credit KUnit test to cover two-slot direct render credit consumption. Signed-off-by: Diljit Singh <[email protected]>
Eliminate remaining mutex and MMIO overhead on the M5 direct submission and completion paths: - Coalesce M5 compute_direct() outer-ring publication, host-port submission, and submission-history update under one held Port::m5_outer guard (released before ringing the mailbox doorbell), avoiding repeated mutex round-trips and keeping m5_outer free during descriptor writes. - Skip the uncached G17_CORE_POWER MMIO read in Port::note_gpu_activity() when back-to-back work falls within FIRMWARE_IDLE_OFF_MS. - Expose Port::outer_domain() and Port::reserve_m5_outer() so steady-state prepare_compute() acquires M5 outer-ring availability and credits without locking shared.state. - Track active, retiring, terminal, witness, replay and polling slots with bitmasks in scan_compute_summary() so steady-state completions avoid redundant full-registry ComputeCell locks, filter retain_render_completions() to matched render QIDs, move worker_deferred onto Shared, and complete steady-state pure-compute event passes in a single shared.state lock hold while preserving idle_check() timer scheduling. - Use a per-CPU high-priority reclaim-safe workqueue for aurora_g17_events on M5 as on other G17 parts so enqueue_on(submitter) dispatches directly to the submitting CPU. Signed-off-by: Diljit Singh <[email protected]>
…trips Two sources of unnecessary host contention on single-die M5 multi-queue workloads, plus M5 outer-credit locking fixes exposed by concurrent direct compute and device-mutex publishers: 1. creator_cluster_scheduling() restricted every drm_sched ordered submit workqueue on M5 to Cpumask::cluster_of(CpuId::current()) at queue creation time. That pinning prevents cross-die migration on multi-die M5 Ultra (num_dies > 1), but on single-die M5 parts (num_dies == 1) queues created on one main thread all get pinned to a single CPU cluster and contend when submitted from worker threads across clusters. Keep event-work submitter tracking on all M5 parts and restrict scheduler clusters only when num_dies > 1. 2. compute_direct() previously ignored the M5 OuterClaim already reserved in self.outer_compute during prepare_compute() and called port.reserve_m5_compute(), causing a redundant Port::m5_outer lock round-trip, double-booked outer-ring slots, and an unused-claim availability wakeup on every direct compute submission. Reuse the held self.outer_compute claim when its remaining count and priority match before falling back to port.reserve_m5_compute(), and restore any unspent held claim back into self.outer_compute outside cell.lock() when compute_direct() falls back to the device-mutex path so pre-reserved credits are preserved without spurious wakeups. 3. Serialize device-mutex OuterClaim reservations (Backend::claim_outer) and OuterScope entry/Drop transitions (Port::outer_scope / PortOuterScope) under Port::m5_outer so Credits::reserved[] and Credits::scoped never race against concurrent direct M5 reservations (Port::reserve_m5_outer / Port::reserve_m5_render_locked). Signed-off-by: Diljit Singh <[email protected]>
…lock release Steady-state render submissions and completions previously incurred three avoidable lock holds and wakeups on the hot path: 1. runtime_event_turn() always exited its fast path whenever any render completion mask arrived, forcing four separate Shared::state mutex acquisitions per render retirement (drain events, drain deferred errors, observe_renders(), and final idle/housekeeping pass). 2. DirectHost::notify_render() held both Port::m5_outer and Port::render across mailbox doorbell I/O even after outer ring producers, credits, and hazard ordering were already committed. 3. Availability::advance() unconditionally acquired the waiter mutex even with zero waiters, and Shared::note_changed() unconditionally called changed.notify_all() even when no thread waited on the condvar. Add Firmware::try_fast_observe_render() to retire healthy coalesced ready render completions (bounded by RENDER_SLOTS and preallocated DeferredBatch room) directly inside runtime_event_turn()'s single device-mutex hold under a pre-acquired preparation epoch, falling back to observe_renders() on any pending error, timeout, close, growth, replay, terminal fault, deferred-room shortage, or remaining backlog. Fold slow-path deferred error draining and rescan checks into runtime_event_turn()'s existing mutex holds so observe_renders() takes only one state lock per turn. Release m5_outer (after submission history) and render in reverse order before port.notify() in DirectHost::notify_render(). Keep Availability's generation bump lock-free when has_waiters is false (preserving Dekker ordering against wait()), and wrap Shared::changed in TrackedCondVar so zero-waiter notify_all() skips the condvar waitqueue lock. Add host unit tests and mutation controls in g17-m5-render-fast-done-tests. Signed-off-by: Diljit Singh <[email protected]>
a2f75bc to
173110e
Compare
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Rebased onto Conflicts were all in
The stack is unchanged: on #2969 ( Host tests: |
Bring in main up to 6ec49ac (the T6050 GPU, fan and display work and the later G17 effort, command-port and lock changes). Conflicts: - drivers/gpu/drm/asahi/g17/initdata/m5.rs: main added set_m5_policy_layouts() where this branch adds m5_history_view(); both are kept. main also reads the M5 submission-history fields through the loaded firmware build's status-config relocation instead of fixed 26A428 offsets, so m5_history_view() now takes its generation, geometry and slot addresses from the same relocation as note_m5_submission_history(). - tools/asahi/run-host-tests.py: both sides register a new g17 test; both are kept. Signed-off-by: Diljit Singh <[email protected]>
…5-direct-render-and-locks Bring in the base PR's merge of main up to 6ec49ac, including its m5_history_view() update for the relocated M5 submission-history fields. Conflict in drivers/gpu/drm/asahi/g17/runtime.rs outer_domain(): main added the same off-M5 early return this branch has, and kept reading the domain under the device mutex; this branch's lock-free read through Port is kept. Signed-off-by: Diljit Singh <[email protected]>
…ahi-g17-m5-multiqueue-contention Bring in the base PR's merge of main up to 6ec49ac, including its m5_history_view() update for the relocated M5 submission-history fields. Conflict in tools/asahi/run-host-tests.py: both sides register a new g17 test; both are kept. Signed-off-by: Diljit Singh <[email protected]>
…i-g17-m5-render-fast-done Bring in the base PR's merge of main up to 6ec49ac, including its m5_history_view() update for the relocated M5 submission-history fields. Conflict in tools/asahi/run-host-tests.py: both sides register a new g17 test; both are kept. Signed-off-by: Diljit Singh <[email protected]>
Bring in main up to a73023b (among others the G17 submit-latency, compute completion fast path, completion cluster and page-fault blame work). Conflict: - drivers/gpu/drm/asahi/g17/runtime/events.rs: main now drains the trace and statistics reports after the pass's completions are signalled on every G17 (c56132f, from #2909), where it was M5 only. This branch throttles that post-signal drain to the housekeeping cadence while work is in flight and drains first on a recovery pass, through drain_post_signal_reports(), which drained on M5 only because only M5 deferred the reports. As every G17 defers them now, the helper and its is_m5() check go away and the throttled sites call drain_reports() directly, as planned when this branch was reconciled with #2909. g17-m5-direct-compute-tests.py checks the same order under the new name. Signed-off-by: Diljit Singh <[email protected]>
…5-direct-render-and-locks Bring in the base branch, which now carries main up to a73023b. Conflicts: - drivers/gpu/drm/asahi/g17/runtime/events.rs: as on the base branch, every G17 now drains its reports after signalling, so the M5-only drain_post_signal_reports() goes away and the recovery and housekeeping sites call drain_reports(). This branch's single-lock fast path for pure-compute passes is kept as it was; it skips the drain only while housekeeping is not yet due, as the slow path does. g17-m5-direct-compute-tests.py follows the new name. - drivers/gpu/drm/asahi/g17/port.rs: main skips the core power register read in note_gpu_activity() within the firmware's idle-off delay (99b0b4c), as this branch did; main's version is kept. - drivers/gpu/drm/asahi/g17/mod.rs: main places the event work in the last submitter's cluster on every G17 and drops follows_submitter (6ff7967), keeping M5's event queue unbound so the worker runs in the submitter's affinity pod. That replaces this branch's switch of M5 to the per-CPU queue, so main's queue choice is kept, without follows_submitter. The worker's preallocated deferred batch stays on Shared, as this branch moved it. Signed-off-by: Diljit Singh <[email protected]>
…ahi-g17-m5-multiqueue-contention Bring in the base branch, which now carries main up to a73023b. Conflicts: - drivers/gpu/drm/asahi/g17/mod.rs, runtime/backend.rs: main restricts every G17's scheduler queues to their creator's cluster and drops follows_submitter (6ff7967). This branch restricts them on M5 only where it has more than one die, so the queues of a single-die M5 are not all tied to the cluster of the thread that created them. Both are kept: pin_scheduler_cluster is now !m5 || id.num_dies > 1, so every other G17 keeps main's restriction and a single-die M5 keeps this branch's unrestricted queues. Without a cpu-map a queue stays unrestricted anyway, as on main. g17-m5-multiqueue-contention-tests.py checks the new expression, and its pin-single-die mutation now pins every queue. Signed-off-by: Diljit Singh <[email protected]>
…i-g17-m5-render-fast-done Bring in the base branch, which now carries main up to a73023b. No conflicts. Signed-off-by: Diljit Singh <[email protected]>
"drm/asahi: g17: reduce M5 direct submit and event lock overhead" moved every caller of Port::note_m5_submission_history() to the variant that runs under a held m5_outer, which left the unlocked wrapper unused and the build warning that it is never used. Remove it and describe the locked variant on its own. No functional change. Signed-off-by: Diljit Singh <[email protected]>
…ahi-g17-m5-multiqueue-contention Bring in the removal of the unused unlocked M5 history update from the base branch. No conflicts. Signed-off-by: Diljit Singh <[email protected]>
…i-g17-m5-render-fast-done Bring in the removal of the unused unlocked M5 history update from the base branch. No conflicts. Signed-off-by: Diljit Singh <[email protected]>
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at beb965667673
Blockers: none
Checked: Full diff audit of drivers/gpu/drm/asahi/g17/ (base M5 direct stack plus #3024 changes in availability.rs, mod.rs, runtime.rs, runtime/events.rs, runtime/render/direct.rs, and runtime/render/observe.rs) plus paginated CI and J714s hardware row verification.
Evidence
- Lock-free wakeup ordering:
Availability::wait()publisheshas_waiters.store(true, SeqCst)before re-checkinggeneration.load(SeqCst), pairing withadvance()'sgeneration.fetch_add(1, SeqCst)beforehas_waiters.load(SeqCst)so no waiter can be lost on the zero-waiter fast path.TrackedCondVar::wait_timeout()incrementswaiters(SeqCst) under the guarded mutex with an RAII decrement guard, matchingnotify_all()'sSeqCstcheck. - Doorbell release & single-lock render fast path:
DirectHost::notify_render()drops bothm5_outerandrenderguards beforeport.notify()mailbox I/O.Shared::runtime_event_turn()takesfast_epochbeforeself.state.lock(), boundsFirmware::try_fast_observe_render()byRENDER_SLOTSanddeferred.has_room(2), falls back cleanly on recovery/replay/grow/error/timeout/closed/missed states, and runsnote_changed()+deferred.finish()after releasing the device mutex. - CI & hardware evidence: Paginated numeric-ID check-runs 19/19 passed (
0 active / 0 bad), commit statuses clean, exact-head J714s Apple M5 Pro pass row posted (wip/m5-wavec-fleet-candidate-20261125atb7b130a75bab); unrun boards are explicitly noted inNot yet:.
|
Tested (
|
The merge-base changed after approval.
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at beb965667673
Blockers: none
Checked:
- Clean-room diff with no Apple copyrighted material, decompiled listings, or copied firmware/tuning data.
- No hardcoded model, board, or firmware gates and no new module or command-line parameters.
- No hardcoded hardware safety limits; safety and hardware values come from machine descriptors and runtime state.
- Clean human
Signed-off-by:DCO on every commit and zero AI attribution across commits and PR text. - Exact-head hardware rows pass on both J714s (M5 Pro) and J700 (Neo) with clean merge preview on
main, and all paginated CI checks are green.
Evidence
- Incremental diff audit above
#2969(9 files):drivers/gpu/drm/asahi/g17/availability.rs:Availability::wait()storeshas_waiters = true(SeqCst) before re-checkinggeneration(SeqCst), pairing withadvance()'sSeqCstfetch_addongenerationandSeqCstload ofhas_waitersso no waiter can be lost on the lock-free fast path.drivers/gpu/drm/asahi/g17/mod.rs:TrackedCondVarincrementswaiters(SeqCst) with an RAII decrement guard, matchingnotify_all()'sSeqCstcheck.drivers/gpu/drm/asahi/g17/runtime/render/direct.rs:DirectHost::notify_render()releases bothm5_outerandrenderlocks before mailbox doorbell I/O (port.notify()).drivers/gpu/drm/asahi/g17/runtime/events.rsandruntime/render/observe.rs:runtime_event_turn()takesfast_epochbeforeself.state.lock(), boundstry_fast_observe_render()byRENDER_SLOTSanddeferred.has_room(2), falls back on recovery, replay, growth, error, timeout, close, missed event, or terminal fault, and runsnote_changed()anddeferred.finish()off-lock.
- Hardware rows & CI:
- Exact-head Apple M5 Pro (
T6050 / J714s / G17S B1) pass row in fleet candidateb7b130a75bab(gpubench-vkok, Vulkan CTS 0 fail, 0 GPU/DART faults). - Exact-head MacBook Neo (
J700 / G17P B1) combined Wave C pass row (7bb607c48427):215/215g17host tests,2,880/2,880timeline semaphore CTS pass,373focused compute/sync CTS pass / 0 fail,5/5compute CRCs, 0 GPU faults / 0 AVCs. - Paginated CI check-runs at
beb965667673: 19/19 green (0active,0failed), clean merge preview ontomain.
- Exact-head Apple M5 Pro (
The merge-base changed after approval.
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at beb965667673
Blockers: none.
Checked: With #2969 merged, reviewed the nine incremental paths, including the preparation epoch, the render completion fallback, and waiter notification. The current merge preview retains all seven disjoint path objects and both reconciled changes in the shared GPU module and host test registry. Hosted checks passed.
Evidence
The exact-head J714s target ran Vulkan CTS and retained working Vulkan after an RTC wake. The exact-head combined Neo regression ran 215 host tests, 2,880 timeline operations and five matching CRCs. Both rows reported zero GPU faults and a verified default restore. The later plain-main Neo control also showed the reduced two-deep overlap relative to the shipped build.
J714s hardware row · Neo hardware row · Neo plain-main control
The merge-base changed after approval.
|
GitHub dismissed the latest approval at Could you merge current |
Merge origin/main (f3bfe50) to keep the union of host test entries in tools/asahi/run-host-tests.py after aurora-silicon#3024, aurora-silicon#3036, and aurora-silicon#3023 landed. Signed-off-by: Diljit Singh <[email protected]>
What: Stacked on #2969. Each steady-state render retirement took four separate
Shared::stateacquisitions because any render completion mask maderuntime_event_turn()leave its single-lockfast_donepath;DirectHost::notify_render()also heldPort::m5_outerandPort::renderacross mailbox doorbell I/O, andAvailability::advance()/Shared::note_changed()took locks with no waiters. Healthy ready render completions now retire inside the single device-mutex hold (falling back toobserve_renders()on any non-steady state), both locks drop before the doorbell, and zero-waiter paths stay lock-free.Tested: J714s M5 Pro (G17S B1), Aurora 7.3.0 M5 integration test kernels (builds 7 and 8): 0 GPU faults, 0 kernel warnings, Vulkan CTS 2,984/2,985 pass, 0 fail; no regressions standalone, and with event-worker placement, multi-flight light render completion latency (d=8/16/32) +17 % to +30.7 % (25.86 → 19.79 us). Host tests
--only g17113/113 pass (7/7 mutations killed).Risk: two-way · M5 family;
runtime_event_turn(),AvailabilityandShared::changedare shared G17 code and also run on Neo (G17P). The doorbell lock release is M5-only.Not yet: Neo (G17P) at this head (its last row predates the
mainmerge), M5 Max (J716C), M5 Ultra (J775D) and M5 (J813) not run; failed systemd units not captured (SELinux is not enabled in the test kernel config).After the
mainmerge (11-25,maina73023bc5f1f): no conflicts.Details
Stacking: stacked cleanly on #2969 (
d13f2358d742, which builds on #2947 and #2955). The sole new commit on top of #2969 isdrm/asahi: g17: single-lock render completion fast path and doorbell lock release(173110e8e3c2). Independent of the idle-housekeeping and cross-QID follow-up PRs; targetsintegration/aurorasoHost testsCI runs on the full stack.Steady-state render submissions and completions previously incurred three avoidable lock holds and wakeups on the hot path:
runtime_event_turn()always exited its single-lockfast_donepath whenever any render completion mask arrived, forcing four separateShared::statemutex acquisitions per render retirement (drain events, drain deferred errors,observe_renders(), and final idle/housekeeping pass).DirectHost::notify_render()held bothPort::m5_outerandPort::renderacross mailbox doorbell I/O even after outer ring producers, credits, and hazard ordering were already committed.Availability::advance()unconditionally acquired the waiter mutex even with zero waiters, andShared::note_changed()unconditionally calledchanged.notify_all()even with no waiters on the condvar.This commit:
Firmware::try_fast_observe_render()to retire healthy coalesced ready render completions (bounded byRENDER_SLOTSand preallocatedDeferredBatchroom) directly insideruntime_event_turn()'s single device-mutex hold under a pre-acquired preparation epoch, falling back toobserve_renders()on any pending error, timeout, close, growth, replay, terminal fault, deferred-room shortage, or remaining backlog.drain_render_deferred()) and rescan checks intoruntime_event_turn()'s existing mutex holds soobserve_renders()takes only one state lock per turn.m5_outer(after submission history) andrenderin reverse lock order beforeport.notify()inDirectHost::notify_render().Availability::advance()lock-free whenhas_waitersis false (preserving DekkerSeqCstordering againstwait()), and wrapsShared::changedinTrackedCondVarso zero-waiternotify_all()skips the condvar waitqueue lock.tools/asahi/g17-m5-render-fast-done-tests.py.Evidence
python3 -I tools/asahi/run-host-tests.py --only g17):113/113passed (g17-m5-render-fast-done-tests: base pass +7/7mutations killed:hold-m5-outer-across-doorbell,hold-render-lock-across-doorbell,skip-pending-error-fallback,single-slot-bailout,skip-epoch-check,unconditional-changed-notify,skip-generation-bump).Apple M5 Pro / J714s / G17S B1): qualified in Aurora 7.3.0 M5 integration test kernel builds 7 and 8 (0GPU faults,0kernel warnings,2,984/2,985Vulkan CTS passed with0failures); zero regressions standalone, and combined with event-worker placement it improved multi-flight light render completion latency (d=8/16/32) by +17% to +30.7% (25.86 -> 19.79 us).Regression tuple (pre-PR checklist §5)
60a40c285fon builds 7/8; test buildgit-8956dffd84(with aurora-silicon/mesa#793) on build 90(microbenchmark health checkgpu_faults_delta=0, stress gate, CTS runs)0(as recorded in the run summaries; the raw dmesg of these runs was not kept)2,984/2,985passed,0failed; build 9:4,058/4,068multi-queue + timeline semaphore passed,0failedCONFIG_SECURITY_SELINUXunsetsystemctl --failedoutput was kept for these runs