fix(libkernel): report free send space for socket write events on Linux #7076

Merged
AlexOfTheForest merged 2 commits from upstream-pr/7076 into main 2026-10-17 20:44:37 +00:00
AlexOfTheForest commented 2026-10-17 10:29:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-17T10:29:56Z.


What

A socket's EVFILT_WRITE (from kevent and from sceKernelAddWriteEvent) reported the whole SO_SNDBUF in data, however much was already queued. FreeBSD 11.4's filt_sowrite reports sbspace(&so->so_snd), the space still free. On Linux, GuestSockets::Ready now subtracts the queued bytes from SIOCOUTQ. Those include the host's per-packet overhead, so the value drops by somewhat more than the bytes sent. Windows has no query for the queued bytes and macOS is not wired up, so both still report SO_SNDBUF. The existing libkernel debt entry, which listed this gap, is updated.

Two commits:

  • fix(libkernel): report free send space for socket write events on Linux: the Udp.cpp change and the debt entry.
  • test(libkernel): check socket write event space shrinks and recovers: in guest_kqueue, on a Unix stream socketpair, data drops by at least the 1000 bytes sent while the peer has not read them, and returns to the idle value once the peer drains them. Off Linux the test only checks that the value stays positive and never grows.

Tested

Linux x86_64: guest_kqueue, guest_socket_events, guest_poll and guest_select all passed 5 of 5 runs. With the fix reverted, guest_kqueue fails at the new check. tools/check_conventions.py --base upstream/main passes; the progress report is unchanged. Not run on Windows or macOS, where the behaviour is unchanged. Merges cleanly with feat/kevent-pipe-write; the two PRs don't depend on each other.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4899321465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7076). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-17T10:29:56Z. --- ### What A socket's `EVFILT_WRITE` (from `kevent` and from `sceKernelAddWriteEvent`) reported the whole `SO_SNDBUF` in `data`, however much was already queued. FreeBSD 11.4's [`filt_sowrite`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c#L3358-L3382) reports `sbspace(&so->so_snd)`, the space still free. On Linux, `GuestSockets::Ready` now subtracts the queued bytes from `SIOCOUTQ`. Those include the host's per-packet overhead, so the value drops by somewhat more than the bytes sent. Windows has no query for the queued bytes and macOS is not wired up, so both still report `SO_SNDBUF`. The existing libkernel debt entry, which listed this gap, is updated. Two commits: - `fix(libkernel): report free send space for socket write events on Linux`: the `Udp.cpp` change and the debt entry. - `test(libkernel): check socket write event space shrinks and recovers`: in `guest_kqueue`, on a Unix stream socketpair, `data` drops by at least the 1000 bytes sent while the peer has not read them, and returns to the idle value once the peer drains them. Off Linux the test only checks that the value stays positive and never grows. ### Tested Linux x86_64: `guest_kqueue`, `guest_socket_events`, `guest_poll` and `guest_select` all passed 5 of 5 runs. With the fix reverted, `guest_kqueue` fails at the new check. `tools/check_conventions.py --base upstream/main` passes; the progress report is unchanged. Not run on Windows or macOS, where the behaviour is unchanged. Merges cleanly with `feat/kevent-pipe-write`; the two PRs don't depend on each other. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 10:51:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T10:51:37Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6542 docs/dev/debt/libkernel.md L128-129

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestKqueue.cpp
PR 6222 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6510 core/libs/tests/GuestKqueue.cpp
docs/dev/debt/libkernel.md
PR 6710 docs/dev/debt/libkernel.md
PR 6962 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/Socket/src/Udp.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233031597 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7076#issuecomment-6233031597). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T10:51:37Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6542](https://www.github.com/boykopovar/AnyPS5/pull/6542) | `docs/dev/debt/libkernel.md` [L128-129](https://github.com/boykopovar/AnyPS5/blob/66702f1cffd3646f2d674ed093fde0a85a70761f/docs/dev/debt/libkernel.md#L128-L129) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestKqueue.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `core/libs/tests/GuestKqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6710](https://www.github.com/boykopovar/AnyPS5/pull/6710) | `docs/dev/debt/libkernel.md` | | [PR 6962](https://www.github.com/boykopovar/AnyPS5/pull/6962) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` |
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!7076
No description provided.