Skip to content

drm/asahi: g17: give each open queue a compute channel before headroom - #3985

Open
DjDeveloperr wants to merge 1 commit into
mainfrom
djdev/g17-compute-channel-per-open-pair
Open

DjDeveloperr wants to merge 1 commit into
mainfrom
djdev/g17-compute-channel-per-open-pair

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: With 27 or more logical queues open, the compute QID budget kept the free QIDs for the render pairs of 24 queues that might open later, so compute stopped short of one channel per open queue even when every open queue ran compute and QIDs were free. Clients then took each other's idle channels, and each handover released a pool and built fresh backing. The headroom now gives way to one compute channel per render pair in current demand.

Tested: Mac Studio J775c (M5 Max, G17C) A/B against main by satchlj: PASS (comment): 35 and 40 open compute queues run 30-34x faster per round, gpubench-stress-vk 5/5, three s2idle cycles clean. Locally: tools/asahi/g17-resource-tests.py passes with a new case that replays the cross_instance capacity snapshot from linux#1964 (main stops at 26 compute channels with 35 queues open; this change reaches 35; with all 58 contexts open compute still keeps its floor of 10). arm64 LLVM=1 W=1 build of drivers/gpu/drm/asahi/ with KUnit enabled: no warnings in the touched files, and the new and updated KUnit cases compile. checkpatch --strict: clean.

Risk: two-way · the compute QID budget shared by every G17 Mac (M5 J714s and J775c, Neo J700) and by the M4 Pro/Max (T6040, T6041), which run the same code with QID floor 32. With 27 to 57 render pairs in demand (16 to 41 at floor 32), compute may now take more QIDs than before: one channel per pair up to 42 pairs (31 at floor 32), then what the pairs leave. Pairs in demand are the open queues plus live sibling and teardown-held pairs. Fewer queues can then open later with dedicated render pairs, until the firmware stops: 45 instead of 49-50 in the J714s cross_instance workload, and 40 instead of 48 in gpubench-stress-vk queue.exhaust on the J775c. Below that range, and with every context open, the budget is unchanged.

Not yet:

  • J714s row: the same four-boot lockdep A/B as linux#1964 (base, head, head, base), plus one production aurora_defconfig pair, at the head of this PR. Pass: compute reaches one channel per open queue in round 1, clean rounds make about 64 compute rebinds and run within 1.10x of the pre-linux#1964 kernel's clean rounds, no OOM kill, no new lockdep report, WARN or BUG. Also record the gpubench-stress-vk queue.exhaust count.
  • J700 (Neo, G17P) row: no regression against main, including the gpubench-stress-vk queue.exhaust count.
Details

QueueIds::compute_room lets compute take a fresh QID only while the QIDs left over cover render_reserve(pairs): two per pair for every open queue plus RENDER_HEADROOM (24) more queues, capped at all 58 execution contexts. That leaves compute at most 78 - 2 * pairs channels, which is less than one per open queue from 27 open queues on. From 34 on, the reserve is the full 118 and compute stops at 10. Compute QIDs never return to render, so whatever compute took while fewer queues were open is all it ever gets.

On the J714s, 16 deqp-vk cross_instance workers keep 35 logical queues open (32 devices plus the desktop), and all 32 devices run compute. The capacity samples from the linux#1964 rows show fresh_fits=0 whenever all 35 are open, on both kernels. Compute grew only when open queues dropped for a moment, and those drops came from failing clients:

  • Before linux#1964, an owner whose queue was shared away before its pool growth began stalled for 30 s and failed. The queues those failures closed let compute reach 32-33 channels by rounds 4-5. Its first four or five rounds failed, then the clean rounds made about 64 rebinds each.
  • linux#1964 removed the stall, so after round 1 nothing closes queues mid-round. Compute stayed at 26-27 channels with 25-26 QIDs free, and every clean round made 4,100-6,200 handovers.

So linux#1964 does not leak or hold a QID. It removed the failures that had been working around this limit.

