Repository navigation
drm/asahi: g17: never hand out a context a queue record still names - #1870
DjDeveloperr wants to merge 2 commits into
Conversation
A returned application context waits until no installed queue record names it (mmu::ContextHold) and the firmware has consumed a control record published after the last such record went. The allocator kept one exception: when every free context still waited, it took the one with the oldest fence and counted an overrun rather than refuse a queue. That exception is reached as soon as the contexts run short. An idle compute queue keeps its record, and with it its last owner's context, until the queue gets its next owner. With nearly every context in use the only free ones are those, and a new queue got one of them. On the A18 Pro, with nine Vulkan clients holding 54 of the 58 contexts, the overrun count went from 0 to 51 in 75 seconds and the GPU faulted three times. Each fault was in a context handed out within the previous six seconds while an idle compute queue's record still named it, and each took the device of the client that had just been given the context. Take a context only when it is ready. The queue creator asks before it reserves anything, after sampling how far the firmware consumed the control ring. With no free context it waits for closing queues as before. With free contexts that all still wait it polls every 10 ms, since neither a replaced record nor firmware progress notifies, within the same bound; then the queue is refused (ENOSPC at the ExecutionContexts site, EBUSY to the client), as it already is when the logical queues or their render identities run out. debugfs capacity reports the creations that had to wait (execution_contexts_fenced waits=) in place of the overruns. tools/asahi/g17-context-reuse-tests.py compiles the production choice and the creator's wait rule on the host; its mutations restore the reuse of a waiting context, ignore the records' holds and drop the bound. Signed-off-by: Diljit Singh <[email protected]>
An installed compute queue keeps the scheduler page and work storage of an exited last owner, and with them the hold on its application context (retained_owner). bind_owner dropped them as soon as the next owner of another VM bound the queue and the queue record was rewritten. The record is not the only place that names the old owner. A queue's context, scheduler page and QoS ID also reach the firmware in the configuration a publication carries, sent when they differ from the last one published. Until the new owner's first publication has run, the last configuration the firmware ran for that queue is the exited owner's. That publication can be far away: it waits for ring room, work states and the submission's inputs, and a first attempt that fails is rolled back with the queue left bound. In that window the context's hold was gone, so one control record later the context counted as ready for another queue, the same state the previous commit refuses from the allocator's side. The scheduler page was unmapped and the work storage went back to the object cache in the same window. Keep the pages as Superseded from the rebind until a publication made after it is witnessed: an exact retirement, the drain witness of a quarantined queue, or an acknowledged kill, the witnesses that already retire Previous. An older configuration still waiting for its witness keeps its place when the queue changes owner again without a publication. debugfs capacity gains retained= and superseded= on the compute_queue line. tools/asahi/g17-capacity-fault-tests.py runs the rebind and both witness paths on the production methods, with negative controls for dropping the pages at the rebind and for retiring them without a publication. Signed-off-by: Diljit Singh <[email protected]>
DjDeveloperr: drm/asahi: g17: never hand out a context a queue record still names # Conflicts: # drivers/gpu/drm/asahi/g17/runtime.rs
|
Blockers: 2.
The core change is sound. HW row: J700 on this head with the nine-client device create/destroy load, against the same load on the base: 0 GPU recoveries, Assisted-by: LLM (Claude:Opus 5.5) |
|
integration/aurora 110861f still has the oldest-fence overrun fallback in A rebased copy is on this repository as Build check of 110861f plus this change (arm64, LLVM=1, Image, dtbs and every directory it touches, Fedora config plus asahi.config): builds, no warnings in the files it touches. Host tests (tools/asahi/run-host-tests.py --only) on 110861f plus this change: g17 fails (80/94 passed); g17-capacity-fault-tests passes (1/1); g17-context-reuse-tests passes (4/4). |
A returned G17 application context is meant to wait until no installed queue record names it (
mmu::ContextHold) and the firmware has consumed a control record published after the last such record went. The allocator kept one exception, from 34b438d: when every free context still waited,Uat::new_execution_contexttook the one with the oldest fence and counted an overrun, rather than refuse a queue.That exception is reached as soon as contexts run short. An idle compute queue keeps its record, and with it its last owner's context, until the queue gets its next owner. With nearly every context in use, the only free contexts are those, and a new queue gets one of them.
What was seen
A18 Pro test boot, nine Vulkan clients creating and destroying devices, 54 to 56 of the 58 contexts in use:
The link between each faulting context and the idle queue comes from capacity samples taken two seconds apart, so it rests on the last binding each queue showed.
Change
mmu.rs: the allocator takes a context only when it is ready: free, named by no record, fence met (ContextRoom,context_room). The oldest-fence fallback is gone for application contexts.pick_returnedis unchanged for its other user, the QoS IDs.g17/runtime.rs,Backend::new: the queue creator samples how far the firmware consumed the control ring and asks for a ready context before it reserves anything. With no free context it waits for closing queues, as before. With free contexts that all still wait it polls every 10 ms, because neither a replaced record nor firmware progress notifies, within the same bound. After that the queue is refused at theExecutionContextssite (EBUSY to the client), as it already is when logical queues or render identities run out.execution_contexts_fenced free_waiting=N waits=Mreplacesoverruns=.waitscounts queue creations that found only waiting contexts.tools/asahi/g17-context-reuse-tests.py: compiles the production choice and the creator's wait rule on the host. Its mutations restore the reuse of a waiting context, ignore the records' holds, and drop the bound.Second commit: the same rule on the compute queue's side
An installed compute queue keeps the scheduler page and work storage of an exited last owner, with the hold on its context.
bind_ownerdropped them as soon as the next owner of another VM bound the queue and the record was rewritten. But a queue's context, scheduler page and QoS ID also reach the firmware in the configuration a publication carries, sent when they differ from the last one published. Until the new owner's first publication has run, the last configuration the firmware ran for that queue is the exited owner's. That publication can be far away (it waits for ring room, work states and inputs, and a failed first attempt is rolled back with the queue left bound).In that window the hold was gone, so one control record later the context counted as ready for another queue: the state the first commit refuses from the allocator's side. The scheduler page was unmapped and the work storage returned to the object cache in the same window.
queue/compute.rs: the pages are kept asSupersededfrom the rebind until a publication made after it is witnessed, by the witnesses that already retirePrevious(exact retirement, the drain witness of a quarantined queue, an acknowledged kill).retained=andsuperseded=on thecompute_queueline.tools/asahi/g17-capacity-fault-tests.py: the rebind and both witness paths on the production methods, with two more negative controls.This one rests on reading the publication path, not on an observed fault. It only keeps things longer.
Cost, and what this does not do
Test plan
tools/asahi/g17-context-reuse-tests.py: 6 tests pass; the 3 mutations are killed.tools/asahi/g17-capacity-fault-tests.py: passes; all 8 negative controls fail as they should.tools/asahi/run-host-tests.py --only g17: 35 of 35.waitsabove zero and no GPU recovery.Draft until the module build, the Neo run and the M5 check are done. Not to be merged before they pass.
🤖 Generated with Claude Code