Repository navigation
drm/asahi: g17: enable M5 direct render submission and reduce direct submit/event lock overhead - #2955
Conversation
|
A note on |
RyanTheTide
left a comment
There was a problem hiding this comment.
Changes Requested at d5ab57b48d8a.
The new M5 direct-render path inherits the post-publication recovery behavior raised above. It makes that path reachable on another firmware family. Please keep the generation check and settle a published render pair through the existing recovery path when recovery starts during publication. The two-slot credit test only checks accounting. Add a lifecycle case for recovery crossing publication and show that the pair settles once and an unrelated client keeps its VM. The new direct doorbell also consumes J813_FORMS. Please document the firmware queue contract behind the pipe choice and use that contract for both publishers.
Source review. I used the test evidence attached to this PR.
d5ab57b to
12fa477
Compare
|
R2 pushed at
Verification: |
|
Hardware qualification update on Apple M5 Pro (
|
Since the event queue became per-CPU on every G17 part, M5's queue_event_records() aims the event work at the CPU that last published work with queue_work_on() on a bound pool, so the worker runs on that very CPU. A thread that publishes directly from its submit ioctl is then preempted by every completion: the event worker has the higher priority, and the completion interrupt is either taken on the submitter's CPU (the AIC cannot be steered) or reaches it by an IPI. The preemption often lands in the middle of a direct compute publication, which holds the compute cell's mutex across Queue::publish(), and the event pass takes that cell next. Its owner is not running, so the worker cannot spin on it: it sleeps, the submitter resumes, and its mutex_unlock() wakes the worker, which preempts it again. Each completion costs the submitter two context switches. Profiled on M5 Pro, one thread keeping 16 light compute submissions in flight took 18.0 us per submission, 11.8 us of it in the submit ioctl, with 93,000 function-call IPIs per second (1.7 per submission), 0.82 context switches of the submitting thread per submission and an IPC of 1.12. __schedule took 8.9% of the cycles, preempt_schedule_irq 7.0% and mutex_unlock 4.4%, all in the submitter's ioctl after an interrupt. Two queues signalling each other showed the same profile. With 64 in flight the scheduler's worker publishes instead, so the event work lands on its CPU, beside the submitting thread rather than on it: 0.26 context switches per submission, an IPC of 2.39, 3.5 us in the submit ioctl and 11.4 us per submission. Make the queue unbound again where the event work follows the submitter, as it was on M5 before. Aimed at a CPU, an unbound queue takes only that CPU's affinity pod, the CPUs sharing its L2, and the scheduler wakes the worker on an idle CPU of the pod. Completion processing stays in the submitter's cluster and on its die, which is why it follows the submitter, and a running submitter is left alone: a worker that meets the cell lock spins on its running owner. Other G17 parts keep the per-CPU queue, where the event work runs on the CPU that queues it, as on system_highpri_wq. The queue stays reclaim-safe and high priority. Shared::new_events_queue() derives the queue's kind from the same follows_submitter value that Shared keeps, so the two cannot disagree. The per-CPU queue reached M5 with "drm/asahi: g17: reduce M5 direct submit and event lock overhead", which this series builds on and which is still under review (#2955). This change takes back that part of it on M5 only, and is not tagged as a fix since that commit is not in any merged tree yet. Add a host test that compiles the queue choice, the event work's queuing and the submitter tracking against a model of where the kernel runs the woken worker: on M5, a completion taken on the submitter's CPU, on another cluster or on the other die runs in the submitter's pod without preempting it, and elsewhere it runs on the queuing CPU. Its mutations include the previous per-CPU queue. Signed-off-by: Diljit Singh <[email protected]>
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]>
Since the event queue became per-CPU on every G17 part, M5's queue_event_records() aims the event work at the CPU that last published work with queue_work_on() on a bound pool, so the worker runs on that very CPU. A thread that publishes directly from its submit ioctl is then preempted by every completion: the event worker has the higher priority, and the completion interrupt is either taken on the submitter's CPU (the AIC cannot be steered) or reaches it by an IPI. The preemption often lands in the middle of a direct compute publication, which holds the compute cell's mutex across Queue::publish(), and the event pass takes that cell next. Its owner is not running, so the worker cannot spin on it: it sleeps, the submitter resumes, and its mutex_unlock() wakes the worker, which preempts it again. Each completion costs the submitter two context switches. Profiled on M5 Pro, one thread keeping 16 light compute submissions in flight took 18.0 us per submission, 11.8 us of it in the submit ioctl, with 93,000 function-call IPIs per second (1.7 per submission), 0.82 context switches of the submitting thread per submission and an IPC of 1.12. __schedule took 8.9% of the cycles, preempt_schedule_irq 7.0% and mutex_unlock 4.4%, all in the submitter's ioctl after an interrupt. Two queues signalling each other showed the same profile. With 64 in flight the scheduler's worker publishes instead, so the event work lands on its CPU, beside the submitting thread rather than on it: 0.26 context switches per submission, an IPC of 2.39, 3.5 us in the submit ioctl and 11.4 us per submission. Make the queue unbound again where the event work follows the submitter, as it was on M5 before. Aimed at a CPU, an unbound queue takes only that CPU's affinity pod, the CPUs sharing its L2, and the scheduler wakes the worker on an idle CPU of the pod. Completion processing stays in the submitter's cluster and on its die, which is why it follows the submitter, and a running submitter is left alone: a worker that meets the cell lock spins on its running owner. Other G17 parts keep the per-CPU queue, where the event work runs on the CPU that queues it, as on system_highpri_wq. The queue stays reclaim-safe and high priority. Shared::new_events_queue() derives the queue's kind from the same follows_submitter value that Shared keeps, so the two cannot disagree. The per-CPU queue reached M5 with "drm/asahi: g17: reduce M5 direct submit and event lock overhead", which this series builds on and which is still under review (#2955). This change takes back that part of it on M5 only, and is not tagged as a fix since that commit is not in any merged tree yet. Add a host test that compiles the queue choice, the event work's queuing and the submitter tracking against a model of where the kernel runs the woken worker: on M5, a completion taken on the submitter's CPU, on another cluster or on the other die runs in the submitter's pod without preempting it, and elsewhere it runs on the queuing CPU. Its mutations include the previous per-CPU queue. Signed-off-by: Diljit Singh <[email protected]>
12fa477 to
8a1ec93
Compare
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
…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]>
|
Merged the updated base (with |
DjDeveloperr
left a comment
There was a problem hiding this comment.
No code blockers.
This PR also carries the fix for the render-observation gap in #2947: render_observation_needed() in the observe_renders() gate. So merge #2947 through this PR rather than on its own (details on #2947).
What I checked
- The
outer_domain()merge resolution againstmain: it keepsmain's non-M5 early return and reads the sameCreditsavailability through the port instead of the device mutex. - The direct M5 render path:
m5_outeris held fromreserve_m5_render_lockedthroughexpose_m5_render_pair, the producer is re-checked before exposure, and the unspent claim drops after both locks.submit_m5_workcannot return EAGAIN after accounting (it fails only with ENODEV). - The
DirectHostguard handling: it re-takes the lock lazily, drops it before the doorbell, and never re-locks while held. scan_compute_summary(): the 128-bit masks fit the 128-entry registry, and the retire filter equalsretire()'s own early return.complete_compute()runs last inevent::service, so the fast-path summary is current.- The
worker_deferredmove toShared, and the per-CPU event queue on M5 (#3036 puts it back to unbound).
To merge:
- a T6050 / J714s (M5 Pro) row built from this head (a batched fleet candidate that contains this head unchanged counts).
- a T8140 / J700 (Neo, G17P) regression row at this head, because this PR changes shared G17 code that also runs on Neo.
- CI: the only red check is
host-tests, and its three failures (m3-recovery-tests,m3-recovery-tests --mutate,m3-runtime-tests) fail the same way onmainitself (0c4e19df, run 45466941208). They are not from this PR. Every G17 host test passes. - Base:
mainhas moved past6ec49ac7(now77561654). The new commits touch none of this PR's files and the head merges cleanly, so a branch update needs no new row.
|
Hardware row at Build: fleet candidate Since the 11-24 row (at Result:
Not run: GLES CTS (the surfaceless |
|
Neo (J700, T8140 / G17P B1) Wave C non-regression PASS at 9ab6f78 (REQ 46078bfa, covers #2947 d10e12a, #2955 2744163, #2969, #3024, #3036, #3023, #3025, #3035 unchanged; aurora.ko sha 004e299ee9668db4, default cmdline, Stage 2 b17): exercises shared G17 runtime/fence/port/sync_input paths (M5-only direct-submit paths gated off on T8140); gpubench-vk 8/8 OK (render.heavy 720p fill d1 407us/d4 260us, compute.heavy alu d1 1493us/d4 1282us, bw d1 3030us/d4 2804us), gl-smoke 32/32 + gpubench-gl 2/2 OK, dEQP-VK short CTS 30/30 PASS (api.smoke 8/8, sync.smoke 12/12, compute.pipeline.basic 10/10), s2idle 1/1 (10 s) + post-sleep GPU PASS, 0 GPU faults/timeouts/recoveries, 0 failed units, Enforcing + 0 AVC, 0 new GPU kernel errors; restored to saved fleet89. |
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]>
"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]>
…asahi-g17-m5-sibling-compute' into wip/m5-wavec-fleet-candidate-20261125 Bring in the removal of the unused unlocked M5 history update (#2955). No conflicts. Signed-off-by: Diljit Singh <[email protected]>
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 61af6c41476a
Blockers: none
Checked: Full diff audit of drivers/gpu/drm/asahi/g17/ (M5 direct compute & render submission, Port::m5_outer serialization, reserve_m5_render_locked/write_m5_render_pair/expose_m5_render_pair, DirectHost render & compute direct paths, render_observation_needed() single-lock fast path, and J813_FORMS gating) plus paginated CI and J714s hardware row verification.
Evidence
- Lock ordering & direct M5 render/compute: Verified
device mutex -> compute queue cell -> render -> m5_outer -> admission/QoS/mailboxacrossport.rs,runtime.rs,runtime/render/direct.rs, andruntime/render/submit.rs. UnspentOuterClaimdrops happen outsidem5_outer,render, and compute cell locks.render_direct()handles mid-publication recovery viarecovery_started+return_render()+queue_events()rather than spuriously failing an unrelated VM. - Event coalescing & J813 safety:
scan_compute_summary()computesin_flight/replay/pollingmasks in one pass so pure-compute passes can skip dropping/re-acquiring the device mutex whenrender_observation_needed()is false;regs.rsshort-circuitssubmit_m5_work/submit_m5_work_heldunderJ813_FORMSandrender_doorbell_message()keeps pipe 0 on J813. - 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 (
|
…is lent Two physical render pairs bound to one logical context share a single free-list Lease. With direct render submission enabled on M5 (PR aurora-silicon#2955) alongside two render pairs per owner, lend_render() prepares the shared pool lease and releases the device mutex while the lent pair builds and publishes off-lock. Previously Lease encoded preparation as a single scalar phase (LeasePhase::Preparing), so when the event worker retired a completed render on the sibling pair while the other pair was lent, Lease::complete_render() saw LeasePhase::Preparing, returned EINVAL, and stopped the GPU runtime (reproduced immediately by gpubench-vk render.light depth=8 on J716c). Track active preparations with a counter (preparing) and whether at least one render of the generation has published (published): - Lease::complete_render() admits completions while sibling preparations are lent, while still rejecting completions with EINVAL if no published render holds references above the reserved preparations. - Add Lease::cancel_prepare() and update Pools::rollback() to undo only the rolled-back preparation instead of restoring a pre-prepare snapshot, preserving any sibling completions or observed control-ring release witnesses that occurred while lent. - Add Firmware::rollback_render_pool() so a rollback that drops the last reference on an already-published generation immediately flushes its pending FreeListRelease (or queues events on EAGAIN). - Add KUnit coverage in freelist.rs and a host mutation test in tools/asahi/g17-freelist-lease-direct-tests.py. Signed-off-by: Erik Bourget <[email protected]>
What: Stacked on #2947. Enables steady-state direct TA/3D render submission on M5 (G17S/G17C/G17D): render pairs reserve two slots on M5's shared outer ring under the existing lock order and publish without holding
shared.state. It also removes remaining lock, MMIO and workqueue overhead from M5's direct submit and completion paths.Tested: J714s M5 Pro (G17S B1), Aurora 7.3.0 M5 integration test kernel (build 2) with the 16-plane SLC devicetree, Borealis test build:
direct_submissions5 → 1,014,639, 0 oops, 0 GPU faults, all CRC checks valid; light compute (d=4) 38.02 → 30.63 us (−19.4 % vs #2947), heavy ALU (d=1) 412.54 → 367.65 us (−10.9 %).asahi*KUnit 337/338 pass, 1 skipped, 0 failed.Risk: two-way · M5 family; the
scan_compute_summary()bitmasks,worker_deferredonSharedand the single-hold pure-compute event pass are in shared G17 code and also run on Neo (G17P).Not yet: Neo (G17P) at this head (its last row predates the
mainmerge), M5 (J813), M5 Max (J716C) and M5 Ultra (J775D) not run.After the
mainmerge (11-25,maina73023bc5f1f):main's cluster-aware event placement (#2217) keeps M5's event queue unbound, so this PR no longer switches M5 to the per-CPU queue;main's idle-off power-read skip (#2909) replaces this PR's identical one. The unused unlockedPort::note_m5_submission_history()is removed.Details
Two commits on top of #2947:
drm/asahi: g17: enable direct render submission on M5(867f16696ba6at the time of the measurements)PortandOuterCredits(consume_direct_count,reserve_m5_render_locked,write_m5_render_pair,expose_m5_render_pair) so steady-state M5 render pairs reserve two slots on M5's shared outer ring under the existing lock order (render -> m5_outer -> admission/QoS/mailbox), issueHardwareSubmission::advance_pair, expose both slots atomically, and record submission history and the pipe-2 doorbell (pipe 0 on J813) without holdingshared.stateacross preparation or publication.acquire_owner_bound()inlend_render(), records the submitting CPU inrender_direct(), and extends theasahi_g17_outer_creditKUnit test for two-slot direct render credit consumption.drm/asahi: g17: reduce M5 direct submit and event lock overhead(d5ab57b48d8aat the time of the measurements;8a1ec9312034now)compute_direct()outer-ring publication, host-port submission, and submission-history update under one heldPort::m5_outerguard (released before ringing the mailbox doorbell).G17_CORE_POWERMMIO read inPort::note_gpu_activity()when back-to-back work falls withinFIRMWARE_IDLE_OFF_MS(while preservingreport_busy()).Port::outer_domain()andPort::reserve_m5_outer()so steady-stateprepare_compute()acquires M5 outer-ring availability and credits without lockingshared.state.scan_compute_summary(), filtersretain_render_completions()to matched render QIDs, movesworker_deferredontoShared, and completes steady-state pure-compute event passes in a singleshared.statelock hold (preservingidle_check()timer scheduling).Uses a per-CPU high-priority reclaim-safe workqueue (Dropped in thenew_percpu_reclaim) foraurora_g17_eventson M5 soenqueue_on(submitter)dispatches directly to the submitting CPU.mainmerge (see below).Stacking: builds directly on #2947 (
002aeb472e66,e07a4facfb7aat the time). Targetsintegration/aurorasohost-testsCI runs on the full stack; once #2947 merges, only the two commits above remain in this PR with zero conflicts (git merge-tree origin/integration/aurora HEADverified clean).Evidence
d5ab57b48d8a06fae13cc23c13fbe8e7b9c84e60 OK(vmlinux,Image,aurora.ko, 1774 modules rebuilt, tree1592dfe9adb352c53a300310f48907f986fcfbf2).asahi*):337/338passed,1skipped (j713_accepts_all_loaded_images),0failed (including extendedasahi_g17_outer_credit).checkpatch.pl --strict:0errors,0warnings,0checks across both commits.Apple M5 Pro / J714s / G17S B1, Aurora 7.3.0 M5 integration test kernel build 2 + 16-plane SLCj714s-slc.dtb, Borealis test build,MESA_SHADER_CACHE_DISABLE=1):direct_submissions:5 -> 1,014,639(render_direct,compute_direct,scan_compute_summarylive in/proc/kallsyms)0kernel oops,0GPU faults (FAULTS DELTA=0), all CRC checksvalid: truecompute.light(queue d=4):38.02 us(drm/asahi: g17: enable direct compute submission on M5 and coalesce event locks #2947) ->30.63 us(timed24.76 us, -19.4%)compute.light(queues d=4):44.48 us(drm/asahi: g17: enable direct compute submission on M5 and coalesce event locks #2947) ->33.92 us(-23.7%)compute.heavy kind=alu(queue d=1 / d=4):367.65 us(-10.9% vs drm/asahi: g17: enable direct compute submission on M5 and coalesce event locks #2947412.54 us, -15.7% faster than macOS 27.0 Metal436.30 us) /263.16 uscompute.heavy kind=bw(queue d=1 / d=4):217.43 GB/s(617.28 us) /318.36 GB/s(421.59 us)render.light kind=clear(queue d=1 / d=4):106.47 us/33.49 us(submit_cpu_us:9.67 us)render.light kind=tri(queue d=1 / d=4):129.47 us/27.42 usrender.light(queues d=4 / d=8):34.06 us/33.32 usrender.postfx(queue d=1 / d=4):391.24 us/198.73 us(crc_valid=True)render.bindless_ubo(queue d=1 / d=4):781.25 us/554.32 us(crc_valid=True)transfer.ops kind=mipchain(queue d=1 / d=4):67.73 GB/s(362.84 us) /128.88 GB/s(190.69 us,crc_valid=True)query(occlusion d=16):27.27 us(overhead_us:0.05 us);timestamp d=1 / d=4:111.56 us/31.81 us