Skip to content

drm/asahi: g16: reuse a pass slot's retired PB epoch - #1543

Open
aeries0x wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
aeries0x:j604-pb-pr-r4
Open

aeries0x wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
aeries0x:j604-pb-pr-r4

Conversation

@aeries0x

@aeries0x aeries0x commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Every G16 render gets a fresh parameter buffer (PB) epoch at SUBMIT and an InitBM ahead of its TA work, so the firmware
rebuilds the allocator state for every render. Reusing the epoch instead cuts a small triangle render at queue depth 1
on a base M4 MacBook Pro (J604) from 1121 to 492 us (table below).

With this change, the next render of the same VM on a pass slot gets the slot's owner epoch (the lease Pools already
keeps until a replacement retires) without a reseed or InitBM, if that epoch's render retired normally and was exposed.

InitBM binds the device-wide pass slot to one epoch and VM, so the epoch is reused only while no other epoch was handed
to the slot since. Reusing it after another VM's render on the slot leads to a firmware recovery and a wedged GPU under
gpubench-stress queue.exhaust (tested). After a failed or aborted render, and after any firmware recovery (also one
that resumes and did not affect the render), the next render on each slot starts fresh too. SUBMIT still allocates a
fresh epoch for every render, so one is always at hand. Renders are bound, published and retired one at a time, so
whenever reuse is allowed the slot's owner is the epoch the slot is bound to.

Apart from the in-flight render's handle (dropped when it retires or fails), nothing here holds a reference of its
own: a slot's binding is tracked by a counter, and the reused epoch is the owner lease itself, so no epoch, VM or
admission permit lives longer than it does without the change. A host test in test-resources.py covers when an epoch
may be reused and that nothing but the owner lease holds it.

Reuse is on by default; aurora.g16_pb_reuse=0 restores a fresh epoch and InitBM per render. Pools gets the flag from
its callers, so pools.rs keeps building in the asahi-m4 host harness, whose Arc mock gains ptr_eq.

Testing

J604 (Mac16,1), GPU firmware 25G83, the installed Aurora userland (Mesa vulkan-aurora 26.3.0 devel), unattended trial
boots of integration/aurora 673f618 + this change (the tested build differs from this commit only in comments and
the commit message). Same kernel, g16_pb_reuse=0 vs the default (1).

gpubench core-a (Vulkan), no desktop session, power-profiles-daemon's performance profile (Omarchy's choice on
AC), median us per submit, two boots per setting (the second one is the error-path boot below):

Test g16_pb_reuse=0 =1 (default)
render.light tri, depth 1 1121 / 1131 492 / 495
render.light tri, depth 8 984 / 909 312 / 318
render.light tri, depth 64 940 / 912 302 / 329
render.light clear, depth 1 330 / 260 267 / 326
compute.light, depth 1 263 / 263 267 / 263

render.light clear at depth 1 varies between boots by up to ~70 us with either setting; compute.light does not use a
PB.

  • gpubench-stress (all tests, 300 s, --kernel-log): the same with 0 and 1: 11 pass, 5 skip (one queue, no sparse
    residency, no ray query), and queue.exhaust ends in the graceful ENOMEM on submit (gpubench counts it as failed
    for that kernel-log line). No firmware recovery or GPU fault.
  • Error paths, with a local fault-injection change that is not part of this PR (stress, life.churn and core-a with
    every 97th completed render reported as failed to the reuse bookkeeping only (the job itself completes) and every
    89th render deferred with EAGAIN after its slot was bound): 1699 injected failures and 86 deferred fresh bindings
    were each followed by a fresh epoch with InitBM on that slot, never by a reuse; 1786 deferred reuses were retried.
    No firmware recovery or GPU fault, stress results as without injection, the same with 0. A render held past the
    5 s deadline is aborted the same way with 0 and 1 (firmware recovery, the render class stays unavailable until
    reboot).
  • Recovery: the render abort above goes through a firmware recovery that completes (the device stays up, only the
    render class is marked failed); recover() now also resets reuse on both slots there, but the render class stays
    unavailable afterwards, so no later render shows the effect. I found no recovery after which renders continue: a
    compute dispatch past its deadline (with another client rendering) fail-stops the device without a firmware
    recovery, the same on the previous revision. The reset itself (Pools::invalidate) is covered by the host test.
  • Lifetimes: vm_bindings in the debugfs stats around 20 short-lived life.churn clients, measured the same way on
    this commit with 0, with 1 and on the base: with the desktop session running it goes from 5 to 6 live (the slot's
    owner lease) and stays there; without it, 1 is left afterwards. The same on all three.
  • Desktop, logged into Omarchy's Hyprland at 120 Hz: wp_presentation frame pacing holds 120 fps in a window and
    fullscreen with both settings, also with blur at 2 passes. glmark2-es2-wayland scores 485 with 0 and 983 with 1,
    with no faults.
  • tools/asahi/run-host-tests.py in an Ubuntu 24.04 container with CI's toolchains: 260/302 on this head and on the
    base, no test failing only with this change.