The change caps the headroom at the QIDs that leave one compute channel per pair in current demand (QID_COUNT - floor - pairs). Current demand (2 * pairs + 2) stays protected. From 43 pairs on, where one channel per pair no longer fits beside the pairs, compute may take what the pairs leave, which comes back down to the floor of 10 with all 58 contexts open. Compute only takes a fresh QID when a client needs a channel (its first, or on M5 a sibling for sustained work) and no released channel fits, so it grows with the clients that run compute at the same time, not to the cap.

Tests:

  • New KUnit headroom_leaves_each_open_pair_a_compute_channel (floors 0, 4 and 32).
  • cancelable_siblings_do_not_block_compute_on_full_qid_table now expects compute to stop at one channel per open queue (32) instead of 14.
  • New host case in tools/asahi/g17-resource-tests.py that fails on main (left: 26, right: 35) and passes here.
Evidence
  • linux#1964 attribution row (bind and capacity data used above): drm/asahi: g17: rebind a compute owner whose queue was shared away #1964 (comment)
  • Capacity samples at 1 Hz on the earlier head, 35 open queues: tiling=38 compute=26 fresh_fits=0 from round 2 on. On the earlier base, compute went 24 → 30 → 33 only in rounds with failing clients (round 1 dropped to 15 open queues, round 3 to 5).
  • Host test on main: assertion left == right failed: each open queue keeps a compute channel; left: 26, right: 35. With this change: compute headroom: open queues each keep a compute channel; full context budget keeps the compute floor.
  • W=1 build: make ARCH=arm64 LLVM=1 W=1 drivers/gpu/drm/asahi/ with CONFIG_KUNIT=y and CONFIG_DRM_ASAHI_M5=y: rc=0, no warnings in kick.rs or runtime.rs.

A fresh compute QID must leave room for the render pairs of every open
logical queue and of RENDER_HEADROOM (24) queues opened later. Once 26
or more queues are open, that headroom alone stops compute growth, even
when every open queue runs compute and QIDs are free. A client without
a channel then takes another open client's idle channel, and each such
handover releases the pool and builds fresh backing before the next
kick. With more busy clients than channels this never settles.

On the M5 Pro, 16 deqp-vk cross_instance workers keep 35 logical queues
open, 32 of them running compute. Compute stopped at 26-27 channels
with 25-26 QIDs free, and every clean round made 4,100 to 6,200 channel
handovers instead of about 64, running 1.12x to 1.29x slower than
before "drm/asahi: g17: rebind a compute owner whose queue was shared
away". Before that change, an owner whose queue was shared away before
its pool growth stalled for 30 s and failed, and the queues those
failures closed let compute grow to 32-33 channels. The change removed
what had been hiding this limit.

Let the headroom give way to one compute channel per render pair in
current demand. The current pairs stay protected, and with every
execution context open compute still keeps only its floor. In that
workload, 10 more logical queues can still open with dedicated pairs.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 2, 2026 19:29
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all 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 Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at f3eee42b: not ready yet

Check Detail
CI at head no failing: host-tests
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at f3eee42b
Conflicts ok none
PR text ok Risk: two-way · the compute QID budget shared by every G17 Mac (M5 J714s and J775c, Neo J700) and by the M4 Pro/Max (T6040, T6041), which run the same code with QID floor 32. With 27 to 57 render pairs in demand (16 to 41 at floor 32), compute may now take more QIDs than before: one channel per pair up to 42 pairs (31 at floor 32), then what the pairs leave. Pairs in demand are the open queues plus live sibling and teardown-held pairs. Fewer queues can then open later with dedicated render pairs, until the firmware stops: 45 instead of 49-50 in the J714s crossinstance workload, and 40 instead of 48 in gpubench-stress-vk queue.exhaust on the J775c. Below that range, and with every context open, the budget is unchanged.

Areas: area:gpu

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

@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member

Hardware A/B verification at exact head f3eee42b75be on Mac Studio (M5 Max / T6050 / G17C B1): PASS

Setup

  • Base: aurora-silicon/linux@main b3a5fda631b9 (7.3.0-1-60.20261202-ARCH), default command line.
  • Head: exact PR head f3eee42b75be71a379ddfdfe276929cf2244ba82 (7.3.0-1-61.3985-ARCH), default command line, one-shot trial boot (systemctl --failed = 0, clean unaided return to default).
  • Userspace: Borealis (Mesa 26.3.0-devel, fb0f929ad5), live Wayland greeter active.

Results

  • Host test (tools/asahi/g17-resource-tests.py): PASS (all assertions, including compute headroom: open queues each keep a compute channel; full context budget keeps the compute floor).
  • Multi-queue round-robin Vulkan compute A/B (N independent VkInstance+VkDevice queues, 2 warmup + 20 timed round-robin rounds, storage-buffer increment checked exact on every device):
Open queues (N) Base (b3a5fda631b9) PR #3985 (f3eee42b75be) Result
N=20 (<27) 61.77 ms wall / 151.2 µs p50 (20/20) 68.84 ms wall / 166.2 µs p50 (20/20) unchanged regime
N=35 4,091.62 ms wall / 6,167.7 µs p50 (35/35) 120.73 ms wall / 166.6 µs p50 (35/35) 33.9× faster wall / 37.0× lower p50
N=40 4,145.46 ms wall / 4,962.4 µs p50 (40/40) 137.51 ms wall / 166.1 µs p50 (40/40) 30.1× faster wall / 29.9× lower p50
N=45 4,468.64 ms wall / 4,954.3 µs p50 (45/45) clean VK_ERROR_OUT_OF_DEVICE_MEMORY on open matches stated render-headroom cap trade-off (with live desktop queues open)
  • gpubench-stress-vk (--duration 50 --kernel-log): 5/5 PASS (0 errors, 0 kernel log errors):
    • queue.exhaust: PASS (5 devices × 8 queues = 40 queues, device 6 cleanly refused with VK_ERROR_OUT_OF_DEVICE_MEMORY, 187 iters / 181 checks; base opened 6×8 = 48 queues — matches the expected render-headroom trade-off documented in the PR)
    • cr.concurrent: PASS (116,908 iters / 116,908 checks)
    • queue.depth: PASS (290,909 iters / 290,909 checks, 12 mixed queues)
    • life.churn: PASS (2,116 iters / 2,116 checks, 390 devices)
    • idle.wake: PASS (1,108 iters / 1,108 checks, 140 bursts)
  • Suspend / resume & post-resume checks:
    • 3/3 consecutive 15 s RTC s2idle cycles (suspend_stats: success=3, fail=0).
    • Post-resume N=35 round-robin compute: 117.15 ms wall / 162.9 µs p50 (35/35 exact).
    • dEQP-VK.api.smoke.*: 8/8 PASS.
    • llama-bench (Llama-2-7B Q4_0): pp128 = 2,919.71 ± 6.27 t/s, tg32 = 120.06 ± 0.10 t/s.
    • HDMI 2560x1440, Wi-Fi 5 GHz, mmc0, accel0 intact; 0 GPU faults, 0 kernel oops/warnings.
  • Note on untested paths: Lockdep-enabled 4-boot A/B and live KUnit execution were not run in this trial.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 2, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: merge, once the J714s and J700 rows pass at this head. The code and tests are correct. I found nothing to change in the code.

Checked at head f3eee42b75be, merged into main 5e9dffbec7d9. The merge is clean and main has no g17 changes since the base. Local merge commit a473d88df2e5, tree 002b9dbb4451.

The new cap (g17/kick.rs, compute_room). I compiled the real QueueIds code from main and from the merge on the host. For every pair demand from 0 to 63, at QID floors 0, 4 and 32, I counted the compute QIDs it grants, both with the current pairs installed and with none installed:

  • Floor 0 (M5, Neo): same as main from 0 to 26 pairs and from 58 up. From 27 to 42 pairs, compute reaches one channel per pair; main gave 24 at 27 and 10 from 34. From 43 to 57, compute gets what the pairs leave: 40 at 43, falling to 10 at 58.
  • After compute grows, the render pair capacity is never below the pair demand, so current demand stays protected at every count on both trees.
  • With all contexts open, compute stops at its floor of 10.
  • The head never grants less compute than main.
  • There is no underflow: floor < FULL_RENDER_RESERVE < QID_COUNT, and the new term uses saturating_sub.

