fix(windows): use precise waits in sub-millisecond polling loops #1551
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1551"
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 MarcZX10 on 2026-10-08T12:06:25Z.
What
Replace sub-millisecond
std::this_thread::sleep_forpolling withPreciseSleepUs()in three host-side loops. On Windows, winpthreads truncates thesenanosleeprequests to whole milliseconds, so requests below 1 ms return immediately and spin. This addresses the Windows busy-spin behavior documented in #1471.WAIT_REG_MEM: 50 µsKeep the focused
precise_waitCTest for the helper.Relationship to #1576
The production call-site changes originated in #1576 and are retained here with Shaan credited as co-author. The maintainer closed #1576 as a duplicate of this PR on 2026-10-10, identifying #1551 as the single carrier. This PR also includes the focused
PreciseSleepUshelper regression test.The AIO substitutions were removed after Windows measurements showed that the AIO wait loops return on their first check and the change had no measurable benefit. The same report found each precise wait takes about 0.5 ms instead of the requested 10–50 µs, so no AIO performance claim is made.
Overlap audit
The automated overlap notice for #1360 is only the insertion point in
core/libs/prx/libc/CMakeLists.txt. #1360 registers its mapping-history test; this PR registers the precise-wait helper test. They add separate targets and test behavior, with no production-file overlap or dependency.Tested
Current PR head is
54a90185147ea49d1913bccfed53fb477e619b9f, rebased linearly onto upstreammainat6cc33583326dd86c35f14710b984d767405d203e. The five-file diff contains three production call sites, the helper test, and its CMake registration.libc,libSceAgcDriver,libSceFont,libkernel,precise_wait_tests,agc_driver_pm4_tests,guest_aio_tests,guest_font_tests, andguest_font_writing_line_tests.precise_wait,agc_driver_pm4,guest_aio,guest_font,guest_font_writing_line; 0.08 s total).python3 tools/check_conventions.py --base upstream/mainandgit diff --check upstream/main...HEADpass locally.sleep_for(10/50/200 µs)returning immediately andPreciseSleepUstaking about 0.50 ms; see the report. An independent Windows 11 Pro 25H2 report on earlier headd6c7e2f6, cherry-picked ontomaind70b8998, used RTX 5060 Ti / NVIDIA 617.42, MinGW-w64 GCC 15.2.0, Release and a full build pluslibs:precise_waitpassed and full CTest passed (511/511) (report). These Windows runs predate this rebase.sleep_for.Checklist
main; one topic: use the precise wait helper at sub-millisecond host polling sites and test the helperImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T12:07:00Z.
Rebased directly onto
upstream/main(c68c7576); current head is679549800f5083fffe17d5ca820af7c2e7fcc3af. The five focused Linux tests passed, including five consecutiveprecise_waitruns; conventions andgit diff --checkpass. Windows remains untested locally. Could a maintainer approve the current-head workflows, which areaction_requiredwith no jobs?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:29:01Z.
Rebased this PR onto current upstream
main(4b6ab6bb) and updated the body with the new head and validation. I also moved theprecise_waitCMake registration besideguest_time_conversion, away from the commonif(BUILD_TESTING)insertion point used by #1806 and #1814. Those PRs remain independent; this one has no dependency on either. The current CMake configure/build and focused CTest pass, and conventions plusgit diff --checkpass.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:29:16Z.
The current-head Build, Conventions and Progress report runs were created as
action_required(no PR checks are reported). The contribution guide says a maintainer must approve fork workflows before they can run. Could a maintainer approve the runs for head0999ed5aso upstream CI can validate this rebase?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:22:52Z.
Rebased onto current upstream
main(364a56b; head0812c0bc). The reviewed six-file diff is unchanged in scope. The focused helper test compiles and passes directly on this head; the prior head passed the CMake configure/build and focused CTest runs. Conventions andgit diff --checkpass. No checks are reported for the rebased head; Windows remains untested locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:24:41Z.
The Build/Conventions workflow runs for current head
0812c0bcec6cfcd55af3902dda6cd2ba561a857fare markedaction_requiredand have no jobs, so upstream CI has not run yet. CONTRIBUTING requires maintainer approval for fork workflows. Could an authorized maintainer approve these current-head runs?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:51:10Z.
The fork Build on the previous head found a Windows link failure in
precise_wait_tests.exe: undefined__gxx_personality_v0. The test target was missingconfigure_windows_unwind, which the repository applies to other C++ test executables. Added that configuration in headb439aa29, rebased onto currentmain94b1eecb; conventions, diff check and the focused helper test pass. I dispatched a new fork Build (37849602930); its Windows result is still pending. Upstream checks remainaction_required.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T22:06:58Z.
The second Windows failure on head
b439aa29confirmed thatconfigure_windows_unwindonly renames unwind sections after linking; it does not provide__gxx_personality_v0. The test now linkslibc(which supplies the project personality symbol) and adds the matching Windows DLL path, while retaining unwind setup. Current head1f8a2cccis rebased ontoae91d978; conventions, diff check and the focused helper test pass. New fork Build37851358263is queued; its Windows result is pending. Upstream checks remainaction_required.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T22:27:46Z.
The re-scoped test-only head is
adc6a7ed. Its upstream Build and Conventions runs areaction_requiredwith no jobs, while the fork Build is running. CONTRIBUTING says a maintainer must approve fork workflows; could an authorized maintainer approve the current-head runs?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T22:55:42Z.
The test-only PR is now rebased onto current
mainf1451396at head87b26330; local conventions and the focused CTest pass. The new upstream Build and Conventions runs areaction_requiredwith no jobs, per the documented fork policy. Could an authorized maintainer approve those current-head runs? The fork Build is queued.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:35:53Z.
Rebased the isolated test-only change onto current upstream
main6cc0503d; the full diff is still just CTest registration and one small regression test. The current Linuxprecise_waittest passes (1/1, 0.00 s), conventions and diff checks pass, and prior Linux/Windows full CTest both passed on this exact test source. Fork Build 37905909616 is running on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:47:14Z.
Fork Build completed with Linux and Windows blocked on the unrelated
agc_shader_fusion_testscompile error:VulkanTestDevice.hppcannot findspirv/unified1/spirv.hpp. All three relinker jobs passed. I recorded the result in the PR description and linked #2093 as the dependency fix.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T11:18:32Z.
Rebased PR #1551 linearly onto current
main(d70b8998). On head46c8f5af, the focused Linux CTest passes (1/1, 0.02 s), conventions and diff checks pass, and GitHub reports it mergeable. The previous fork full CTest results remain disclosed in the body and were not rerun after this rebase. Under #2113, could a collaborator with write access run Actions → Build for this PR so the full Linux, Windows and relinker checks are recorded on the new head?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T12:04:39Z.
I expanded this PR to include the four sub-millisecond polling call-site changes from #1576 and credited Shaan as co-author. On exact head
d6c7e2f6, the Linux Release build and focused CTest pass (7/7), conventions pass, andgit diff --checkpasses. The fork Build dispatch is skipped by its eligibility gate because manual full builds require a PR open in the fork; upstream currently reports only Conventions. Under #2113, could a collaborator with upstream write access run/approve Build for this head, including the Windows full CTest?Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T12:38:45Z.
Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
-DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build pluslibs. d6c7e2f6 cherry-picked onto currentmaind70b8998(applies cleanly).precise_waitpasses.guest_aio,guest_ampr_markers,guest_font,guest_font_writing_lineandagc_driver_pm4_failure.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:11:14Z.
Thanks for the Windows report: it covers the exact PR head
d6c7e2f6on currentmain, and the full Windows CTest passes (511/511). That supplies the Windows evidence. The upstream PR still reports only Conventions; could an authorized collaborator run the official Build for this head to record Linux and the relinker matrix as well?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T19:33:15Z.
Rebased the existing PR linearly onto current
main(ae3d5f95) at heada62e5f49. The diff still contains the same four wait-site changes and focused helper test. On this source diff, all affected Linux libraries and test targets build, and the seven focused CTests pass (7/7). Local and GitHub Conventions pass. I updated the description to label the Windows full-suite report as pre-rebase evidence.\n\nCould a collaborator with write access run the required upstream Linux/Windows Build and relinker matrix for this exact head under #2113?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T20:02:08Z.
Validation on the updated head
I rebased the existing branch linearly onto upstream
mainat8b393b6eand pushed head46a77cca. The full six-file diff still contains the same four polling changes and focused helper test. On this source, all affected libraries and seven focused tests build; CTest passes 7/7. Local Conventions andgit diff --checkpass. The Windows full-suite report remains clearly labeled as pre-rebase evidence.The matching production call-site work from #1576 is integrated here with Shaan credited as co-author. #1551 remains the fuller candidate because it includes the same production changes plus the helper regression test. The required upstream Build and relinker matrix is still pending for this head.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:57:49Z.
Review: CHANGES_REQUESTED
Thanks for the Windows evidence and the helper test. One blocker:
Pm4.cpp:816,Apr.cpp:589,Aio.cpp:256/:281,State.cpp:60) are the same edits as the open #1576, which CONTRIBUTING doesn't allow (no open PR implementing the same change). Co-authoring the commit doesn't change that: two PRs can't both land them.core/libs/tests/PreciseWait.cpp+ its CMake registration (the scope it had before 2026-10-09), with #1576 in Depends on if you want the test to cover it. Or, if you and the author of #1576 prefer this one to carry the change, agree that there and close the other.precise_waitpasses onmainwithout any of these changes (it only exercises the helper), so it won't catch a call site reverting tosleep_for. That's fine as a helper test, just don't claim it covers the call sites.Checked: Linux build,
precise_wait,agc_driver_pm4,guest_aio,guest_font*pass on this head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T07:22:03Z.
Thanks for the review. I agree that the two PRs cannot both land the same production changes, and that the helper test does not prove the call sites use the helper.
I rebased #1551 onto current
main(a291ae0f) and reran the affected Linux builds and focused tests: all five focused CTests pass, and local Conventions passes. I updated the description to state the helper test's limits and to mark the overlap with #1576 explicitly.I have asked Shaan on #1576 to confirm one carrier. My preference is #1551 because it preserves the four production changes with Shaan credited and includes the helper regression test. If Shaan prefers #1576, I will remove the production changes from #1551. I will not ask for both to merge; the overlap remains unresolved until Shaan replies.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T07:27:22Z.
Follow-up to the review
precise_waittest covers the helper's requested minimum delay. It does not prove production call sites use the helper; the PR description now states that limitation.6c240d55; local Conventions andgit diff --checkpass.The current GitHub Build has passed eligibility and Ubuntu register-context jobs. Its Linux and Windows full-build jobs are skipped by the fork eligibility gate; macOS and relinker jobs are still running. The PR description records these limits. Please re-review this updated scope when convenient.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T07:29:26Z.
Current-head CI result
Build run 38034401344 completed successfully on head
6c240d55.The local focused Linux CTests pass 5/5 as recorded in the description. The full CI build matrix did not run on this fork PR; Windows reports in the body are from earlier heads. Please re-review this updated scope and CI result when convenient.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T08:36:22Z.
Rebased #1551 onto upstream
mainat6cc33583(head54a90185). The affected Linux Release libraries and tests build; the five focused CTests pass (5/5), and local Conventions plusgit diff --checkpass.The maintainer closed #1576 as a duplicate of this PR, so the three production call sites remain consolidated here with Shaan credited as co-author. The current Build and Conventions runs are queued (Build, Conventions); full Linux and Windows jobs are skipped by the fork eligibility gate. Please re-review when the current checks finish.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T08:52:26Z.
Follow-up on the review blocker
The duplicate has now been resolved: maintainer adriadam10 closed #1576 as a duplicate of #1551, noting that this PR is the single carrier for the shared call-site changes and includes the helper regression test. Shaan remains credited as co-author.
The current posted head is
54a90185147ea49d1913bccfed53fb477e619b9f. Its eligible GitHub checks have completed:The PR description also clarifies that
precise_waittests the helper's requested minimum delay; it does not prove that production call sites remain wired to the helper. The local focused Linux test results are recorded there as well.Could you revisit the
CHANGES_REQUESTEDreview with the duplicate closed and these checks complete? I understand the skipped full Linux/Windows jobs still require collaborator-triggered validation under the contribution guide.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:52:46Z.
Review: APPROVED
Checked the three call sites (
Pm4.cppWAIT_REG_MEM,Apr.cppcounter/address wait,State.cppfont backoff) against the existingPreciseSleepUshelper on main; they build andprecise_waitpasses on main + this PR (Linux). Windows evidence from @rmz-24 (full ctest 511/511) and @popcoder565's measurements in #1471 cover the behaviour we can't run here. Note the helper test only pins the minimum delay, not the call sites. Merging.