fix(net): use native Windows condition waits for empty epoll #1588

Merged
Roojool merged 2 commits from upstream-pr/1588 into main 2026-10-10 01:12:41 +00:00
Roojool commented 2026-10-08 13:50:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Roojool on 2026-10-08T13:50:48Z.


What

Related to #1471 (the empty-registration sceNetEpollWait path only).

With the supported WinLibs toolchain, std::condition_variable::wait_until uses winpthreads' coarse GetTickCount64 deadline. A 1,000 us empty epoll wait can therefore take approximately one 15.6 ms tick despite the process requesting a 0.5 ms timer resolution.

Use a translation-unit-local Windows SRW lock and native condition variable for the network registry. Preserve the existing steady-clock deadline, 100 ms polling slices, wake-all notifications, socket lifetimes and guest error behavior. Linux retains std::mutex and std::condition_variable. Unexpected native wait failures throw, matching the project's exact-or-throw policy.

Extend GuestSceNet.cpp with empty finite and zero waits, abort consumption, abort/destroy of indefinite waits, and adding a readable socket to a waiting epoll instance. The timing regression checks the median of nine 1 ms waits rather than imposing a bound on every sample.

Tested

Windows 11 Home 10.0.26300, supported WinLibs GCC 15.2.0 UCRT POSIX SEH r7; WSL Ubuntu 26.04 LTS, GCC 15.2.0. Release builds, BUILD_TESTING=ON, at most two compiler jobs, based on upstream fd5342b6.

  • Original Windows implementation: 40 requests for 1,000 us had a 15.494 ms median; the new regression failed. Original Linux functional regression passed.
  • Final Windows patched PRX: 40 requests had a 1.492 ms median; final Linux patched PRX: 1.099 ms. Every probe request waited at least 1 ms and returned zero events.
  • Nine relevant CTest cases, three consecutive passes each on both platforms: 54 passes, zero failures/skips. Cases: guest_sce_net, guest_tcp, guest_udp, guest_poll, guest_addresses, guest_cond_timedwait, guest_nanosleep, guest_pthread_sem, guest_sync_on_address.
  • Windows guest_sce_net also passed with APS5_COARSE_TIMED_WAITS=1 and APS5_NO_TIMER_RESOLUTION=1: two additional passes. The latter intentionally omits the latency ceiling while retaining the timeout lower bound and all functional checks. Its 15.558 ms median reproduced an independent review finding, which the corrected test guard resolves.
  • Repository convention checker, PR template check, test-registration checker on both platforms, and git diff --check: passed.
  • Built and NID-patched libc, libkernel, libSceNet and libSceNetCtl, then loaded the patched network library and invoked its epoll exports by NID on both platforms. Used the repository's patcher and the same --preserve-exports input as CMake; the generated packaging target's unrelated dependency fan-out was cancelled.

Build and CTest commands (Windows build; Linux /home/roojool/anyps5-net-epoll-linux):

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build --target guest_sce_net_tests guest_tcp_tests guest_udp_tests guest_poll_tests guest_address_tests guest_cond_timedwait_tests guest_nanosleep_tests guest_pthread_sem_tests guest_sync_on_address_tests nid_patcher --parallel 2
ctest --test-dir build -R '^(guest_sce_net|guest_tcp|guest_udp|guest_poll|guest_addresses|guest_cond_timedwait|guest_nanosleep|guest_pthread_sem|guest_sync_on_address)$' --output-on-failure --timeout 120 --repeat until-fail:3
python tools/check_test_registration.py build
python tools/check_conventions.py --base upstream/main

Full-project/GPU tests, console hardware and proprietary titles were not tested. The non-empty socket path still uses the existing bounded WSAPoll/poll waits. The existing registration-snapshot notification window remains bounded by the unchanged 100 ms slice. WSL reported that userfaultfd write watch was unavailable and used its existing memory-comparison fallback; no memory tracking behavior was changed.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes — Codex implementation, independent OpenCode review, additional Antigravity source review; the author is responsible for the change
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4787818184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1588). Originally posted by [Roojool](https://github.com/Roojool) on 2026-10-08T13:50:48Z. --- ### What Related to #1471 (the empty-registration `sceNetEpollWait` path only). With the supported WinLibs toolchain, `std::condition_variable::wait_until` uses winpthreads' coarse `GetTickCount64` deadline. A 1,000 us empty epoll wait can therefore take approximately one 15.6 ms tick despite the process requesting a 0.5 ms timer resolution. Use a translation-unit-local Windows SRW lock and native condition variable for the network registry. Preserve the existing steady-clock deadline, 100 ms polling slices, wake-all notifications, socket lifetimes and guest error behavior. Linux retains `std::mutex` and `std::condition_variable`. Unexpected native wait failures throw, matching the project's exact-or-throw policy. Extend `GuestSceNet.cpp` with empty finite and zero waits, abort consumption, abort/destroy of indefinite waits, and adding a readable socket to a waiting epoll instance. The timing regression checks the median of nine 1 ms waits rather than imposing a bound on every sample. ### Tested Windows 11 Home 10.0.26300, supported WinLibs GCC 15.2.0 UCRT POSIX SEH r7; WSL Ubuntu 26.04 LTS, GCC 15.2.0. Release builds, `BUILD_TESTING=ON`, at most two compiler jobs, based on upstream `fd5342b6`. - Original Windows implementation: 40 requests for 1,000 us had a 15.494 ms median; the new regression failed. Original Linux functional regression passed. - Final Windows patched PRX: 40 requests had a 1.492 ms median; final Linux patched PRX: 1.099 ms. Every probe request waited at least 1 ms and returned zero events. - Nine relevant CTest cases, three consecutive passes each on both platforms: 54 passes, zero failures/skips. Cases: `guest_sce_net`, `guest_tcp`, `guest_udp`, `guest_poll`, `guest_addresses`, `guest_cond_timedwait`, `guest_nanosleep`, `guest_pthread_sem`, `guest_sync_on_address`. - Windows `guest_sce_net` also passed with `APS5_COARSE_TIMED_WAITS=1` and `APS5_NO_TIMER_RESOLUTION=1`: two additional passes. The latter intentionally omits the latency ceiling while retaining the timeout lower bound and all functional checks. Its 15.558 ms median reproduced an independent review finding, which the corrected test guard resolves. - Repository convention checker, PR template check, test-registration checker on both platforms, and `git diff --check`: passed. - Built and NID-patched `libc`, `libkernel`, `libSceNet` and `libSceNetCtl`, then loaded the patched network library and invoked its epoll exports by NID on both platforms. Used the repository's patcher and the same `--preserve-exports` input as CMake; the generated packaging target's unrelated dependency fan-out was cancelled. Build and CTest commands (Windows `build`; Linux `/home/roojool/anyps5-net-epoll-linux`): ```sh cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ cmake --build build --target guest_sce_net_tests guest_tcp_tests guest_udp_tests guest_poll_tests guest_address_tests guest_cond_timedwait_tests guest_nanosleep_tests guest_pthread_sem_tests guest_sync_on_address_tests nid_patcher --parallel 2 ctest --test-dir build -R '^(guest_sce_net|guest_tcp|guest_udp|guest_poll|guest_addresses|guest_cond_timedwait|guest_nanosleep|guest_pthread_sem|guest_sync_on_address)$' --output-on-failure --timeout 120 --repeat until-fail:3 python tools/check_test_registration.py build python tools/check_conventions.py --base upstream/main ``` Full-project/GPU tests, console hardware and proprietary titles were not tested. The non-empty socket path still uses the existing bounded `WSAPoll`/`poll` waits. The existing registration-snapshot notification window remains bounded by the unchanged 100 ms slice. WSL reported that userfaultfd write watch was unavailable and used its existing memory-comparison fallback; no memory tracking behavior was changed. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes — Codex implementation, independent OpenCode review, additional Antigravity source review; the author is responsible for the change
oneandonlydean commented 2026-10-09 09:23:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:23:06Z.


Conflicts with main in core/libs/tests/GuestSceNet.cpp since #1119 and #1838 landed; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078132844 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1588#issuecomment-6078132844). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:23:06Z. --- Conflicts with main in `core/libs/tests/GuestSceNet.cpp` since #1119 and #1838 landed; please rebase.
adriadam10 commented 2026-10-10 00:17:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T00:17:46Z.


Rebased onto current main (only core/libs/tests/GuestSceNet.cpp conflicted after #1119/#1838; kept both test functions).

Added one commit of our own: sceNetGetMemoryPoolStats (new on main) locked g_mutex with std::lock_guard<std::mutex>, which would not compile on Windows now that g_mutex is a HostMutex. It uses CTAD like the rest.

Checked: build + the 11 tests in the touched directories pass on Linux. The 1 ms latency check only runs under _WIN32, so the Linux run does not exercise it; the Windows numbers are yours.

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091506261 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1588#issuecomment-6091506261). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T00:17:46Z. --- Rebased onto current `main` (only `core/libs/tests/GuestSceNet.cpp` conflicted after #1119/#1838; kept both test functions). Added one commit of our own: `sceNetGetMemoryPoolStats` (new on `main`) locked `g_mutex` with `std::lock_guard<std::mutex>`, which would not compile on Windows now that `g_mutex` is a `HostMutex`. It uses CTAD like the rest. Checked: build + the 11 tests in the touched directories pass on Linux. The 1 ms latency check only runs under `_WIN32`, so the Linux run does not exercise it; the Windows numbers are yours. Merging once CI is green.
copilot-pull-request-reviewer[bot] commented 2026-10-10 00:17:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-10T00:17:51Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476550048 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1588#pullrequestreview-5476550048). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-10T00:17:51Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
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!1588
No description provided.