Repository navigation
drm/asahi: g16: start-full render UMA pool with 5 s idle shrink - #3990
DjDeveloperr merged 5 commits into
Conversation
Back each base G16G render allocator private UMA pool with a permanent 8 MiB (2048-page) base plus six detachable 4 MiB (1024-page) pieces (32 MiB / 8192 pages full at creation) so the first render of any newly opened heavy client starts with the full 32 MiB pool and avoids 0x70 recovery. After 5000 ms of VM render quiescence, a system_unbound delayed work item checks per-allocator firmware-cache safety (never-published allocator, displaced hardware UMA slot, or GFX idle power-off) plus circular ring settlement and detaches the six 4 MiB pieces, updating descriptor head, tail, seeded count, and ROW_WORDS (+0x48) and returning 24 MiB per shrunk base allocator (up to 48 MiB per idle rendering VM). Shrunk pools stay at 8 MiB for light desktop compositing and re-grow proactively via circular-ring append in Cache::prepare() when heavy signals fire (batch or in-flight demand >= 4, extension render tier, PB heap growth, or per-render ring churn > backed / 2). Add unit tests for the shrink/re-grow ring invariants and production Allocator/Pools lifecycle in the asahi-m4 host selftest suite. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Review at 052bc063cd9b. The close and suspend handling, the preparing_renders window and the lock order (ready, then the device state) look right, and the ring math holds. The firmware-cache part does not, so this can't merge as it is.
Must change
- Re-grow rewrites a live descriptor with no firmware-cache check.
uma_shrink_idle()only runs afteruma_slot_shrink_safe().uma_regrow_one()writes the same+0x24,+0x2cand+0x48words plus thelistrows on any quiescent submit. By then the slot is published, and usually neither displaced nor powered off. On main this descriptor is ASC-cached (FwCoherent), its rule is no host store after publication, and main deliberately doesn't readCOMPLETEDfrom it (flight_retired()). A stale or written-back line loses the append, or takes back the cursors. Re-grow needs the same rule as shrink, or a second descriptor the firmware can't name (what #3695 does for compute). - "GFX power-off makes the ASC reload the descriptor" has no evidence here, and the check doesn't hold. The slot table and the cached lines are on the ASC side, not in the GFX domain. The state lock is also dropped before the rewrite, so another VM's submit can wake GFX in the middle of it. Getting the shrink side wrong means free-list entries that point at unmapped pages. Please either drop this branch or show the reload on the 26B123
FwCoherentmapping, with the check held across the rewrite. The J604 runs usedfbc7693b7, which isn't public, and your Not yet says theFwCoherentmapping hasn't run. - On main it mostly just polls. GFX stays on at idle on main (#3697 measured it on in 32/32 control windows), and with a few VMs a slot is never displaced. A published pool then never shrinks, and
shrink_idle_uma()returnsRetryAfter(1000)forever: a 1 Hz wakeup that takes the device lock and reads the PMGR on an idle desktop. Re-arm from an event (displacement, power-off), not a timer. - It adds a smaller pool than main has. Main already seeds the base pool with 32 MiB (
uma_manager::SEEDS= 8192), so starting full isn't new. What's new is that after 5 s idle a client has 8 MiB, about 736 pages above your own 1312-page reserve. The first heavy render after that gets no growth:churnis only learned while shrunk, and only from renders that already ran. A client that keeps renders in flight is never quiescent at submit, sodemand >= 4from in-flight work only recordswant. Please keep the high-water mark from before the shrink, and grow before the first render of a VM that has needed more.
Scope: this backend also runs T6030 (G15S) and T8122 (G15G). Placement::Base is shared, so they get the shrink too. Risk and Tested only name M4.
Wording: on main 0x70 is the first render pair's TA event, not a recovery. Please say what actually failed. Named fields instead of UMA_SHRINK[7] would help too.
Checked on main 2c667a4b + this head: drivers/gpu/drm/asahi/ W=1 builds, asahi-m4 host tests 27/27, g16 host tests 2/2, checkpatch --strict clean. No textual conflict with #3340; #3695 and #3699 conflict with it in test-resources.py, and #3697 decides whether the power-off branch can run at all. #2700 is USB only. Hosted host-tests, apple-build and KUnit show as skipped at this head, so nothing ran in CI.
Rows at the next head: J773g (T8132) and J516s (T6030) on 26B123. Each needs: 8 or more render clients open and closed, 6 s idle and then one heavy render, pipelined load after idle, s2idle and deep sleep while shrunk, a recovery while shrunk, the uma_shrink: line before and after, idle wakeups vs base, 0 GPU faults, 0 recoveries. One T8122 boot from a peer.
There was a problem hiding this comment.
Verdict: REQUEST CHANGES at 052bc06
Failure: In pools.rs, a shrunk UMA pool can be published again by a small render. A later quiescent submit with growth demand enters uma_regrow_one() and rewrites that same published descriptor and its freelist. The growth path only checks host-side quiescence and does not apply the firmware-cache ownership check that shrink uses. This violates the existing no-host-store-after-publication rule for the ASC-cached descriptor. Guard both operations with the same valid firmware-ownership boundary.
Failure: In resources.rs, a published pool that still owns its slot with GFX on makes shrink_uma() report retry. shrink_idle_uma() then returns RetryAfter(shrink_ms.min(1000).max(100)). A quiescent published pool kept in its slot therefore keeps waking and checking the device every second, even with no further render or ownership transition. Re-arm on a change that can make it safe to shrink.
Checked: Reviewed the new shrink and grow paths against the existing published-descriptor lifetime. The maintainer’s exact review records the matching cases and the base behavior.
Address review feedback on G16 render UMA idle shrink and re-grow: - Enforce the same FwCoherent firmware-cache safety rule on both shrink and re-grow: hold shared.state across Pools::uma_slot_fw_safe() and all descriptor/list/ring reads and writes so a live ASC-cached descriptor is never modified or read while retained in firmware. - Drop the unproven GFX-power-off safety branch; rely strictly on verified slot displacement (retained_uma[k] replaced by another lease) or never-published allocators while holding shared.state. - Replace 1 Hz RetryAfter(1000) idle polling with event-driven re-arming: return WaitEvent for undisplaced idle VMs (0 Hz idle wakeups) and re-arm uma_shrink when Pools::retire_flight() displaces a previous RenderUmaLease. - Track and preserve each allocator pre-shrink high-water mark (both heavy demand while full and pre-shrink ring churn) so a heavy VM immediately pre-grows back to 32 MiB before its first render after idle while its slot is still displaced. - Replace UMA_SHRINK[0..10] indices with named UmaShrinkStats fields, update scope comments for shared Placement::Base on T6030/T8122, fix 0x70 TA event wording, and expand host unit tests to cover all four behaviors. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
@DjDeveloperr Thanks for the detailed review. Pushed forward commit
Verified offline at
Live 26B123 hardware rows at |
There was a problem hiding this comment.
Verdict: MERGE at c6903ad
Checked: Both growth and shrink now keep the GPU state lock across the slot ownership check and the firmware-cached descriptor and ring accesses. A published allocator needs an idle, displaced slot. The preparation and in-flight checks keep host and firmware ownership separate during regrowth. The five-second idle window arms once, and a pool still retained in its slot waits for a displacement event. The exact resource suite passed 92 cases, and the direct UMA suite passed all seven, including high-water regrowth and slot-displacement safety.
A shrunk pool could only grow again while its VM looked heavy and firmware did not hold its descriptor. Firmware takes the descriptor with the first publication and keeps it until another lease retires on the same slot. With 16 warm slots that may be never, so a VM that was light when it came back from idle rendered with 8 MiB for good. Neither a quarantine nor another VM's render in flight on the slot let a heavy one grow either. The estimate of who is heavy did not work: the ring cursor wraps at 16384 pages, so 600 renders of 4000 pages each read as 13 pages per render. Restore the full 32 MiB in Cache::prepare() before it accepts a render and fail the SUBMIT if that fails, as it already does for the arena itself. Only an idle VM holds a shrunk pool now, so the high-water, demand and churn heuristics go. Both directions now put the pool back to its state at creation, the whole descriptor but for COMPLETED, instead of patching the fields that name the pages and keeping the rest of what firmware saved there. Firmware can't reach a descriptor that is neither retained nor held for a publication on its slot, whatever else runs there, so that alone is the check for both directions. A published descriptor on a slot without a retained lease no longer passes it. The check reads the published flag under the device lock. Every displacement also armed the shrink work after 1 ms, which walked all VMs and took their locks for each render that changed a slot's lease. A displacement ends in a completion, which arms the 5 s work anyway, so drop the extra event. A VM whose first render never ran no longer re-arms the work every 5 s. Signed-off-by: DjDeveloperr <hey@djdev.me>
A publication that fails before it is visible, for example with EAGAIN while a recovery is pending, dropped the slot's candidate VM, arena and UMA lease even when an earlier render of the same VM was still in flight there. That render then retired without them, so the slot kept naming the owner before it while firmware held the new descriptor, and the idle shrink would have taken a live descriptor for a displaced one. Keep them until the last render in flight on the slot has retired. Signed-off-by: DjDeveloperr <hey@djdev.me>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at dfcbdce1e48e: only the hardware rows are missing. I pushed two fix commits on top of yours (maintainer edits are on) instead of sending it back; your commits are unchanged.
What was still wrong at c6903ad356d6, all fixed now:
- A pool that came back light stayed at 8 MiB. The growth check only passes until the first publication. After that firmware keeps the descriptor until another lease retires on the same slot, and with 16 warm slots that may be never. A host test at that head still reads 2048 pages after 10000 heavy renders. A heavy VM that woke while another VM had a render in flight on its slot, or whose slot was quarantined, wasn't grown either.
44db68e57f7arestores the full 32 MiB inCache::prepare()before any render is accepted, and fails the SUBMIT if it can't. - The heavy-use estimate read nearly zero. The ring cursor wraps at 16384 pages, so 600 renders of 4000 pages each came out as 13 pages per render. With 1. it isn't needed, so the high-water, demand and churn code is gone. The cost is that a light VM is no longer kept at 8 MiB while it renders; only idle VMs save.
- Each displacement armed the shrink work after 1 ms (
poll.rs), which walks every VM and takes its lock. A displacement ends in a completion, which arms the 5 s work anyway, so the extra event is gone. - A second render that failed before it was visible dropped the slot's hold of the first one in flight (
cancel_alloc(), also on main). The slot then kept naming the owner before it, and the new check called a live descriptor safe to rewrite.dfcbdce1e48ekeeps the hold until the last render on the slot retires.
Smaller: the restore and the shrink now write the whole descriptor as at its creation (a saved +0x28 used to stay behind), the check reads published under the device lock, and a VM whose first render never ran no longer re-arms the work every 5 s.
My earlier points: 1 (firmware-cache rule on re-grow), 2 (power-off branch) and 3 (1 Hz polling) are settled; 4 (smaller pool than main) by the first fix; scope and wording are fine. I'm dismissing that change request.
Checked: lock order (ready, device state, pieces; no allocation or unmap under the last two), close, deep sleep (the work is joined before the stop), recovery and quarantine while shrunk. Merged with main: drivers/gpu/drm/asahi/ W=1 with the same 40 warnings as main, asahi-m4 27/27 and g16 host tests, checkpatch clean. Merged with #3695, #3699 and #3340: the same checks pass; the only conflict is added tests in test-resources.py. Ten one-line mutations of the fix each fail a test. No Apple material, no gates, no parameters. I updated the PR body.
Rows at dfcbdce1e48e: J773g (T8132) and J516s (T6030) on top of #3695, #3699 and #3340: shrink and restore with and without other clients, 24 clients opened and closed, pipelined load after idle, s2idle and deep sleep (J516s: s2idle) while shrunk, a recovery while shrunk, idle wakeups, render rows against base. max_ns in uma_shrink: is the time a wake-up pays per pool; it needs to stay within 8 ms (half a 60 Hz frame) for each. We run both. Your J604 row at this head is welcome, and so is a T8122 boot.
|
@DjDeveloperr Thanks for the review and for pushing |
|
J773g (Apple M4 Mac mini, Build & Arms (
|
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Forward-merged main |
|
Thanks for forward-merging |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed 5c74c6aa14cc. The render-prep guard and the firmware-held descriptor check cover the transition into publication. The base pool is restored before render acceptance, and detached pages are dropped after the device lock is released. The exact-head UMA helper tests passed 4/4. I pushed this merge, so the required approval needs another maintainer.
I would land #4035 first once its J773g and J516s A/B is in. It caps reuse of standby parameter-buffer epochs to avoid depth-64 submit churn. This PR changes a separate allocation and can follow on its own evidence. The current-head J604 and J516s runs should show reclaimed bytes across idle clients, the first-frame cost after idle, and recovery while shrunk. uma_shrink: max_ns measures both shrink and regrow, so record first-frame timing separately.
|
Thanks for the review at |
|
J516s (M3 Pro, T6030) at With four idle VMs, available memory was 13,415 → 13,553 MiB (+138 MiB). First verified frame after 8 s idle was 20.94 → 23.41 ms median (+2.47 ms), max 23.69 → 26.50 ms (12 samples per arm, head first). Maximum measured pool restore was 6.92 ms. The earlier v2 run exercised s2idle because its Stage 2 lacked the T6030 GP PCIe tunables. This v3 run verified real deep entry and wake on both arms. An independent maintainer approval is still needed at this head. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
No blocking findings at 5c74c6aa14cc89b724497a5754a902a59adc245d. I reviewed all ten files. Render preparation restores the full 32 MiB before accepting a base-pool render. I traced the firmware-lease check through publication, cancellation and retirement, and checked allocation failure and suspend-worker teardown.
The J516s idle-memory tradeoff is acceptable. The +138 MiB is system-wide MemAvailable. The boots started 65.8 MiB apart, leaving +72.4 MiB after adjusting for that difference. The counters independently show three additional 24 MiB pools detached at each idle sample. The receipt's +2.47 ms uses the upper middle of 12 first frames per arm. Averaging the two middle values gives 19.99 → 22.65 ms (+2.66 ms) after eight seconds idle. The 6.92 ms maximum occurred during a regrow and met the row's 8 ms bound. The checked clients survived recovery and both deep sleeps. I see no reason to change the idle delay or restore path. Paired hardware row
The J773g driver patch ID matches (97d38c0b5ff6). All ten files merge cleanly onto main 56a577e83350 with identical added and removed lines. I ran the UMA helper and resource suites on both trees: 4/4 and 105/105 at the PR head, 4/4 and 110/110 on the integration. GitHub readiness passed. The hosted host-test, Apple build/KUnit and PR-text workflows show action_required on the fork PR event.
What: A G16/G15 render VM that has not rendered for 5 s gives back 24 MiB of each base render UMA pool whose descriptor firmware can't reach (32 MiB down to 8 MiB). It gets them back before its next render is accepted, so no render ever runs with less than main's 32 MiB. A VM whose second pool never rendered (the usual case on a desktop) saves 24 MiB; one whose pools have both been displaced by other VMs saves 48 MiB.
Tested: offline at
dfcbdce1e48emerged withmain1ab453e8b404(tree1e89ff66a486):drivers/gpu/drm/asahi/W=1 builds with no new warning,asahi-m4andg16host tests pass,checkpatch --strictis clean. The same on top of #3695, #3699 and #3340.5c74c6aa14ccin candidatea1f8c4e0on main148f5ca2. Shrink/regrow, GPU recovery while shrunk, and two deep sleeps per arm passed. With four idle VMs, system-wide available memory was 138.2 MiB higher. Adjusting for the start-of-row difference gives 72.4 MiB, consistent with three additional 24 MiB pools detached. The conventional median for the first verified frame after 8 s idle rose from 19.99 to 22.65 ms (+2.66 ms). Maximum pool restore was 6.92 ms. Paired receipt.dfcbdce1e48e. The driver patch carries unchanged through the forward merge to5c74c6aa14cc. Earlier row and scope.Risk: two-way · M4 (
T8132) and M3 (T6030,T8122), which share theg16backend. No uAPI or parameter change. SCS pools and recovery arenas are untouched. A plain revert restores fixed 32 MiB pools.Not yet: memory savings on an idle desktop and with 8+ idle clients, an exact-head J604 run, and a T8122 boot.
Details
Pools::uma_slot_fw_safe(), with the device state lock held across the check and the rewrite).Cache::prepare()restores the full pool underCache::ready, before it accepts a render, and fails the SUBMIT with the allocation's error if it can't. SCS renders use their own pools and skip it.submitted.Evidence
At
dfcbdce1e48e(the author's two commits plus two fixes on top), no GPU used:main1ab453e8b404(tree1e89ff66a486, driver tree548995b0e37f;main5f32aa72fa7echanges nothing under the driver or its tests):make W=1 modules_prepare drivers/gpu/drm/asahi/on arm64 (gcc 16.2.0, rustc 1.100.1,CONFIG_DRM_ASAHI=m,CONFIG_DRM_ASAHI_G16=y) linksaurora.o, 0 errors, 40 warnings as onmain.bc7b1395, drm/asahi: g16: rebuild a drained compute UMA manager without reseeding its pool #3699e8a8a9bcand drm/asahi: g16: widen compute concurrency to 64/16 and cache shared UMA and fw_stamp #3340eb8c98e6(treeb666cedc2aa4): the same build, 0 errors, 39 warnings as without this PR. The only textual conflict is intest-resources.py, where both sides add tests at the same place.run-host-tests.py --only asahi-m4(27 scripts) and--only g16pass on both trees, in thehost-tests.ymltoolchain (ubuntu 24.04, rustc 1.96.0).test-resources.py: 92/92 on themainmerge, 105/105 on the other.checkpatch.pl --strict --ignore FILE_PATH_CHANGESon both fix commits: 0 errors, 0 warnings, 0 checks.c6903ad356d6the same scenarios leave a pool at 2048 pages after 10000 heavy renders, and at 2048 pages for a heavy VM that wakes while another VM has a render in flight on its slot.