fix(libkernel_sys): wait for AIO timeouts until one deadline, precisely on Windows #11416
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11416"
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 LeandroLP23 on 2026-10-26T11:55:19Z.
What
Part of #1471.
aio_suspendandaio_waitcompletewaited for their timeout withstd::condition_variable::wait_for. On Windows that goes through winpthreads, which ends a timed wait only onceGetTickCount64has advanced, in 15.6 ms steps, so a 1 ms timeout returned after about 15.6 ms. Both calls also passed the full timeout towait_foragain on every wake that did not finish their wait, so completions or cancellations of other requests restarted it: a 30 msaio_suspendreturned only once those stopped.Both calls now compute one deadline from the timeout (
TimedWait::NowNanosplus the existingWaitTimerounding) and wait onTimedWait::Conditionuntil it, as Rudp, AvPlayer, EventFlag and Equeue already do. On Windows that wait ends on time; on other hosts it is the samecondition_variablewait as before, now against a fixed deadline.libkernel_syscompileslibkernel/Time/TimedWait.cppin, likelibSceRudpandlibSceVideoOut.guest_kernel_sys_aiogainsTimedWaits, with the worker held so a queued request never completes:aio_suspendcalls with a 1 ms timeout, and 20aio_waitcompletecalls with a 1 ms timeout, must each take 20 to 200 ms in total;aio_suspendwhile 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,
maincbaacd2910.guest_kernel_sys_aio: passes 3 of 3 on this head. Withmain'sAio.cppandCMakeLists.txtput back and the new test kept, it fails 2 of 2 at the first timing check.main'sAio.cppaio_suspend, 1 msaio_waitcomplete, 1 msaio_suspend30 ms, with other requests waking itcheck_conventions.py --base origin/mainpasses.pr_overlap.pyfinds #10741, and #9297 and #9302 (which conflict withmain, so not compared), each adding a source to the sameadd_libraryline oflibkernel_sys/CMakeLists.txt; whichever lands second adds its file to that line.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 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 shortaio_suspend, shortaio_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.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 onmain27ad7244dwith 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_aiopasses, 3 of 3 runs. The relatedguest_kernel_sys*/AIO tests pass, 21 of 21.mainwithout the PR: 1361/1361.core/libs/prx/libkernel_sys/Aio.cppand itsCMakeLists.txtreverted tomain(new test kept),guest_kernel_sys_aiofails 3 of 3 at line 225, the 30 msaio_suspendwith the waker thread. The two 1 ms loops pass onmainhere.main'sAio.cppaio_suspend, 1 msaio_waitcomplete, 1 msaio_suspend30 ms, other requests waking itOn
mainthe 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.