Tests.

  • Head's tools/asahi/g17-resource-tests.py, run in the CI image (rust 1.96):
    • on main it fails with each open queue keeps a compute channel; left: 26, right: 35;
    • at the head and on the merge it passes.
  • KUnit for arm64 can't run here, so I ran the new KUnit case against the same host build. At floors 0/4/32, compute stops at 18/14/10 on main and reaches 30 at the head.
  • The runtime case's arithmetic gives 14 on main and 32 at the head, which matches the changed expectation.

Merge-tree checks (pc).

  • make ARCH=arm64 LLVM=1 W=1 drivers/gpu/drm/asahi/ with CONFIG_DRM_ASAHI_M5=y and CONFIG_KUNIT=y: rc 0, with asahi_core.o rebuilt.
    • No warning names g17/kick.rs or g17/runtime.rs.
    • Two dead-code warnings at driver.rs:297 and :336 don't appear in the head-only build. They come from main's 33a77d5.
  • run-host-tests.py --only g17 in the CI image: 329/329 passed.
  • The hosted host-tests failure is only centauri-scan-tests, which #3987 fixed on main. On the merge it passes (2/2).

Rows. satchlj's J775c PASS covers the target SoC at this head. The owed J714s A/B and a J700 row are enough before merge. Please record the gpubench-stress-vk queue.exhaust count in both: that's where this change costs capacity (on the J775c, 40 queues at the head vs 48 on base).

The Risk line missed one thing; I've fixed it in the body. T6040/T6041 (M4 Pro/Max) run this code with QID floor 32. There the changed range is 16 to 41 pairs instead of 27 to 57. The new KUnit case covers floor 32. We have no T604x, so that row can come after merge and shouldn't hold this PR.

One more note, not a change request: the cap counts pairs in demand, not open queues. On G17C/G17D, a queue with a live sibling counts twice, so compute can reach two channels per queue there. The code comment says exactly that, and the J775c run is clean.

Body edits I made:

  • Tested: added the J775c result.
  • Risk: added the M4 Pro/Max floor-32 range, the J775c queue.exhaust numbers, and that the lost capacity lasts until the firmware stops.
  • Not yet: added the J700 row and the queue.exhaust count.
  • Details: one channel per pair stops fitting at 43 pairs, not 42.

@github-actions github-actions Bot added blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) and removed blast:all Macs affected, from Merge risk (bot) labels Dec 2, 2026
@DjDeveloperr

DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, T8140, G17P): FAIL at f3eee42b75be on one of the kit's bars (a 40-client open)

One one-shot trial boot on 2026-12-03 of 7.3.0-pr2196-299b3771-pr3985-f3eee42b: main 4c6f0f70989f + linux#2196 (merge f9401d0316e6) + this PR (merge f7c06f00028a, tree 8af7e9750576). Stock aurora_defconfig. There is no main arm yet, so this doesn't say whether the failing case is a regression against main.

Check Result
20 compute clients together PASS. 20/20 clients pass, 21 compute channels (at least one per open queue), 1 rebind across VMs (20 compute QIDs; rebound <= 60 wanted)
35 compute clients together PASS. 35/35 clients pass, 39 compute channels, 17 rebinds (<= 105 wanted). On the J714s the PR reports main thrashing here; I have no main number on the J700
40 compute clients together FAIL. 39/40 clients pass. One client got vkQueueSubmit = VK_ERROR_OUT_OF_DEVICE_MEMORY on its first work. All 40 clients were alive at once, but the all-40-open sample was never taken, so that check is INCOMPLETE
s2idle × 3 PASS. Success 3 → 6, fail 0, GPU render valid after each wake
Whole boot 0 GPU fault, recovery, lost-device or OOM lines, 0 WARN, BUG or Oops, watchdog armed throughout

What the 40-client refusal is. The driver printed G17 capacity refusal LogicalQueues count=… at g17/runtime.rs:1408, which is the render_fits check for a new queue. Compute QIDs never return to render, so after the 20 and 35 rounds the boot already held 39 compute QIDs (40 after the 40 round). 128 physical QIDs minus 40 leaves 88, which is 44 render pairs, and the desktop already had 4 logical queues open (43 was the highest I saw). One more pair didn't fit. That matches the trade-off in this PR's "Risk" section ("Fewer queues can then open later with dedicated render pairs"), which names 40 for queue.exhaust on the J775c. This is the J700's number after the earlier rounds, not a fresh-boot one.

