fix(libkernel_sys): wait for AIO timeouts until one deadline, precisely on Windows #11416

Merged
LeandroLP23 merged 1 commit from upstream-pr/11416 into main 2026-11-02 10:27:51 +00:00
LeandroLP23 commented 2026-10-26 11:55:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-26T11:55:19Z.


What

Part of #1471. aio_suspend and aio_waitcomplete waited for their timeout with std::condition_variable::wait_for. On Windows that goes through winpthreads, which ends a timed wait only once GetTickCount64 has advanced, in 15.6 ms steps, so a 1 ms timeout returned after about 15.6 ms. Both calls also passed the full timeout to wait_for again on every wake that did not finish their wait, so completions or cancellations of other requests restarted it: a 30 ms aio_suspend returned only once those stopped.

Both calls now compute one deadline from the timeout (TimedWait::NowNanos plus the existing WaitTime rounding) and wait on TimedWait::Condition until it, as Rudp, AvPlayer, EventFlag and Equeue already do. On Windows that wait ends on time; on other hosts it is the same condition_variable wait as before, now against a fixed deadline. libkernel_sys compiles libkernel/Time/TimedWait.cpp in, like libSceRudp and libSceVideoOut.

guest_kernel_sys_aio gains TimedWaits, with the worker held so a queued request never completes:

  • 20 aio_suspend calls with a 1 ms timeout, and 20 aio_waitcomplete calls with a 1 ms timeout, must each take 20 to 200 ms in total;
  • a 30 ms aio_suspend while another thread keeps queueing and cancelling other requests, which wakes the waiter, must return within 30 to 300 ms. The other thread stops by itself after 600 ms, so the old behaviour fails the check rather than hanging.

Tested

Windows 11 10.0.26300, AMD Ryzen AI 7 350, WinLibs GCC 15.2, Release, main cbaacd2910.

  • guest_kernel_sys_aio: passes 3 of 3 on this head. With main's Aio.cpp and CMakeLists.txt put back and the new test kept, it fails 2 of 2 at the first timing check.
  • Durations from a local copy of the test that prints them instead of checking them, three runs each:
this head main's Aio.cpp
20 × aio_suspend, 1 ms 20.1, 20.1, 20.1 ms 307.7, 307.0, 608.7 ms
20 × aio_waitcomplete, 1 ms 20.4, 20.0, 20.1 ms 313.2, 313.7, 629.0 ms
aio_suspend 30 ms, with other requests waking it 30.1, 30.0, 30.7 ms 386.6, 649.0, 536.1 ms
  • Linux not run; the change there is limited to the fixed deadline.
  • check_conventions.py --base origin/main passes. pr_overlap.py finds #10741, and #9297 and #9302 (which conflict with main, so not compared), each adding a source to the same add_library line of libkernel_sys/CMakeLists.txt; whichever lands second adds its file to that line.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5016969948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11416). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-26T11:55:19Z. --- ### What Part of #1471. `aio_suspend` and `aio_waitcomplete` waited for their timeout with `std::condition_variable::wait_for`. On Windows that goes through winpthreads, which ends a timed wait only once `GetTickCount64` has advanced, in 15.6 ms steps, so a 1 ms timeout returned after about 15.6 ms. Both calls also passed the full timeout to `wait_for` again on every wake that did not finish their wait, so completions or cancellations of other requests restarted it: a 30 ms `aio_suspend` returned only once those stopped. Both calls now compute one deadline from the timeout (`TimedWait::NowNanos` plus the existing `WaitTime` rounding) and wait on `TimedWait::Condition` until it, as Rudp, AvPlayer, EventFlag and Equeue already do. On Windows that wait ends on time; on other hosts it is the same `condition_variable` wait as before, now against a fixed deadline. `libkernel_sys` compiles `libkernel/Time/TimedWait.cpp` in, like `libSceRudp` and `libSceVideoOut`. `guest_kernel_sys_aio` gains `TimedWaits`, with the worker held so a queued request never completes: - 20 `aio_suspend` calls with a 1 ms timeout, and 20 `aio_waitcomplete` calls with a 1 ms timeout, must each take 20 to 200 ms in total; - a 30 ms `aio_suspend` while another thread keeps queueing and cancelling other requests, which wakes the waiter, must return within 30 to 300 ms. The other thread stops by itself after 600 ms, so the old behaviour fails the check rather than hanging. ### Tested Windows 11 10.0.26300, AMD Ryzen AI 7 350, WinLibs GCC 15.2, Release, `main` `cbaacd2910`. - `guest_kernel_sys_aio`: passes 3 of 3 on this head. With `main`'s `Aio.cpp` and `CMakeLists.txt` put back and the new test kept, it fails 2 of 2 at the first timing check. - Durations from a local copy of the test that prints them instead of checking them, three runs each: | | this head | `main`'s `Aio.cpp` | |---|---|---| | 20 × `aio_suspend`, 1 ms | 20.1, 20.1, 20.1 ms | 307.7, 307.0, 608.7 ms | | 20 × `aio_waitcomplete`, 1 ms | 20.4, 20.0, 20.1 ms | 313.2, 313.7, 629.0 ms | | `aio_suspend` 30 ms, with other requests waking it | 30.1, 30.0, 30.7 ms | 386.6, 649.0, 536.1 ms | - Linux not run; the change there is limited to the fixed deadline. - `check_conventions.py --base origin/main` passes. `pr_overlap.py` finds #10741, and #9297 and #9302 (which conflict with `main`, so not compared), each adding a source to the same `add_library` line of `libkernel_sys/CMakeLists.txt`; whichever lands second adds its file to that line. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-26 11:59:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T11:59:35Z.

Review: APPROVED


Reviewed exact head dbae6cb7a7ca58b92c8ab2eddb53364e75488e4e. The AIO calls now compute one deadline and reuse it across wakeups; the predicate loops still recheck completion under the lock, and the test holds the worker so the timed-out request cannot complete accidentally. The three reported Windows runs cover short aio_suspend, short aio_waitcomplete, and repeated unrelated wakeups, with negative controls failing on the prior code. I did not run the Windows test locally; hosted product checks are skipped by path policy, while eligibility, conventions, intake, labels, and report checks pass. I checked the listed CMake overlap with #10741, #9297, and #9302: these add different sources, so preserve all entries when the shared source list is reconciled.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5651586522 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11416#pullrequestreview-5651586522). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T11:59:35Z. **Review:** APPROVED --- Reviewed exact head `dbae6cb7a7ca58b92c8ab2eddb53364e75488e4e`. The AIO calls now compute one deadline and reuse it across wakeups; the predicate loops still recheck completion under the lock, and the test holds the worker so the timed-out request cannot complete accidentally. The three reported Windows runs cover short `aio_suspend`, short `aio_waitcomplete`, and repeated unrelated wakeups, with negative controls failing on the prior code. I did not run the Windows test locally; hosted product checks are skipped by path policy, while eligibility, conventions, intake, labels, and report checks pass. I checked the listed CMake overlap with #10741, #9297, and #9302: these add different sources, so preserve all entries when the shared source list is reconciled.
jotitadev commented 2026-10-27 02:10:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T02:10:32Z.

Review: COMMENTED


A Linux run, since the description lists Linux as not run. The 1 ms timeouts are already on time on Linux, but the second problem the PR describes (a wake from other requests restarting the full timeout) reproduces there, and this change fixes it.

Exact head dbae6cb7a7, merged on main 27ad7244d with no conflicts. Linux x86_64 (bare metal, not WSL), i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Ninja, Release, BUILD_TESTING=ON, full build.

  • guest_kernel_sys_aio passes, 3 of 3 runs. The related guest_kernel_sys*/AIO tests pass, 21 of 21.
  • Full non-GPU suite on the same main without the PR: 1361/1361.
  • With only core/libs/prx/libkernel_sys/Aio.cpp and its CMakeLists.txt reverted to main (new test kept), guest_kernel_sys_aio fails 3 of 3 at line 225, the 30 ms aio_suspend with the waker thread. The two 1 ms loops pass on main here.
  • Durations from a copy of the test that prints them instead of checking them, 3 runs each:
this head main's Aio.cpp
20 × aio_suspend, 1 ms 21.7, 21.6, 21.4 ms 21.3, 21.4, 21.4 ms
20 × aio_waitcomplete, 1 ms 21.7, 21.6, 21.4 ms 21.3, 21.4, 21.4 ms
aio_suspend 30 ms, other requests waking it 30.0, 30.0, 30.1 ms 630.1, 630.1, 630.1 ms

On main the 30 ms wait returns only after the waker thread stops at 600 ms, so the fixed deadline matters on Linux too, not only on Windows.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661449330 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11416#pullrequestreview-5661449330). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T02:10:32Z. **Review:** COMMENTED --- A Linux run, since the description lists Linux as not run. The 1 ms timeouts are already on time on Linux, but the second problem the PR describes (a wake from other requests restarting the full timeout) reproduces there, and this change fixes it. Exact head `dbae6cb7a7`, merged on `main` `27ad7244d` with no conflicts. Linux x86_64 (bare metal, not WSL), i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Ninja, Release, `BUILD_TESTING=ON`, full build. - `guest_kernel_sys_aio` passes, 3 of 3 runs. The related `guest_kernel_sys*`/AIO tests pass, 21 of 21. - Full non-GPU suite on the same `main` without the PR: 1361/1361. - With only `core/libs/prx/libkernel_sys/Aio.cpp` and its `CMakeLists.txt` reverted to `main` (new test kept), `guest_kernel_sys_aio` fails 3 of 3 at line 225, the 30 ms `aio_suspend` with the waker thread. The two 1 ms loops pass on `main` here. - Durations from a copy of the test that prints them instead of checking them, 3 runs each: | | this head | `main`'s `Aio.cpp` | |---|---|---| | 20 × `aio_suspend`, 1 ms | 21.7, 21.6, 21.4 ms | 21.3, 21.4, 21.4 ms | | 20 × `aio_waitcomplete`, 1 ms | 21.7, 21.6, 21.4 ms | 21.3, 21.4, 21.4 ms | | `aio_suspend` 30 ms, other requests waking it | 30.0, 30.0, 30.1 ms | 630.1, 630.1, 630.1 ms | On `main` the 30 ms wait returns only after the waker thread stops at 600 ms, so the fixed deadline matters on Linux too, not only on Windows. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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!11416
No description provided.