Repository navigation
drm/asahi: g16: rebuild a drained compute UMA manager without reseeding its pool - #3699
Conversation
A VM's shared compute UMA manager lived in a per-VM ASC-uncached
object next to its host-written counter. The firmware saves and
unbinds a manager whenever a command finishes with COMPLETED equal to
the counter. A client with one job at a time (8 processes in
compute.light procs) paid a save and a rebind on every job, with
every access to the manager uncached.
Map the managers as macOS 26B123 does. In the J773g Metal procs-d8
snapshot, each of the 8 compute managers
sits alone on its own page with leaf 0x443 (ASC write-back), each
counter is on a separate page, and an idle manager's counter equals
COMPLETED.
- Each hardware compute UMA slot gets two device-lifetime manager
records, ASC-cached on their own pages and never freed: 1 MiB for
all 32 slots, allocated on a slot's first use. The host rewrites
only a record that the firmware's slot table cannot name, so each
slot needs a second record.
- The counter stays on an uncached page of its own. While the
manager has commands in flight it runs one past the submissions,
so the firmware never saves the manager. When the manager's last
command retires, the counter drops back to the submission count.
An idle manager stays bound with its cursors in the hardware, and
its counter equals COMPLETED, as on macOS.
- The firmware's bind loads only the incoming record and never saves
the outgoing manager. In 26B123, the save runs only past the
COMPLETED == *counter gate. So the host tracks which manager each
slot holds:
- The same manager keeps its record, with no host write.
- Any other return waits for the manager's own commands to retire.
That covers another VM's manager or a private SCS unit taking
the slot, an idle power-down, a sleep and a recovery. The host
then rebuilds a record the slot table does not name, and reseeds
the drained freelist and pool rows with it.
- A private unit waits for shared commands in its slot.
- The slot ledger keeps only identities and counts. As before, a
closed VM's manager, pool and live-VM charge go when its last
flight retires.
- The host never reads the cached manager. Retirement uses two
receipts: the service stamp, which the firmware stores after its
last access to the command's work, microsequence and manager; and
the GPU end tick.
The firmware powers the GPU down after an idle delay, and that drops
the hardware state of a manager left bound. The host checks for this
only at a publication pass where it has nothing in flight and a
shared manager may be bound. It reads the firmware's powered flag,
which 26B123 and the T6030 firmware record, and treats every binding
as stale unless the flag shows the GPU powered. Firmware without the
flag keeps the GPU powered while it runs. Passes with work in flight
and render-only work read nothing.
Signed-off-by: DjDeveloperr <hey@djdev.me>
On J516s (T6030) the compute UMA idle check invalidated the held managers at nearly every publication from an empty engine. The G15S handoff byte at +0x638 does not read nonzero there while the GPU is powered, so each such job rebuilt its manager record and reseeded its 64 KiB freelist. compute.light procs d2 went from 43.6 to 56.6 us. The driver stats show the cost: about 5 us more prefix time per publication, and 14 us more for each publication after the engine drained. On J773g the byte reads 1 while the GPU is powered, so J773g was not affected. Trust the flag only after it has read nonzero at a publication pass with nothing in flight. The GPU is then idle and powered, and only a flag that tracks GPU power shows that. A flag that stays zero, or one set only while work runs, never earns trust and invalidates nothing, as on firmware without the flag. Bindings on such firmware rely on the GPU staying powered while the firmware runs, which holds on J516s and J773g today, and on the invalidation at system sleep and recovery. A change that makes such firmware power the GPU down must first make the flag earn trust. Report the residency in aurora-g16/stats as "compute_uma: rebuilds N invalidations M powered_flag 0|1". Signed-off-by: DjDeveloperr <hey@djdev.me>
The error path after the compute UMA counter write-back completed only the flight's own job with the error. Compute jobs folded into the flight's group were left with fences that never signal. Complete them with the error like the other fail-stop paths in retire_oldest. Signed-off-by: DjDeveloperr <hey@djdev.me>
… power off Compute UMA managers stay bound across short idle gaps under the in-flight hold, so their allocator cursors live only in the hardware, and a GPU power-off drops them. The previous check trusted the firmware's powered byte once it had read nonzero at idle. That byte is not a validated witness of continuous power: it reads zero on G15S, so nothing was ever invalidated there, and a byte seen high once does not prove that the GPU stayed powered. Decide from the power policy that boot actually sends instead. The session records it with the final boot control. START with a zero argument asks the firmware to wake the GPU and hold it powered, and the firmware then never powers the GPU off on its own while idle (measured on main: 0 of 16 checks off at 250 ms on J773g and J516s). Under that hold a bound manager cannot be lost while idle, so nothing is invalidated and the managers keep their fast reuse. System sleep and recovery still invalidate, as before. When a policy lets the firmware power the GPU off on its own, there is no qualified power-loss witness yet (a firmware power-loss generation, or a power hold that spans this check through the firmware's consumption of the next kick). So every publication pass that finds nothing in flight after retiring what it can, with a shared manager held, invalidates the held managers. Their next commands rebuild into the slot record that the firmware's slot table does not name. A pass with work in flight invalidates nothing, because a flight in flight keeps the GPU busy. A later change can replace this with a qualified witness. The change that releases the power hold must set the flag where it sends that policy. The flag is set next to the START control, so such a change conflicts with this one visibly instead of silently. Drop the powered-byte heuristic and its stat. The stats line becomes "compute_uma: rebuilds N invalidations M idle_invalidations K". Signed-off-by: DjDeveloperr <hey@djdev.me>
…ng its pool When a shared compute UMA manager's binding may be gone (it was displaced, or the GPU may have powered off while idle), its next command rebuilds its manager record. The rebuild also rewrote all 8192 freelist records (64 KiB of uncached writes) and the 16 pool-table rows. When the firmware may power the GPU off on its own, every publication with nothing in flight invalidates the held managers, so nearly every job after an idle gap paid for that. The freelist is a ring of 16384 records. The hardware takes pages at the head cursor and returns them at the tail cursor, and both wrap at the record count that bind loads with them. A rebuild restarts the cursors at their seed: head 0, tail 8192. Taking a page only reads its record; returning one writes the record at the tail. So after a restart, returns fill the records from 8192 upwards, and none reaches the first 8192 records before one has written the last record of the ring. Until then the first 8192 records still hold the seed, every page exactly once, and cursors at their seed describe the drained pool exactly, wherever the hardware cursors were. Pages the hardware still held when its cursors were lost do not matter: they are in the seed, and with no command in flight no page is in use. So the rebuild now reads two freelist records before it decides. The last record reads zero until a return reaches it: the freelist is zeroed when it is allocated, and a returned record holds a page address. The first record still holds the first seed unless taking a page wrote its record. If both hold, the rebuild writes only the 160-byte manager record and the 16 pool-row words. Otherwise it reseeds the freelist as before and clears the last record, so that a later rebuild can trust the seed again. Some events do not show in the freelist. A system sleep, a recovery, and a shared command that failed or was aborted advance a seed generation in the slot ledger, and the next rebuild of every manager then reseeds, whatever its freelist shows. Sleep and recovery call the new restart_compute_uma(), which also invalidates the bindings; the idle path still calls only invalidate_compute_uma(). On J773g, with #3695 and #3697 combined, skipping the reseed unconditionally (idle invalidations unchanged, about 179k per boot) measured: row as is no reseed no invalidation idle.wake 2/20/200 ms 175/272/539 145/193/458 142/192/458 compute queue d1 121.5 99.1 101.2 compute procs d2 67.9 59.0 58.3 That run passed the CRC smoke test 10/10 and the idle.wake stress with checked compute, with the GPU physically off in 16 of 16 checks and no faults. The reseed was the whole cost of the idle rebuild. This change skips it only while the ring has not reached its end since the last seed, which a run of short jobs between idle gaps never does. The stats line gains the reseed count: "compute_uma: rebuilds N invalidations M idle_invalidations K reseeds R". Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: HOLD at 61d33810
Blockers:
- Stacked on open PR
#3695: targets feature branchfeat/g16-uma-slot-records(not yet merged tomain; fullapple-build/host-tests/ KUnit CI suites have not run on this feature-branch PR). - Pending hardware rows & exact-head SHA record: per
Not yet, the J773g row onmainwithout#3697and the J516s row with#3697are still pending, andpr-readinessflagsHardware row at head: nountil a line naming head SHA61d33810with a Mac and result is recorded.
Checked:
- Audited all production changes (
drivers/gpu/drm/asahi/g16/poll.rs,recovery.rs,resources.rs,sleep.rs,slots.rs). - Verified
pool_stateandpage_listare allocated withClass::Shared+Client::nc(...), so CPUr64/w64reads/writes inuma_seed_intact()andreseed_uma_pool()are coherent with GPU/firmware writes. - Verified the freelist ring invariant in
uma_seed_intact()(r64(last_uma_record(seeds)) == 0 && r64(0) == pool): on a drained pool,records[0..seeds)hold every pool page exactly once whenever the tail never wrapped throughlast_uma_record(seeds)and the first seed remains intact, andreseed_uma_pool()clearslast_uma_record(seeds)when non-zero so later rebuilds recover the fast path. - Verified
uma_seed_gendistrust paths cover system sleep (sleep.rs->restart_compute_uma()), recovery (recovery.rs->restart_compute_uma()), affected shared-compute errors (mark_dirty()), and aborts (quarantine()), andSharedComputeUmaInner::init_record()updatesself.seed_genon initial bind and after every intact-check/reseed. - Combined J773g ABBA row (
#3699 + #3695 + #3697vs#3697:-6%to-9.7%compute.light,36,794dEQP-VK Pass with275,745rebuilds and2reseeds,0faults) and26/26host tests (4new) are clean; no code defects found.
Evidence
- Head SHA:
61d33810c21377716c86e62ce2f7fe2ada64c572(base=feat/g16-uma-slot-records,MERGEABLE,pr-textandreadinesspassed).
|
PASS — J773g (M4 mini, T8132 G16G) target row at PASS — J516s (M3 Pro, T6030 G15S) second-generation row at J773g on main (no #3697)Setup:
J516s with #3697 (M3 lead)The run compares
On every boot:
Counters per combined boot: On the earlier combined tree without this commit ( |
A recovery quarantines an aborted flight instead of retiring it, so its commands stay counted in the compute UMA ledger of its slot for good: uma_shared_flights, uma_private_flights and the manager's outstanding count. prefix_compute waits on those counts before publish_prefix_body checks the slot quarantine. An SCS command in a slot where a shared flight was aborted, and a shared manager rebuilding in a slot where a private flight was aborted, both returned EAGAIN forever. With nothing else in flight the publication deadline then expired with ETIMEDOUT and the whole GPU fail-stopped, where the job alone used to fail with EIO. Check the quarantine with the other admission checks at the top of publish_prefix_body, before any wait. A job's UMA mask is fixed when it is prepared and nothing in between changes the quarantine, so a job in a healthy slot takes the same path as before. The host tests run those admission checks over the real slot ledger after a shared and after a private flight is aborted in a slot. Signed-off-by: DjDeveloperr <hey@djdev.me>
There was a problem hiding this comment.
Verdict: HOLD at 106e864c
Blockers:
- Stacked on open PR #3695 (
base=feat/g16-uma-slot-records); retarget/rebase ontomainonce #3695 merges. - Hosted CI at
106e864cis still running (CI=PENDING). - Exact-head hardware confirmation at
106e864cis pending (posted J773g and J516s rows are at61d33810).
Checked:
- Verified
106e864cis a clean, conflict-free merge of #3695's421240d7(drm/asahi: g16: fail compute in a quarantined UMA slot before waiting) into previously audited61d33810(engine.rs,slots.rs,test-publication.py,test-resources.py), with no unintended changes to the drained-rebuild logic. - Verified J773g (on
mainand with#3697) and J516s second-generation rows posted at61d33810.
Evidence
- Diff
61d33810...106e864cmatches421240d7file-for-file (engine.rs+9/-3,slots.rs+3/-2,test-publication.py+0/-1,test-resources.py+140/-0). - Ready once #3695 lands, this PR is retargeted onto
main, hosted CI completes green, and head SHA is confirmed on hardware.
|
PASS — J773g (M4 mini, T8132 G16G) exact-head row at
|
There was a problem hiding this comment.
Verdict: MERGE at 106e864c4ffe
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - Verified 106e864c is a clean, conflict-free merge of #3695's 421240d7 (drm/asahi: g16: fail compute in a quarantined UMA slot before waiting) into previously audited 61d33810 (engine.rs, slots.rs, test-publication.py, test-resources.py), with no unintended changes to the drained-rebuild logic.
- Verified J773g (on
mainand with#3697) and J516s second-generation rows posted at61d33810.
Follow-ups (not blocking): Merge parent #3695 first; follow-ups: retarget, CI, head hardware confirmation
Main added the render UMA and PB record pools in g16/object.rs and g16/resources.rs, and their mocks in the asahi-m4 resources test, at the places where this branch adds the compute UMA manager records. Keep both sides; the test module imports UniqueArc for main's pools. Signed-off-by: DjDeveloperr <hey@djdev.me>
Main's "stop G15S in prepare and preserve firmware SRAM" sends START with argument 1 on layouts that record the GPU's power, so the firmware may power the GPU off while idle. This branch sent START with argument 0 and kept a flag saying so. Keep main's START: the flag becomes Session::idle_power_off(), the same layout test that now picks START's argument. Held compute UMA managers are then rebuilt after every idle gap on those layouts, and stay bound across it where the firmware holds the GPU powered. The rest are adjacent edits: main's per-pair render statistics, sleep_restart(held), and the queue_passed() and render-only mocks it dropped. Keep both sides. Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed 7cfc913 against the #3695 branch. Reuse is limited to drained managers whose uncached freelist still has both seed sentinels and an unchanged generation. Faults, aborts and restart force a reseed before reuse. The reported combined M3 and M4 rows support the optimization at their recorded revisions.
There was a problem hiding this comment.
Verdict: MERGE at 7cfc913
Checked: The merge preserves the production proof before reusing a drained pool. The generation plus first and last freelist checks determine whether reseeding is required. The rows are rebuilt on either branch, and a reset or stale generation forces a fresh seed. The updated fixture retains the base's read counters and the author reports all 26 Asahi M4 host suites passing. Merge the parent #3695.
…build Signed-off-by: DjDeveloperr <hey@djdev.me>
… recovery Dropping the in-flight hold at publication, or the freelist distrust in sleep_restart() or recover(), left every case passing. Check the three call sites and their order. Signed-off-by: DjDeveloperr <hey@djdev.me>
The base branch was changed.
|
New head
The push dismissed the approvals at Checks (local, pc): Not covered by any row yet: innocent compute in flight across a GPU recovery while its manager is held (the cursors are only in the hardware then), and a sleep cycle with managers held. Rows owed, together with #3695: J773g and J516s. T8122 has none; it keeps the GPU on, so only sleep and recovery invalidate there. |
There was a problem hiding this comment.
Verdict: MERGE at e8a8a9b
Checked: Compared the five G16 production patches relative to the old and new #3695 parents. The source additions and removals match in all five. The new publication and recovery assertions run against the exact source. The host suite passed 93/93. Removing the existing counter increment, sleep invalidation or recovery invalidation separately trips the new assertions. Merge parent #3695 first and land this immediately after it.
|
J773g (Apple M4 Mac mini, Build & Arm Identification
Results (
|
|
J516s (MacBook Pro 16" M3 Pro, Build & Arm Identification
Key Highlights (
|
The merge-base changed after approval.
|
Local check of the merge with main, 2026-12-03.
#3695 landed as Not run: the full host suite. |
What: Rebuild a drained G16 compute UMA manager without rewriting its 64 KiB freelist when the freelist provably still holds its seed. With #3697's firmware idle power-off, #3695 rebuilds held managers after every idle gap. Before this change, that rebuild cost about 75 µs per wake on J773g. With this change, the combined tree is faster than #3697 alone on every compute row. Contains #3695; merge that first.
Tested:
Risk: two-way · M4 (T8132) and M3 (T6030/T8122), which share the g16 backend.
Not yet: J773g and J516s rows at the current head, together with #3695. The earlier rows (J773g at
106e864c, J516s at61d33810) ran before #3695's merge with main's firmware-managed idle. No row has a GPU recovery with innocent compute in flight, or a sleep cycle. T8122 has none.Details
The freelist is a ring of 16384 records holding 8192 pages:
The rebuild reads those two records:
Events that don't show in the freelist always force a reseed: system sleep, recovery, and a failed or aborted shared command. Each advances a seed generation in the slot ledger. Sleep and recovery go through a new
restart_compute_uma(), and the idle path is unchanged.No parameters, no SoC gates. The stats line gains a reseed count:
Evidence
Setup:
42169a04, which has the samedrivers/gpu/drm/asahiase6c7b032.aurora.kofrom the lab mergelab/g16-uma-drained-on-36976f929cd5(drm/asahi: g16: keep compute UMA managers bound and ASC-cached #3695e85c6d2e+ this commit61d33810+ drm/asahi: allow firmware-managed GFX idle power-off #369798d103b8) vs drm/asahi: allow firmware-managed GFX idle power-off #369798d103b8alone.285776c6af, gpubench-vkae90a40, 600 ms warmup, 6 × 250 ms windows, two passes per boot.Every combined boot is faster than every #3697 boot on all rows except queue d1, where the boots overlap. Counters per combined boot:
rebuilds ~300k idle_invalidations ~177k reseeds ~5.2k.Bound measured before this change (same combined tree, one boot each):
So the reseed was the whole cost of the idle rebuild.
Correctness on every combined boot:
compute.uber uniformd4b022fbaf,render.postfx msaa=4d1/d2668d6f0a,render.bindless_ubo 512d21af53d5c,render.deferred tile msaa=4d26dc74b48.gpubench-stress-vk --test idle.wakepassed: render plus a checked compute ring in one device across 2/20/200 ms gaps.