Assisted-by: LLM

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

@aeries0x Two things before we take this. Pools now keeps an Arc of the last bound epoch per slot even with the parameter at 0, which keeps that VM's state and admission permit alive until another render uses the slot; please drop those references when the VM goes away or when the submit fails before publication. And if the stress results hold, we would rather have the reuse on by default than behind a parameter; is there a case you know of where it must stay off? We will run the default and =1 cases on an M4 Pro.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Results with the parameter at its default (0), on our J616s (M4 Pro, G16S), merged on integration e661192 as a one-shot test kernel:

  • glmark2-es2 (short run): 22093, against 22736 on the production kernel. That's within what one short run varies by.
  • Vulkan api.smoke: 8/8.
  • No GPU faults or recoveries, 0 DART faults, 0 AVC.
  • 3 s2idle cycles completed cleanly.

We haven't run the =1 case yet. The two questions above (dropping the retained epoch references when the VM goes away or a submit fails, and whether the reuse should be on by default) are still open. We'll merge once those are settled and we've done an =1 run.

Every G16 render gets a fresh parameter buffer epoch at SUBMIT and an
InitBM ahead of its TA work, so the firmware rebuilds the allocator
state for each render. Reusing the epoch instead cuts a small triangle
render at queue depth 1 on a base M4 MacBook Pro (J604) from 1121 to
492 us.

With this change, the next render of the same VM on a pass slot gets the
slot's owner epoch, without a reseed or InitBM, if that epoch's render
retired normally and was exposed. InitBM binds the device-wide slot to
one epoch and VM, so this happens only while no other epoch was handed
to the slot since; after another VM's render on the slot, after a failed
or aborted render, or after any firmware recovery, the next render
starts fresh. SUBMIT still allocates a fresh epoch for every render, so
one is always at hand. Renders are bound, published and retired one at a
time, so the slot's owner is the epoch it is bound to whenever reuse is
allowed.

The reused epoch is the slot's existing owner lease, so this holds no
epoch, VM or admission permit beyond what the lease already holds: a
slot binding is tracked by a counter, not by a reference. A host test
covers when an epoch may be reused and that nothing else holds it.

aurora.g16_pb_reuse=0 restores a fresh epoch and InitBM per render.
The stats line counts reused and fresh bindings.

Assisted-by: LLM
Signed-off-by: Friedrich <261542475+aeries0x@users.noreply.github.com>
@aeries0x aeries0x changed the title drm/asahi: g16: optionally reuse a pass slot's retired PB epoch drm/asahi: g16: reuse a pass slot's retired PB epoch Nov 13, 2026
@aeries0x

Copy link
Copy Markdown
Contributor Author

Thanks for testing on the J616s. Pushed a new revision for both points.

References: the change adds no reference to Pools. A pass slot's binding is a counter now (each render keeps the count it was bound with), and the epoch that gets reused is the slot's owner lease that owners already keeps until a replacement retires. That lease is the one reference left after a VM goes away or a submit fails before publication, with 0 or 1 alike, and it is the base's: InitBM bound the slot to that epoch, so it stays until a later render on the slot replaces it, which this change does not alter. Measured the same way on this commit with 0, with 1 and on the base kernel, vm_bindings goes from 5 to 6 live after 20 short-lived clients with the desktop running (1 left without it) and does not grow further.

Default: now on, with g16_pb_reuse=0 kept as a way back. I don't know of a case where it must stay off, but I have tested only on the J604 (firmware 25G83): stress the same with both settings, no recovery or fault, including the many-clients queue.exhaust case that broke an earlier local version, and injected failures on the reuse paths always followed by a fresh epoch. Your M4 Pro run would be the first run with reuse on another machine. If you'd rather drop the parameter entirely, I'll remove it.

