Skip to content

drm/asahi: g17: keep G17P work nodes and compute descriptors firmware-cached - #3186

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/g17p-cached-work-nodes
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/g17p-cached-work-nodes

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Map the G17P work-node page and the compute descriptor ring firmware-cached again.

Tested: J700 (A18 Pro, G17P), system Mesa 26.3.0-30, separate one-shot boots of origin/main 16da00248bc9 without and with this commit (same change, rebased here onto 61c7b88aca91). Results without → with:

row (µs/submit) main this PR 7.3.0-41
render.light queue d4 / d8 / d32 42.5 / 37.8 / 36.4 35.9 / 31.2 / 29.4 33.7 / 28.9 / 27.3
render.light queues d2 / d4 / d8 57.5 / 47.4 / 43.8 52.5 / 42.2 / 38.4 50.5 / 39.9 / 36.3
compute.light queue d4 26.4 21.3 20.3
  • Gates on this PR:
    • dEQP-VK.synchronization2.op.multi_queue.*: 4266 Pass / 0 Fail / 0 recoveries, three times.
    • Compute CRCs 5/5; offline Geekbench 6 Vulkan 8/8 twice, 0 validation errors.
    • 0 GPU fault, timeout, quarantine, WARN or AVC lines.
  • Host tests: python3 -I tools/asahi/run-host-tests.py --only g17 224/224 at this head (main: 220; the 4 new mutations are all killed). 0 new warnings in the touched files.

Risk: two-way door · G17P Macs (A18 Pro, M4 Pro/Max); M5 unchanged.

Not yet:

Details

Where the time goes

One J700 boot with a test-only debugfs knob (never for merge) that gives each #3170 family back its pre-#3170 cached prefix (µs/submit):

