Skip to content

fix(libSceNet): pace hot zero-timeout epoll polls and record epoll events in the observation log - #49

Open
AlxcBTW wants to merge 2 commits into
mainfrom
fix/net-epoll-t54
Open

AlxcBTW wants to merge 2 commits into
mainfrom
fix/net-epoll-t54

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

What

Fixes hub T54. Games on Mono (Unity) answer Socket.Poll(0, ...) with a throwaway epoll per call: sceNetEpollCreate, sceNetEpollControl ADD, sceNetEpollWait with timeout 0, DEL, sceNetEpollDestroy. Seven never-sleeping threads did this about 175 000 times per second in total (1.7 M calls in 15 s) and starved the main thread of a game that then sat on a black screen on loading.

What the code showed: readiness and closed descriptors already behave correctly (a fresh epoll reports a writable datagram socket at once; control on a closed descriptor answers EBADF, a closed descriptor leaves the epoll; the resolver reports failure with an error). So the loop is legitimate guest behaviour that nothing slowed down.

  • sceNetEpollWait with a zero timeout paces a thread that polls hot and empty: after 32 empty polls less than 0.5 ms apart it yields, after 256 it sleeps about 1 ms per call. A returned event or a pause in the loop resets the count.
  • The observation log now records the event mask of sceNetEpollControl (events) and the events sceNetEpollWait returned (ready, as ident to events), which were missing when this was investigated.
  • New test net_epoll_per_call with the scenarios udp (writable and readable datagram socket, level triggered), tcp (non-blocking connect then writable, data, peer close), refused (failed connect wakes the poll), closed (closed descriptor), spin (seven spinning threads are paced) and observe (the new log fields).

Tested

Not run on a game yet; CI builds and runs the tests, and a Windows toolkit of this head is built from the Nightly workflow for the game test on Windows.

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 (hub T54)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@AlxcBTW
AlxcBTW marked this pull request as ready for review October 28, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant