perf(agc): take the retire registry snapshot only when a shadow reads it #26179
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26179"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-23T11:48:15Z.
What
Builds on #25963, which is merged: this branch is that PR's head (
86765d3651) plus two commits, so the diff against main is those two commits. It extends #25963's skip from the unit-shadows-off case to the default path. The branch is not rebased onto today's main; it merges cleanly with main7db4926943.When a guest
munmapormprotectwaits for an unpinned range,WaitForLeasesAndImportsretires the host imports over that range. Before each retire pass it copied the registry (GuestAllocationsAcquireRegistered). While the registry holds retiring ranges that call walks every range and copies ashared_ptrfor each one. The profile in #6453 (PPSA01474, the scene change that remaps memory through AMM command buffers) has that copy at 50 % of the main thread, and its A/B with the copy skipped underAPS5_NO_UNIT_SHADOW=1gives 34, 35 against 51, 46 presents in the first minute.The copy has one reader: the coverage test that
RetireShadowruns for a live unit of the import's unit shadow. An import with no shadow, or with a shadow that has no live unit, never reads it. #25963 uses that for the case where unit shadows are off. This PR uses it for every pass:RetireShadowReadsRegistered(import)answers with the same conditionRetireShadowapplies before it calls the coverage test (shadows on, a shadow exists, a live unit with a non-empty range).retireImportsOver, shared by both sites) starts without a snapshot. When it meets an overlapping import whose shadow would read one, it leaves the import table's mutex, takes the snapshot, and walks the table again from the start. That happens at most once per pass. Imports retired before that point did not need the snapshot.The part that carries the risk, stated plainly:
RetireShadowalready uses insideretireImport.MarkShadowed).The
[address-sync]profile line gains two counts: retire passes that took the snapshot and passes that retired imports without it.Tested
agc_host_import_retire_snapshot(mock device, Linux, needs/dev/udmabuf): an unmap retires an import with no shadow, with a shadow that has no live unit, and with a live unit, each with the device lock free and held, so both retire sites run. Only the live unit takes a snapshot, and its results are copied into the import before the buffer is destroyed. The test fails when the check answers no for a live unit, when the pass always takes the snapshot, when the snapshot is taken but not handed to the retire, and when the counts are not kept.agc_host_import_sparse_testspasses in both modes;tools/check_conventions.py,tools/debt_fold.py --check,tools/env_reference.py --checkandtools/check_test_registration.pypass.APS5_PROFILE_DRAW=1, the[address-sync] leasesline), Linux, RTX 4090. PPSA04263, a 420 s route replay with 290 s of gameplay: 378 pin-contention waits, retire registry snapshots 0 taken, 227 skipped. PPSA21564, 240 s of a level: 7 waits, 0 taken, 5 skipped. No retire pass met a shadow with a live unit in either title, so every pass on the default path skipped the copy; the path that takes the snapshot ran only in the new test. These are counts from single runs, not a paired frame time comparison._WIN32lines of the waiter, which this change does not touch.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T12:23:17Z.
Review: COMMENTED
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T12:38:06Z.
Review: APPROVED
Windows check of head
6520616bd2with GCC 16 on an NVIDIA and an AMD GPU, merged ontomain071799dc88(clean merge), and a read of the retire pass. The newagc_host_import_retire_snapshotneeds/dev/udmabuf, so it skips here. This is a regression check of the shared retire path on Windows, which also runsreleaseSettleRetiredafter it.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). This was built together with #26096, #26174 and #26178, which touch other files.agc_host_import*, the unmap, retire andmprotecttests and the unit-shadow tests (^(agc_host_import.*|agc_.*unmap.*|agc_.*retire.*|agc_.*mprotect.*|agc_driver_unit_shadow.*|agc_unit_shadow.*)$):main23 of 23, and with this PR 24 of 24 in 2 of 2 runs, on both GPUs. The only skips areagc_host_import_sparseand the newagc_host_import_retire_snapshot, which need/dev/udmabuf. NoVUID-lines.The code:
RetireShadowReadsRegisteredasks the same thingRetireShadowdoes before it calls the coverage test: shadows on, a shadow found, and a live unit with a non-empty range. A live unit whose range is empty is dropped either way (RetireShadowdrops it without asking), so skipping the snapshot for it changes nothing. InretireImportsOver, the imports retired before a restart were ones that didn't read the snapshot, so retiring them with the empty lease is equivalent. The restart happens at most once, becauseleasedstays set. mihiii1337'sliveUnits == 0early-out would cut the extra walk for idle shadows without changing any of this.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T14:11:33Z.
Review: COMMENTED
Reviewed follow-up head
92ce50f1e50e42c51de2397ca3af676e939dec1bagainst the previously reviewed6520616bd2. The only new implementation change is the requestedshadow->liveUnits == 0early-out underregistry.mutex, so an idle shadow no longer incurs the O(Units) scan on every overlapping retire pass. That resolves my source-level concern, and the current head has green Windows, portability, conventions, eligibility, PR and report checks.I am not treating the performance evidence gate as cleared: the existing
perflabel bot still asks for pairedaps5-summary.jsonllines, traces, andtools/trace_digest.pyoutput from the same title/scene/machine. That is separate from this resolved source concern.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T14:55:43Z.
Review: APPROVED
Follow-up on Windows for head
92ce50f1e5, which adds theliveUnits == 0early-out.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). Merged ontomain26508fa3f9(clean merge), built together with #26174 and #21948, which touch other files.agc_host_import*, the unmap, retire andmprotecttests and the unit-shadow tests:main23 of 23, and with this PR 24 of 24 in 2 of 2 runs, on both GPUs. The only skips areagc_host_import_sparseandagc_host_import_retire_snapshot, which need/dev/udmabuf. NoVUID-lines.The change:
liveUnitsis read under the sameregistry.mutexas the unit walk, and a shadow with no live unit has nothing forRetireShadow's coverage test to keep. So the answer is unchanged, and an idle shadow costs nothing more. No test can tell the early-out from the walk, so the runs only show the retire path is unchanged on Windows.AI-assisted: yes (Claude Code)