Skip to content

drm/asahi: bound the queue structures held for firmware poweroff - #3234

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/g13-bound-poweroff-contexts
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/g13-bound-poweroff-contexts

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: On G13/G14 (M1/M2), the queue structures of destroyed queues are kept until the firmware reports a PowerOff, and under sustained load that boundary can be minutes away. This caps the list at 1024 contexts and releases the oldest first. It's Ryan's change from #2619, rebased onto main unchanged, plus a KUnit test of the bound and a hardware selftest that shows the growth.

Tested: host build of drivers/gpu/drm/asahi (asahi.config, LLVM, Rust, with CONFIG_KUNIT=y) at 783c379faaab: builds with no new warnings, and the new KUnit cases compile. The asahi-m4 host suite passes. The cap itself has Ryan's M1 Pro and M2 rows from #2619 (table below), which ran the same hunk on an older base. No row yet at this head.

Risk: two-way door · M1 and M2 Macs (the legacy G13/G14 manager only; G15, G16 and G17 don't use powered_contexts)

Not yet: G13 and G14 rows at this head (requested from PEER-ROWS): queue-churn on base and on this head, the churn mix under load with no firmware crash, and Shmem returning after idle. A faster churner (M1 Max/Ultra), as #2619 notes. CI.

Details

1. drm/asahi: bound the queue structures held for firmware poweroff (Ryan Murray)

This is the commit from #2619, cherry-picked onto main. The only conflict was textual: main had since added garbage_action() next to the new constant. GpuManager::alloc() pushes each invalidated context's retained queue structures onto powered_contexts, and fw_power_off() releases them only when a statistics batch ends with a PowerOff. When more than MAX_POWERED_CONTEXTS (1024) contexts wait, the commit releases those invalidated longest ago, under the same locks as the push.

The bound comes from Ryan's measurements:

  • 256 still crashed the G13S firmware, after about 6,400 churned contexts;
  • 512, 1024 and 4096 each ran tens of thousands of churned contexts under load without a crash;
  • 1024 gives a 2x margin over 512, for about 30 MB more at the bound.

Releasing at every PowerOff instead is not safe: it brings the G13S firmware crash back.

Mac cap mix x32 600 s load firmware crash Shmem after load / after idle
M1 Pro none 16/16 (x16) 32,956 processes (300 s) 0 +2.17 GB, not returned
M1 Pro 256 crash in run 7 not run 1 -
M1 Pro 1024 (this hunk) 32/32 67,854 processes 0 0.20 / 0.14 GB
M2 1024 32/32 50,843 processes 0 0.19 / 0.16 GB

2. drm/asahi: test the bound on queue structures held for firmware poweroff

The bound moves into release_oldest_powered() with no change in behaviour, and asahi_gpu_garbage gets two cases:

  • MAX_POWERED_CONTEXTS contexts all wait for a PowerOff;
  • four times as many leave only the newest 1024, in invalidation order.

tools/testing/selftests/drivers/gpu/asahi-churn/queue-churn shows the growth on hardware:

  • A child keeps the GPU busy with back-to-back compute dispatches of about 20 ms each, so the firmware reports no PowerOff.
  • Meanwhile the test creates a Vulkan device, runs one fill on it and destroys it, 6144 times by default, printing Shmem every 1024 contexts.
  • Without the bound Shmem grows by about 60 KiB per context, so roughly 360 MB. With it, growth stays under the bound's worth (it fails above 128 MiB).
  • After the load stops and the GPU idles, the rest is released.

It needs the Vulkan loader and Mesa, so it isn't in the selftests' TARGETS.

Evidence
  • ./linux-build/build kernel --profile asahi <tree> -- olddefconfig drivers/gpu/drm/asahi/ with CONFIG_KUNIT=y: exit 0. The module object holds the new KUnit case names, and there is no warning in gpu.rs.
  • rustfmt: no new diffs in gpu.rs.
  • checkpatch --strict: 0/0/0 on Ryan's commit. The second commit's warnings are the Vulkan API's CamelCase names, the selftest's CHECK() macro and the MAINTAINERS reminder for the new directory.
  • tools/asahi/run-host-tests.py --only asahi-m4: 1/1 passed.
  • queue-churn.c builds with cc -O2 -Wall -Wextra ... -lvulkan. Its SPIR-V is glslc --target-env=vulkan1.0 output, and passes spirv-val.

RyanTheTide and others added 2 commits November 26, 2026 05:19
The queue structures of invalidated contexts are kept until a statistics
batch ends with a PowerOff. Under sustained load the firmware reports each
PowerOff together with the following PowerOn, so that boundary can be
minutes away, and idle sends none. A load that keeps creating and
destroying rendering contexts then pins about 60 KiB of kernel memory per
destroyed context: on the M1 Pro, 20,000 retained contexts and +1.4 GB of
Shmem in 180 seconds, and the same pattern on the M2 (G14G).

Releasing at every PowerOff is not safe: it brings the G13S firmware crash
back. Instead keep the boundary and cap the list. When more than 1024
contexts wait, release those invalidated longest ago. With a cap of 256
the firmware crash still occurred, after about 6,400 churned contexts;
512, 1024 and 4096 each ran about 100,000 churned contexts without one.

Signed-off-by: Ryan Murray <[email protected]>
Move the bound from the previous commit into release_oldest_powered(),
so that KUnit can check it: up to MAX_POWERED_CONTEXTS invalidated
contexts all wait for a PowerOff, and four times as many leave only the
newest of them, in invalidation order.

Add tools/testing/selftests/drivers/gpu/asahi-churn/queue-churn for the
hardware. A child process keeps a G13/G14 GPU busy with back-to-back
compute dispatches, so that the firmware reports no PowerOff, while the
test creates a Vulkan device, runs one fill on it and destroys it, 6144
times. Shmem then grows by about 60 KiB per destroyed context without
the bound, and by at most the bound's worth with it; what is left goes
once the GPU is idle. It needs the Vulkan loader and Mesa, so it is not
in the selftests' TARGETS.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 10:25
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 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) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 783c379f: not ready yet

