feat(libkernel): support EV_CLEAR on sockets and pipes in kevent on Linux #7129

Merged
AlexOfTheForest merged 7 commits from upstream-pr/7129 into main 2026-10-19 17:56:36 +00:00
AlexOfTheForest commented 2026-10-17 12:50:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-17T12:50:13Z.


What

kevent threw NotImplemented for EV_CLEAR on a socket or the read end of a pipe. Boost.Asio's kqueue reactor, among others, registers every socket with EV_ADD | EV_CLEAR. This adds edge-triggered knotes on Linux, following FreeBSD 11.4's kern_event.c:

  • A knote is activated when kqueue_register finds it ready. That happens on add, and again on every later EV_ADD or EV_ENABLE of an enabled knote.
  • It is also activated on each KNOTE the object raises (sorwakeup, sowwakeup, pipeselwakeup).
  • kqueue_scan re-runs the filter before reporting and drops a knote that is no longer ready.
  • After a report the knote stays inactive until the next activation.

How it maps onto the host:

  • Each EV_CLEAR knote registers its host socket or pipe with a private epoll instance in edge-triggered mode: EPOLLIN | EPOLLRDHUP for EVFILT_READ, EPOLLOUT for EVFILT_WRITE.
  • A host wakeup with that mask stands for a KNOTE and arms the knote. When armed, it is checked with the existing level-triggered readiness test and reported with the current data and EV_EOF, or disarmed if it is no longer ready.
  • A wait blocks on the watch's epoll descriptor instead of the socket, so a socket that stays readable while its knote is cleared does not wake it or make it spin.

Commits:

  1. refactor(libkernel): let an equeue filter name the descriptor its waits block on: KernelFilter::waitDescriptor. The filter's owner is held for the length of the wait.
  2. feat(libkernel): add an epoll edge watch over a host descriptor: the new Equeue/{include,src}/EdgeWatch. Off Linux, opening a watch throws.
  3. feat(libkernel): support EV_CLEAR on sockets and pipes in kevent on Linux: wiring in Kqueue.cpp, GuestSockets::NativeDescriptor, and a new libkernel debt entry.
  4. test(libkernel): cover EV_CLEAR reads on a socket: fires once per arrival; stays quiet while data sits unread, with a CPU-time check that the 150 ms wait does not spin; fires again on re-add; is dropped when an arrival is read before the next scan; wakes a blocking kevent; reports EV_EOF once.
  5. test(libkernel): cover EV_CLEAR writes on a socket: fires on add, not after the guest's own send, again when the peer drains and frees space, on re-add, and with EV_EOF when the peer closes.
  6. test(libkernel): cover EV_CLEAR on a pipe and with EV_DISPATCH: pipe reads and EOF; EV_DISPATCH reports once, and EV_ENABLE re-runs the filter as kqueue_register does.

Known differences, written up in the debt entry:

  • Linux TCP wakes EPOLLOUT waiters only after a write found the socket full (SOCK_NOSPACE, tcp_check_space), so a TCP writer that never fills its buffer sees fewer EVFILT_WRITE events than on FreeBSD.
  • The host may coalesce data wakeups.
  • Windows and macOS still throw. EV_CLEAR on the timer, user and vnode filters is unchanged and works everywhere.

Tested

Linux x86_64, as root in a container:

  • guest_kqueue, guest_socket_events, guest_equeue_events, guest_poll, guest_select and guest_select_wait all passed 5 of 5 runs.
  • All 140 libkernel tests were built and run: 138 pass. guest_tcp and guest_named_shm_concurrency fail identically on unmodified main in the same container (the shm one expects EACCES, which root bypasses), so they are environmental.
  • Mutation checks: without waitDescriptor the read test fails on its CPU-time check; without disarming, the "stays quiet" checks fail.
  • tools/check_conventions.py --base upstream/main passes; the progress report is unchanged.
  • Not run on Windows or macOS, where these paths still throw.

