fix(libkernel): prevent sub-millisecond timed wait busy-spinning on Windows #11725

Merged
camezaro-intc merged 2 commits from upstream-pr/11725 into main 2026-10-30 11:44:24 +00:00
camezaro-intc commented 2026-10-27 05:52:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by camezaro-intc on 2026-10-27T05:52:16Z.


What

Reduce LEAD_NANOS in libkernel::TimedWait from 500,000 ns (0.5 ms) to 20,000 ns (20 µs), so sub-millisecond timed waits sleep on high-resolution waitable timers and only spin the last 20 µs with YieldProcessor(). Adds the guest_timed_wait_cpu regression test (500 µs sceKernelUsleep and scePthreadCondTimedwait, bounds overshoot and, on Windows, calling-thread CPU time).

Tested

Windows 11 Pro, Call of Duty: Modern Warfare III (PPSA24263). Verified that worker polling threads with sub-millisecond wait intervals (such as 500 µs via sceKernelUsleep) sleep via high-resolution waitable timers instead of burning 100% CPU on spin-waits, reducing CPU usage during polling from 100% across multiple cores down to ~1.5%. Author's Windows 11 / Ryzen 5 3600X run of the revised test (ctest --test-dir <build> --repeat until-fail:20 --no-tests=error -R '^guest_timed_wait_cpu$' -V): 20/20 passed on this PR's TimedWait.cpp; with TimedWait.cpp from main the same test fails at the 100 µs case (93.5% calling-thread CPU, limit 40%, abort 0xc0000409). Worst over the 20 runs, P99 / max overshoot / CPU: sceKernelUsleep(100 us) 1366 µs / 2641 µs / 3.1%; sceKernelUsleep(500 us) 1259 µs / 2466 µs / 5.7%; scePthreadCondTimedwait(500 us) 1552 µs / 2299 µs / 5.4%. Not rerun from the final pushed head 3d4e1e0930.

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: #12135 (this PR lands after #12135; the changes merge cleanly in either order)
  • Fixes: none
  • Unblocks: PPSA24263 #11591
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5029298261 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11725). Originally posted by [camezaro-intc](https://github.com/camezaro-intc) on 2026-10-27T05:52:16Z. --- ### What Reduce `LEAD_NANOS` in `libkernel::TimedWait` from 500,000 ns (0.5 ms) to 20,000 ns (20 µs), so sub-millisecond timed waits sleep on high-resolution waitable timers and only spin the last 20 µs with `YieldProcessor()`. Adds the `guest_timed_wait_cpu` regression test (500 µs `sceKernelUsleep` and `scePthreadCondTimedwait`, bounds overshoot and, on Windows, calling-thread CPU time). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro, Call of Duty: Modern Warfare III (PPSA24263). Verified that worker polling threads with sub-millisecond wait intervals (such as 500 µs via `sceKernelUsleep`) sleep via high-resolution waitable timers instead of burning 100% CPU on spin-waits, reducing CPU usage during polling from 100% across multiple cores down to ~1.5%. Author's Windows 11 / Ryzen 5 3600X run of the revised test (`ctest --test-dir <build> --repeat until-fail:20 --no-tests=error -R '^guest_timed_wait_cpu$' -V`): 20/20 passed on this PR's `TimedWait.cpp`; with `TimedWait.cpp` from `main` the same test fails at the 100 µs case (93.5% calling-thread CPU, limit 40%, abort `0xc0000409`). Worst over the 20 runs, P99 / max overshoot / CPU: `sceKernelUsleep(100 us)` 1366 µs / 2641 µs / 3.1%; `sceKernelUsleep(500 us)` 1259 µs / 2466 µs / 5.7%; `scePthreadCondTimedwait(500 us)` 1552 µs / 2299 µs / 5.4%. Not rerun from the final pushed head 3d4e1e0930. ### 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: #12135 (this PR lands after #12135; the changes merge cleanly in either order) <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: PPSA24263 #11591 <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-27 05:58:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T05:58:57Z.

Review: APPROVED


Reviewed exact head e7e3825aaeb71b030ea5028ab8ea024ac144c8aa. The wait-loop changes preserve the event/counter checks and deadline condition while reducing the precise-spin tail from 500 µs to 20 µs; SwitchToThread() gives other ready threads an opportunity to run before the processor pause. The CMake quoting change correctly keeps the forced-include path as one argument when it contains spaces.

git diff --check passed. I syntax-checked the changed Windows translation unit with MinGW GCC 12 using a compatibility definition for CREATE_WAITABLE_TIMER_HIGH_RESOLUTION (absent from this old toolchain's headers); compilation passed. The author reports a Windows 11 title run showing polling CPU use fall from 100% across multiple cores to about 1.5%, and a successful ctest -R libkernel -V. I could not run a native Windows runtime test here; hosted product jobs are skipped by path policy. No blocking issue found in the reviewed change, so approving based on the supplied Windows run and local static check.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662846224 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11725#pullrequestreview-5662846224). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T05:58:57Z. **Review:** APPROVED --- Reviewed exact head `e7e3825aaeb71b030ea5028ab8ea024ac144c8aa`. The wait-loop changes preserve the event/counter checks and deadline condition while reducing the precise-spin tail from 500 µs to 20 µs; `SwitchToThread()` gives other ready threads an opportunity to run before the processor pause. The CMake quoting change correctly keeps the forced-include path as one argument when it contains spaces. `git diff --check` passed. I syntax-checked the changed Windows translation unit with MinGW GCC 12 using a compatibility definition for `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION` (absent from this old toolchain's headers); compilation passed. The author reports a Windows 11 title run showing polling CPU use fall from 100% across multiple cores to about 1.5%, and a successful `ctest -R libkernel -V`. I could not run a native Windows runtime test here; hosted product jobs are skipped by path policy. No blocking issue found in the reviewed change, so approving based on the supplied Windows run and local static check.
adriadam10 commented 2026-10-28 09:01:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T09:01:37Z.

Review: CHANGES_REQUESTED


Thanks for the measurements. Before this can become the default for every Windows title:

  • Regression test: the 500 µs case has no test in the PR (the only changed file besides TimedWait.cpp is CMake), as @oneandonlydean asked. Add a registered guest test that waits ~500 µs through sceKernelUsleep or scePthreadCondTimedwait, and bounds both the overshoot and the calling-thread CPU time (GetThreadTimes) so it fails on main (100% spin) and passes here.
  • Tail latency: your own table shows P95 on 500 µs waits going from ~502 µs on main to 735–1020 µs with this PR, and max up to ~1.5 ms. Please say whether SwitchToThread() in the final spin causes that (it can give up the core for a whole quantum when another thread is ready) and whether a bounded number of SwitchToThread calls, or only YieldProcessor() in the last 20 µs, keeps the tail down. The test above should pin the bound you accept.
  • Overlap: #12135 changes the same spin loops in TimedWait.cpp (SleepUntil/SleepNanosUnlessChanged). Rebase on whichever lands first and list it under Depends on.
  • One topic: the -include quoting in core/libs/CMakeLists.txt is unrelated to timed waits; please move it to its own PR.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680106893 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11725#pullrequestreview-5680106893). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T09:01:37Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements. Before this can become the default for every Windows title: - **Regression test**: the 500 µs case has no test in the PR (the only changed file besides `TimedWait.cpp` is CMake), as @oneandonlydean asked. Add a registered guest test that waits ~500 µs through `sceKernelUsleep` or `scePthreadCondTimedwait`, and bounds both the overshoot and the calling-thread CPU time (`GetThreadTimes`) so it fails on `main` (100% spin) and passes here. - **Tail latency**: your own table shows P95 on 500 µs waits going from ~502 µs on `main` to 735–1020 µs with this PR, and max up to ~1.5 ms. Please say whether `SwitchToThread()` in the final spin causes that (it can give up the core for a whole quantum when another thread is ready) and whether a bounded number of `SwitchToThread` calls, or only `YieldProcessor()` in the last 20 µs, keeps the tail down. The test above should pin the bound you accept. - **Overlap**: #12135 changes the same spin loops in `TimedWait.cpp` (`SleepUntil`/`SleepNanosUnlessChanged`). Rebase on whichever lands first and list it under **Depends on**. - **One topic**: the `-include` quoting in `core/libs/CMakeLists.txt` is unrelated to timed waits; please move it to its own PR.
XairRrR commented 2026-10-29 03:08:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T03:08:13Z.

Review: DISMISSED


Reviewed — changes requested

The LEAD_NANOS change is small and merges cleanly, but the new Windows regression test can fail on an idle machine because of how it bounds CPU time and latency, which the author's own Windows runs of this head also show.

What I ran

  • Head: 1cf6f482c03f3f2d033ecccc65931289d549bbc1
  • main: 3a2b91981651569163768854a1fcdc7193b6667b
  • Host: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF. I had no Windows host, so this covers Linux only.
git fetch -q origin main pull/11725/head:refs/review/11725
git checkout -q --detach origin/main
git merge -q --no-ff --no-edit refs/review/11725
git diff --check origin/main...refs/review/11725
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs
cmake --build build -j10 --target guest_cond_recursive_mutex_tests guest_cond_timedwait_tests guest_cond_unowned_mutex_tests guest_nanosleep_long_request_tests guest_nanosleep_tests guest_sleep_cancel_tests guest_sleep_wake_tests guest_timed_join_tests guest_timed_wait_cpu_tests
ctest --test-dir build -j4 --output-on-failure --no-tests=error -R "^guest_(timed|nanosleep|sleep|cond)"
ctest --test-dir build --output-on-failure --repeat until-fail:50 -R "^guest_timed_wait_cpu$"
ctest --test-dir build -j4 --output-on-failure --repeat until-fail:5 -R "^guest_(timed|nanosleep|sleep|cond)"
# negative control
git checkout origin/main -- core/libs/prx/libkernel/Time/TimedWait.cpp
cmake --build build -j10 --target guest_timed_wait_cpu_tests
ctest --test-dir build --output-on-failure --repeat until-fail:20 -R "^guest_timed_wait_cpu$"
git checkout HEAD -- core/libs/prx/libkernel/Time/TimedWait.cpp
# overlap with #12135
git merge-tree --write-tree HEAD <#12135 head>

Results

Check Result
Merge into main Clean
git diff --check 1 issue: blank line at end of core/libs/tests/GuestTimedWaitCpu.cpp
tools/check_conventions.py Passed
Build libs and the timing test targets (Linux) Passed
53 timing tests (guest_cond_*, guest_nanosleep*, guest_sleep_*, guest_timed_*) 53/53 passed, 9.0 s
Same 53 tests, -j4, repeated 5 times All passed, 45.1 s
guest_timed_wait_cpu repeated 50 times 50/50 passed, about 64 ms per run
Textual merge with #12135 Clean
ctest excerpts
53/53 Test #2449: guest_nanosleep_long_request ........................   Passed    9.00 sec
100% tests passed out of 53
Total Test time (real) =   9.04 sec

# --repeat until-fail:50 -R ^guest_timed_wait_cpu$
100% tests passed out of 1
Total Test time (real) =   3.20 sec

Negative control

I restored core/libs/prx/libkernel/Time/TimedWait.cpp from main (LEAD_NANOS = 500000), rebuilt, and ran guest_timed_wait_cpu 20 times. It passed every run. This is expected: LEAD_NANOS is only read in the _WIN32 paths (WaitEventUntil, SleepUntil, SleepNanosUnlessChanged), and the test's CPU assertion is under #ifdef _WIN32. On Linux and macOS the test only checks that a 500 µs wait takes between 500 µs and 3 ms, and that already holds on main. I could not run the test on Windows, which is the only platform where it can fail on main.

Findings

Blocking

  1. The CPU assertion can fail on an idle Windows machine (core/libs/tests/GuestTimedWaitCpu.cpp:53, :92). Each API is measured over 50 waits of about 500–700 µs, so the window is about 25–35 ms (about 32 ms per API on this host). GetThreadTimes advances in clock-tick increments (15.625 ms by default), and 40% of a 32 ms window is about 12.8 ms. One tick charged to the thread during the window is therefore enough to fail the test, even when the thread hardly ran. The author's comments describe the same thing: idle runs measured 45–55%. If this test lands as it is, it will fail intermittently on the Windows CI runs that follow every merge to main.
    Fix: make the window long enough that one tick is small compared with the bound (the author's local 500-wait version would do), or measure with QueryThreadCycleTime instead of tick-based times. Also fail when GetThreadTimes fails, instead of returning 0 (:22).

  2. The per-wait < 3000 µs bound fails under ordinary scheduling noise (:45, :77). With LEAD_NANOS = 20000, the wait ends on a waitable-timer expiry and the thread then has to be scheduled again, so its tail depends on the host. The author reports that this exact head failed this assertion on the third Windows run, with a measured 5.664 ms wait. CPU load from other tests running at the same time (ctest -j) makes this more likely.
    Fix: bound a percentile and set a looser cap on the maximum, as the author proposes, and push that version. Then report repeated runs of the pushed head on Windows, and a run of the same test against main, where it should fail on the CPU bound.

Non-blocking

  1. No evidence for 50–500 µs waits. On main, a Windows wait between YIELD_BELOW_NANOS (50 µs) and 500 µs spins to the deadline. With this change it sleeps on the timer until 20 µs before the deadline (TimedWait.cpp:25), and condition waits through WaitEventUntil do this for anything over 20 µs. The author's measurements give a P95 of about 1 ms for 500 µs waits, so a 100 µs wait could plausibly overshoot by several times its length. Since this becomes the default for every title, please add a measurement or test point at a shorter wait (for example 100 µs), so the accepted overshoot is stated. If CreateWaitableTimerExW(... HIGH_RESOLUTION) fails, the fallback WholeMilliseconds / AlertableSleep path is now taken for these short waits too, with a 1 ms minimum (or the system timer period for SleepEx).
  2. Tested section. The description still says ctest -R libkernel passed. That pattern does not select the timing tests (guest_nanosleep, guest_cond_timedwait, guest_timed_wait_cpu, …), as noted earlier. Please replace it with the exact Windows CTest names and counts for the pushed head, run with --no-tests=error.
  3. Depends on. #12135 changes the final spin loops in SleepUntil and SleepNanosUnlessChanged, which this change makes shorter. It merges cleanly with this PR, but CONTRIBUTING asks overlapping PRs to agree on an order and declare it on the Depends on line, which is still none. The author's comments also say the PR is "on hold" or "in draft", but it is not marked as a draft. Please mark it as a draft until the test update is pushed.
  4. Trailing blank line at the end of core/libs/tests/GuestTimedWaitCpu.cpp:101 (git diff --check).

Not verified

  • Anything on Windows: the CPU reduction, the Windows result of guest_timed_wait_cpu at this head, and whether it fails on main there.
  • The title run on PPSA24263 and the "100% to ~1.5%" CPU figure in the description.
  • How this behaves when combined with #12135 at run time; I only checked that the two merge cleanly.

To get this to a good state

  1. Push the revised test: a longer measurement window or cycle-based CPU time, a percentile latency bound, and failure when GetThreadTimes fails.
  2. Run it repeatedly on Windows at the pushed head (for example ctest --repeat until-fail:20 --no-tests=error -R "^guest_timed_wait_cpu$"), and once against a checkout of main to show it fails there. Put both results in Tested.
  3. Add one shorter-wait data point (for example 100 µs), or bound it in the test.
  4. Declare the order with #12135 on the Depends on line, and remove the trailing blank line.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692386422 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11725#pullrequestreview-5692386422). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T03:08:13Z. **Review:** DISMISSED --- # Reviewed — changes requested The `LEAD_NANOS` change is small and merges cleanly, but the new Windows regression test can fail on an idle machine because of how it bounds CPU time and latency, which the author's own Windows runs of this head also show. ## What I ran - Head: `1cf6f482c03f3f2d033ecccc65931289d549bbc1` - `main`: `3a2b91981651569163768854a1fcdc7193b6667b` - Host: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF. I had no Windows host, so this covers Linux only. ```sh git fetch -q origin main pull/11725/head:refs/review/11725 git checkout -q --detach origin/main git merge -q --no-ff --no-edit refs/review/11725 git diff --check origin/main...refs/review/11725 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs cmake --build build -j10 --target guest_cond_recursive_mutex_tests guest_cond_timedwait_tests guest_cond_unowned_mutex_tests guest_nanosleep_long_request_tests guest_nanosleep_tests guest_sleep_cancel_tests guest_sleep_wake_tests guest_timed_join_tests guest_timed_wait_cpu_tests ctest --test-dir build -j4 --output-on-failure --no-tests=error -R "^guest_(timed|nanosleep|sleep|cond)" ctest --test-dir build --output-on-failure --repeat until-fail:50 -R "^guest_timed_wait_cpu$" ctest --test-dir build -j4 --output-on-failure --repeat until-fail:5 -R "^guest_(timed|nanosleep|sleep|cond)" # negative control git checkout origin/main -- core/libs/prx/libkernel/Time/TimedWait.cpp cmake --build build -j10 --target guest_timed_wait_cpu_tests ctest --test-dir build --output-on-failure --repeat until-fail:20 -R "^guest_timed_wait_cpu$" git checkout HEAD -- core/libs/prx/libkernel/Time/TimedWait.cpp # overlap with #12135 git merge-tree --write-tree HEAD <#12135 head> ``` ## Results | Check | Result | |---|---| | Merge into `main` | Clean | | `git diff --check` | 1 issue: blank line at end of `core/libs/tests/GuestTimedWaitCpu.cpp` | | `tools/check_conventions.py` | Passed | | Build `libs` and the timing test targets (Linux) | Passed | | 53 timing tests (`guest_cond_*`, `guest_nanosleep*`, `guest_sleep_*`, `guest_timed_*`) | 53/53 passed, 9.0 s | | Same 53 tests, `-j4`, repeated 5 times | All passed, 45.1 s | | `guest_timed_wait_cpu` repeated 50 times | 50/50 passed, about 64 ms per run | | Textual merge with #12135 | Clean | <details><summary>ctest excerpts</summary> ``` 53/53 Test #2449: guest_nanosleep_long_request ........................ Passed 9.00 sec 100% tests passed out of 53 Total Test time (real) = 9.04 sec # --repeat until-fail:50 -R ^guest_timed_wait_cpu$ 100% tests passed out of 1 Total Test time (real) = 3.20 sec ``` </details> ## Negative control I restored `core/libs/prx/libkernel/Time/TimedWait.cpp` from `main` (`LEAD_NANOS = 500000`), rebuilt, and ran `guest_timed_wait_cpu` 20 times. It **passed** every run. This is expected: `LEAD_NANOS` is only read in the `_WIN32` paths (`WaitEventUntil`, `SleepUntil`, `SleepNanosUnlessChanged`), and the test's CPU assertion is under `#ifdef _WIN32`. On Linux and macOS the test only checks that a 500 µs wait takes between 500 µs and 3 ms, and that already holds on `main`. I could not run the test on Windows, which is the only platform where it can fail on `main`. ## Findings ### Blocking 1. **The CPU assertion can fail on an idle Windows machine** (`core/libs/tests/GuestTimedWaitCpu.cpp:53`, `:92`). Each API is measured over 50 waits of about 500–700 µs, so the window is about 25–35 ms (about 32 ms per API on this host). `GetThreadTimes` advances in clock-tick increments (15.625 ms by default), and 40% of a 32 ms window is about 12.8 ms. One tick charged to the thread during the window is therefore enough to fail the test, even when the thread hardly ran. The author's comments describe the same thing: idle runs measured 45–55%. If this test lands as it is, it will fail intermittently on the Windows CI runs that follow every merge to `main`. *Fix:* make the window long enough that one tick is small compared with the bound (the author's local 500-wait version would do), or measure with `QueryThreadCycleTime` instead of tick-based times. Also fail when `GetThreadTimes` fails, instead of returning 0 (`:22`). 2. **The per-wait `< 3000 µs` bound fails under ordinary scheduling noise** (`:45`, `:77`). With `LEAD_NANOS = 20000`, the wait ends on a waitable-timer expiry and the thread then has to be scheduled again, so its tail depends on the host. The author reports that this exact head failed this assertion on the third Windows run, with a measured 5.664 ms wait. CPU load from other tests running at the same time (`ctest -j`) makes this more likely. *Fix:* bound a percentile and set a looser cap on the maximum, as the author proposes, and push that version. Then report repeated runs of the pushed head on Windows, and a run of the same test against `main`, where it should fail on the CPU bound. ### Non-blocking 1. **No evidence for 50–500 µs waits.** On `main`, a Windows wait between `YIELD_BELOW_NANOS` (50 µs) and 500 µs spins to the deadline. With this change it sleeps on the timer until 20 µs before the deadline (`TimedWait.cpp:25`), and condition waits through `WaitEventUntil` do this for anything over 20 µs. The author's measurements give a P95 of about 1 ms for 500 µs waits, so a 100 µs wait could plausibly overshoot by several times its length. Since this becomes the default for every title, please add a measurement or test point at a shorter wait (for example 100 µs), so the accepted overshoot is stated. If `CreateWaitableTimerExW(... HIGH_RESOLUTION)` fails, the fallback `WholeMilliseconds` / `AlertableSleep` path is now taken for these short waits too, with a 1 ms minimum (or the system timer period for `SleepEx`). 2. **Tested section.** The description still says `ctest -R libkernel` passed. That pattern does not select the timing tests (`guest_nanosleep`, `guest_cond_timedwait`, `guest_timed_wait_cpu`, …), as noted earlier. Please replace it with the exact Windows CTest names and counts for the pushed head, run with `--no-tests=error`. 3. **Depends on.** #12135 changes the final spin loops in `SleepUntil` and `SleepNanosUnlessChanged`, which this change makes shorter. It merges cleanly with this PR, but CONTRIBUTING asks overlapping PRs to agree on an order and declare it on the `Depends on` line, which is still `none`. The author's comments also say the PR is "on hold" or "in draft", but it is not marked as a draft. Please mark it as a draft until the test update is pushed. 4. **Trailing blank line** at the end of `core/libs/tests/GuestTimedWaitCpu.cpp:101` (`git diff --check`). ## Not verified - Anything on Windows: the CPU reduction, the Windows result of `guest_timed_wait_cpu` at this head, and whether it fails on `main` there. - The title run on PPSA24263 and the "100% to ~1.5%" CPU figure in the description. - How this behaves when combined with #12135 at run time; I only checked that the two merge cleanly. ## To get this to a good state 1. Push the revised test: a longer measurement window or cycle-based CPU time, a percentile latency bound, and failure when `GetThreadTimes` fails. 2. Run it repeatedly on Windows at the pushed head (for example `ctest --repeat until-fail:20 --no-tests=error -R "^guest_timed_wait_cpu$"`), and once against a checkout of `main` to show it fails there. Put both results in Tested. 3. Add one shorter-wait data point (for example 100 µs), or bound it in the test. 4. Declare the order with #12135 on the `Depends on` line, and remove the trailing blank line.
adriadam10 commented 2026-10-29 19:22:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T19:22:27Z.

Review: CHANGES_REQUESTED


Thanks for the investigation. Points still open on 1cf6f482c0:

  • core/libs/tests/GuestTimedWaitCpu.cpp:53, :92: 50 waits are a ~32 ms window and GetThreadTimes advances in 15.625 ms ticks, so one tick fails the 40% bound on an idle machine. Use a longer window (your 500-wait version) or QueryThreadCycleTime, and fail when GetThreadTimes fails instead of returning 0 (:22).
  • :45, :77: a hard < 3000 µs per wait fails under ordinary scheduling noise (you measured 5.664 ms). Bound a percentile and a looser maximum, as in your local revision. Please push it; the head still has the flaky version.
  • Show the pushed test failing on main on Windows and passing repeatedly here (ctest --repeat until-fail:20 --no-tests=error -R "^guest_timed_wait_cpu$"), and put the exact CTest names and results in Tested (-R libkernel does not select the timing tests). On Linux the test passes on main too, since the CPU assertion is _WIN32 only.
  • Add one shorter-wait data point (e.g. 100 µs): waits between 50 µs and 500 µs now sleep until 20 µs before the deadline instead of spinning, so the accepted overshoot should be stated.
  • #12135 also changes the final spin in TimedWait.cpp; agree the order with its author and record it in Depends on.
  • Remove the trailing blank line at GuestTimedWaitCpu.cpp:101.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5703696346 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11725#pullrequestreview-5703696346). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-29T19:22:27Z. **Review:** CHANGES_REQUESTED --- Thanks for the investigation. Points still open on `1cf6f482c0`: - `core/libs/tests/GuestTimedWaitCpu.cpp:53`, `:92`: 50 waits are a ~32 ms window and `GetThreadTimes` advances in 15.625 ms ticks, so one tick fails the 40% bound on an idle machine. Use a longer window (your 500-wait version) or `QueryThreadCycleTime`, and fail when `GetThreadTimes` fails instead of returning 0 (`:22`). - `:45`, `:77`: a hard `< 3000 µs` per wait fails under ordinary scheduling noise (you measured 5.664 ms). Bound a percentile and a looser maximum, as in your local revision. Please push it; the head still has the flaky version. - Show the pushed test failing on `main` on Windows and passing repeatedly here (`ctest --repeat until-fail:20 --no-tests=error -R "^guest_timed_wait_cpu$"`), and put the exact CTest names and results in Tested (`-R libkernel` does not select the timing tests). On Linux the test passes on `main` too, since the CPU assertion is `_WIN32` only. - Add one shorter-wait data point (e.g. 100 µs): waits between 50 µs and 500 µs now sleep until 20 µs before the deadline instead of spinning, so the accepted overshoot should be stated. - #12135 also changes the final spin in `TimedWait.cpp`; agree the order with its author and record it in `Depends on`. - Remove the trailing blank line at `GuestTimedWaitCpu.cpp:101`.
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!11725
No description provided.