Skip to content

drm/asahi: g17: never reuse a work state before its fence on the A18 Pro - #1978

Merged
DjDeveloperr merged 3 commits into
integration/aurorafrom
djdev/g17-object-fence-after-release
Nov 16, 2026
Merged

DjDeveloperr merged 3 commits into
integration/aurorafrom
djdev/g17-object-fence-after-release

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

The driver keeps returned firmware objects in a cache and hands them to new queues and contexts. A returned object waits for a fence: the firmware must have consumed a control record published after the object came back. When no ready object is left and a family has no room for another cached one, a new context takes an object whose fence was not met, and the capacity snapshot counts an overrun.

On the A18 Pro every such overrun is a work state. Creating contexts publishes no control record, and a teardown pass publishes all its scheduler releases before it returns any work state. So during a burst of context creations (the GL conformance cases that keep many contexts alive, for example), every work state returned by the last teardown waits for a record that does not come. The family fills up, and new contexts get work states whose fence was never met. That is the reuse 34b438d fenced after an M4 Pro firmware crash on a recycled work state.

Change

  • The capacity snapshot counts waiting objects and overruns per family, as well as in total.
  • On the A18 Pro, descriptor storage, queue records and queue configuration are reused once the firmware has consumed every control record published before they came back. That includes the owner's release.
  • On the A18 Pro, each cached work state records how far its address reached the firmware, and that decides its fence when it comes back:
    • never named by a record or command: no fence;
    • owner's release consumed and work list empty: reused at once;
    • anything else, including one named by a compute queue record kept installed after its owner exited: the strict fence.
  • A work state is never handed out before its fence on the A18 Pro: with the family full, the new one stays uncached. The snapshot counts uncached objects per family and work-state returns per class.
  • Unchanged: scheduler pages, and all families on the other GPUs.

Testing

  • Builds for arm64 with the MacBook Neo kernel configuration; no new warnings in the changed files. tools/asahi/run-host-tests.py --only g17 and --only asahi-m4 pass, including a new test of the work-state classes and of the unchanged decisions on the other GPUs.
  • MacBook Neo, kits on the 7.3.0-40 release, the same soak: dEQP-EGL multi-context cases in one, two and three processes at once, plus Vulkan stress.
    • Per-family counters only: 528 overruns, all work states. The other three families had none, and peaked at 61 of 64.
    • The first two commits (per-family counters, relaxed fence): 422, again all work states. The other three families had none waiting.
    • All three commits: 0 overruns. 154 work states stayed uncached; returns were 1,325 never named, 657 released and 116 strict.
    • No GPU fault, recovery or lost device in any run.
  • MacBook Neo, one kit of exactly this PR and drm/asahi: g17: keep other clients alive after work loses its completion stamps #2052 on integration/aurora 41eb932 (before the rebase below): 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: 0 lost devices, life.churn 3/3, 4,500/4,500 dEQP-VK cases passed.
  • Not tested on the M4 Pro/Max or M5 (unchanged there).

Rebased onto integration/aurora a163d7f (after #1977, #1981 and #1982 merged). The only conflict was in g17/fw/variant.rs, where #1981's render_id_at_create and this PR's objects_after_release now sit side by side, both set for the A18 Pro only. context.rs merged on its own: the two changes there are independent (#1981's render pool identity, this PR's work-storage return mark). Every file's diff is the same as before, so the logic is unchanged. Host tests: g17 38/38, asahi-m4 1/1. Fedora compile and link check OK. The only new warning is one fetch_update deprecation in object.rs, the same as the existing ones in freelist.rs and mmu.rs. try_update would not build with the Rust 1.85 toolchain the Neo kits use.

🤖 Generated with Claude Code

@DjDeveloperr DjDeveloperr changed the title drm/asahi: g17: let released queue objects be reused without waiting for a later record drm/asahi: g17: never reuse a work state before its fence on the A18 Pro Nov 16, 2026
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 16, 2026 07:28
The capacity snapshot counts the times a cached firmware object was
handed out again before the firmware had consumed a control record
published after the object came back, but only as one total. The cache
holds five families of objects (descriptor storage, work states, queue
records, queue configuration and, on M5, scheduler pages), and the total
does not say which of them ran into that limit.

Give each family's line its own waiting and overrun counts. The total
line is unchanged.

Signed-off-by: Diljit Singh <[email protected]>
The driver keeps returned firmware objects in a cache and hands them to
new queues and contexts. A returned object waits for a fence: the
firmware must have consumed a control record published after the object
came back. The driver returns descriptor storage, queue records and
queue configuration only after the firmware has consumed their owner's
release, or when the firmware never saw them, and it already frees the
owners' other firmware-visible storage at that point. The fence then
waits for a further control record, which may not come while queues are
only being created. When a client opens dozens of contexts at once, the
objects from the last teardown stay behind that fence, the families fill
up, and new queues take objects whose fence was never met.

On the A18 Pro, reuse those three families once the firmware has
consumed every control record published before the object came back,
which includes the owner's release, without waiting for a later one.
Work states and scheduler pages keep the stricter fence on every GPU,
and so do all families on the other GPUs: that fence came with a fix for
an M4 Pro crash on a recycled work state, and stays there until it is
shown not to be needed.

Signed-off-by: Diljit Singh <[email protected]>
A returned work state waits for the strict fence: the firmware must
have consumed a control record published after the object came back.
Creating a context publishes no control record, and a teardown pass
publishes all of its scheduler releases before any of its contexts is
dropped, so every work state of that pass waits for a record that may
not come while clients only create queues. When a client opens dozens
of contexts at once the family fills up, and new contexts take work
states whose fence was never met. On the A18 Pro these are the only
cached objects still handed out that way.

On the A18 Pro, let each cached work state record how far its address
reached the firmware, and pick its fence from that when it comes back:

- Unseen: no queue record or command ever named it, because its
  context failed or closed before publishing anything. The firmware
  cannot reference it, so it needs no fence.

- Released: the firmware consumed its owner's scheduler release and
  the work list was empty. It is reused at once. The driver already
  frees the owner's other firmware-visible storage at that point, and
  reuses descriptor storage and queue records then.

- Strict: everything else keeps control_fence(). That is a work state
  a record or command may still name, and one named by a compute queue
  record kept installed after its owner exited. Such a record is
  rewritten when the queue is bound again, possibly for another VM, and
  nothing on the control ring shows when the firmware stops following
  the old one, so a later release does not lift the fence there. This
  is the case 34b438d fenced after an M4 Pro crash on a recycled work
  state.

Every accessor that hands the address to the firmware, the work-list
head for queue records and a node for commands, marks the work state.
Comparisons with the host's own reads of the head use a separate
accessor that does not.

A full work-state family whose entries all still wait no longer has
its oldest entry reused: the new work state is left uncached, as when
every entry is in use. The capacity snapshot counts uncached objects
per family and work-state returns per class.

M4 and M5 are unchanged: their work states carry no mark and keep the
strict fence and the old reuse rule. tools/asahi/g17-object-fence-tests.py
compiles the pool and the context accessors against host stubs and
checks both.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/g17-object-fence-after-release branch from c186da0 to 8122212 Compare November 16, 2026 08:35
@DjDeveloperr
DjDeveloperr merged commit 2b1ee66 into integration/aurora Nov 16, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the djdev/g17-object-fence-after-release 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