Repository navigation
drm/asahi: g16: Keep compute commands in flight; one 64 MiB PB heap per VM (J773g) - #2419
Open
DjDeveloperr wants to merge 7 commits into
Open
DjDeveloperr wants to merge 7 commits into
DjDeveloperr wants to merge 7 commits into
Conversation
Every G16 render gets a fresh parameter buffer epoch at SUBMIT and an InitBM ahead of its TA work, so the firmware rebuilds the allocator state for each render. Reusing the epoch instead cuts a small triangle render at queue depth 1 on a base M4 MacBook Pro (J604) from 1121 to 492 us. With this change, the next render of the same VM on a pass slot gets the slot's owner epoch, without a reseed or InitBM, if that epoch's render retired normally and was exposed. InitBM binds the device-wide slot to one epoch and VM, so this happens only while no other epoch was handed to the slot since; after another VM's render on the slot, after a failed or aborted render, or after any firmware recovery, the next render starts fresh. SUBMIT still allocates a fresh epoch for every render, so one is always at hand. Renders are bound, published and retired one at a time, so the slot's owner is the epoch it is bound to whenever reuse is allowed. The reused epoch is the slot's existing owner lease, so this holds no epoch, VM or admission permit beyond what the lease already holds: a slot binding is tracked by a counter, not by a reference. A host test covers when an epoch may be reused and that nothing else holds it. aurora.g16_pb_reuse=0 restores a fresh epoch and InitBM per render. The stats line counts reused and fresh bindings. Assisted-by: LLM Signed-off-by: Friedrich <261542475+aeries0x@users.noreply.github.com>
G16 published one command at a time and built the next only after the previous one fully retired on the host, so every compute command paid the whole firmware and host round trip: on the J773g Mac mini a 1.5 us dispatch cost ~270 us per submission at any queue depth, and dependent work (one command buffer per dispatch, as Geekbench records it) was bound by it. Queue compute commands behind in-flight compute commands on the one firmware compute queue: - A VM gets more retained compute units, each in its own hardware UMA slot (unit k in slot 1 + k). All units in slot 1, as before, is not safe once commands are queued: the firmware starts the next command while the previous one still runs, and with long commands two owners of one slot then corrupt each other (firmware recovery within seconds on queued ALU work). With one slot per unit, ~115k queued commands ran without a recovery. - The displacement ledger generalizes to N owners: owners retire in publication order, and an owner is reusable once any later publication retired (the firmware finished it before starting that one). Publication stays serialized for the render pass slots. - Every queued command posts its own submit record and doorbell (the firmware does not pick up a WRITE advance without one) behind unconsumed ones, with room checks before anything is visible. - A flight with later compute flights behind it retires on "passed" receipts: its stamp, queue READ cursor and the submit pipe's cursors have moved past it. The newest flight keeps the exact receipt. - A compute command may follow its queue's published (not yet retired) compute predecessors: the firmware compute queue runs commands in publication order, each to its Finalize. Renders and every cross-engine dependency still wait for completion, and nothing is published behind a render or a failed, doomed or recovering flight. - Only the same VM's commands queue behind each other: with six dEQP clients, compute queued behind another VM's lost writes (image and sampler cases failed) and stalled the firmware queue. Nothing queues behind a command with user timestamps either: the host writes them when the command retires, and a query copy queued behind it ran before they existed and never finished. - Recovery matches a snapshot entry against every flight and marks every unfinished one; a failed flight dooms the later flights of its queue (their commands would follow a hole). - Two units per VM as before; a VM that submits compute back to back (three submissions within 2 ms each, or three compute commands in one submission) gets four more, mapped at 0x7090000000, so ordinary clients keep the old memory cost. - Up to 16 jobs per logical queue reach the engine (was 2). - The engine statistics and the compute owner ledger move to the heap: `Firmware` is built on the probe's stack, and its larger frame overflowed the 32 KiB kernel stack. - `aurora-g16/tune` (debugfs, root) sets the depth (compute_flights; 1 = the serialized engine), the units of a growing VM and the completion repoll interval for measurements. J773g Mac mini (G16G B0, 25G83), gpubench, before -> after (macOS 27.2 on the same machine): compute.light d8 268 -> 136 us/submit, d64 269 -> 125 (gap between commands 266 -> 16.5 us; macOS 19.7), compute.heavy alu d4 874 -> 557, d64 871 -> 554 (GPU time 554; macOS 540), compute.heavy bw d16 1667 -> 1275 (macOS 1437). Signed-off-by: Diljit Singh <hey@djdev.me>
Every rendering VM pinned two 256 MiB parameter-buffer heaps, one per render allocator (pass slot), so each rendering process cost ~0.5 GiB of unevictable memory and a few dozen clients (a dEQP-EGL run at six jobs) exhausted a 24 GiB Mac mini. macOS 27.2 on the same machine adds ~24 MiB of wired memory per rendering process. A render is published only while nothing else is in flight and retires with its PB blocks returned to its manager, so the two pass slots' PB managers never hand out heap blocks at the same time. Back both with one heap at the first slot's address. Signed-off-by: Diljit Singh <hey@djdev.me>
A hardware slot's last owner stays bound until a later owner displaces it, because the firmware may still write that owner's descriptor then. The leases held the owner's whole VM state, and with it every arena of the VM: a closed client whose compute unit was the last in some UMA slot kept its 256 MiB PB heap and its compute pools pinned until another VM happened to use that slot. With more compute units, slots used only by clients that queue compute are displaced rarely, and closed clients stayed pinned. Each lease now holds exactly the arena of its unit (compute) or pass slot (render) beside the VM state, and the VM's cache lets go of its arenas when the client closes the VM. What jobs and leases still need, they hold themselves; the rest is freed at close. Signed-off-by: Diljit Singh <hey@djdev.me>
Each render submission allocated a fresh PB epoch: three firmware objects, their GPU and firmware mappings and a shared-L2 synchronisation. With PB epoch reuse most renders never expose that epoch, and its deferred teardown unmaps it again. Render submission cost ~390 us of CPU per vkQueueSubmit on the J773g Mac mini (compute ~25 us). Return a retired job's never-exposed epochs to its VM (up to four, under a spinlock: a job may drop in any context) and hand them to the next render submissions before allocating. A spare keeps the budget permit it was created with. A spare holds its VM, which holds the cache, so the cache drops its spares, and takes no more, when the client closes the VM. Signed-off-by: Diljit Singh <hey@djdev.me>
The parameter-buffer heap was the whole 256 MiB window, fully backed and pinned for every rendering VM. The 25G83 firmware copes with a PB that runs out without the host: with only 64 blocks (8 MiB) posted, heavy and tiler-overflow renders still complete, no growth event arrives, and counters in the PB manager move only for the scenes that overran it. Back 64 MiB of the window by default and name only the backed part in the page and block lists. `aurora-g16/tune` sets the heap of VMs created later (pb_heap_mb, 8..256) and caps the blocks a fresh epoch posts (pb_blocks), for measurements. Signed-off-by: Diljit Singh <hey@djdev.me>
Nothing is published behind a render, so a job submitted while one is in flight waits for the poll pass after its retirement anyway. With more jobs admitted per queue, each such submit still ran a full publication pass (ring drain, health and power checks) under the device lock and delayed the retire-to-publish path: gpubench render.light at depth 8 took 389-396 us per submission. Enqueue only; the next poll publishes it (344 us; stock 350, macOS 47). Signed-off-by: Diljit Singh <hey@djdev.me>
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the J773g Mac mini (M4, G16G B0, 25G83 firmware), G16 had two structural gaps against macOS 27.2 on the same machine. It published one GPU command at a time and built the next only after the previous one retired on the host, so a 1.5 µs dispatch cost ~270 µs per submission at any depth. And every rendering process pinned ~0.5 GiB: two 256 MiB parameter-buffer heaps plus its arenas.
Stacking: the first commit is #1543 (@aeries0x, PB epoch reuse), included because commits 2-6 build on its epoch handling. Merge #1543 first; the six commits after it are this PR. Hardware results are with #2239 (J773g S10) as well, as on the mini.
Commits
Firmwaremoved its new state to the heap: it is built on the probe's stack, and the larger frame overflowed the 32 KiB stack.aurora-g16/tuneexposes depth, units and the repoll interval.vkQueueSubmit(the epoch allocation, mappings and L2 sync were wasted with epoch reuse). The cache drops spares at close; a spare holds its VM.pb_heap_mb.Results (J773g Mac mini, kernel 7.3.0-ARCH-m4drv8; macOS 27.2 on the same machine)
gpubench, µs per submit; stock = the kernel's own
aurora.ko, run back to back with this PR's module.Memory (unevictable delta per process, settled): 8 × render.light 158 MB (stock 551, macOS 60); 4 × render.heavy 100 / 124 MB (stock 324 / 348, macOS 111 / 95). Idle desktop after boot: 0.47 GB unevictable (before 2.75 GB). Compute-only process: 52 MB with 2 units, 149 MB with the 6 units a pipelining client gets.
Regressions against stock (same kernel)
aurora-g16/tunecompute_units=2 keeps 52 MB but gives back the pipelining.Tests
tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.py: 23/23. Harness mocks were updated for the new calls, and host cases were added for the N-owner ledger, the published frontier, in-order "passed" retirement and cache close.Not done
🤖 Generated with Claude Code