re-cached render.light d4 d8 d32 compute.light d4
none (main) 43.6 38.2 37.0 26.4
render queue records 41.9 36.3 34.6 26.5
work nodes 36.4 31.6 29.5 22.7
compute descriptors 43.9 38.2 36.5 24.5
compute graph 43.7 38.2 36.6 26.4
all (pre-#3170) 34.1 29.1 27.3 21.1

Why these two are safe to cache and queue records are not

  • Queue records: the J716c revert needs the host to rewrite, in place, a line the firmware may still hold dirty. Queue records are rewritten exactly that way: set_owner retargets them, and on G17P bind_work_slot writes +0x38 on every render submission while the previous kick may still run. They stay uncached.
  • Work nodes: the host re-initialises a node only after WorkStorage::drained() has read the firmware's final completed from memory, and zeroes a returned work state only after its pool fence.
  • Compute descriptors: a slot is rewritten only after the kick that last used it retired (at most DESCRIPTORS kicks are in flight).

Test-only detector (J700, never for merge)

The detector read every work node back just before the host re-initialised it. It also hashed every compute descriptor in 256-byte chunks right after the host wrote it and again just before the host rewrote it. Each mode ran the full multi_queue CTS family, render.light, compute.light and the CRCs:

mode node re-inits host words reverted firmware data in node lines 2–3 already in memory descriptor rewrites firmware change near the end already in memory
cached (this PR) 1,151,688 0 100% 778,522 99.94%
uncached (main) 1,007,416 0 100% 700,934 99.94%
  • Footprint: uncached, the firmware writes node lines 0, 2 and 3 and the descriptor's last 256 bytes (where M5 keeps its +0xfac accounting word). So G17P descriptors are not firmware-read-only. The safety argument is the ordering above, and with the cached mappings those stores are in memory at the same rate as uncached.
  • CTS: 4266/0 in both modes.

…-cached

linux#3170 made every firmware-mutable pooled G17 object uncached after a
J716c (T6050) compute queue record, rebound in place, had a dirty firmware
line revert the host's owner fields. On the MacBook Neo (J700, A18 Pro)
that made light submissions 20-30% slower, because the G17P firmware
reads and updates these objects on every kick. In one boot, giving each
family back its pre-linux#3170 cached prefix showed where the time goes
(gpubench-vk, us per submission):

  family re-cached          render.light queue d4  d8    d32   compute.light d4
  none (main)                                43.6  38.2  37.0              26.4
  render queue records                       41.9  36.3  34.6              26.5
  work nodes                                 36.4  31.6  29.5              22.7
  compute descriptors                        43.9  38.2  36.5              24.5
  compute graph                              43.7  38.2  36.6              26.4
  all of them (pre-linux#3170)               34.1  29.1  27.3              21.1

The host rewrites neither the work nodes nor the compute descriptors
while the firmware may still be updating them:

- It rewrites a work node only after WorkStorage::drained() has read the
  firmware's final completed count from memory, and zeroes a returned
  work state only once its pool fence is met.
- It rewrites a compute descriptor slot only after the kick that last
  used it retired; at most DESCRIPTORS kicks are in flight.

A test-only detector on J700 checked this while the full
dEQP-VK.synchronization2.op.multi_queue.* family, render.light,
compute.light and the compute CRCs ran. It read each work node back just
before the host re-initialised it, and hashed each compute descriptor
after the host wrote it and again just before the host rewrote it.
With the cached mappings, across 1,151,688 node re-inits and 778,522
descriptor rewrites, no host-written word of a node was ever reverted.
The firmware's stores to node lines 2-3 were already in memory at every
re-init, and its stores near the end of a descriptor at 99.94% of
rewrites: the same fractions as with the uncached mappings
(1,007,416 and 700,934 checks). The CTS family passed 4266/0 in both
modes.

Objects the host rewrites in place while their queue may run keep
linux#3170's uncached mappings everywhere: render queue records
(retargeted, and bound to a work slot on every G17P render submission),
the compute graph, and the M5 scheduler pages. M5 keeps all of
linux#3170. On G17P, map the work-node page and the compute descriptor
ring firmware-cached again, and pin the policy in
tools/asahi/g17-object-fence-tests.py with four mutations.

On origin/main 16da002, separate one-shot J700 boots, without and
with this change: render.light queue d4/d8/d32 42.5/37.8/36.4 ->
35.9/31.2/29.4 us, queues d2/d4/d8 57.5/47.4/43.8 -> 52.5/42.2/38.4 us,
compute.light d4 26.4 -> 21.3 us; the multi_queue CTS family 4266/0
three times, compute CRCs 5/5, offline Geekbench 6 Vulkan 8/8 with no
validation errors, and no GPU fault, WARN or AVC.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 03:26
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 8fd602eb: not ready yet

Check Detail
CI at head ok 19 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 8fd602eb
Conflicts ok none
PR text ok Risk: two-way · G17P Macs (A18 Pro, M4 Pro/Max); M5 unchanged.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (M4 Mac mini, G16G) no-regression row at 8fd602ebb8b9: PASS, with no change on G16. The one problem found, multi_queue GPU faults, is on the base and on stock too.

How it was run: two guarded one-shots on the default cmdline.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict at 8fd602eb: MERGE.

Blockers: none.

Checked

  • On G17P, only the work-node page (not the counter page the host writes every kick) and the compute descriptors become firmware-cached. M5 stays uncached (linux#3170). The no-rewrite-while-firmware-updates argument holds:
    • nodes are rewritten only after WorkStorage::drained reads the final completed count, and zeroed only once the pool fence is met;
    • descriptor slots are rewritten only after the kick that used them has retired.
  • The host-test cache-policy check pins all four choices, with four new mutations killed (224/224).
  • Row: J700 at this head against main, the same day. Submit costs are back near the 7.3.0-41 level, sync2 multi_queue CTS is 4266/0 with 0 recoveries ×3, compute CRCs 5/5, GB6 Vulkan 8/8 ×2, and there are 0 GPU faults or timeouts. CI is green.

Nit: Risk names M4 Pro/Max as G17P. The M4 Pro in our lab reports G16S, so please check that wording.

@RyanTheTide
RyanTheTide merged commit d6fd71f into main Nov 27, 2026
21 checks passed
@RyanTheTide
RyanTheTide deleted the fix/g17p-cached-work-nodes branch November 27, 2026 13:21
RyanTheTide added a commit that referenced this pull request Nov 30, 2026
Bring the branch up to date with main. main made the G17P compute
descriptors firmware-cached (#3186); this branch maps them firmware-only.
Keep both: cached on G17P as main does, firmware-only on every G17.

Signed-off-by: Ryan Murray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants