perf(libSceAgcDriver): stop the idle store for a thread blocked on the GPU mutex #20145
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20145"
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 xXPBSXx on 2026-11-14T17:59:00Z.
What
When queue 0 has nothing queued, the queue worker stores the pending storage-image results back to guest memory (
VulkanDevice::StoreIdleResults, which callsStorageTexture::FlushAllPendingUntilin pieces of 4 MiB) while holdingGuestMemory::GpuMutex. Its stop test looks only at the queue state, so a title thread that is blocked on the mutex and therefore has queued nothing does not make it stop: the store runs on, and the title waits behind it.In Slay The Princess (PPSA24423) on
mainthe title waited behind the idle store for up to 348 to 373 ms (single waits in the 20 s capture windows), and the worker sat inidle_and_completion_pollfor up to 1.5 s. This PR adds two things.GpuMutexType::Waiters()counts the threads blocked inlock(), spinning included (a relaxed atomic that is only counted, nothing waits on it).YieldToGpuMutexWaiters(stop)wraps the stop predicate: it never stops before the first piece has been stored, and after that stops as soon as another thread is blocked on the mutex.StoreIdleResultspasses it toFlushAllPendingUntil. The rest of the pending results is stored in the next idle round, as before.Side effects. The counter changes no ordering and cannot deadlock (no thread waits for it). The first piece is always stored, so a mutex that is always contended does not starve the store; a store that yields stores its remaining images in later idle rounds, so the number of submits per image can grow (not measured separately). #16011 makes
FlushPendingwait for the recorder after a piece of an idle flush, under the mutex; it does not touch this predicate and merges with this change without a conflict, but each piece it stores then holds the mutex for that wait too. #20015 ends the 50 ms quiet-period wait of queue 0 inQueueWorker.cppwhen a completion is pending; it is the same idle path but another wait (this change stops a store that is already running for a thread blocked on the mutex), and it merges with this change without a conflict. The tests of #20015 and #16011 were not run on a tree with this change.What is not claimed: the frames are not free of stalls. With this change, residual stalls remain in some intervals (see the table), for example a 246 ms frame in one capture window where the worker was in
idle_and_completion_pollfor 239 ms while the title was not blocked on the mutex; I do not know their source.Tested
Windows 10 Pro, AMD Ryzen 7 5800X3D, NVIDIA GeForce RTX 4080 SUPER (driver
NVIDIA 610.74as shown in the summary lines) and AMD Radeon RX 6400 for the tests. WinLibs GCC Release.Tests. Two pairs, each test commit failing on
mainand the following fix commit passing, on the RTX 4080 SUPER: the newCountsMutexWaiters(GpuMutexType::Waiters()is 0 without a waiter and while holding, 1 while a thread is blocked, 0 again afterwards) andStopsForMutexWaiter(with a thread blocked on the mutex an idle store stops after exactly one of two pending images and reports it is not finished; with none it stores both; the result of both stores is in guest memory). Without the fixagc_driver_idle_store_yieldsaborts, with it it passes; the pairs were run again onmain0f4538fa022as the base (the series was rebased from0d2db33e0d5;git range-diffshows the two fix commits unchanged and the two test commits differing only by two comments removed fromGuestMemory.hpp), on the RTX 4080 SUPER. With the validation layer (VK_LAYER_KHRONOS_validation, inserted into the device asVK_LOADER_DEBUG=layershows) the new test program on this head passes on the RTX 4080 SUPER and on the RX 6400 with 0VUID-lines, and the test commit without the fix aborts at the same place as without the layer on both GPUs.ctestof the 279 tests ofagc_driver_*whose name containsdraw,pipeline,present,label,recorder,commit,frame_replay,idle,storeormutex, onmain0f4538fa022and on this head, once each on both GPUs, without the validation layer: the same result in all four runs: one test (agc_driver_write_data_written_ahead_draw_pipeline) fails the same way onmainand on this head in all four full runs, but passes in 12 of 12 separate runs of that test alone (3 per arm and GPU), so it depends on the run of the whole group and not on this change; three tests were not run in the full runs because their programs were not built (agc_driver_batch_cap_wait_draw_pipeline,agc_driver_color_write_mask_dynamic_in_pipeline,agc_driver_prepared_shaders_abi_deferred_background_draw) and pass when built and run (3 of 3 on each arm and GPU); andagc_driver_present_upscaleandagc_driver_partially_committed_volume_page_samplesskip themselves (on the RX 6400agc_driver_copied_writer_label_orderand_drainskip as well). On the earlier base0d2db33e0d5the same run over 267 tests had no failing test (24 programs not built in the first pass passed in a second pass on each arm and GPU). The validation layer crashes in most of the other tests on the base too, so I do not claim that no new validation message appears outside the new test program.Frame stalls, PPSA24423, measured on the earlier base
0d2db33e0d5(A) and the head before the rebase0a74e649147(B), 1920x1080, 600 s runs,APS5_TRACE_SUMMARY_EVERY=10,APS5_TRACE_SECONDS=300:20,APS5_TRACE_EVENTS=2097152, noAPS5_PROFILE_DRAW, arms interleaved (B A B A B A B A), same session. A stall interval is a 10 s interval from 60 s on whose longest frame is over 40 ms; the scene differs between runs (title state, not controlled), so the share per run varies from 24 to 83 %.Over the four pairs there were fewer stall intervals with the change (the rebased series differs only by two removed comments): 98 of 185 (53 %) against 142 of 195 (73 %), and the head is lower in all four pairs (38 against 76, 78 against 83, 65 against 71, 24 against 63 %). In the capture windows (one 20 s window per run) the title waited on the mutex for more than 50 ms in two of the four
mainwindows (1 and 3 waits, up to 348 and 373 ms) and in none of the four head windows (up to 19 ms); in the other twomainwindows it did not wait either (up to 11 ms) although those runs had stall intervals, so stalls also have other sources. The longest wait of the worker inidle_and_completion_pollin a window was 238 ms with the change and 1548 ms onmain. Presents per 10 s: medians 544 to 600 with the change, 530 to 572 onmain; frame time p50 about 16.7 to 16.9 ms in all runs (the title runs at 60 fps between stalls).VK_ERROR_DEVICE_LOST: 0 of the 8 runs ended that way (title and arm). The GPU was also used by other jobs of the machine's owner:nvidia-smievery 30 s for runs 5 to 8: mean 18, 27, 15 and 20 % (single readings 1 to 45 %); there are no readings for runs 1 to 4 (the log of that series was overwritten). Working set maximum of the process in runs 5 to 8: 3978 and 4192 MiB with the change (runs 7 and 5) against 4106 and 4639 MiB onmain(runs 8 and 6), so it is not larger with the change.The summary line of one capture window of each commit (
mainrun 2, head run 1) and the digests are below; the traces are attached.Overlap: the 97 other open pull requests that change one of the four files of this branch (found by reading the changed files of all 1542 open pull requests at about 16:28 UTC; nearly all of them through
VulkanDevice.cpp) were test-merged on 2026-11-14 at about 16:35 UTC againstmain32a2f1e1d73(the branch is based on0f4538fa022, which is an ancestor of it); the branch merges intomainwithout a conflict. 55 of them already conflict withmainwithout this change and still conflict with it, 42 merge cleanly with and without it; none conflicts only with this change. Three pull requests that touch the same code path through other files were merged with this branch separately, againstmain0a32f988315at about 16:43 UTC: #16011 (Texture.cpp) and #20015 (QueueWorker.cpp, the quiet period's wait) merge cleanly with and without it, #13963 already conflicts withmain. The tests of #20015 and #16011 were not run on a tree with this change.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)NVIDIA 610.74in the trace summary lines) and AMD Radeon RX 6400 (driver 32.0.21033.3005), versions as reported by Windows, Windows 10 Pro 10.0.19045Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T19:00:54Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and its targeted tests support merging, though I did not run the reported checks myself.
What I ran
Reviewed head
645c18f94226de139809028b89e7ef10e0806907. I read the prepared description, commits, manifest, and diff, plus the changedGuestMemory.hpp,GuestMemory.cpp, andIdleStoreYields.cppand targeted context inMutex.hpp,HandoffSpin.hpp,Texture.cpp, andVulkanDevice.cpp.VulkanDevice.cppwas excluded from the prepared full-text files but its changed function was read through the pinned reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the build, tests, or GPU measurements. The reported Windows and GPU results were not independently verified. Files reviewed:
GuestMemory.hpp,GuestMemory.cpp,VulkanDevice.cppchanged function, andIdleStoreYields.cpp; targeted context:Mutex.hpp,HandoffSpin.hpp, andTexture.cpp. No changed files were excluded from source inspection;VulkanDevice.cppwas omitted from the prepared full-text bundle because it was too large, then read through the repository reader.To get this to a good state
Nothing is required.