Other numbers

  • queue.exhaust (gpubench-stress-vk 7a0dfcf, run after everything above): 32 queues opened (4 devices × 8), then device 5 refused its first work with VK_ERROR_OUT_OF_DEVICE_MEMORY. Information only, and not comparable with a fresh-boot number from main, because the compute QIDs were already taken.
  • Ten GPU load cases (render.light d1/d8, compute.light d1/d8, compute.heavy-bw d2, two rounds) all passed their own checks.

What would settle it: main at the same 20/35/40 order on the same boot image, plus 40 clients on a fresh boot for both arms. I can run those on the J700; the sealed main 4c6f0f70 kernel exists.

Things worth knowing

  • The whole-boot checks are shared with linux#2196, which passed its own row in the same boot.
  • The wait loop on Mini gave up early when SSH dropped during the sleeps. I resumed waiting for the same running row and didn't start it again. Recovery was dead-man-only (the M4 mini wasn't held).

Stock restored: boot-ctxr.bin byte-identical to before, no trial marker left, stock 7.3.0-41, PMU boot-error count 00.

@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.

Reviewed f3eee42. The reserve still protects all render pairs in current demand and limits the headroom reduction to one compute channel per pair where capacity allows. I checked the reserve across the three tested QID floors. The J775c row measures the benefit and the description records the reduced capacity for queues opened later.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, T8140, G17P) at f3eee42b75be, main arm and head arm: the earlier 40-client refusal is the PR's own behaviour, not main's

Four one-shot trial boots on 2026-12-03 (baseA, headA, baseB, headB). Base = main 4c6f0f70 (no PR). Head = the same main + #2196 (299b3771) + this PR (f3eee42b), so a difference here is "#2196 or #3985", and I can't separate them. Every client runs a small compute workload for 10 s; "refused" counts come from the driver's own counters. baseA and headA run 20, 35 and 40 clients on one boot; baseB and headB run 40 on a fresh boot.

Clients main head
20 20 of 20, 53,187 submits/s, 1 queue rebind 20 of 20, 53,040 submits/s, 1 rebind
35 24 of 35, 22,946 submits/s, 4,097 rebinds. 11 clients ended with a lost device (GPU work of a client failed (ENOMEM, g17/runtime/backend.rs:75), 11 kernel lines) 35 of 35, 51,506 submits/s, 17 rebinds, 0 such lines
40, same boot (A) 40 of 40, 5,442 submits/s, 7,523 rebinds 39 of 40, 46,690 submits/s, 38 rebinds, 2 refusals at the logical-queue limit
40, fresh boot (B) 40 of 40, 5,118 submits/s, 8,943 rebinds 39 of 40, 51,199 submits/s, 0 rebinds, 2 refusals at the logical-queue limit
queue.exhaust after 40 (information only) 40 queues opened (5 devices × 8) 32 queues opened (4 devices × 8)

What this says about the earlier FAIL (39 of 40): it reproduces twice on the head and not on main, which opens all 40. So the refusal at 40 clients comes with the PR (or #2196), in exchange for about 9 to 10 times the submit rate and no rebind thrash at 35 to 40 clients. At 35 clients it is the other way round: main loses 11 clients to ENOMEM, the head loses none. The gated part of the row (identity, fault lines, watchdog) passes on headA, headB and baseB. It fails on baseA, because main's ENOMEM device losses are GPU fault lines.

Not covered: whether the 39-of-40 limit is wanted (a design decision for the PR), #2196 and #3985 separately, s2idle, and other generations. The runs were on one J700 with one boot per plan, so the rates are indicative.

How it ran: dead-man-only recovery (30 min), reset route checked before each slot, no reset used. Stock restored after every boot (boot-ctxr.bin byte-identical, no trial marker, PMU boot-error count 00, stock 7.3.0-41).

This branch has not been deployed

No deployments
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) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants