Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Roojool:fix/net-epoll-precise-timeout
Oct 10, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Roojool:fix/net-epoll-precise-timeout

Conversation

@Roojool

@Roojool Roojool commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 force-pushed the fix/net-epoll-precise-timeout branch from a006569 to bb54bff Compare October 10, 2026 00:17
Copilot AI balanced review requested due to automatic review settings October 10, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@adriadam10
adriadam10 merged commit d11caf7 into boykopovar:main Oct 10, 2026
6 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…-timeout

fix(net): use native Windows condition waits for empty epoll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants