Repository navigation
drm/asahi: g17: keep other clients alive after work loses its completion stamps - #2052
Merged
Merged
Conversation
…nnot be reused A render pair can keep work that no other owner can bind past: a quarantine, or a group that retired on its pass record while its completion stamps are still owed. Only the firmware draining the pair (the stamps arriving, or a kill of its context) or a processor stop ends either. Retiring such a group still drops the command's admission lease, and can clear the slot's admission quarantine, so once the owner closed, admission counted the slot as free and even preferred it, as the least recently used released pair. Each new render client given that slot was refused by the pair on every retry. After the two-second publication wait it failed with ETIMEDOUT and lost its device, although none of its work had run. Each victim's close released the slot again, so one stuck context went on costing later render clients their devices; short-lived clients under capacity pressure lost them one after another. Admission now keeps a held mask. The runtime sets a slot's bit from its pair's state each time it puts the pair back, and where a VM failure or a deferred error quarantines the pair in place. It does so under the device mutex, before that pass's deferred retirements drop their leases, so the slot is never free for another owner in between. No new or other owner is given a held slot: not as a first pair, a sibling, a reassigned or freed spare, a reused killed pair, nor by scheduler admission. Its own open owner keeps using it. Clearing the bit (the pair drained) wakes the waiters, and a processor stop clears every bit. The cost is capacity: a held slot is lost to other clients until the pair drains (after its owner's teardown) or the firmware stops. A new client that finds only held slots gets a render capacity refusal, waits as under any other shortage, and fails its command with EBUSY if the wait expires, instead of losing its device. Held slots count as used and are shown as held= in the debugfs capacity line. This is host bookkeeping and applies to every G17 GPU: on any of them such a pair refuses every other owner. The admission-order host test now builds the real admission state, its slot choices and the hold, and thirteen registered mutations, each dropping one part of the rule or applying it to the owner's own pair, must fail. Signed-off-by: Diljit Singh <[email protected]>
…ead of failing its client A compute command retires on its completion record once its stamp is 50 ms late and the rest of its submit ioctl has completed. While the ioctl's other work does not complete, that bound restarts, and if the stamp never comes the command waits for its watchdog. The watchdog then found the queue's head finished (its record present) and failed it as its own at once: the client lost its device although its work had run. A command retired on its record also stayed at the front of its queue until a stamp covered it, so every later command of that queue waited behind it until its own watchdog failed it the same way. A finished head is now a Retire decision instead of Own. The compute watchdog ends that command's stamp wait and runs the retirement pass, which retires it on its record with its stamp owed, as after the fallback bound: its client gets its result and the job is not failed. Where it does not retire that way (M5, whose record can precede the command's writes; ring entries not consumed yet; a recovery since), the watchdog fails it as its own, as before. A render head is never finished; a render whose stamps lag still retires on its pass record when it is failed. The first few such retirements of a boot are logged. The retirement pass now steps past commands that owe their stamps and retires the commands behind them, each on its stamp or its record. Every retired command keeps its place in the queue and its descriptor until a stamp covers it, and a command that retires behind them is held the same way and leaves after them. Nothing the firmware can still use is released earlier than before: held commands count against the queue's in-flight window, so their descriptor and record slots are not reused, the queue can neither be rebound nor give up its pool, and a previous binding stays until a stamp covers the first publication. Behind held commands, a command that crossed a recovery waits for its stamp, a failed command leaves the held ones' results and classes alone, and the watchdog weighs the oldest command that has not retired rather than one that has. The timeout path no longer fails a command its own final pass just retired. Renewals, allowances, excuses and the failed-blocker rule are unchanged. A new host test compiles the real retirement pass, the compute watchdog's decision and timeout paths and timeout.rs against mock firmware state: a head whose stamp never comes retires together with the command behind it while a third still runs, held commands keep their descriptors until stamps cover them, and unfinished or unretirable work is deferred or failed as before. Thirteen registered mutations, each restoring the old behaviour or dropping one part of the rule, must fail. Signed-off-by: Diljit Singh <[email protected]>
…d back its compute exit A closed context's render pair whose commands all ran but were never stamped keeps its pool lease until a kill of the context is acknowledged. The compute exit was taken only for failed compute or once every render pool was released, and the render-only kill only once no compute queue held the context. A context whose compute commands retired without their completion stamps, or whose compute timed out, met neither: its compute exit waited for the pools that only the kill releases, and the render-only kill waited for the compute queue still holding those commands. Nothing killed it, so the context, its pairs, its compute queues and its pools stayed held until the processors stopped. On Neo a stress run left three such contexts in teardown for the rest of the boot with no kill ever published, and their render slots were lost to every other client. Such a context now takes the compute exit: a kill that releases executed render pairs no longer waits for their pools. Its kill waits the way a failed context's kill and a render-only kill already do. It waits only for a moment without other contexts' compute, with the memory-pressure escape, the slow-kill warning and the 100 ms retry. Before, it would also have waited, silently, for every other client's render work. A closed owner's compute queue whose commands all retired without their stamps runs nothing and is itself waiting for its kill, so other kills no longer wait for it; two dead contexts left that way would have waited for each other. An open owner's queue still counts while it holds a command. The kill guards are unchanged: - A context is killed at most once. Once a kill of it was published, by either path, the new route is closed, and the render-only kill keeps refusing it. - Nothing is freed before the acknowledgement. The pairs are held for the kill, and their unstamped work is released only once the scheduler page reports it. The compute commands are settled only once the kill is acknowledged. The graphs stay kept while the firmware may still link work, and the held slots stay held until the context's scheduler release is consumed. - A queue with a running ray traversal is never killed. - The kill names only queues of its context, and none is published during a recovery. M5 is unchanged. A new host test compiles the real route choice, its inputs, the compute queue's exit predicates and the KUnit cases against mock firmware state. Its rows are the contexts of that run, and seven registered mutations, each restoring the old behaviour or dropping one part of the rule, must fail. Signed-off-by: Diljit Singh <[email protected]>
The admission hold kept other owners off a slot only while its pair held work nobody else can bind past: a quarantine or owed completion stamps. A closed owner's pair can also be unbindable with no work at all. From the close until the firmware consumed the scheduler release of the pair's context and the teardown parked the pair, the pair refuses every other owner, and that release is published only once the context's compute is idle and its pools are released. A closed context whose compute still holds commands (retired on their record with their stamps owed, or failed and waiting for a kill) stays there for as long as that lasts. Its idle pair has no lease, no quarantine and no hold, so admission counted the slot as free and, as the least recently used released pair, gave it to new owners first. Each was refused on every retry and, after the two-second publication bound, failed with ETIMEDOUT and lost its device; its close released the slot again for the next one. On Neo, short-lived render clients lost their devices this way one after another, about two seconds apart, after a stress run. The two quarantined slots of that run were not the cause: admission's quarantine mask already keeps every other owner off them. The hold now follows one rule for a slot's pair: it is held while the pair keeps unreusable work or while the scheduler release of its context is pending. The runtime applies the rule wherever a pair is put back (as before, now also after a growth or a preparation), where a VM failure or a deferred error quarantines a pair in place, and re-derives every slot at three more points: when an owner closes, before admission releases its slots, since admission does not take the device mutex; when a rebind displaces another context; and on each housekeeping pass, after consumed releases park their pairs. A pair lent out keeps its bit until it is put back, but is held at once if its owner closes meanwhile, since a growth borrows an idle pair without a lease. A slot without an installed pair is never held. Admission takes a whole resync under one lock and wakes its waiters when a hold clears. Admission cannot ask the pair itself: it runs without the device mutex, which the pair's state needs, and the runtime calls into admission under that mutex. The cost is that a closing owner's slots go to no other owner until its release is consumed, usually within a pass, or for as long as a stuck teardown lasts. A new client then gets a render capacity refusal and waits, or fails its command with EBUSY, instead of losing its device. In that window a closing owner's unused, never-published spare is no longer given away or cancelled for compute identities either. The admission-order host test now also compiles the hold rule, the runtime's resync and put-back, the owner close, the scheduler-release teardown and the admission state against mock pairs. A closed owner's pair is held before admission releases its slot, through retirements and resyncs, until its release is consumed; quarantined and owed pairs are held by the same rule and kept by their own owner; a lent pair keeps its bit and is held when its owner closes. Ten registered mutations, each dropping one part, must fail. A KUnit case covers the batched update. Signed-off-by: Diljit Singh <[email protected]>
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.
Under capacity exhaustion, a render or compute command can finish without its completion stamps. Its render pair then stays unusable for anyone else: quarantined, owing stamps, or idle but waiting for the scheduler release of its closed owner's context. That release never comes, because the two kill paths for such a context wait for each other. Admission meanwhile offers the pair's slot to new clients first, as the least recently used free slot. Each new client is refused until the two-second publication bound and then loses its device; its own close frees the slot again for the next one. Separately, a compute command that finished but lost its stamp is failed as its own client's fault.
On the MacBook Neo, after one 8-client Vulkan stress, every later short-lived rendering client lost its device about two seconds apart, until a firmware stop.
Change
held=.The cost is capacity rather than devices: a slot that cannot be reused is refused to others until it is released, and a client that finds no other slot waits or gets EBUSY.
Testing
tools/asahi/run-host-tests.py --only g17: 77/77, with new tests and mutations for the hold, the owed-stamp retirement, the kill route and the hold rule.--only asahi-m4: 1/1.life.churn, 3 runs) and three 1,500-case dEQP-VK lists.life.churnfailed 3 of 3, and 4 to 26 clients lost their devices with ETIMEDOUT. The stuck pairs and the pending context release stayed until the next boot.life.churnstill 0/3, through the closed-owner case covered by the last commit.life.churnrun still passed, with no lost devices;life.churn3/3 and 4,500/4,500 dEQP-VK cases passed, with 0 lost devices.life.churn3/3, 4,500/4,500 dEQP-VK cases passed.🤖 Generated with Claude Code