Skip to content

drm/asahi: g17: keep other clients alive after work loses its completion stamps - #2052

Merged
DjDeveloperr merged 4 commits into
integration/aurorafrom
djdev/g17-timeout-victims
Nov 16, 2026
Merged

DjDeveloperr merged 4 commits into
integration/aurorafrom
djdev/g17-timeout-victims

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Admission never offers another client a render slot whose pair cannot be reused. The capacity snapshot reports such slots as held=.
  • A compute command that finished but lost its stamp is retired on its completion record with the stamp owed, instead of failing its client. The retirement pass steps past such commands, and their storage stays in place until a stamp covers them.
  • A closed context whose executed render pairs held back its compute exit is killed with the failed-context wait rules, so its pairs, queues and context are released.
  • A slot is also held while its closed owner's context release is pending. The hold is re-derived when an owner closes, when a rebind displaces a context, and on each housekeeping pass.

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.
  • Builds for arm64 with the MacBook Neo kernel configuration; no new warnings in the changed files.
  • MacBook Neo, kits on the 7.3.0-40 release (whose G17 runtime is this base's): 8 dEQP-VK synchronization2 clients for 180 s, then short-lived clients (gpubench life.churn, 3 runs) and three 1,500-case dEQP-VK lists.
    • Unchanged driver: life.churn failed 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.
    • Admission hold and owed-stamp retirement only (an earlier test kit): life.churn still 0/3, through the closed-owner case covered by the last commit.
    • All four commits, plus a test-only switch (not in this PR) to restore the old kill route in the same boot:
      • with the old kill route: a stuck pair remained, and a life.churn run still passed, with no lost devices;
      • with the new route: the stuck pair, owed work and pending context release were gone within 10 s, with no firmware error or recovery;
      • afterwards: life.churn 3/3 and 4,500/4,500 dEQP-VK cases passed, with 0 lost devices.
    • Not addressed here: the client whose own render lost its stamps still loses its device, and why stamps are lost under exhaustion is still open.
  • MacBook Neo, one kit of exactly this PR and drm/asahi: g17: never reuse a work state before its fence on the A18 Pro #1978 on the integration/aurora tip this PR is based on: the fast CTS gate (a sample of every Vulkan CTS group plus EGL, GLES 3.0 and 3.1) had 0 regressions and no GPU errors in the kernel log. After it, the same 8-client stress, short-lived clients and dEQP-VK lists: one compute command lost its stamp during the stress and its client was not failed; 0 lost devices, life.churn 3/3, 4,500/4,500 dEQP-VK cases passed.
  • Not tested on the M4 Pro/Max or M5. The admission hold applies to every G17 GPU; the owed-stamp retirement and the new kill route are not used on M5.

🤖 Generated with Claude Code

…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]>
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 16, 2026 07:28
@DjDeveloperr
DjDeveloperr merged commit 6fc7d6f into integration/aurora Nov 16, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the djdev/g17-timeout-victims branch November 17, 2026 23:52
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.

1 participant