Also new: any firmware recovery, also one that resumes, makes the next render on each slot start fresh, and a host test in test-resources.py covers when an epoch may be reused and that only the owner lease holds it.

The numbers in the description are from this change on top of 673f618 (the tested build differs from the pushed commit only in comments and the commit message). I have not tested suspend with reuse on; if your M4 Pro run includes s2idle again, that would be the first one with the default.

@aeries0x

Copy link
Copy Markdown
Contributor Author

A correction to the desktop line in the description: "also with blur at 2 passes" measured nothing extra. Omarchy ships blur off and blurs only behind see-through surfaces, and the test window was opaque. Measured again with Omarchy's Glassy look (every window 75 % + blur 2 passes), same kernel (673f618 + this change), a 900x600 client pinned in front, 15 s per row, performance profile:

scenario g16_pb_reuse=0 default (1)
idle terminals behind 40.1 fps 60.7 fps
a terminal scrolling 30.0 50.9
workspace switching 37.4 58.6
windows opening/closing 36.1 56.2

Hyprland does ~19-27 renders per frame there. With the default look (no blur) it is 120 fps with both settings.

@davishann15-commits

Copy link
Copy Markdown

Tested on a J604 (MacBook Pro 14", M4, Mac16,1; os-fw 26.6.2, system-fw 27.0; aura 1.0.0b13). The kernel was alarm-aurora's pkgrel 38 recipe on integration/aurora 7c71d6d, plus #1543, #1894, #1895, #1917, #1918, #1919 and #1922. It booted on its own J604 tree as an aura-try trial. Userspace: Hyprland 0.57.2, mesa-aurora 26.3.0_devel.202611130318, speakerguardd-v2 1.0.0alpha.1-40.

glmark2-es2-drm --off-screen at 3024x1964, with Hyprland running, two runs:

scene 2129f55 (no #1543), this morning, no desktop this kernel, Hyprland running
build 512 fps 685 / 677 fps
shading (phong) 509 fps 667 / 667 fps
refract 50 fps 81 / 82 fps
score 356 476 / 474

No GPU fault or recovery line in the log. This is not a same-boot A/B: g16_pb_reuse has no sysfs node (its permissions are commented out), so it can only be set at boot. The two kernels also differ by everything between 2129f55 and 7c71d6d. Treat the gain as an indication rather than this PR's own number.


Disclosure: an LLM (Claude) ran these tests on my Mac and drafted this. I did the listening and looking, reviewed it, and am responsible for it.

Assisted-by: LLM

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-ran our J616s row on head cdb7d9c, now with the parameter at its new default (1): cherry-picked onto integration/aurora fc05050, one-shot test kernel, SELinux enforcing.

The J616s (T6040) binds the G17 backend (apple,agx-t6040 -> ProbeConfig::G17), and g16/ only binds apple,agx-t8132, so the epoch reuse itself doesn't run on this Mac. This is a no-regression row for the shared asahi_core.rs change; the reuse needs a T8132 (J604/J713) row.

production kernel this kernel
gpubench render.light, depth 1 / 8 (median us/submit) 111.5 / 25.3 114.2 / 25.3
gpubench compute.light, depth 1 102.8 99.3
gpubench-stress --all 30 s 16/17 (queue.exhaust: one ETIMEDOUT, lost device) 17/17, queue.exhaust PASS
glmark2-es2-wayland off-screen (build, phong, refract) 13980 15397

0 GPU faults, firmware crashes or recoveries, 0 DART faults, 0 AVC. One s2idle cycle completed, and render.light afterwards was 117.5 us at depth 1. The production queue.exhaust failure was one run on a kernel without this change, not something this branch fixes.

@aeries0x

Copy link
Copy Markdown
Contributor Author

J604 (M4, G16G) results for cdb7d9c, GPU firmware 25G83. I cherry-picked it unchanged onto integration/aurora
c0a2a75 and reverted #1888 locally, because our test kernels keep the speaker path off. The same kernel was
booted once with aurora.g16_pb_reuse=0 and once with the default. No desktop session, performance profile.

=0 =1 (default)
gpubench render.light tri, depth 1 / 8 (median us/submit) 1042 / 842 425 / 233
gpubench compute.light, depth 1 (us/submit) 363 304
gpubench-stress --all 30 s 11 pass, 5 skip, queue.exhaust FAIL 11 pass, 5 skip, queue.exhaust FAIL
glmark2-es2-drm off-screen score (build, phong, refract) 440 697

compute.light does not use a PB, so its difference is boot-to-boot spread. queue.exhaust ends in the driver's ENOMEM
on submit, and --kernel-log counts that log line as a failure. Without --kernel-log it passed on the =1 boot.
The skipped tests need a second queue, sparse residency or ray query.

No GPU faults, firmware crashes, recoveries or DART faults with either setting.

I also ran 6 s2idle cycles with =1 on a third boot of the same kernel. All resumed. Four slept 1 to 9 minutes and
woke on a key press. Two woke on their own within 2 seconds. render.light tri at depth 1 was 421 to 441 us after
each resume, and the kernel log stayed clean.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Tested on J773g (Mac mini M4, 24 GB): a large win, and no regressions in what I ran.

Kernel 7.3.0-ARCH-m4gpu1: linux-aurora pin 9125b31 + #1898 + #1191 + #2232 + the T8132 apple-pmp-thermal cluster fix. Arch Linux ARM, Mesa 26.3.0-devel d4ad4a4dce. Stock module against stock + this PR (cherry-picked clean, g16_pb_reuse at its default 1). The test module also carries #2239 (the J773g S10 top state). That changes only the GPU clock (1470 → 1578 MHz), so ALU-bound rows move about 7% from it alone. The render rows below move far more than that.

gpubench c36cbbe (Vulkan, KWin running, headless), median µs per submit, best of the passes:

test stock + #1543 ratio
render.light tri d1 1351 740 0.55
render.light tri d8 992 331 0.33
render.light tri d64 1000 292 0.29
render.light clear d1 / d8 319 / 272 324 / 266 ~1.0
render.heavy fill 720p d16 1163 533 0.46
render.heavy fill 1080p d16 1389 786 0.57
render.heavy fill 2160p d16 2632 1894 0.72
render.heavy geom 1080p d16 1405 807 0.57
render.tvb 8192 tris d4 2101 1454 0.69
compute.light d16 (no PB) 261 260 1.00

Correctness:

  • A 1/16 sample of the Vulkan CTS 1.4.7.1 mustpass ran on this module: 198,732 cases (84,183 Pass, 114,548 NotSupported, 1 QualityWarning api.object_management.alloc_callback_fail.descriptor_set_layout_empty), 0 Fail/Crash. WSI was excluded; it ran headless at 6 jobs.
  • Over the whole session: 0 GPU faults, recoveries or fail-stops, KWin compositing on the GPU throughout, and a clean Geekbench 6 Vulkan run.

Open, not attributed: gpubench render.light --mode procs at depth 16 hits the graceful submit failed ... ENOMEM on stock too. Once, with this PR, that case then stalled with the GPU idle and was never resumed. I couldn't reproduce it: two later runs of the case alone and of the whole multi chunk passed. I'll report back if it shows up again.

🤖 Generated with Claude Code

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Correction to my J773g report above: the render.light --mode procs depth-16 ENOMEM and the one "stall" came from my harness, not this PR or the driver.

My benchmark ran in a systemd unit with MemoryMax=8G. GPU buffer memory is charged to that cgroup. With 16 rendering processes it hit the limit: the kernel logged submit failed ... ENOMEM, then memcg OOM killed a gpubench process and systemd stopped the whole unit.

Run without the cap, or under 20 GB, the case passes, with stock and with this PR. Nothing is open against #1543 from my side.

🤖 Generated with Claude Code

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Tested on the J773g Mac mini (M4, G16G B0) as the base of #2419, which stacks on this commit: with it, almost every render reuses its slot's retired epoch (30,582 reused / 114 fresh over a gpubench round), and Vulkan CTS 1/16 (84,219 Pass, 0 Fail) and the public GLES/EGL plan (0 Fail) are clean on the stack. #2419 also keeps never-exposed epochs for the next render, which takes render submit CPU from ~190-435 µs to 35-46 µs.

🤖 Generated with Claude Code

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.

4 participants