perf(agc): look ahead of the queue workers' write-watch walks on Windows #2863
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2863"
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 DotDebian on 2026-10-10T16:49:44Z.
What
Problem
On Windows a queue worker walks the write-watch state of every range it collects, once per collect epoch. Astro Bot has 18 epochs per frame (one per ordering point), and the worker that records the draws makes about 1,400
GetWriteWatchcalls per frame at a fixed cost of about 10 us each. Almost none of them finds a written page (about 30 dirty pages per frame).Change
Two commits:
GetWriteWatchbuffer to the range (WindowsMappings::Collect). The call was given the whole remaining capacity (65,536 entries) for every piece. Its cost follows the entry count, so a 64 KiB range cost about 7 us instead of 0.5 us. The count is now the smaller of the capacity and the range's pages, which gives the same results. As suggested by @exiled96 in discussion #357.GetWriteWatchwithout reset and outside every lock (WindowsMappings::ProbeClean). A clean range has its 64 KiB blocks marked inwalkedBlocks, under the tracker mutex, with a generation taken before the look. A completed resetting walk marks the blocks it covered whole.Safety (epoch contract of
GuestMemory.hpp)Measurement
Host: Windows 11, Core Ultra 9 285K, RTX 5080. Astro Bot (PPSA21564) at the Crash Site, 150 s runs:
Caveat: these runs had direct memory backed by write-watched private pages (#637). On
main, direct memory is mapped as shared views. The prewalk leaves views to their existing per-view tracking, so its gain onmainis limited to private memory until direct memory is watched the same way (#637 or #2054). Neither commit depends on those PRs. The buffer sizing (commit 1) was not measured separately here; the 7 to 0.5 us figure is @exiled96's.Disabling
APS5_NO_PREWALK=1. The helper starts on the first epoch that repeats a key and is stopped and joined when its worker returns. UnderAPS5_PROFILE_DRAWthe[guestmem]line counts looks, clean looks and trimmed collects.Tested
Windows 11, MinGW GCC 15.2 Release, Astro Bot (PPSA21564) for the measurement above.
agc_write_trackinggainsCheckPrewalk(Windows), which checks three cases:cteston Windows (MinGW GCC 15.2, Release): 709/709 passed.agc_write_tracking,agc_shared_writeand the graphics tests also pass withAPS5_NO_PREWALK=1.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Discussion: #357. Written with AI assistance (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T19:18:10Z.
Please split the
GetWriteWatchbuffer sizing into its own PR; it's small and exact and can go in on its own. The prewalk's 9.6 → 10.9 FPS was measured with direct memory as private watched pages (#637), which main doesn't have, so it needs numbers on main or aDepends on: #637(#218).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T00:15:41Z.
Review: CHANGES_REQUESTED
Following up on @oneandonlydean's request, which is still open:
GetWriteWatchbuffer sizing (WindowsMappings::Collect,core/libs/prx/libc/include/WindowsMappings.hpp:270) into its own PR. It is small, exact and independent of the prewalk.maindirect memory is mapped as shared views, which the prewalk leaves alone, so the gain onmainis not shown. Either post before/after numbers onmain, or declareDepends on: #637(or #2054) instead ofnone, and rebase once that lands (#218).docs/dev/TechnicalDebt.md, under an accurate section (not at the end of one).Checked: the diff builds and the Linux ctest scope is green. The prewalk code is
_WIN32only, so we could not runCheckPrewalkhere; the Windows result rests on your run.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:57:32Z.
Windows run, since the PR has no Intel or Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto
maind31b57a4in one build with #3217, #3202, #3167, #3137, #2863, #2849 and #2847, on an RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_write_tracking(WriteTracking.cpp) passes on both GPUs, along with the rest of the write-watch tests.Full
ctestof that build on both GPUs has no failure that isn't also on plainmainhere (guest_filesystemneeds the symlink privilege, #3169; the Intel ones are listed on #2114 and #3207).AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:42:18Z.
Additional platform validation of standalone PR head
4f9aadb3c9f17518a7ef4cffdd21a60d6dee8537(2026-10-11):Linux: passed with skips — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.3 checks, 0 failures, 1 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
agc_write_tracking,agc_shared_write,agc_driver_graphics.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(agc_write_tracking|agc_shared_write|agc_driver_graphics)$".This scope checks CPU-side behavior; no GPU execution result is claimed.
Internal limitation: heap-mirror subcases returned early because the guest arena was not write-watched in WSL. Zero CTest skips does not include that early return.
No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T13:12:37Z.
Rebase handoff — rebased onto current
main, authorship unchanged (all three commits).Two test-file conflicts with main's newer write-tracking tests, resolved by keeping both sides: main's
ArenaHostHole/CheckHostHoleand this PR'sCheckPrewalkare independent additions, and both are called from the Windows block; the style commit's comment removal is preserved.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV — note the prewalk itself is Windows-only code, so this verifies the rebase doesn't regress the Linux build/suite, not the prewalk behavior):tools/check_conventions.py --base origin/mainpassesTo pick it up:
Head is
d14548903.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:24:31Z.
Closing: the 2026-10-10 request for numbers on
main(orDepends on: #637) and the TechnicalDebt entry has had no reply or push. TheGetWriteWatchsizing went in through #4875.Reopen it, or comment here, when it's addressed; it can be picked up again then.
Pull request closed