perf(agc): resume an idle store that yielded to a GPU mutex waiter #26450
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26450"
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-23T23:03:51Z.
What
An idle store that yields to a thread blocked on the GPU mutex is now resumed while queue 0 stays idle, instead of leaving its remaining results pending.
Since #20145
StoreIdleResultsstops after a piece as soon as another thread is blocked onGuestMemory::GpuMutex. The queue worker did not come back for the rest: after the yield, queue 0 went dormant with results still pending, and nothing stored them until the idle epoch moved and another 50 ms quiet period passed. One short lock by a thread that queues nothing (the presenter, the draw committer, a title thread) therefore cancelled the store for that idle stretch, and the next submissions met pending images. That matches what #25535 measures on PPSA20423: about 150000 pending-image fast-fails per run with the yield against about 200 without it, whileGpuMutex.waitstays at about 10 ms per 10 s in both arms.VulkanDevice::StoreIdleResultsnow returns whether it finished. When it stopped early and queue 0 is still idle, the worker stands back for the blocked thread (at most 2 ms, ended at once by new work) and then takes the next piece without a new quiet period. What #20145 gave is kept: a blocked thread waits for one piece at most, and the first piece of each pass is still always stored, so a mutex that is always contended cannot starve the store. If work came and went during the store, the quiet period applies again as before.Related: #25535. I do not have PPSA20423 or PPSA24423 (the title #20145 was measured on), so this PR does not claim the beach numbers; see Tested.
Tested
New test
agc_driver_idle_store_resumes(tests/execution/IdleStoreResumes.cpp): eight pending storage images and a thread that keeps taking the GPU mutex without queueing anything; the results must be stored while queue 0 stays idle and nothing is submitted. Onmain47d328f1c4it fails ("an idle store that yielded to a thread blocked on the GPU mutex left results pending while queue 0 stayed idle"); with this change it passed 3 of 3 runs.agc_driver_idle_store_yields,agc_driver_idle_store_over_unmap,agc_driver_queue_zero_quiet_interrupt,agc_driver_storage_idle_store_completes,agc_driver_store_idle_results,agc_driver_store_idle_results_wakeandagc_driver_store_idle_results_disabledpass with it. Linux, RTX 4090.No-harm check on a title I have: Linux, RTX 4090 (24 GB), i9-14900KF, PPSA21564 01.007.000, 3840x2160,
-lvl hub_crashsitefrom a save, no input, no profile, 180 s per arm, one exclusive window, order warm-up (discarded),main, PR, PR,main.mainis47d328f1c4, the PR arm is this head. Means of the last two 10 s windows of each arm:mainmainNeutral:
main60.1 ms, PR 60.1 ms on average, and the two arms of one build differ by 0.4 ms (main) and 1.5 ms (PR). It shows only that nothing got slower on this scene.Not tested here: PPSA20423 (the #25535 beach) and PPSA24423. An A/B of this head against
mainon those two scenes is what would show the gain and that the waits #20145 removed stay gone.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 malekaifa on 2026-11-23T23:13:43Z.
Review: CHANGES_REQUESTED
Blocking fairness gap on exact head
abb9aa2e615c6222a835b30b85bbf65a64ecc8a1.The resume idea addresses the measured pending-image problem, but the implementation does not yet guarantee the PR's stated property that a thread already blocked on
GuestMemory::GpuMutex()waits for at most one stored piece.GpuMutexType::block()keepsWaiters()nonzero until the waiter actually acquires the underlyingAgcDriver::Mutex; that mutex is barging (unlock()storesUnlockedand thennotify_one(), while a new caller may wintry_lock()before the notified waiter runs). InQueueWorker.cpp, after a yielded store we wait only untilWaiters()==0or 2 ms expires. If the counted waiter has not been scheduled/acquired within those 2 ms, queue 0 immediately loops, takesStoreIdleResults()again, and itsYieldToGpuMutexWaitersdeliberately stores the first 4 MiB piece before checking waiters. The same waiter can therefore sit through multiple pieces/passes; under scheduler load this can reintroduce the long lock hold #20145 was intended to cap.The new
IdleStoreResumestest only proves eventual completion while another thread repeatedly acquires/releases the mutex; it does not prove that the waiter which caused a yield gets the handoff before the next store piece.Please make the resume condition observe an actual handoff (or otherwise avoid reacquiring while the causal waiter is still counted), and add a regression that starts a single counted waiter and proves it acquires before queue 0 begins the second resumed piece. New work must still interrupt the wait immediately. I did not find another blocker in the four-file diff. Hosted checks were still queued at review time, so I am not making a CI claim here.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:49:53Z.
Review: COMMENTED
Reviewed — comments
The code review found no verified blocking defect, but the reported tests and target-scene performance results were not independently run or confirmed.
What I ran
Reviewed head
9ce2c86411b7150a289e3aa58bc65bb2e4a98b90against the prepared diff and targeted source context usingrepo_read.py. No tests or builds were run.Results
Negative control
Not run. The PR description reports that the new test fails on the stated
mainrevision and passes on this head; I did not independently confirm those runs.Findings
Blocking
None found in the code reviewed.
Non-blocking
Sources
QueueWorker.cpp:248-262andVulkanDevice.cpp:3156-3163.Not verified
VulkanDevice.hpp,QueueWorker.cpp,VulkanDevice.cpp(targeted range), andIdleStoreResumes.cpp(targeted range).VulkanDevice.cppwas excluded from the prepared full-text bundle because of size; its changed function was read throughrepo_read.py.To get this to a good state
Nothing is required. Optional: provide matched A/B results on PPSA20423 and PPSA24423 to support the stated performance goal.
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-26T15:59:28Z.
Review: APPROVED
Re-reviewed exact head
9ce2c86411b7150a289e3aa58bc65bb2e4a98b90against the fairness issue raised onabb9aa2e615c6222a835b30b85bbf65a64ecc8a1.The 2 ms escape is gone. After
StoreIdleResultsyields, queue 0 stays in the handoff loop untilGpuMutex().Waiters() == 0, new queue-0 work, a pending completion, or an idle-epoch change.GpuMutexType::block()increments the count before waiting and decrements it only afterLockSpinninghas acquired the underlying mutex, so zero is an actual handoff rather than a timer. A clean handoff resumes the pending store without another quiet period; work/completion/epoch interruptions return to the ordinary idle path. I found no remaining blocking defect in the changed code.On the single-waiter variant: I do not think it adds a distinct regression signal. The observable fairness window is when one waiter has acquired the mutex while another is still counted. The two-waiter regression deliberately creates that interval and checks that queue 0 does not re-enter while the second waiter remains blocked. With only one waiter,
Waiters()reaches zero at the handoff, at which point queue 0 is supposed to resume; a separate test would duplicate the lower-level single-waiter accounting already covered byIdleStoreYields::CountsMutexWaiters, or require additional instrumentation to measure the next stored piece. Keep the current two-waiter regression.The exact-head hosted Build, Emscripten portability, and Progress report workflows are successful. The PR discussion also contains GPU regression runs from the author (3/3) and an additional RTX 3070 report (3/3 with the validation layer). I did not run a local GPU test in this review.
One non-blocking description correction remains: the PR body still says “at most 2 ms”; the implementation now waits without a time limit until the handoff or an interruption. Please update that wording.