perf(agc): wake a short sleep once the CPU label it waits for has landed #8858
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8858"
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 Dripl1x on 2026-10-21T03:30:58Z.
What
An unimported queue-0 label is stored by the CPU after a recorder sync (#7464). The GPU progress watcher, and
finish()for a batch with completion actions, woke short guest sleeps (#6658) as soon as the last batch of that sync completed, before the CPU store. A guest that polls the label between short sleeps woke, did not find it, slept again, and only the store's own wake ended the second sleep.commitLabelandrecordDeferredLabelsopen aRecorder::LabelWakeHandoffaround each label and wake through it (WakeNow) after the CPU store.Recorder::SyncForCpuLabelinstead ofSync. It arms the recorder's wake ledger with the newest serial before it submits, so the watcher cannot see that batch complete before the ledger is armed.finish()on the label's own thread, leave the wake for that serial and later ones to the label: the ledger records it as owed, and the handoff pays it after the store, or on any other exit (an exception, a label that ends up on the GPU) when it closes. Earlier batches of the same sync still wake when they complete.APS5_NO_LABEL_WAKE_HANDOFF=1restores the earlier wakes (row added todocs/dev/ENVIRONMENT.md).agc_driver_label_wake_handoff(--label-wake-handoff-onlyofagc_driver_same_queue_label_wait_tests): a 1 ms guest sleep while a DCB runs a short dispatch and writes a label in a block no import covers. Each attempt must take the unimported path (syncedUnimportedLabelsgrows); no early wake may come before the store, and a label that lands in the sleep must end it.Tested
Windows 11 Pro (26300), NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42 (Vulkan 1.4.351), MinGW GCC 15.2 Release build.
agc_driver_label_wake_handoff: 33 runs passed, about 1 s each. In the 21 runs whose output was kept, every run had 16 early wakes after the store, 0 before it, 0 sleeps that ran out after the label landed, and 0 labels on another path. Also 5 runs passed withAPS5_PIPELINED_DRAWS=0, where the label goes through the deferred-label path, with the same counts.APS5_NO_LABEL_WAKE_HANDOFF=1: the test fails in each of 13 runs. In each run, 13 to 31 early wakes came before the store, with 16 after it.agc_driver_cpu_label_wake,agc_driver_same_queue_label_wait,agc_driver_unimported_label_order,agc_driver_indirect_arguments_pending_producer,guest_sleep_wake,guest_nanosleep.agc_recorder_device_selection,agc_gpu_timing_complete,agc_gpu_timing_incomplete,agc_recorder_read_list,agc_recorder_deferred_failure_report,agc_copied_direct_ordering,agc_storage_write_back,agc_storage_writeback_blocks,agc_storage_written_buffer_order,agc_pending_write_snapshot,agc_space_pending_writes,agc_pending_key_stores.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V; RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 11 Pro build 26300;DISABLE_LAYER=1turned off a third-party implicit layer then installed here, FPS Monitor, whosevkDestroyInstancehook crashedagc_parked_import_unmapon main as well) on #7464b31bc845fband on53b177f2d5: 67 and 68 tests, all pass, neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and both report the same VUIDs the same number of times (VUID-VkImageViewCreateInfo-usage-022754,VUID-vkCmdCopyBuffer-srcBuffer-001182), so the change adds none.libSceAgcDriverbuilds.SuperTuxKart captures for the before/after requirement: Windows 11 Pro build 26300, Ryzen 7 5800H, RTX 3070 Laptop GPU, NVIDIA 617.42, WinLibs GCC 15.2.0 r7, Release; SuperTuxKart (PPSA69421) tutorial prompt over the main menu, 1920x1080 internal rendering in a maximized 2560x1369 window, warm shader caches, audio muted, no input;
APS5_TRACE_SECONDS=20:8withAPS5_TRACE_EVENTS=1048576, console output not redirected, no profiling switches other than the local counters'APS5_REVIEW_PROBE; 2026-10-21, order base, (fence-spin variant), base + this PR, base + this PR, (fence-spin variant), base.nr21-p01-paircd700fe9ec+ #7464 + #7465 + probesea3754973876nr21-p06-paircd700fe9ec+ #7464 + #7465 + probesea3754973876nr21-p03-pair-handoff9e2a338d5082nr21-p04-pair-handoff9e2a338d5082The FPS difference (25.38 / 25.67 against 26.32 / 25.43) is within the run-to-run spread; this PR claims no FPS change. What it saves is shown under Where it helps.
Summary lines (main first, then this PR)
tools/performance_compare.py(first capture of each side)Performance comparison
Configuration differences
Frame and GPU times (ms)
Top phases (ms per frame)
tools/trace_digest.pyoutput (first capture of each side; all digests are in the evidence archive)nr21-p01-pairseconds 20:8 from present 131: 204 presents, frame p50 38.4 / p90 42.6 / p99 56.1 / max 58.7 ms, GPU busy 4.7 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit ea3754973876, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
nr21-p03-pair-handoffseconds 20:8 from present 128: 211 presents, frame p50 37.2 / p90 41.7 / p99 45.2 / max 49.6 ms, GPU busy 4.7 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit 9e2a338d5082, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Where it helps
The path only runs when queue-0 labels are stored on the CPU, which in this scene happens once #7465 leaves the label blocks unimported: with #7464 and #7465 the title makes about 59 such syncs per frame. Measured on main
cd700fe9ecwith #7464 and #7465 merged locally (the base), and with this PR on top:SleepWake::Sleep)KernelWakeSleeperscallsRecorder::SynccallsThe guest's short sleeps and the wakes that end them halve: a sleep is no longer woken by the batch completion before the label it polls for lands, so it does not sleep a second time. Counters come from a local probe build that is not part of this PR (
review-probe-nr21.patchin the evidence archive): the same 13 counters and timers were inserted into the base and into the base with this PR, and the captures above ran on those builds. Values are per flip over the trace window, medians of two runs per side. Without #7465 the path is rarely taken: on main with #7464 alone the counts barely change (184 → 175 short sleeps per frame).Reproduction evidence
nr21-handoff-evidence.zip (traces, summary lines,
trace_digest.pyandperformance_compare.pyoutput, loaded-module hashes), the counters where-nr21.json and where-nr21-pair.json, and the probe review-probe-nr21.patch.Checklist
b31bc845fb(its base is main2185dbf92e); merges cleanly into current maincd700fe9ectogether with #7464 and #7465, which is the measured build; 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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T03:42:40Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppL164core/libs/prx/libSceAgcDriver/CMakeLists.txtL2025Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/SynchronizationStatistics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/DeferredLabels.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mddocs/dev/debt/libkernel.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:53:55Z.
Review: COMMENTED
The race it fixes is understandable (a short sleep woken before the CPU label store, so a polling guest wakes, doesn't find the label, and sleeps again), and the A/B on the test is clean (13 to 31 early wakes before the store without the switch, 0 with it).
perf, but the evidence is wake counts in a synthetic test with a 1 ms sleep. No title and no frame time is shown. Which title polls a label between short sleeps, and what does it gain? Per the Performance report form, post the summary lines of main and this PR from that title and scene (PPSA, presents per 10 s, p50/p99), noAPS5_PROFILE_*. A change that only moves a wake by a store's duration may not be measurable; if it isn't, say so in the description.LabelWakeHandoffaround each label,SyncForCpuLabel, a "skip a completion that the store's wake already followed" rule in the watcher, and an owed-wake that is paid on any exit. That is four interacting states for one wake. The failure mode of a missed wake is a sleeping guest thread that waits out its full sleep (or longer, for a long one), and the failure mode of an extra wake is a spurious wake the guest must tolerate. Please state which of these the ledger guarantees never happens, and add a stress test with many labels from two queues so the ledger is exercised under contention (the single DCB test can't show a race between the watcher andfinish()).[sync]profile line separating the new stall; this PR's wake correctness is only meaningful once that path is merged. Rebase when it lands so the diff is the handoff alone.Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-22T03:01:17Z.
Closing: the handoff removes early wakes, but the total sleep per frame stays the same, so there is no measurable gain to justify the added state. Thanks @CnRJay for the review.
Pull request closed