This touches the same areas of GuestKqueue.cpp and docs/dev/debt/libkernel.md as my open pipe-write and socket-write-space PRs (the pipe-write one also touches SocketRuntime.hpp). There's no logical dependency; whichever merges later gets a small rebase.

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:4900188762 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7129). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-17T12:50:13Z. --- ### What `kevent` threw `NotImplemented` for `EV_CLEAR` on a socket or the read end of a pipe. Boost.Asio's kqueue reactor, among others, registers every socket with `EV_ADD | EV_CLEAR`. This adds edge-triggered knotes on Linux, following FreeBSD 11.4's `kern_event.c`: - A knote is activated when `kqueue_register` finds it ready. That happens on add, and again on every later `EV_ADD` or `EV_ENABLE` of an enabled knote. - It is also activated on each `KNOTE` the object raises (`sorwakeup`, `sowwakeup`, `pipeselwakeup`). - `kqueue_scan` re-runs the filter before reporting and drops a knote that is no longer ready. - After a report the knote stays inactive until the next activation. How it maps onto the host: - Each `EV_CLEAR` knote registers its host socket or pipe with a private epoll instance in edge-triggered mode: `EPOLLIN | EPOLLRDHUP` for `EVFILT_READ`, `EPOLLOUT` for `EVFILT_WRITE`. - A host wakeup with that mask stands for a `KNOTE` and arms the knote. When armed, it is checked with the existing level-triggered readiness test and reported with the current `data` and `EV_EOF`, or disarmed if it is no longer ready. - A wait blocks on the watch's epoll descriptor instead of the socket, so a socket that stays readable while its knote is cleared does not wake it or make it spin. Commits: 1. `refactor(libkernel): let an equeue filter name the descriptor its waits block on`: `KernelFilter::waitDescriptor`. The filter's owner is held for the length of the wait. 2. `feat(libkernel): add an epoll edge watch over a host descriptor`: the new `Equeue/{include,src}/EdgeWatch`. Off Linux, opening a watch throws. 3. `feat(libkernel): support EV_CLEAR on sockets and pipes in kevent on Linux`: wiring in `Kqueue.cpp`, `GuestSockets::NativeDescriptor`, and a new libkernel debt entry. 4. `test(libkernel): cover EV_CLEAR reads on a socket`: fires once per arrival; stays quiet while data sits unread, with a CPU-time check that the 150 ms wait does not spin; fires again on re-add; is dropped when an arrival is read before the next scan; wakes a blocking `kevent`; reports `EV_EOF` once. 5. `test(libkernel): cover EV_CLEAR writes on a socket`: fires on add, not after the guest's own send, again when the peer drains and frees space, on re-add, and with `EV_EOF` when the peer closes. 6. `test(libkernel): cover EV_CLEAR on a pipe and with EV_DISPATCH`: pipe reads and EOF; `EV_DISPATCH` reports once, and `EV_ENABLE` re-runs the filter as `kqueue_register` does. Known differences, written up in the debt entry: - Linux TCP wakes `EPOLLOUT` waiters only after a write found the socket full (`SOCK_NOSPACE`, `tcp_check_space`), so a TCP writer that never fills its buffer sees fewer `EVFILT_WRITE` events than on FreeBSD. - The host may coalesce data wakeups. - Windows and macOS still throw. `EV_CLEAR` on the timer, user and vnode filters is unchanged and works everywhere. ### Tested Linux x86_64, as root in a container: - `guest_kqueue`, `guest_socket_events`, `guest_equeue_events`, `guest_poll`, `guest_select` and `guest_select_wait` all passed 5 of 5 runs. - All 140 libkernel tests were built and run: 138 pass. `guest_tcp` and `guest_named_shm_concurrency` fail identically on unmodified `main` in the same container (the shm one expects `EACCES`, which root bypasses), so they are environmental. - Mutation checks: without `waitDescriptor` the read test fails on its CPU-time check; without disarming, the "stays quiet" checks fail. - `tools/check_conventions.py --base upstream/main` passes; the progress report is unchanged. - Not run on Windows or macOS, where these paths still throw. This touches the same areas of `GuestKqueue.cpp` and `docs/dev/debt/libkernel.md` as my open pipe-write and socket-write-space PRs (the pipe-write one also touches `SocketRuntime.hpp`). There's no logical dependency; whichever merges later gets a small rebase. ### 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 13:08:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T13:08:31Z.


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 7088 core/libs/prx/libkernel/Equeue/src/Kqueue.cpp L154
docs/dev/debt/libkernel.md L117, L181-182
PR 7121 docs/dev/debt/libkernel.md L117-118
PR 7605 docs/dev/debt/libkernel.md L181
PR 7653 docs/dev/debt/libkernel.md L117
PR 7937 docs/dev/debt/libkernel.md L116-117

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 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
core/libs/tests/GuestKqueue.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6226 core/libs/prx/libkernel/CMakeLists.txt
PR 6446 docs/dev/debt/libkernel.md
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7049 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
core/libs/tests/GuestKqueue.cpp
docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 7332 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7509 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/prx/libkernel/Equeue/Equeue.hpp
docs/dev/debt/libkernel.md
PR 7541 docs/dev/debt/libkernel.md
PR 7554 docs/dev/debt/libkernel.md
PR 7556 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234254419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7129#issuecomment-6234254419). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T13:08:31Z. --- <!-- 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 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp` [L154](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L154)<br>`docs/dev/debt/libkernel.md` [L117](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/docs/dev/debt/libkernel.md#L117), [L181-182](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/docs/dev/debt/libkernel.md#L181-L182) | | | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` [L117-118](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/docs/dev/debt/libkernel.md#L117-L118) | | | | [PR 7605](https://www.github.com/boykopovar/AnyPS5/pull/7605) | `docs/dev/debt/libkernel.md` [L181](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/docs/dev/debt/libkernel.md#L181) | | | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` [L117](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/docs/dev/debt/libkernel.md#L117) | | | | [PR 7937](https://www.github.com/boykopovar/AnyPS5/pull/7937) | `docs/dev/debt/libkernel.md` [L116-117](https://github.com/boykopovar/AnyPS5/blob/8444508241a9e4a6f5d5604d007451ce62d39cc0/docs/dev/debt/libkernel.md#L116-L117) | | | 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 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`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/prx/libkernel/CMakeLists.txt`<br>`core/libs/tests/GuestKqueue.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6446](https://www.github.com/boykopovar/AnyPS5/pull/6446) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `core/libs/prx/libkernel/Equeue/Equeue.cpp`<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`core/libs/tests/GuestKqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `core/libs/prx/libkernel/Equeue/Equeue.cpp`<br>`core/libs/prx/libkernel/Equeue/Equeue.hpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7541](https://www.github.com/boykopovar/AnyPS5/pull/7541) | `docs/dev/debt/libkernel.md` | | [PR 7554](https://www.github.com/boykopovar/AnyPS5/pull/7554) | `docs/dev/debt/libkernel.md` | | [PR 7556](https://www.github.com/boykopovar/AnyPS5/pull/7556) | `docs/dev/debt/libkernel.md` |
blawesom commented 2026-10-18 09:58:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T09:58:46Z.


Rebase handoff — rebased onto current main (authorship unchanged). The conflicts reconcile main's newer NOTE_LOWAT support with this PR's edge-triggered EV_CLEAR:

  • Kqueue.cpp: main's DescriptorLowWater (the NOTE_LOWAT validation) kept alongside your PollEdge/ResetEdge/WatchEdges machinery, and AddDescriptorKnote now computes the low-water mark and installs the edge watch for EV_CLEAR — your NOTE_LOWAT stub is superseded by main's real support
  • SocketRuntime.hpp: main's Type/Listening declarations kept alongside your NativeDescriptor
  • GuestKqueue.cpp: main's newer write-end low-water test kept (with its #ifndef __linux__ structure intact)
  • debt entries unioned

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; the kqueue tests pass; full suite green apart from the known main regression (agc_driver_tessellation segfault — Mesa, #5444), not this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7129
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 01db86eb8.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248504228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7129#issuecomment-6248504228). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-18T09:58:46Z. --- **Rebase handoff** — rebased onto current `main` (authorship unchanged). The conflicts reconcile `main`'s newer NOTE_LOWAT support with this PR's edge-triggered EV_CLEAR: - `Kqueue.cpp`: `main`'s `DescriptorLowWater` (the NOTE_LOWAT validation) kept alongside your `PollEdge`/`ResetEdge`/`WatchEdges` machinery, and `AddDescriptorKnote` now computes the low-water mark **and** installs the edge watch for `EV_CLEAR` — your `NOTE_LOWAT` stub is superseded by `main`'s real support - `SocketRuntime.hpp`: `main`'s `Type`/`Listening` declarations kept alongside your `NativeDescriptor` - `GuestKqueue.cpp`: `main`'s newer write-end low-water test kept (with its `#ifndef __linux__` structure intact) - debt entries unioned Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; the kqueue tests pass; **full suite green apart from the known `main` regression** (`agc_driver_tessellation` segfault — Mesa, #5444), not this PR. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/7129 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `01db86eb8`.
AlexOfTheForest commented 2026-10-18 12:04:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-18T12:04:27Z.


@blawesom thanks for the handoff. I redid the rebase on my side so the commits stay under my identity, following your NOTE_LOWAT reconciliation: main's DescriptorLowWater is kept, AddDescriptorKnote sets the low-water mark and then installs the edge watch for EV_CLEAR. One addition: the edge poll now applies the mark too (a cleared knote below NOTE_LOWAT is dropped, like filt_soread returning false in kqueue_scan), with a test for EV_CLEAR + NOTE_LOWAT that fails without that check. The six kqueue/equeue/poll/select tests pass 5/5 on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249694797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7129#issuecomment-6249694797). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-18T12:04:27Z. --- @blawesom thanks for the handoff. I redid the rebase on my side so the commits stay under my identity, following your NOTE_LOWAT reconciliation: main's DescriptorLowWater is kept, AddDescriptorKnote sets the low-water mark and then installs the edge watch for EV_CLEAR. One addition: the edge poll now applies the mark too (a cleared knote below NOTE_LOWAT is dropped, like filt_soread returning false in kqueue_scan), with a test for EV_CLEAR + NOTE_LOWAT that fails without that check. The six kqueue/equeue/poll/select tests pass 5/5 on Linux.
thuanquang commented 2026-10-18 21:30:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-18T21:30:19Z.


The new EdgeTriggeredSocketRead in GuestKqueue.cpp takes start after it creates the sender thread that acts after 50 ms, then requires waited >= 40 ms. Under parallel load the main thread can be preempted between creating that thread and reading the clock, so waited comes out under 40 ms although kevent did wait for the send. PipeRead in the same file has this order and aborts that way on Windows: on our RX 6700 XT PC, 9 of 120 runs under load. A timing probe caught 4 such aborts, and in each the main thread took start 39 to 68 ms after creating the writer, with kevent returning 0.3 to 1.4 ms after the write. #7670 moves start before the thread there and in guest_socket_events. Taking start before creating the sender here keeps the new check from flaking the same way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255381866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7129#issuecomment-6255381866). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-18T21:30:19Z. --- The new `EdgeTriggeredSocketRead` in `GuestKqueue.cpp` takes `start` after it creates the sender thread that acts after 50 ms, then requires `waited >= 40 ms`. Under parallel load the main thread can be preempted between creating that thread and reading the clock, so `waited` comes out under 40 ms although `kevent` did wait for the send. `PipeRead` in the same file has this order and aborts that way on Windows: on our RX 6700 XT PC, 9 of 120 runs under load. A timing probe caught 4 such aborts, and in each the main thread took `start` 39 to 68 ms after creating the writer, with `kevent` returning 0.3 to 1.4 ms after the write. #7670 moves `start` before the thread there and in `guest_socket_events`. Taking `start` before creating the sender here keeps the new check from flaking the same way.
adriadam10 commented 2026-10-19 17:57:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:57:57Z.


Checked the diff against FreeBSD 11.4 kqueue_register/kqueue_scan: the edge watch arms on add/EV_ENABLE, re-checks readiness (including NOTE_LOWAT) before reporting and disarms after a report; the wait blocks on the epoll descriptor so a still-readable socket doesn't spin. The debt entry covers the TCP EPOLLOUT and coalescing differences.

Rebased on current main (conflicts in Kqueue.cpp and docs/dev/debt/libkernel.md next to AddStandardInputKnote and the mprotect entry, both kept) and added one commit: EdgeTriggeredSocketRead now takes start before creating the sender thread, so a preempted main thread can't make waited >= 40 ms fail (the flake reported above). Libkernel tests built and run on the rebased tree; only guest_kernel_fcntl failed under parallel ctest, it passes alone and doesn't touch this code; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273736894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7129#issuecomment-6273736894). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T17:57:57Z. --- Checked the diff against FreeBSD 11.4 `kqueue_register`/`kqueue_scan`: the edge watch arms on add/`EV_ENABLE`, re-checks readiness (including `NOTE_LOWAT`) before reporting and disarms after a report; the wait blocks on the epoll descriptor so a still-readable socket doesn't spin. The debt entry covers the TCP `EPOLLOUT` and coalescing differences. Rebased on current `main` (conflicts in `Kqueue.cpp` and `docs/dev/debt/libkernel.md` next to `AddStandardInputKnote` and the mprotect entry, both kept) and added one commit: `EdgeTriggeredSocketRead` now takes `start` before creating the sender thread, so a preempted main thread can't make `waited >= 40 ms` fail (the flake reported above). Libkernel tests built and run on the rebased tree; only `guest_kernel_fcntl` failed under parallel ctest, it passes alone and doesn't touch this code; merged.
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!7129
No description provided.