perf(agc): re-check only the host imports a registry change can reach #9402
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9402"
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 janzezno on 2026-10-21T20:49:12Z.
What
refreshImportsre-checked every live host import, and every remembered failure and refusal, each time the guest allocation registry changed. A title that maps memory often pays that walk constantly. SuperTuxKart (PPSA69421) maps about 1650 times a second at its menu. With #8091's budget fix, about 440 imports (~1.1 GiB) stay live there, and the walk alone costs ~118 ms of CPU per second on the frame's critical path. The frame rate falls as the import budget grows: ~34 FPS with the default budget, ~48 FPS withAPS5_HOST_IMPORT_MIB=128.This PR makes the refresh incremental:
(address, bytes, weak_ptr)of every range in the lease it was last checked against. The snapshot holdsweak_ptrs because a lease pins its ranges: unmap waits whileuse_count() != 1.owner_before, assameRundoes). The result is the address spans whose ranges were added, removed or replaced, whatever mutation did it, including backing renewals.[base / window * window, max(that + window, base + bytes))) touches a changed span are checked again. These are found with alower_boundon the import map plus one predecessor; imports never overlap, aspeekImportalready relies on.importRun,exactRunandjoinedRunread only ranges inside that span. The scan carries a cursor across the changed spans, so each import is checked at most once per refresh even when several separate spans fall in one window.pendingImports); retiring an import removes its base, so the set never holds more than the live imports.checkis the only place either walk retires an import, so #8926's handling of retired imports (now onmain) sits there:checknotes the unwatched ranges of each import it retires, and those ranges go back in the write watch once after both walks.sameRun, so this is cleanup only.One behaviour differs, and it is recorded in
docs/dev/debt/libSceAgcDriver.md. An unchanged import whose run could now be larger, because a remembered refusal no longer holds, is kept until its window changes. A request that needs the larger run still retires it (wouldRetireImport). Onmain, any registry change anywhere retired it. Under a 128 MiB budget in SuperTuxKart,mainretired and re-made the same three still-valid single-range imports about 1650 times a second for this reason.New test
agc_windowed_import_refresh(128 KiB window, three windows):It passes on
mainand on this PR. It fails when the window query is narrowed tolower_bound(begin): "an import whose window gained a continuing range was kept".Two local probes (not in this PR) checked the review follow-ups:
Tested
Arch Linux (kernel 7.2.11), Ryzen 5 7500F, AMD Radeon RX 7900 GRE, RADV Mesa 26.2.5, on
main716cb74e08. SuperTuxKart (PPSA69421 00.001.000, catalog sha256f2240bf0…b712a), relinked with--trap-sdk-syscall-stubs. Main menu with no input, headlessgamescope --backend headless -W 1920 -H 1080,APS5_TRACE_SUMMARY_EVERY=10, 70 s runs. Each side's first run creates the game's configuration and starts in a different first-launch scene, so it only warms the shader caches and is not counted. Then four rounds of one run per side, main first. The FPS is the presents in the last 8 s of each run (VideoOut telemetry).Why #8091 is applied on both sides. On RADV, plain
mainlowers the import budget after memfd-backed imports are refused (#8091). The menu then randomly settles in a GPU-bound ~3 FPS mode, with GPU ~90% busy and a CPU nearly idle, or a fast mode with ~74 MiB of imports. Both sides do this: on plainmaineaff87674c, main ran 2.9 / 2.7 / 3.3 FPS and this PR 1.0 / 3.2 / 53.7 FPS. That noise hides the walk. Both builds below therefore carry #8091's one-line production change inimportRunAt. This PR does not depend on #8091.Round 1 started right after this PR's build finished (load average 12.7) and is slower on both sides, so it is listed apart; the fourth round was added for that reason. On the previous base
1e20650e84the same protocol gave 32.3 / 32.3 / 32.2 onmainand 39.7 / 38.5 / 38.5 with this PR, and onb7d1d47a5f37.2 / 35.9 / 36.8 and 51.8 / 54.0 / 53.2.mainwas built from716cb74e08and this PR from its pushed head90b365b5b9, each with #8091's one-line change uncommitted, so both sides' summary lines show as dirty.tools/trace_digest.pyof the first clean run (round 2) of each side (summary files of all runs attached):main + #8091
6 intervals, 0.0 to 60.1 s, 1790 presents
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit
716cb74e08(dirty)this PR + #8091
6 intervals, 0.0 to 60.1 s, 2051 presents
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit 90b365b5b9f0 (dirty)
Trace windows for the perf check.
APS5_TRACE_SECONDS=40:10, same scene, machine and builds as the runs above. Two windows per side: main 322 / 326 presents, p50 31.1 / 30.7 ms, p99 32.2 / 31.6 ms; this PR 370 / 364 presents, p50 26.7 / 27.3 ms, p99 33.1 / 30.9 ms. The first PR window has one 43 ms frame, which puts its p99 and max abovemain's; the second does not. The first window of each side, with its trace attached (aps5-trace-716cb74e0871-151594ismain,aps5-trace-90b365b5b9f0-151903is this PR):main + #8091:
this PR + #8091:
tools/trace_digest.py, main + #8091seconds 40:10 from present 1149: 322 presents, frame p50 31.1 / p90 31.7 / p99 32.2 / max 33.7 ms, GPU busy 1.9 ms per present
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit
716cb74e08(dirty), dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 29.7, Driver.WorkerWait.idle_and_completion_poll 29.7, Graphics.Draw 2.8, Vulkan.DrawFromRecipe 2.6, Graphics.DrawWithRecipe 2.6, Graphics.DrawWithRecipe.draw_and_resource_release 2.6, Graphics.Draw.draw_and_resource_release 2.1, Recorder.Submit 2.0, batch 1.9, Graphics.Draw.validate 0.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, this PR + #8091seconds 40:10 from present 1328: 370 presents, frame p50 26.7 / p90 29.3 / p99 33.1 / max 43.2 ms, GPU busy 1.9 ms per present
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit 90b365b5b9f0 (dirty), dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 25.7, Driver.WorkerWait.idle_and_completion_poll 25.7, batch 1.9, Recorder.Submit 1.9, Graphics.Draw 1.8, Vulkan.DrawFromRecipe 1.5, Graphics.DrawWithRecipe 1.5, Graphics.DrawWithRecipe.draw_and_resource_release 1.5, Graphics.Draw.draw_and_resource_release 1.5, Driver.Packet 0.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/performance_compare.pyPerformance comparison
716cb74e08Configuration differences
Frame and GPU times (ms)
Top phases (ms per frame)
perf, measured on the previous base, 10 s from 40 s into a run, same scene, on
1e20650e84+ #8091: onmain,_Rb_tree_increment3.0%,importRunBounds1.9%,leasedIndexContaining1.5%,walkRun1.1% andsameRange0.7% of samples. With this PR,_Rb_tree_incrementis 2.2%,refreshImportsitself 0.8%, andimportRunBounds,leasedIndexContaining,walkRunandsameRangeare each 0.2% or less.clock_gettimeis about 22% on both sides.Other measurements (same machine and scene, menu,
maineaff87674c+ #8091):APS5_PROFILE_GPU=1shows the same recorded GPU time per present on both sides (2.4 ms in 59 batches), andAPS5_NO_DRAW_INPUTS_IN_PLACE=1changes nothing. So this is not #5895's in-place read cost.importRun4.3%,_Rb_tree_increment2.3%,leasedIndexContaining1.8% andsameRange1.6% of user samples. With this PR,importRun,leasedIndexContainingandsameRangestay under 0.3%.refreshImportsitself is 1.7%: the lease diff is linear in the ~800 registered ranges, and the remembered failures and refusals are still iterated.sameRangefor every import the incremental refresh skipped. With the default budget it found 0 differences in ~3.4M skipped checks. None of the skippedunwatchedimports were back in the write watch, and no imports overlapped. With a 128 MiB budget, the only differences were the refusal-dependent run shapes described above.AGC, shader recompiler:
ctest --test-dir build -R "agc|shader|recompiler" -V -j6withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, onmain7903201bb4and on this change applied to it, same machine, without #8091.mainhas since moved to716cb74e08with documentation changes only. Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS.main: 1045 of 1046 passed. This PR: 1046 of 1047, with the new test.agc_driver_tessellation(segfault, Mesa 26.2, #5444) fails on both.VkPipelineColorBlendStateCreateInfo-pAttachments-00605×26.Overlap with open pull requests, from
tools/pr_overlap.pyon3c4aab5acc, which reports none:checkand after both walks, as described above.refreshImportskeeps itsstate.gateRefusals.clear()after the generation check, before this PR's window test. Its color-target imports are made inimportRunAt, which records them inpendingImports, so the incremental walk checks them.agc_windowed_import_refreshgets its WindowsPATHin its ownif(WIN32)block after its registration, not in the sharedset_tests_propertieslist that #6182, #6185, #6186, #9565, #9712, #9875, #9898 and #11451 also extend.main, memoizesimportRun's run bounds, which lowers the cost of each check. This PR lowers how many checks run.refreshImports,retireImport,importRunAtorClearHostImports:GuestMemory::Unwatchline in the import loop, which this PR moves intocheck, and notes every import it re-unwatches. With this PR only re-checked imports are re-unwatched. Write watching only comes back on a range through a registry change (a new mapping, or a remap, whoseProtectreplaces the ranges), through a settle that marks its import watched, or through #8926's rewatch of a retired import's ranges, which skips ranges a live unwatched import still covers. So a skipped import is never back in the write watch, as the check mode above also found.importRunAtmakes an import, not the refresh; #7457 only readsrefreshedGeneration.importRunAtcreates a dma-buf import; the import is still added through the sameemplace, which records it inpendingImports.refreshImportscall with the whole acquired lease, as the other callers pass, and makes its joined import throughimportRunAt, sopendingImportsrecords it.ClearHostImports; it does not touch the line this PR adds there.retireImport,importRunAt,refreshImportsandClearHostImportsnext to this PR's lines (its epoch counter), not the lines themselves.mainadded onerefreshImportscaller since the last base (WatchedAfterSettle,44141f9aaf); it passes the whole acquired lease, as the others do.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 github-actions[bot] on 2026-10-21T20:49:29Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by janzezno on 2026-10-21T20:51:54Z.
Summary files (
APS5_TRACE_SUMMARY_EVERY=10) of the six SuperTuxKart runs in the table above, onmain0c6a5bd593:GitHub does not accept
.jsonl, so each file is a JSON array of its interval lines. To digest one withtools/trace_digest.py, convert it back first:Imported from boykopovar/AnyPS5. Originally posted by janzezno on 2026-10-21T21:03:54Z.
Traces of the two windows whose summary lines are in the description: main + #8091 (
0c6a5bd593) and this PR + #8091 (ceefc5bcde),APS5_TRACE_SECONDS=40:10.aps5-trace-0c6a5bd5938f-742372.json.gz
aps5-trace-ceefc5bcdeac-742647.json.gz
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T05:37:32Z.
Review: DISMISSED
This is a substantial performance investigation. The report includes same-machine SuperTuxKart comparisons, traces, an equivalence check across millions of skipped validations, a large focused test set, and paired Vulkan validation results with matching VUIDs.
git diff --checkpasses; GitHub reports the head mergeable, and eligibility, conventions, intake, labels, and report checks pass.I’m requesting changes for the remaining contribution-rule items:
0c6a5bd593andeaff87674c; currentmainis4a17c71757. Please rebase onto currentmain, rerun the focused AGC tests on the same machine and GPU with the required validation-layer settings on both current main and the change, compare VUIDs, and refresh the performance summaries/traces against that base.pendingImportsif both changes land. Agree on order with its author and reflect any prerequisite inDepends on:. Also refresh the overlap check and coordinate any actual same-line overlaps found in the import insertion, test registration, and debt entry with their authors; the current body records adjacent conflicts with #7261, #6820/#8104, and #7844, while the current overlap scan did not complete in my shared checkout due concurrent temporary-ref updates.No local AGC test or GPU run was possible in this review environment. The reported older-base results are useful evidence, but the repository requires current-main validation for this change before it is ready.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T00:38:27Z.
Review: CHANGES_REQUESTED
Checked the incremental refresh against the current
main(5e6ae6e3d):changedSpans, the window test, the predecessor and cursor across spans,pendingImports, and the keys of the remembered failures and refusals. No defect found in the code. Before merge:main, but the validation runs were onb7d1d47a5f.GuestBufferMemory.cppchanged onmainsince then (completeSpaceWrites,MarkDirectWrites,WriteBack). Please rerunctest --test-dir build -R "agc|shader|recompiler" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon currentmainand on this change, same machine and GPU, and compare the VUIDs.The open CHANGES_REQUESTED review needs a re-review after these before it can merge.