Repository navigation
drm/asahi: g17: cut allocations and copies in the submit path - #2228
jgoyvaerts wants to merge 3 commits into
Conversation
Every publication allocated a DeferredBatch with room for two rings of completions (64 entries, about 3.5 KB through kvmalloc) and freed it when the publication ended: on the direct compute and render paths this was a kvmalloc and a kvfree in every submit ioctl. The backend now keeps the batch of its last publication once it is finished and lends it to the next one. A batch that still holds work is dropped as before, and concurrent publishers of one queue (the two engines' scheduler workers and the ioctl) each get their own: the first one back is kept. The batches are created and used exactly as before. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
prepare_submission collected the validated commands and their VM pins in two vectors allocated by every submit ioctl and freed at its end. The queue now keeps both, empty between ioctls, so their room is allocated once. Commands are drained from them in the same order, and whatever an error leaves unsubmitted is released at the same point as before. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Packet::new built the packet, with its 1.3 KB validated command, on the stack and moved it into the Arc. The compiler kept three stack copies of the command for that, so every submitted command was copied four times here. Allocate the packet first and initialise it in place: the command is copied once. A failed allocation still drops the command unpublished. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
954fc9b to
1c33065
Compare
|
Commit messages only, for the pre-PR checklist: the commits no longer carry Assisted-by: LLM (Claude:Opus 5.5) |
|
Looks good; approve once the HW row below is in. I checked the three changes. PublicationBatch (drivers/gpu/drm/asahi/g17/runtime.rs:917-925, 1586-1597) takes the spare before allocating, so nothing is allocated under the mutex. It returns a batch only when is_idle() holds, after finish() has drained every vector and cleared has_source_completions, and it is dropped at the end of each publisher with no other lock held. No path replaces a lent batch's vectors, so the room checks (render/tvb/vacated) behave as before. In queue/mod.rs the scratch vectors are taken out of the queue for the ioctl and cleared before
HW row: one more G17 Mac other than the J616s (M4 or M5) on a kernel with only these commits on top of integration/aurora: gpubench compute/render rows plus a deqp-vk subset with no new failures and 0 GPU recoveries, and a regression row on the J616s (0 SELinux denials, 0 failed units, 0 new kernel errors). Assisted-by: LLM (Claude:Opus 5.5) |
|
I tried the nit and left the code as it is; the head stays With the arm64 The J616s regression row will follow the next kernel build of our tree. We'd take your offer to run the other G17 Mac row (M4 or M5) in your lab. Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial review at 1c3306581218 against the pre-PR checklist.
No code, CI, attribution, or policy blockers found:
- CI & Attribution/Policy (§1–§4, §6):
host-testsis green on1c3306581218; all three commits carry human author/committer and humanSigned-off-by:only; PR body disclosure is clean; no model gating or naming issues. - PublicationBatch reuse (
drivers/gpu/drm/asahi/g17/runtime.rs:917-925, 1429-1436, 1571-1597):spare_batchis a leaf mutex never held across allocation (DeferredBatch::publication()?),kvfree(when a competing batch drops because*spareis already populated, the guard drops beforebatch), orshared.state.DeferredBatch::is_idle()checks every field (has_source_completions,values,bindings,vacated,render,tvb), andreserve_replaysis never called on a publication batch so lent capacities stay bounded. - Queue scratch vectors (
drivers/gpu/drm/asahi/g17/queue/mod.rs:108-115, 447-530, 587-645): Movingself.scratchout withcore::mem::takeand clearingpendingthenguardsbefore restoringself.scratchpreserves error-path cleanup semantics. (Ifoutputs.publish()fails afterguards.drain_all(),guardsdrains beforescratch.pending.clear(), which matches the pre-existingguards.into_iter()drop order.) - In-place
Packet::new(drivers/gpu/drm/asahi/g17/job.rs:152-169):UniqueArc::new_uninit+init_with(init!(...))is sound, avoids theArc::initclosure-move stack/memcpy regression you measured under LLVM=1, and preserves allocation-failure cleanup.
Remaining before approval (§5)
- Clean same-head HW & regression run on J616s (default command line, without the unrelated tiler-heap PRs / unincluded 4th patch noted in the PR body): 0 SELinux denials, 0 failed units, 0 new kernel errors, 0 GPU recoveries.
- One additional G17 Mac (M4 or M5) on top of
integration/aurorawithgpubench+ adeqp-vksubset showing no new failures and 0 GPU recoveries.
Assisted-by: LLM (Gemini 4 Neon)
Three changes that remove per-submit allocations and copies on the G17 submit path. They don't change what is submitted or where it runs.
DeferredBatchwith room for two rings of completions: 64 entries, about 3.5 KB through kvmalloc. It freed the batch when the publication ended, so the direct compute and render paths did a kvmalloc and a kvfree in every submit ioctl.prepare_submissioncollected the validated commands and their VM pins in two vectors allocated and freed by every ioctl. The queue now keeps both, empty between ioctls. Whatever an error leaves unsubmitted is released at the same point as before.Packet::newbuilt the packet, with its 1.3 KB validated command, on the stack and then moved it into theArc. The compiler kept three stack copies of the command for that. The packet is now allocated first and initialised in place, so the command is copied once.Tested on the J616s (M4 Pro, 48 GiB, 25G83)
These have been in our daily kernel since 11-18. Before and after are separate boots, compared with gpubench and kmem tracing, with 0 GPU recoveries. The one result that holds across boots is the allocation count.
Allocations (kmem trace,
compute.lightpinned at depth 1, 139 submits). Per submit, 12 before (11 kmalloc + 1 kmem_cache_alloc) and 9.3 after. The per-ioctl temporaries are gone: theDeferredBatchpublication (4096 B), andprepare_submission's pending vector (2048 B) plus its VM-guard vector (192 B). What is left is objects that outlive the ioctl, plus adrm_execin 2% of submits.Submit ioctl CPU time,
compute.light, in us at depth 1 / 8 / 64. Only rows with the same P-cluster frequency floor compare:So the change in submit CPU time is not measurable across boots: depth 64 is lower on cpu5, level on cpu11 and higher unpinned. The differences follow each boot's cluster load, not this code. The same floor gave 8.75 and 13.31 us at depth 1 on the two boots. Depth 1 is set by core type, cluster and frequency, which #2217 and #2222 address. What these commits measurably do is remove three per-submit allocations.
Not an A/B for these commits:
compute.heavyandcopy.bwsubmit CPU at depth >= 2 doubled. That is not this code. 99% of those submits ran on E-cores 1-2, because EAS parks the thread while the GPU works; pinned to a P core it is 19.3 us. Changing the cpufreq floor or the idle states made no difference.On this branch: KUnit 697 of 698 passed, one skipped (needs
CONFIG_UCLAMP_TASK). That includes the newa_publication_batch_comes_back_only_when_idle.tools/asahi/run-host-tests.py --only g17passed 90/90.Not done
Assisted-by: LLM (Claude:Opus 5.5)