Check Detail
CI at head running running: KUnit macsmc, KUnit clpc, KUnit trusted-keys
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 783c379f
Conflicts ok none
PR text ok Risk: two-way · M1 and M2 Macs (the legacy G13/G14 manager only; G15, G16 and G17 don't use poweredcontexts)

Areas: area:gpu

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

@RyanTheTide

Copy link
Copy Markdown
Contributor

783c379 J413 (M2 Air, G14G B0) + J316s (M1 Pro, G13S C0) PASS (0-diff merge onto main, default cmdline): J413 stock fleet89 FAIL (+402,272 KiB / 65.5 KiB/ctx) -> PR PASS (+52,368 KiB / 8.5 KiB/ctx), 32/32 churn mix x1024 PASS, 600s 2x glmark2-gbm + 4x queue-churn 256 PASS (160/160 rounds / 40,960 ctx, Shmem flat +186..+212 MiB, +9.7 MiB 4s after idle); J316s PR PASS (+69,184 KiB / 11.3 KiB/ctx flat 4096..6144 ctx), 32/32 churn mix x1024 PASS, 600s 2x glmark2-gbm + 4x queue-churn 256 PASS (148/148 rounds / 37,888 ctx, Shmem flat +216..+249 MiB, +13.1 MiB 4s after idle); both: 0 vkerr, 0 GPU faults/fw crashes, Enforcing, 0 failed, 0 AVC, stock fleet89 restored.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 26, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 783c379f (once cancelled CI checks are rerun green)

Blockers: none (code, KUnit, and two-generation exact-head G13/G14 hardware rows are ready; rerun the 16 cancelled CI checks before merge).

Checked:

  • drivers/gpu/drm/asahi/gpu.rs:14-35,1898: verified MAX_POWERED_CONTEXTS = 1024 and release_oldest_powered() drains oldest invalidated contexts first (powered.drain(..excess)) in the G13/G14 legacy manager only (G15/G16/G17 unaffected).
  • Verified KUnit tests (contexts_up_to_the_bound_all_wait_for_poweroff, churn_without_poweroff_holds_only_the_newest_contexts) and tools/testing/selftests/drivers/gpu/asahi-churn/queue-churn.c.
  • Verified exact-head (783c379faaab) hardware rows on both J413 (M2 Air, G14G: stock +402 MiB FAIL -> PR +52 MiB PASS, 600 s 40,960-ctx stress flat) and J316s (M1 Pro, G13S: +69 MiB flat).
Evidence
  • Diff reviewed at 783c379f (all 4 files, 466 lines).
  • CI at review time: 3 passed, 0 failed, 16 cancelled.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train status at 783c379f (App approval noted; rows: 16 cancelled; J413 + J316s exact-head PASS). @DjDeveloperr code-owner ping (6-point rule, point 6): merge earliest 17:15 AEDT once full CI is green (I re-ran cancelled jobs) and the second-family row point holds. Revert: git revert -m 1 <merge>.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at 783c379f. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J413+J316s. (5) There's no blocking review. (6) Dj was pinged here 551 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 909f4e7 into main Nov 28, 2026
23 of 84 checks passed
@RyanTheTide
RyanTheTide deleted the fix/g13-bound-poweroff-contexts branch November 28, 2026 14:22
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:m1 Macs affected, from Merge risk (bot) blast:m2 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