Skip to content

drm/asahi: g17: cheaper submits and a deeper compute queue - #1076

Merged
RyanTheTide merged 5 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:pr/g17-compute-queue-depth
Nov 7, 2026
Merged

RyanTheTide merged 5 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:pr/g17-compute-queue-depth

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

These five commits cut the CPU and GPU idle time of compute-heavy workloads on the G17 runtime. They were found with Astro Bot under KytyPS5 on the M4 Pro, which keeps about 200 compute commands queued:

  • rust: dma_fence: let drivers adopt a fence reference from C makes Fence::from_raw() public (it stays unsafe), so a driver can take ownership of a reference that a C helper returns.
  • merge long dependency lists into one scheduler fence: drm_sched_job_add_dependency() deduplicates by fence context, scanning every dependency added before. Each g17 completion fence has its own context, so a command behind ~120 pending producers made the submit ioctl quadratic, at about 1 ms of CPU per vkQueueSubmit. That scan was 85% of the submit ioctl's kernel time. Past eight dependencies, the scheduler now gets one __dma_fence_unwrap_merge() fence. The wait doesn't change, and the packet keeps each fence for its own status checks.
  • keep a compute queue's in-flight FIFOs on the heap: with 16 entries, Backend::ensure_compute already had a 10,128-byte stack frame and Queue::new a 5,856-byte one. With this commit they are 5,120 and 3,408 bytes. A deeper window would otherwise have grown both.
  • keep up to 32 compute commands in flight per queue: the firmware stores an ioctl's completion stamps only once all of its kicks have finished. Short commands in an ioctl with a long one therefore hold their in-flight place until the long one ends. The window moves from 16 to 32, the number of descriptor and record slots a queue already has, and a compile-time assert ties the slot rings to the window.
  • retain compute timestamp pages for a deep queue: the per-context page cache held 8 pages, so nearly every submit created a shmem GEM object, a write-combined vmap and a GPU mapping. Nearly every retirement tore them down again with a TLB invalidation. The cache now grows to 256 pages, but only in contexts that queue that deep: at most 4 MiB per context.

No uAPI change.

Testing (J616s, M4 Pro, 25G83)

  • Astro Bot (KytyPS5):
    • with the same userspace, 31.1–31.5 fps before and 33.0 fps after;
    • GPU idle went from 9.9% to 4.7%;
    • the submit ioctl went from 7.6% to 4.4% of samples, and Completion::new from 2.03% to 0.40%;
    • the merged fence cut submit kernel CPU about 5x, per a trace on our test kernel.
  • Daily use: these have been on our daily kernel since 2026-11-04 09:53, under the desktop, games and dEQP-VK runs, with no new GPU faults or recoveries attributable to them.
  • This branch: clean cherry-picks onto integration/aurora 068dfce19780. It builds with no new warnings in our tree on aurora-wip 57222e0ee261, which contains integration/aurora.

🤖 Generated with Claude Code

A driver's C helper can return a struct dma_fence with a reference the
caller owns, for example from __dma_fence_unwrap_merge(). Fence::from_raw()
was crate-private, so a driver had no way to adopt that reference without
taking a second one. Make it public; it stays unsafe.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
drm_sched_job_add_dependency() deduplicates by fence context with a scan
of every dependency added before. Each g17 completion fence owns its own
context, so nothing deduplicates: a compute command behind a frontier of
about 120 pending producers made the submit ioctl quadratic. Under Astro
Bot (Kyty, M4 Pro) 85% of the submit ioctl's kernel time was that scan,
about 1 ms of CPU per vkQueueSubmit.

Past eight dependencies, hand the scheduler one fence from
__dma_fence_unwrap_merge() instead. It signals once every member has, so
the wait is unchanged; already signalled members are dropped and
same-context ones deduplicated. The packet keeps each fence for its own
status checks.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
A compute Queue carries the FIFOs of its active and replayed commands,
each IN_FLIGHT entries, inline, and Queue::new builds it on the stack
before the caller boxes it. With 16 entries that already gives
Backend::ensure_compute a 10,128-byte frame and Queue::new a 5,856-byte
one on a 16 KiB kernel stack, and a deeper window would grow both by
the size of the entries.

Allocate the entries instead, before Queue::new does anything else, so
an allocation failure leaves nothing to undo.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
The firmware stores the completion stamps of one submit ioctl's commands
only once every kick counted on the ioctl's work-state node has finished,
and a compute command retires on its stamp. Short commands of an ioctl
that also carries a long one therefore keep their in-flight place until
the long one ends.

With 16 places, Astro Bot under KytyPS5 keeps about 200 compute jobs
queued behind a full window: commands that finished 1.6 ms earlier still
hold their credits, the next commands are published only after the long
command retires, and the GPU idles for the completion, publication and
start hop. A trace of 8 s puts a quarter of the remaining GPU idle there.

Allow 32 compute commands in flight, the number of descriptor and cached
record slots a queue already has, and derive the scheduler credits and
the retirement window from the one depth. Both slot rings are reused by
slot, so assert that they outlast the window.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
Every compute command takes its context's timestamp page when it is
submitted and returns it when its completion drops. The cache kept 8
pages, while Astro Bot under KytyPS5 keeps about 200 compute commands
queued. Nearly every submit therefore created a shmem GEM object, its
write-combined vmap and its GPU mapping, and nearly every retirement
tore them down again with a TLB invalidation: about a third of the
submit thread's kernel time in a 6 s perf sample (6,700 compute
commands per second).

Let the cache grow to 256 pages, only in contexts that queue that deep.
A context keeps at most 4 MiB of these pages until it is destroyed.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Merge-train review (MTR-J, 11-07): approved, merging.

Review:

  • Merged dependency fence: __dma_fence_unwrap_merge() returns a new reference (or NULL on ENOMEM), and Fence::from_raw() adopts it.
    • The packet still holds every input fence for its status checks.
    • Dependencies here are g17 completion fences, not same-scheduler drm_sched fences, so merging doesn't lose the scheduler's pipelining shortcut.
  • Window 16 -> 32:
    • DeferredBatch::DEPTH already used max(RENDER_DEPTH 32, COMPUTE_DEPTH), so it is unchanged.
    • QIDS * IN_FLIGHT = 4096 stays below NO_REQUEST.
    • The new static assert ties IN_FLIGHT to DESCRIPTORS/RECORD_SLOTS. Active and replay FIFOs together never exceed the window, because replays come from active.
  • Heap FIFOs: they are allocated before anything else in Queue::new, so there is nothing to unwind.
  • Timestamp cache: put() already ran under a sleeping mutex, so the GFP_KERNEL reserve there is fine. The bound is 256 pages per context.

Gates (integration b8ae494f + linux PRs 1073-1076 merged locally, tree cc6fe2d0):

  • Buildbox: fleet-recipe build with 0 new warnings. W=1 g17/sync_input.o has 0 warnings. run-host-tests 193/193 and apple-dcp 86/86, both equal to fleet19.
  • J616s one-shot, against fleet19 boots of the same evening, system Mesa:
    • The boot is clean: err 0, 0 AVC, 0 failed units.
    • dEQP-VK L1 stride slice (33,463 cases): identical to fleet19.
    • A synchronization/compute slice (1,350 cases, timeline_semaphore one_to_n / wait_before_signal / wait, compute.pipeline): 1316 Pass in 2 of 2 runs with 0 GPU errors. On fleet19 the same slice failed in 2 of 3 runs: once a GPU firmware crash, once two ETIMEDOUT lost-device cases. That instability is fleet19's own and was reported to the fleet lane.
    • gpubench (us/submit): compute.light at depth 1/16/64 is 3.8/5.3/5.1% lower than fleet19. fleet19's own boot-to-boot spread there is 1-4%. The heavy rows are within 0.1%. No regression.
  • Neo (G17P): one-shot of the same kernel vs the fleet20 default; the GPU code is the same as fleet19. Both boots: CTXR window enforcing, execmem-confine 1696/0, os_uuid pin, err 0, 0 AVC, 0 failed units, vkcube/glmark equal. dEQP-VK L1 stride slice (33,463 cases) and the sync/compute slice (1,350 cases) gave identical results, 0 GPU errors. gpubench, thermally paired (3 runs each from <=66 C): compute.heavy and render.heavy within 0.2%, compute.light 3% faster at depth 16/64.

@RyanTheTide
RyanTheTide merged commit 3204eed into aurora-silicon:integration/aurora Nov 7, 2026
3 checks passed
RyanTheTide added a commit that referenced this pull request Nov 7, 2026
Brings aurora-wip up to the tested release branch: CTXR execmem
(#985, #1079), KFIX speaker sleep and resume fixes (#1077, #1080),
JPEG v2 (#1072), Jonathan's G17 and USB work (#1073-#1076), brcmfmac
flowring count (#1081), ANE H16 startup restart (#1066) and the
Touch ID per-prompt match (#904).

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants