refactor(libc): map a run of shared guest pages as one view on Windows #9505

Merged
EagleBearerYS merged 8 commits from upstream-pr/9505 into main 2026-10-25 21:33:18 +00:00
EagleBearerYS commented 2026-10-21 23:43:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T23:43:56Z.


What

On Windows, WindowsMappings::Map maps shared guest memory one 16 KiB page at a time. That covers direct memory while shared imports are attached, shm_open memory and JIT shared memory. Each page costs a placeholder split, a view, a protect and three VirtualQuery calls: two to find the placeholder the page splits from, one to see whether its section page still needs a commit. All of it runs under the mappings mutex. A 1 GiB map places 65,536 views.

This ports two of fable-void's commits from his fork (wip/new-gpu-path, 027bff5198 and 3d695fbba6), with his authorship. On top of them are our two adjustments for main's file mappings, a bench, and a change after review:

  • 6c1f63674e (bench): windows_shared_map_cost maps 4 MiB, 256 MiB and 1 GiB of shared memory through WindowsMappings::Map, then releases it, five times each. It prints the median map and release times and the number of views. It only measures and always passes.
  • 312fb247a9 (fable-void): a page-by-page mapping commits its section range once, through one window. Each page then splits off the placeholder the previous page left, whose extent is already known. A page now costs a placeholder split, its view and its protection.
  • a16262ba76 (adapts 027bff5198): only mappings that pass no section size, i.e. direct and shared memory, commit the range up front. A file mapping passes the bytes its file still has. A read-write window over it can run past the end of a short file, and a read-only file section refuses one, so file mappings keep committing each view as before.
  • bdf9bfe14a (fable-void): each run of shared pages that need a view becomes one view: one placeholder split, one map at read-write-execute (the cap later guest protections need) and one protect per run. Per-page protections and write tracking still change 4 KiB subpages inside the view. A view splits only where a release or a remap cuts it, and the split restores every 4 KiB protection. An alias of a page elsewhere, or a per-page protection, leaves the view whole.
  • 1f19ce0f2a (adapts 3d695fbba6): a run view needs a read-write-execute section and the whole run committed, which a file mapping can't give. File mappings take the per-page path they took before: one view per page at the file's view protection, with the last page cut at the end of the file.
  • a2e0bf19e6 (after MarcZX10's review): the VirtualQuery counter that 312fb247a9 adds for windows_write_watch is compiled only into that test, through APS5_COUNT_MAPPING_QUERIES, so the runtime's query() does no atomic update per query. main has had the same counter since #10070, which took it from this PR so that whichever landed second would drop its copy, so after the merge with main the PR's diff no longer carries it.

fable-void's message on 312fb247a9 lists agc_private_collect among the tests he ran. That test comes with his private-collect commit (2760ad8089 on his branch), which isn't part of this PR.

Measured on GitHub's Windows runner, three runs each: main with the bench (6c1f63674e, run) against this PR (run).

shared map main: map median (views) this PR release median, main → this PR
4 MiB 1.60–1.69 ms (256) 0.16–0.19 ms (1) 0.85–0.88 → 0.25–0.27 ms
256 MiB 151–181 ms (16,384) 10.0–12.0 ms (1) 63–64 → 17.6–18.4 ms
1 GiB 549–614 ms (65,536) 49–50 ms (1) 273–277 → 71.7–72.3 ms

On his machine, fable-void measured the 1 GiB shared map and import in agc_driver_committed_imports at 190–196 ms on the mapping thread, against 418–427 ms before.

These measure the mapping itself. A Resident Evil Village (PPSA01556) pair (under Tested) shows no measurable change in a 40 s window of its load, so this PR makes no frame-rate claim.

Overlap: checked with git merge-tree against every open PR touching these files, on main a6dcea9279. Two of ours overlap, on adjacent added lines only:

  • #9098 changes the private-memory collect, not shared mappings. On their current heads (git merge-tree) it conflicts on a test registration in core/libs/CMakeLists.txt, on the query counter in WindowsMappings.hpp (its accessor and the count in query(), which this PR now guards with APS5_COUNT_MAPPING_QUERIES), and on a test function before main() in WindowsWriteWatch.cpp.
  • #9159 has merged since, and this PR's merge of main 0ea0f25e1b takes it in: its aliasDemoted reset and unreported marks are in both of this PR's loops, and both sides' cases run in WindowsWriteWatch.cpp (see Tested).

Both are mine. Merge order: #9098 goes after this PR, lists it under Depends on, and resolves these conflicts when it rebases.

The eight PRs that conflict with main themselves were checked by their diffs: none changes WindowsMappings.hpp. #6044, #7201, #7275, #8285, #8650 and #9224 add root library test registrations in core/libs/CMakeLists.txt next to this PR's windows_shared_map_cost and the windows_write_watch_tests definition. Whichever PR rebases keeps every registration, and checks after resolving that ctest -N still lists all of them.

Tested

  • GitHub's Windows runner at 1f19ce0f2a (run):
    • windows_shared_map_cost, windows_write_watch, guest_memory, guest_jit_shared_memory, guest_shm_open and guest_raise_exception pass ×3;
    • the libc (142) and libkernel (207) suites pass.
    • main's code doesn't build windows_write_watch there, because fable-void's two new cases use the query counter 312fb247a9 adds. His messages give their reds: "775 queries for 256 pages" and "a shared gibibyte was mapped as 65536 views instead of one".
  • a2e0bf19e6 on GitHub's Windows runner (run): windows_shared_map_cost and windows_write_watch pass 5 runs in a row, and the libc suite passes (142). In both attempts of that run, libkernel's guest_raise_in_system_call timed out after 30 s near the end of the suite. Run alone 20 times in a row, it and guest_raise_exception pass at a2e0bf19e6 (run) and at 1f19ce0f2a (run), while main's a6dcea9279 times out guest_raise_exception within its 20 (run).
  • 5fd76aff60, merged with main 1e20650e84 (run). The one conflict was the list of cases in WindowsWriteWatch.cpp's main(), where main added three private-commit cases next to this PR's two; all five run. main now has the same APS5_COUNT_MAPPING_QUERIES query counter (from #10070), so after the merge this PR no longer changes those lines. Its other added and removed lines are unchanged.
    • on Windows, windows_write_watch, windows_shared_map_cost, guest_memory, guest_shm_open, guest_jit_shared_memory and guest_raise_exception pass ×10: 6 run, 6 pass, 0 skip, 0 fail;
    • on Linux, guest_memory, guest_shm_open, guest_jit_shared_memory and guest_raise_exception pass ×10: 4 run, 4 pass, 0 skip, 0 fail;
    • the libc and libkernel suites pass on both (147 and 213 tests on Windows, 120 and 203 on Linux), run with APS5_SKIP_TIMING_TESTS=1.
  • fbf50df422, merged with main 0ea0f25e1b (run). Both conflicts come from #9159, which main has taken since:
    • in WindowsMappings.hpp, #9159 added two lines to the per-page loop this PR replaces: the aliasDemoted = false reset after a resident alias is demoted, and the unreported = allSubpages mark on a new view of compared shared memory. The merge carries both into this PR's per-page loop and into its run loop, where each run view takes the mark from its shared page. The PR's other added and removed lines are unchanged;
    • in WindowsWriteWatch.cpp's main(), the list of cases keeps this PR's two and #9159's four;
    • on Windows, windows_write_watch, windows_shared_map_cost, the write-tracking tests (#9159's agc_rewatched_direct_shared, agc_import_alias_shared and agc_compared_shared_generations among them), guest_memory, guest_shm_open, guest_jit_shared_memory and guest_raise_exception pass ×10: 14 run, 13 pass, 1 skip (agc_driver_compared_shared_snapshot, no Vulkan device), 0 fail. With main's implementation, windows_write_watch fails: "a shared mapping queried the address space for every page: 775 queries for 256 pages";
    • on Linux, agc_write_tracking, agc_write_watch_coverage, guest_memory, guest_shm_open, guest_jit_shared_memory and guest_raise_exception pass ×10: 6 run, 6 pass, 0 skip, 0 fail;
    • an ^agc sweep, once (run): Linux 987 run, 923 pass, 64 skip, 0 fail. Windows 1,017 run, 287 pass, 726 skip, 4 fail: agc_submit_progress, agc_submit_progress_no_timeline, agc_driver_pipelined_metadata_pass and agc_driver_pipelined_metadata_pass_draw_pipeline stop at vkCreateInstance (-9) on GitHub's runner, which has no Vulkan device, and fail the same way on main c9b2660d56 alone (run);
    • the libc and libkernel suites pass on both (170 and 221 tests on Windows, 143 and 205 on Linux), run with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • Our two adjustments each have a red from existing tests on the Windows runner, in guest_memory's regular file mapping case. Those runs were on an earlier branch of this port that also carried his private-collect commit, which doesn't touch file mappings.
    • Without a16262ba76 (run), a read-only shared map of a read-only file fails: "Guest memory check failed at core/libs/tests/GuestMemory.cpp:2922".
    • Without 1f19ce0f2a (run), a shared map of a two-page file fails: "Guest memory check failed at core/libs/tests/GuestMemory.cpp:2899". guest_jit_shared_memory and guest_shm_open fail there too.
  • guest_raise_exception timed out once (30 s) in an earlier run of the port. It passed in a recheck (run) and in all three runs above. This PR doesn't touch libkernel.
  • Linux (same run): WindowsMappings.hpp is Windows-only, so Linux builds unchanged code. guest_memory, guest_jit_shared_memory, guest_shm_open and guest_raise_exception pass ×3, and libkernel's suite passes (197). libc's suite has one failure, precise_wait, a timing test that flakes on that runner.
  • JJenkx's run (comment): Ryzen 9 5950X, Windows 11, WinLibs GCC 15.2.0 UCRT, Release, this PR's a2e0bf19e6 merged into main d9c99c9ba4. windows_shared_map_cost (not on main), windows_write_watch, guest_memory, guest_jit_shared_memory and guest_shm_open pass 3 of 3, and libc's suite passes (142). guest_raise_exception times out there with and without this PR, as guest_raise_in_host_code does once on main; JJenkx's breakdown of that time is #9610.
  • check_conventions.py passes, with no comment lines added.
  • Resident Evil Village (PPSA01556), a traced pair on an RTX 3070 Laptop GPU (NVIDIA 617.42, Windows 11). GPU clocks weren't held: P0 for 99.6% of samples on both, 780-1785 MHz graphics, median 1290.
    • Trees: A is a local test tree, d56bdc5155: main 1ff5c8ac5c plus four local AGC driver commits, none in libc. D is A with this PR's six commits on top (ca13192259, the same diff as this PR).
    • Runs:
      • the same environment on both (APS5_LAZY_SHADER_PREPARE=1, APS5_NO_GPL=1, APS5_HOST_IMPORT_MIB=6400, APS5_TRACE_SECONDS=900:40), the same route and a warm shader cache;
      • each 40 s window falls inside the dark load after New Game's Yes: about 119 s after it on A (presents 4935-5055), and about 68 s after it on D (presents 5249-5371).
    • A: 120 presents, frame p50 323.5 / p90 383.1 / p99 577.4 / max 1447.3 ms, GPU busy 75.8 ms per present.
    • D: 122 presents, frame p50 336.1 / p90 384.2 / p99 433.6 / max 495.3 ms, GPU busy 74.1 ms per present.
    • No measurable effect in this window:
      • p50 +4% and GPU busy −2%, with dispatch and memory wait within 1%;
      • A's p99 and max come from a single 1.45 s shader-resolve stall (present 5047), so the difference there isn't a gain.
    • Files: A's and D's trace, aps5-summary.jsonl line and tools/trace_digest.py output.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none. Merge order with thuanquang's #11152 (overlapping lines in core/libs/prx/libc/include/WindowsMappings.hpp): this PR first, then #11152 rebases onto it
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959857107 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T23:43:56Z. --- ### What On Windows, `WindowsMappings::Map` maps shared guest memory one 16 KiB page at a time. That covers direct memory while shared imports are attached, `shm_open` memory and JIT shared memory. Each page costs a placeholder split, a view, a protect and three `VirtualQuery` calls: two to find the placeholder the page splits from, one to see whether its section page still needs a commit. All of it runs under the mappings mutex. A 1 GiB map places 65,536 views. This ports two of fable-void's commits from his fork ([`wip/new-gpu-path`](https://github.com/fable-void/AnyPS5/tree/wip/new-gpu-path), 027bff5198 and 3d695fbba6), with his authorship. On top of them are our two adjustments for `main`'s file mappings, a bench, and a change after review: - **6c1f63674e (bench):** `windows_shared_map_cost` maps 4 MiB, 256 MiB and 1 GiB of shared memory through `WindowsMappings::Map`, then releases it, five times each. It prints the median map and release times and the number of views. It only measures and always passes. - **312fb247a9 (fable-void):** a page-by-page mapping commits its section range once, through one window. Each page then splits off the placeholder the previous page left, whose extent is already known. A page now costs a placeholder split, its view and its protection. - **a16262ba76 (adapts 027bff5198):** only mappings that pass no section size, i.e. direct and shared memory, commit the range up front. A file mapping passes the bytes its file still has. A read-write window over it can run past the end of a short file, and a read-only file section refuses one, so file mappings keep committing each view as before. - **bdf9bfe14a (fable-void):** each run of shared pages that need a view becomes one view: one placeholder split, one map at read-write-execute (the cap later guest protections need) and one protect per run. Per-page protections and write tracking still change 4 KiB subpages inside the view. A view splits only where a release or a remap cuts it, and the split restores every 4 KiB protection. An alias of a page elsewhere, or a per-page protection, leaves the view whole. - **1f19ce0f2a (adapts 3d695fbba6):** a run view needs a read-write-execute section and the whole run committed, which a file mapping can't give. File mappings take the per-page path they took before: one view per page at the file's view protection, with the last page cut at the end of the file. - **a2e0bf19e6 (after MarcZX10's review):** the `VirtualQuery` counter that 312fb247a9 adds for `windows_write_watch` is compiled only into that test, through `APS5_COUNT_MAPPING_QUERIES`, so the runtime's `query()` does no atomic update per query. `main` has had the same counter since #10070, which took it from this PR so that whichever landed second would drop its copy, so after the merge with `main` the PR's diff no longer carries it. fable-void's message on 312fb247a9 lists `agc_private_collect` among the tests he ran. That test comes with his private-collect commit (2760ad8089 on his branch), which isn't part of this PR. **Measured on GitHub's Windows runner**, three runs each: `main` with the bench (6c1f63674e, [run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39690199563)) against this PR ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39692846229)). | shared map | `main`: map median (views) | this PR | release median, `main` → this PR | |---|---|---|---| | 4 MiB | 1.60–1.69 ms (256) | 0.16–0.19 ms (1) | 0.85–0.88 → 0.25–0.27 ms | | 256 MiB | 151–181 ms (16,384) | 10.0–12.0 ms (1) | 63–64 → 17.6–18.4 ms | | 1 GiB | 549–614 ms (65,536) | 49–50 ms (1) | 273–277 → 71.7–72.3 ms | On his machine, fable-void measured the 1 GiB shared map and import in `agc_driver_committed_imports` at 190–196 ms on the mapping thread, against 418–427 ms before. These measure the mapping itself. A Resident Evil Village (PPSA01556) pair (under Tested) shows no measurable change in a 40 s window of its load, so this PR makes no frame-rate claim. **Overlap:** checked with `git merge-tree` against every open PR touching these files, on `main` a6dcea9279. Two of ours overlap, on adjacent added lines only: - #9098 changes the private-memory collect, not shared mappings. On their current heads (`git merge-tree`) it conflicts on a test registration in `core/libs/CMakeLists.txt`, on the query counter in `WindowsMappings.hpp` (its accessor and the count in `query()`, which this PR now guards with `APS5_COUNT_MAPPING_QUERIES`), and on a test function before `main()` in `WindowsWriteWatch.cpp`. - #9159 has merged since, and this PR's merge of `main` 0ea0f25e1b takes it in: its `aliasDemoted` reset and `unreported` marks are in both of this PR's loops, and both sides' cases run in `WindowsWriteWatch.cpp` (see Tested). Both are mine. Merge order: #9098 goes after this PR, lists it under Depends on, and resolves these conflicts when it rebases. The eight PRs that conflict with `main` themselves were checked by their diffs: none changes `WindowsMappings.hpp`. #6044, #7201, #7275, #8285, #8650 and #9224 add root library test registrations in `core/libs/CMakeLists.txt` next to this PR's `windows_shared_map_cost` and the `windows_write_watch_tests` definition. Whichever PR rebases keeps every registration, and checks after resolving that `ctest -N` still lists all of them. ### Tested - **GitHub's Windows runner at 1f19ce0f2a** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39692846229)): - `windows_shared_map_cost`, `windows_write_watch`, `guest_memory`, `guest_jit_shared_memory`, `guest_shm_open` and `guest_raise_exception` pass ×3; - the libc (142) and libkernel (207) suites pass. - `main`'s code doesn't build `windows_write_watch` there, because fable-void's two new cases use the query counter 312fb247a9 adds. His messages give their reds: "775 queries for 256 pages" and "a shared gibibyte was mapped as 65536 views instead of one". - **a2e0bf19e6 on GitHub's Windows runner** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39702572385)): `windows_shared_map_cost` and `windows_write_watch` pass 5 runs in a row, and the libc suite passes (142). In both attempts of that run, libkernel's `guest_raise_in_system_call` timed out after 30 s near the end of the suite. Run alone 20 times in a row, it and `guest_raise_exception` pass at a2e0bf19e6 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39704435944)) and at 1f19ce0f2a ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39704399097)), while `main`'s a6dcea9279 times out `guest_raise_exception` within its 20 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39704502550)). - **5fd76aff60, merged with `main` 1e20650e84** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40073350994)). The one conflict was the list of cases in `WindowsWriteWatch.cpp`'s `main()`, where `main` added three private-commit cases next to this PR's two; all five run. `main` now has the same `APS5_COUNT_MAPPING_QUERIES` query counter (from #10070), so after the merge this PR no longer changes those lines. Its other added and removed lines are unchanged. - on Windows, `windows_write_watch`, `windows_shared_map_cost`, `guest_memory`, `guest_shm_open`, `guest_jit_shared_memory` and `guest_raise_exception` pass ×10: 6 run, 6 pass, 0 skip, 0 fail; - on Linux, `guest_memory`, `guest_shm_open`, `guest_jit_shared_memory` and `guest_raise_exception` pass ×10: 4 run, 4 pass, 0 skip, 0 fail; - the libc and libkernel suites pass on both (147 and 213 tests on Windows, 120 and 203 on Linux), run with `APS5_SKIP_TIMING_TESTS=1`. - **fbf50df422, merged with `main` 0ea0f25e1b** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40121922758)). Both conflicts come from #9159, which `main` has taken since: - in `WindowsMappings.hpp`, #9159 added two lines to the per-page loop this PR replaces: the `aliasDemoted = false` reset after a resident alias is demoted, and the `unreported = allSubpages` mark on a new view of compared shared memory. The merge carries both into this PR's per-page loop and into its run loop, where each run view takes the mark from its shared page. The PR's other added and removed lines are unchanged; - in `WindowsWriteWatch.cpp`'s `main()`, the list of cases keeps this PR's two and #9159's four; - on Windows, `windows_write_watch`, `windows_shared_map_cost`, the write-tracking tests (#9159's `agc_rewatched_direct_shared`, `agc_import_alias_shared` and `agc_compared_shared_generations` among them), `guest_memory`, `guest_shm_open`, `guest_jit_shared_memory` and `guest_raise_exception` pass ×10: 14 run, 13 pass, 1 skip (`agc_driver_compared_shared_snapshot`, no Vulkan device), 0 fail. With `main`'s implementation, `windows_write_watch` fails: "a shared mapping queried the address space for every page: 775 queries for 256 pages"; - on Linux, `agc_write_tracking`, `agc_write_watch_coverage`, `guest_memory`, `guest_shm_open`, `guest_jit_shared_memory` and `guest_raise_exception` pass ×10: 6 run, 6 pass, 0 skip, 0 fail; - an `^agc` sweep, once ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40121991147)): Linux 987 run, 923 pass, 64 skip, 0 fail. Windows 1,017 run, 287 pass, 726 skip, 4 fail: `agc_submit_progress`, `agc_submit_progress_no_timeline`, `agc_driver_pipelined_metadata_pass` and `agc_driver_pipelined_metadata_pass_draw_pipeline` stop at `vkCreateInstance` (-9) on GitHub's runner, which has no Vulkan device, and fail the same way on `main` c9b2660d56 alone ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40109333265)); - the libc and libkernel suites pass on both (170 and 221 tests on Windows, 143 and 205 on Linux), run with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **Our two adjustments each have a red from existing tests** on the Windows runner, in `guest_memory`'s regular file mapping case. Those runs were on an earlier branch of this port that also carried his private-collect commit, which doesn't touch file mappings. - Without a16262ba76 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39686876737)), a read-only shared map of a read-only file fails: "Guest memory check failed at core/libs/tests/GuestMemory.cpp:2922". - Without 1f19ce0f2a ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39686932515)), a shared map of a two-page file fails: "Guest memory check failed at core/libs/tests/GuestMemory.cpp:2899". `guest_jit_shared_memory` and `guest_shm_open` fail there too. - `guest_raise_exception` timed out once (30 s) in an earlier run of the port. It passed in a recheck ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39691330096)) and in all three runs above. This PR doesn't touch libkernel. - **Linux** (same run): `WindowsMappings.hpp` is Windows-only, so Linux builds unchanged code. `guest_memory`, `guest_jit_shared_memory`, `guest_shm_open` and `guest_raise_exception` pass ×3, and libkernel's suite passes (197). libc's suite has one failure, `precise_wait`, a timing test that flakes on that runner. - **JJenkx's run** ([comment](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6332644669)): Ryzen 9 5950X, Windows 11, WinLibs GCC 15.2.0 UCRT, Release, this PR's a2e0bf19e6 merged into `main` d9c99c9ba4. `windows_shared_map_cost` (not on `main`), `windows_write_watch`, `guest_memory`, `guest_jit_shared_memory` and `guest_shm_open` pass 3 of 3, and libc's suite passes (142). `guest_raise_exception` times out there with and without this PR, as `guest_raise_in_host_code` does once on `main`; JJenkx's breakdown of that time is #9610. - `check_conventions.py` passes, with no comment lines added. - **Resident Evil Village (PPSA01556), a traced pair** on an RTX 3070 Laptop GPU (NVIDIA 617.42, Windows 11). GPU clocks weren't held: P0 for 99.6% of samples on both, 780-1785 MHz graphics, median 1290. - **Trees:** A is a local test tree, d56bdc5155: `main` 1ff5c8ac5c plus four local AGC driver commits, none in libc. D is A with this PR's six commits on top (ca13192259, the same diff as this PR). - **Runs:** - the same environment on both (`APS5_LAZY_SHADER_PREPARE=1`, `APS5_NO_GPL=1`, `APS5_HOST_IMPORT_MIB=6400`, `APS5_TRACE_SECONDS=900:40`), the same route and a warm shader cache; - each 40 s window falls inside the dark load after New Game's Yes: about 119 s after it on A (presents 4935-5055), and about 68 s after it on D (presents 5249-5371). - **A:** 120 presents, frame p50 323.5 / p90 383.1 / p99 577.4 / max 1447.3 ms, GPU busy 75.8 ms per present. - **D:** 122 presents, frame p50 336.1 / p90 384.2 / p99 433.6 / max 495.3 ms, GPU busy 74.1 ms per present. - **No measurable effect in this window:** - p50 +4% and GPU busy −2%, with dispatch and memory wait within 1%; - A's p99 and max come from a single 1.45 s shader-resolve stall (present 5047), so the difference there isn't a gain. - **Files:** [A's](https://github.com/EagleBearerYS/AnyPS5/tree/pr-assets/9505/a-base-d56bdc5155) and [D's](https://github.com/EagleBearerYS/AnyPS5/tree/pr-assets/9505/d-pr-ca13192259) trace, `aps5-summary.jsonl` line and `tools/trace_digest.py` output. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none. Merge order with thuanquang's #11152 (overlapping lines in `core/libs/prx/libc/include/WindowsMappings.hpp`): this PR first, then #11152 rebases onto it - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 23:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T23:44:08Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329071722 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6329071722). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T23:44:08Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
MarcZX10 commented 2026-10-22 00:43:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:43:22Z.

Review: CHANGES_REQUESTED


The implementation has substantial Windows coverage: the PR reports successful shared-view, write-watch, guest-memory, JIT, shm, libc/libkernel and relinker runs, plus repeated same-runner map/release measurements. Eligibility, conventions, intake, labels, report and the reported matrix checks pass. I did not run Windows tests locally.

I’m requesting changes for these items:

  1. The required performance report is still missing. The perf label bot correctly asks for the aps5-summary.jsonl lines for main and this change, traces for both, and tools/trace_digest.py output. CONTRIBUTING.md requires that evidence for a speed claim. The custom windows_shared_map_cost timing table is useful, but it does not provide those report artifacts. Please attach them for the same workload and machine, or revise the performance claim and checklist to match the evidence available.

  2. Please complete overlap coordination for #9098 and #9159. The live overlap scan reports shared edits in WindowsMappings.hpp and WindowsWriteWatch.cpp (and the CMake test registration for #9098). The PR description says the changes compose, but does not record agreement with those authors about merge order. Please confirm the order with them; add Depends on if this PR must follow either one, then rebase/recheck the resulting combined diff.

  3. The test query counter adds an unconditional atomic operation to production. WindowsMappings::query() now performs queries.fetch_add() for every VirtualQuery, even in the runtime library where the counter is not read. Please compile the counter only into the test target (or otherwise keep it out of production), so a performance change does not add a global atomic RMW to this hot path.

The measured view-count and map-time improvements are promising; these requests concern the required report, merge-order process, and the production cost of the new instrumentation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607943185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#pullrequestreview-5607943185). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T00:43:22Z. **Review:** CHANGES_REQUESTED --- The implementation has substantial Windows coverage: the PR reports successful shared-view, write-watch, guest-memory, JIT, shm, libc/libkernel and relinker runs, plus repeated same-runner map/release measurements. Eligibility, conventions, intake, labels, report and the reported matrix checks pass. I did not run Windows tests locally. I’m requesting changes for these items: 1. **The required performance report is still missing.** The `perf` label bot correctly asks for the `aps5-summary.jsonl` lines for main and this change, traces for both, and `tools/trace_digest.py` output. CONTRIBUTING.md requires that evidence for a speed claim. The custom `windows_shared_map_cost` timing table is useful, but it does not provide those report artifacts. Please attach them for the same workload and machine, or revise the performance claim and checklist to match the evidence available. 2. **Please complete overlap coordination for #9098 and #9159.** The live overlap scan reports shared edits in `WindowsMappings.hpp` and `WindowsWriteWatch.cpp` (and the CMake test registration for #9098). The PR description says the changes compose, but does not record agreement with those authors about merge order. Please confirm the order with them; add `Depends on` if this PR must follow either one, then rebase/recheck the resulting combined diff. 3. **The test query counter adds an unconditional atomic operation to production.** `WindowsMappings::query()` now performs `queries.fetch_add()` for every `VirtualQuery`, even in the runtime library where the counter is not read. Please compile the counter only into the test target (or otherwise keep it out of production), so a performance change does not add a global atomic RMW to this hot path. The measured view-count and map-time improvements are promising; these requests concern the required report, merge-order process, and the production cost of the new instrumentation.
MarcZX10 commented 2026-10-22 01:20:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:20:02Z.

Review: CHANGES_REQUESTED


The performance evidence and hosted product checks are now present and green, so I withdraw the earlier performance-report concern. I verified the current heads directly with git merge-tree: #9505 and #9098 conflict in core/libs/CMakeLists.txt, core/libs/prx/libc/include/WindowsMappings.hpp, and core/libs/tests/WindowsWriteWatch.cpp. In particular the shared APS5_COUNT_MAPPING_QUERIES accessor/counter hunks in WindowsMappings.hpp conflict, so the PR description’s statement that these parts merge cleanly is stale. #9505 and #9159 also conflict in WindowsWriteWatch.cpp. The contribution rule requires author-agreed order for actual shared-line overlaps and Depends on for prerequisites. Please coordinate with #9098 and #9159 authors, update this PR’s overlap account/checklist, and rerun the merge-tree/overlap check after any rebase. The content-level work appears distinct; I’m requesting changes for the inaccurate overlap/order record only. Hosted eligibility, conventions, relinker matrix, ASan and write-watch checks pass; full Linux/Windows product jobs are skipped. I did not run local Windows tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608175142 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#pullrequestreview-5608175142). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T01:20:02Z. **Review:** CHANGES_REQUESTED --- The performance evidence and hosted product checks are now present and green, so I withdraw the earlier performance-report concern. I verified the current heads directly with `git merge-tree`: #9505 and #9098 conflict in `core/libs/CMakeLists.txt`, `core/libs/prx/libc/include/WindowsMappings.hpp`, and `core/libs/tests/WindowsWriteWatch.cpp`. In particular the shared `APS5_COUNT_MAPPING_QUERIES` accessor/counter hunks in `WindowsMappings.hpp` conflict, so the PR description’s statement that these parts merge cleanly is stale. #9505 and #9159 also conflict in `WindowsWriteWatch.cpp`. The contribution rule requires author-agreed order for actual shared-line overlaps and `Depends on` for prerequisites. Please coordinate with #9098 and #9159 authors, update this PR’s overlap account/checklist, and rerun the merge-tree/overlap check after any rebase. The content-level work appears distinct; I’m requesting changes for the inaccurate overlap/order record only. Hosted eligibility, conventions, relinker matrix, ASan and write-watch checks pass; full Linux/Windows product jobs are skipped. I did not run local Windows tests.
EagleBearerYS commented 2026-10-22 01:38:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T01:38:00Z.


Thanks, @MarcZX10, on both reviews.

  1. a2e0bf19e6 compiles the VirtualQuery counter only into windows_write_watch_tests, through APS5_COUNT_MAPPING_QUERIES, so the runtime's WindowsMappings::query no longer updates it (run).
  2. #9098 and #9159 are both mine, so the order is settled: #9098 goes after this PR, lists it under Depends on and resolves the CMakeLists.txt, WindowsMappings.hpp and WindowsWriteWatch.cpp hunks when it rebases. This PR and #9159 don't wait on each other, and whichever lands second rebases. The Overlap section now says so, and no longer says the counter parts merge cleanly with #9098.
  3. Thanks for withdrawing the performance-report point. A Resident Evil Village (PPSA01556) capture pair still runs, as extra evidence: its load, on the same base with and without this PR, with the summary lines, a trace for each and the trace_digest.py output. I'll post it here when it's in.

The description also gains the GPUs tested line it was missing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330579665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6330579665). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T01:38:00Z. --- Thanks, @MarcZX10, on both reviews. 1. a2e0bf19e6 compiles the `VirtualQuery` counter only into `windows_write_watch_tests`, through `APS5_COUNT_MAPPING_QUERIES`, so the runtime's `WindowsMappings::query` no longer updates it ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39702572385)). 2. #9098 and #9159 are both mine, so the order is settled: #9098 goes after this PR, lists it under Depends on and resolves the `CMakeLists.txt`, `WindowsMappings.hpp` and `WindowsWriteWatch.cpp` hunks when it rebases. This PR and #9159 don't wait on each other, and whichever lands second rebases. The Overlap section now says so, and no longer says the counter parts merge cleanly with #9098. 3. Thanks for withdrawing the performance-report point. A Resident Evil Village (PPSA01556) capture pair still runs, as extra evidence: its load, on the same base with and without this PR, with the summary lines, a trace for each and the `trace_digest.py` output. I'll post it here when it's in. The description also gains the `GPUs tested` line it was missing.
MarcZX10 commented 2026-10-22 02:07:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:07:40Z.


Thanks for documenting #9098 as a dependent rebase and #9159 as independent. I checked the remaining overlap warnings: #5021 does not change core/libs/CMakeLists.txt; #6044, #7201, #7275, #8285, #8650 and #9224 do add root library test registrations, so the shared CMake insertions need to be preserved on rebase even if the changes are otherwise independent. Please note that plan and verify all registrations remain after resolving the CMake conflicts. One separate repository rule remains: this PR still has title perf(...) and label perf, while its benchmark is a test-only mapping microbenchmark rather than the prescribed same-title/same-scene warm-cache capture with summary lines, attached traces and digests. The Resident Evil Village pair is still described as running. Please add the required report artifacts if retaining the perf title/label, or change the title/scope so it no longer claims a performance change. I did not run tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330960150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6330960150). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:07:40Z. --- Thanks for documenting #9098 as a dependent rebase and #9159 as independent. I checked the remaining overlap warnings: #5021 does not change `core/libs/CMakeLists.txt`; #6044, #7201, #7275, #8285, #8650 and #9224 do add root library test registrations, so the shared CMake insertions need to be preserved on rebase even if the changes are otherwise independent. Please note that plan and verify all registrations remain after resolving the CMake conflicts. One separate repository rule remains: this PR still has title `perf(...)` and label `perf`, while its benchmark is a test-only mapping microbenchmark rather than the prescribed same-title/same-scene warm-cache capture with summary lines, attached traces and digests. The Resident Evil Village pair is still described as running. Please add the required report artifacts if retaining the perf title/label, or change the title/scope so it no longer claims a performance change. I did not run tests locally.
MarcZX10 commented 2026-10-22 02:07:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:07:42Z.

Review: CHANGES_REQUESTED


The Windows mapping change is supported by broad author-reported regression coverage and a dedicated mapping benchmark. I am requesting changes for repository policy/evidence: the perf(...) title/label requires valid same-title, same-scene, same-machine warm-cache summary lines, attached base/change traces and tools/trace_digest.py output. The current mapping benchmark does not meet that title-scene report requirement, and the described Resident Evil Village pair has not been posted yet. Please attach the compliant capture report or remove the performance claim/perf labeling. Also preserve the documented #9098/#9159 order and root test registrations during rebases. I did not run tests locally; hosted product build jobs are skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608461228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#pullrequestreview-5608461228). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:07:42Z. **Review:** CHANGES_REQUESTED --- The Windows mapping change is supported by broad author-reported regression coverage and a dedicated mapping benchmark. I am requesting changes for repository policy/evidence: the `perf(...)` title/label requires valid same-title, same-scene, same-machine warm-cache summary lines, attached base/change traces and `tools/trace_digest.py` output. The current mapping benchmark does not meet that title-scene report requirement, and the described Resident Evil Village pair has not been posted yet. Please attach the compliant capture report or remove the performance claim/perf labeling. Also preserve the documented #9098/#9159 order and root test registrations during rebases. I did not run tests locally; hosted product build jobs are skipped.
EagleBearerYS commented 2026-10-22 02:19:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:19:37Z.


Thanks, @MarcZX10. The perf title stays for now. A Resident Evil Village (PPSA01556) capture pair is queued on this PC in a matched rotation: the same base with and without this PR, a warm cache, and the same machine and scene. I'll attach both summary lines, a trace for each arm and the trace_digest.py output here. If it shows no measurable effect in that title, the description will cut the claim to the mapping bench, and the title will drop perf. The CMake registrations are in the Overlap section now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331111459 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6331111459). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T02:19:37Z. --- Thanks, @MarcZX10. The `perf` title stays for now. A Resident Evil Village (PPSA01556) capture pair is queued on this PC in a matched rotation: the same base with and without this PR, a warm cache, and the same machine and scene. I'll attach both summary lines, a trace for each arm and the `trace_digest.py` output here. If it shows no measurable effect in that title, the description will cut the claim to the mapping bench, and the title will drop `perf`. The CMake registrations are in the Overlap section now.
MarcZX10 commented 2026-10-22 04:23:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:23:06Z.

Review: DISMISSED


The #9098/#9159 ordering is now documented, the runtime query counter is test-only, and the CMake registration conflicts are accounted for. I am withdrawing the earlier overlap coordination request. One repository requirement remains: this PR still has a perf(...) title and perf label, but its body still says the PPSA01556 capture pair is queued and includes no summary lines, attached traces or trace_digest.py output. The mapping benchmark does not replace the prescribed same-title, same-scene, same-machine warm-cache report. Please attach that complete capture pair or remove the perf title/claim and revise the description accordingly. No local Windows/title tests were run by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609236005 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#pullrequestreview-5609236005). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:23:06Z. **Review:** DISMISSED --- The #9098/#9159 ordering is now documented, the runtime query counter is test-only, and the CMake registration conflicts are accounted for. I am withdrawing the earlier overlap coordination request. One repository requirement remains: this PR still has a `perf(...)` title and `perf` label, but its body still says the PPSA01556 capture pair is queued and includes no summary lines, attached traces or `trace_digest.py` output. The mapping benchmark does not replace the prescribed same-title, same-scene, same-machine warm-cache report. Please attach that complete capture pair or remove the `perf` title/claim and revise the description accordingly. No local Windows/title tests were run by me.
JJenkx commented 2026-10-22 04:23:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:23:14Z.


Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release, BUILD_TESTING=ON. I compared main d9c99c9ba4 with a local merge of your head a2e0bf19e6 into it (c66a5dbc72, no conflicts).

Focused tests, 3 runs each:

merge main
windows_shared_map_cost pass 3/3 not on main
windows_write_watch, guest_memory, guest_jit_shared_memory, guest_shm_open pass 3/3 pass 3/3
guest_raise_exception timeout 3/3 (30 s) timeout 2/3

Suites:

merge main
libc 142/142 pass not run
libkernel 205/207; guest_raise_exception and guest_raise_in_host_code time out run 1: 207/207; run 2: guest_raise_in_host_code times out

The libkernel timeouts aren't from this PR: main shows them too, and this PR doesn't touch libkernel. Run outside ctest, guest_raise_exception passes but takes 35.6 s and 37.4 s on this machine. I filed the breakdown as #9610: 14.8 s of it is raises on a thread looping in sceKernelSyncOnAddressWake.

Not tested: a title, or a performance pair.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332644669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6332644669). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T04:23:14Z. --- Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release, `BUILD_TESTING=ON`. I compared `main` d9c99c9ba4 with a local merge of your head a2e0bf19e6 into it (c66a5dbc72, no conflicts). **Focused tests, 3 runs each:** | | merge | `main` | |---|---|---| | `windows_shared_map_cost` | pass 3/3 | not on `main` | | `windows_write_watch`, `guest_memory`, `guest_jit_shared_memory`, `guest_shm_open` | pass 3/3 | pass 3/3 | | `guest_raise_exception` | timeout 3/3 (30 s) | timeout 2/3 | **Suites:** | | merge | `main` | |---|---|---| | libc | 142/142 pass | not run | | libkernel | 205/207; `guest_raise_exception` and `guest_raise_in_host_code` time out | run 1: 207/207; run 2: `guest_raise_in_host_code` times out | The libkernel timeouts aren't from this PR: `main` shows them too, and this PR doesn't touch libkernel. Run outside ctest, `guest_raise_exception` passes but takes 35.6 s and 37.4 s on this machine. I filed the breakdown as #9610: 14.8 s of it is raises on a thread looping in `sceKernelSyncOnAddressWake`. Not tested: a title, or a performance pair.
EagleBearerYS commented 2026-10-22 05:39:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T05:39:32Z.


@JJenkx thanks for the Windows run on the 5950X, and for tracking guest_raise_exception's time down in #9610. It's in Tested now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333634627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9505#issuecomment-6333634627). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T05:39:32Z. --- @JJenkx thanks for the Windows run on the 5950X, and for tracking `guest_raise_exception`'s time down in #9610. It's in Tested now.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9505
No description provided.