fix(libkernel): use precise waits for select timeouts #4754
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4754"
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-12T20:44:08Z.
What
Use the existing
PreciseSleepUntilhelper for the timeout-only path of guestselect(), capping each wait at the guest deadline. After the descriptor-group refactor inmain, this path isgroups.empty(). Descriptor dispatch, socket/host pollers, readiness reporting and error handling are preserved. No user configuration, dependencies or additional runtime tools are required.Rebased onto
mainat61b8742b6b4508db14e8d253e60cfaa7d105379b. The patch is three files, 85 additions and 2 deletions.guest_select_waitnow also runs twenty empty-set selects of 1 ms and requires their total to stay between 20 ms and 200 ms, as theguest_pollcheck in #4980 does forpoll(). The earlier checks only required that a call did not return before its deadline, so they passed without the fix.Related:
poll()path inUdp.cpp; this PR changesselect()inSocket.cpp.libkernel/CMakeLists.txtandSocket.cpp. Neither builds on the other; as noted in the review, whichever merges second rebases.Tested
Windows 11, Ryzen 7 5800H, WinLibs MinGW-w64 GCC 15.2.0 r7, Release; Ubuntu 26.04 under WSL, GCC 15.2.0, Release. Head
6e9fbc0519a41dc58779dab878d38064b8d825e2onmain61b8742b6. Raw test output, per-call wait measurements and the probe source are in this comment.Socket.cppfrommainand the new test,guest_select_waitfails 3 of 3 runs withtwenty 1 ms selects did not stay close to their deadlines. With the fix it passes 21 of 21 runs.guest_udpreached its existing 20 s limit. The earlier published baseline/patched comparison also recorded this Windows timeout. The limit was not raised.Socket.cppfrommain, because the host wait is already precise on Linux; it is a Windows regression check.guest_select_waitcovers 20 scenarios: zero/short deadlines, the repeated 1 ms wait, invalid arguments, unready/ready devices, unchanged timeout and descriptor bits abovenfds.git diff --checkpassed.Earlier measurements from the first publication base remain in the earlier evidence comment.
Not tested: macOS, retail titles, game FPS, a complete build of all project targets, or the full graphics suite. This corrects the wait duration of the call; no game-scene speed change is claimed and no performance traces were captured. Only the three implementation/test files belong to this PR; local validation scripts, snapshots and logs are not committed.
Checklist
main; no equivalent open PR implements thisselect()timeout-wait changeImported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-12T20:46:38Z.
Local validation and measured timeout waits for this PR.
Publication base:
27873b0f7437dd4516ae1f35ab5b494e3ee5749d; tested/published commit:aee3971199b80b6624dde0818fed96154de64bc5. Windows 11, Ryzen 7 5800H, WinLibs MinGW-w64 GCC 15.2.0 r7, Release; Ubuntu 26.04 under WSL, GCC 15.2.0, Release.Windows used the full project CMake configuration, the original supported compiler/binutils and the pinned bundled dependency sources. Only libc/libkernel and the relevant test targets were built. Linux used the actual upstream libc/libkernel CMake subdirectories in a local validation wrapper. A complete build of all targets, graphics tests and game FPS were not run. The Windows UDP timeout also occurred in the earlier unchanged-main comparison. Local build and loaded-library paths are redacted from the public logs below; all timing samples, test results and library hashes are preserved.
Windows publication-base test output
Linux publication-base test output
The official convention checker passes on the committed branch with the PR title/body;
git diff --checkpasses. The patch contains exactly three files, 76 additions and 2 deletions.Before/after wait measurements
Measurement base:
682ef0c17451e41c41e1b2008f982a700341b665. nine alternating-order pairs, one warmup and 40 samples per timeout per process. Each process checks that the absolute loaded libkernel path is the selected variant.Socket.cpp,SocketSelectDeadline.hpp,PreciseWait.hppand kernel timer initialization are unchanged between the measurement and publication bases.The figures summarize elapsed waits through the guest ABI in the compiled PRX library; they are not FPS measurements or hard scheduling guarantees.
Compared library SHA-256 hashes
Probe source used for the measurements
Pair 1: baseline, raw samples and loaded library
Pair 1: patched, raw samples and loaded library
Pair 2: patched, raw samples and loaded library
Pair 2: baseline, raw samples and loaded library
Pair 3: baseline, raw samples and loaded library
Pair 3: patched, raw samples and loaded library
Pair 4: patched, raw samples and loaded library
Pair 4: baseline, raw samples and loaded library
Pair 5: baseline, raw samples and loaded library
Pair 5: patched, raw samples and loaded library
Pair 6: patched, raw samples and loaded library
Pair 6: baseline, raw samples and loaded library
Pair 7: baseline, raw samples and loaded library
Pair 7: patched, raw samples and loaded library
Pair 8: patched, raw samples and loaded library
Pair 8: baseline, raw samples and loaded library
Pair 9: baseline, raw samples and loaded library
Pair 9: patched, raw samples and loaded library
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:36:50Z.
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/libkernel/CMakeLists.txtL1058-1065core/libs/prx/libkernel/Socket/src/Socket.cppL4Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:22:30Z.
Review: DISMISSED
Thanks for the PR. The change itself looks right (wait capped at the guest deadline, only the
groups.empty()path).One blocking issue:
core/libs/tests/GuestSelectWait.cpppasses without the fix. I revertedSocket.cpptomainandguest_select_waitstill passes. Every wait check only asserts the call does not return before the deadline (Clock::now() - start >= micros); nothing bounds how late it returns, so the oldsleep_for(which only overshoots) satisfies it too. Please add a repeated short wait (e.g. N empty-set selects of 1 ms) and assert the average/total stays well below the coarse ~15.6 ms Windows tick, as theguest_pollcheck in #4980 does, so the test fails onmainon Windows.The conflict with #5013 is only adjacent lines in
libkernel/CMakeLists.txtandSocket.cpp; whoever merges second rebases.Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T17:24:55Z.
@adriadam10 addressed in
6e9fbc051.guest_select_waitnow also runs twenty empty-set selects of 1 ms and requires their total to stay between 20 ms and 200 ms, the same bounds as theguest_pollcheck in #4980.Windows 11, Ryzen 7 5800H, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, on
main61b8742b6:Socket.cppfrommainand the new test,guest_select_waitfails 3 of 3 runs:twenty 1 ms selects did not stay close to their deadlines.On Linux (Ubuntu 26.04 under WSL, GCC 15.2.0) the new check passes with and without the fix, because the host wait is already precise there.
To reproduce the control on this head:
git checkout origin/main -- core/libs/prx/libkernel/Socket/src/Socket.cpp, rebuildguest_select_wait_tests, runctest -R '^guest_select_wait$' --output-on-failure.Wait per call on Windows, median of 40 calls of
select_nid_postfix(0, nullptr, nullptr, nullptr, &timeout)from a local probe (source and raw samples below; the probe is not part of the PR):Socket.cppfrommainThe type is now
fixinstead ofperf, as in #4980: the change corrects the wait duration and claims no game-scene speed change. The branch is rebased ontomainand the description is updated. Local build paths in the logs are replaced with<build>.Windows control: Socket.cpp from main, new test (3 of 3 fail)
Windows with the fix: guest_select_wait, 20 repeats
Windows with the fix: socket and wait tests (8 of 9; guest_udp reaches its existing 20 s limit)
Linux with the fix: socket and wait tests (10 of 10)
Linux control: Socket.cpp from main, new test (5 of 5 pass)
Windows probe output with the fix
Windows probe output with Socket.cpp from main
Probe source
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T18:49:30Z.
@p3n1cillin the PR overlap report lists #5013 against this PR. A trial
git merge-treeof6e9fbc051with76a168fccconflicts in two places, and keeping both sides resolves each:core/libs/prx/libkernel/Socket/src/Socket.cpp: the two added#includelines (PreciseWait.hpphere,File/include/File.hppin yours).core/libs/prx/libkernel/CMakeLists.txt: this PR adds theguest_select_waitregistration right before theguest_selectblock that yours makes unconditional.Neither change builds on the other. Proposed order: this PR first, since it is older and already reviewed, and #5013 rebases with that resolution and lists this PR as its dependency, so the report stops listing the pair. If you prefer the opposite order, say so and I will list #5013 here and rebase after it.
AI-assisted (Claude Code).