feat(libkernel): implement kevent EV_DISABLE, EV_DISPATCH and EV_FORCEONESHOT #5847

Merged
akkadbakkad89 merged 2 commits from upstream-pr/5847 into main 2026-10-15 21:01:11 +00:00
akkadbakkad89 commented 2026-10-14 13:44:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-14T13:44:56Z.


What

kevent no longer throws on EV_DISABLE, EV_DISPATCH, EV_FORCEONESHOT or a negative nevents, following kqueue_register/kqueue_scan in FreeBSD 11's kern_event.c:

  • KernelEqueueEvent gains an enabled flag (FreeBSD's KN_DISABLED). PollEvents, TriggerExpiredTimers, TriggerEvent, WaitForDescriptors interest registration and NextTimerWaitMicros all skip disabled knotes, so a disabled knote never fires.
  • EV_DISABLE on EV_ADD registers the knote disabled; on an existing knote EV_DISABLE/EV_ENABLE toggles it. EV_ENABLE | EV_DISABLE still returns EINVAL.
  • EV_DISPATCH reports the event once, then disables the knote until re-enabled - both collect paths (CollectTriggered, CollectOncePerWait).
  • EV_FORCEONESHOT is ignored on a new knote; on an existing knote it sets EV_ONESHOT and fires it, as kqueue_register does at l.1339-1341.
  • A modify updates only udata, the filter's touch/fflags and enable/disable - no flag adoption, matching kqueue_register.
  • Negative nevents returns EINVAL.

Known deviation documented in docs/dev/debt/libkernel.md: a NOTE_TRIGGER raised while a user knote is disabled is kept and reported after EV_ENABLE, where FreeBSD's knote drops it.

File-level overlap note: Kqueue.cpp/Equeue.cpp are also touched by open PRs #5749 (EVFILT_VNODE on macOS) and #5493 (vnode error naming) - different code paths, line-adjacent only.

Tested

WSL Ubuntu 24.04, gcc, host CPU only:

  • guest_kqueue: all pass, including DisableAndDispatch cases - register-disabled socket knote stays silent until EV_ENABLE; EV_DISPATCH fires once, suppresses further data, re-arms on EV_ENABLE, disables again; EV_FORCEONESHOT on add stays a normal level knote (delivers twice), on modify sets oneshot and fires (EV_DELETE then ENOENT); disabled user knote keeps its NOTE_TRIGGER until re-enable; Errors gains the nevents < 0 -> EINVAL check and the old EV_DISABLE throw expectation is removed
  • guest_equeue_events, guest_ult_queue_* (8 tests): pass
  • Rebuilt neighbors guest_socket_pair, guest_dup, guest_fstatfs, guest_getrlimit, guest_signals: pass
  • tools/check_conventions.py --base upstream/main: clean

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4858848122 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5847). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-14T13:44:56Z. --- ### What `kevent` no longer throws on `EV_DISABLE`, `EV_DISPATCH`, `EV_FORCEONESHOT` or a negative `nevents`, following `kqueue_register`/`kqueue_scan` in FreeBSD 11's `kern_event.c`: - `KernelEqueueEvent` gains an `enabled` flag (FreeBSD's `KN_DISABLED`). `PollEvents`, `TriggerExpiredTimers`, `TriggerEvent`, `WaitForDescriptors` interest registration and `NextTimerWaitMicros` all skip disabled knotes, so a disabled knote never fires. - `EV_DISABLE` on `EV_ADD` registers the knote disabled; on an existing knote `EV_DISABLE`/`EV_ENABLE` toggles it. `EV_ENABLE | EV_DISABLE` still returns `EINVAL`. - `EV_DISPATCH` reports the event once, then disables the knote until re-enabled - both collect paths (`CollectTriggered`, `CollectOncePerWait`). - `EV_FORCEONESHOT` is ignored on a new knote; on an existing knote it sets `EV_ONESHOT` and fires it, as `kqueue_register` does at l.1339-1341. - A modify updates only `udata`, the filter's touch/fflags and enable/disable - no flag adoption, matching `kqueue_register`. - Negative `nevents` returns `EINVAL`. Known deviation documented in `docs/dev/debt/libkernel.md`: a `NOTE_TRIGGER` raised while a user knote is disabled is kept and reported after `EV_ENABLE`, where FreeBSD's `knote` drops it. File-level overlap note: `Kqueue.cpp`/`Equeue.cpp` are also touched by open PRs #5749 (EVFILT_VNODE on macOS) and #5493 (vnode error naming) - different code paths, line-adjacent only. ### Tested WSL Ubuntu 24.04, gcc, host CPU only: - `guest_kqueue`: all pass, including `DisableAndDispatch` cases - register-disabled socket knote stays silent until `EV_ENABLE`; `EV_DISPATCH` fires once, suppresses further data, re-arms on `EV_ENABLE`, disables again; `EV_FORCEONESHOT` on add stays a normal level knote (delivers twice), on modify sets oneshot and fires (`EV_DELETE` then `ENOENT`); disabled user knote keeps its `NOTE_TRIGGER` until re-enable; `Errors` gains the `nevents < 0` -> `EINVAL` check and the old `EV_DISABLE` throw expectation is removed - `guest_equeue_events`, `guest_ult_queue_*` (8 tests): pass - Rebuilt neighbors `guest_socket_pair`, `guest_dup`, `guest_fstatfs`, `guest_getrlimit`, `guest_signals`: pass - `tools/check_conventions.py --base upstream/main`: clean ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
adriadam10 commented 2026-10-14 13:52:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:52:58Z.

Review: CHANGES_REQUESTED


Thanks, the enabled flag and the EV_DISPATCH collect paths look right and guest_kqueue passes here. Two points differ from kern_event.c (the commit the debt entry cites):

  • EV_FORCEONESHOT on a new knote: kqueue_register only clears it from kn_kevent.flags on the attach path (l.1303-1304). It sets EV_ONESHOT and activates the knote only when the knote already exists (l.1339-1341). Kqueue.cpp:252 applies it on add, and GuestKqueue.cpp:250-253 pins that. Please follow the source: no oneshot on add; on an existing knote set EV_ONESHOT and trigger it.
  • ModifyKnote (Kqueue.cpp:232) ORs EV_ONESHOT | EV_CLEAR | EV_DISPATCH into an existing knote. kqueue_register does not do that for an existing knote (only udata, the filter's touch/fflags, and enable/disable). It also lets EV_CLEAR through on a socket knote, which AddDescriptorKnote throws on at add time. Drop the line (or, if you have a source for it, cite it and keep the throw for EV_CLEAR on sockets), and fix the PR body and the debt entry accordingly.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5519029415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5847#pullrequestreview-5519029415). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T13:52:58Z. **Review:** CHANGES_REQUESTED --- Thanks, the enabled flag and the EV_DISPATCH collect paths look right and `guest_kqueue` passes here. Two points differ from `kern_event.c` (the commit the debt entry cites): - `EV_FORCEONESHOT` on a new knote: `kqueue_register` only clears it from `kn_kevent.flags` on the attach path (l.1303-1304). It sets `EV_ONESHOT` and activates the knote only when the knote already exists (l.1339-1341). `Kqueue.cpp:252` applies it on add, and `GuestKqueue.cpp:250-253` pins that. Please follow the source: no oneshot on add; on an existing knote set `EV_ONESHOT` and trigger it. - `ModifyKnote` (`Kqueue.cpp:232`) ORs `EV_ONESHOT | EV_CLEAR | EV_DISPATCH` into an existing knote. `kqueue_register` does not do that for an existing knote (only `udata`, the filter's touch/fflags, and enable/disable). It also lets `EV_CLEAR` through on a socket knote, which `AddDescriptorKnote` throws on at add time. Drop the line (or, if you have a source for it, cite it and keep the throw for `EV_CLEAR` on sockets), and fix the PR body and the debt entry accordingly.
akkadbakkad89 commented 2026-10-14 14:17:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-14T14:17:47Z.


Both points fixed in 637cb1ed4, thanks for the line references:

  • EV_FORCEONESHOT on add now does nothing beyond KNOTE_CLEARED_FLAGS stripping it; on an existing knote ModifyKnote sets EV_ONESHOT and marks the knote triggered. The test now pins both halves: EV_ADD | EV_FORCEONESHOT delivers as a normal level knote twice, then the same change on the existing knote fires once and the knote is gone (EV_DELETE -> ENOENT).
  • The EV_ONESHOT | EV_CLEAR | EV_DISPATCH OR on modify is dropped; a modify now touches only udata, enable/disable, EV_FORCEONESHOT and the filter's touch/fflags, matching kqueue_register. No EV_CLEAR can reach a socket knote through modify any more.

PR body and the libkernel.md debt entry updated to describe the new behaviour. guest_kqueue green locally (WSL).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6170493519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5847#issuecomment-6170493519). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-14T14:17:47Z. --- Both points fixed in `637cb1ed4`, thanks for the line references: - `EV_FORCEONESHOT` on add now does nothing beyond `KNOTE_CLEARED_FLAGS` stripping it; on an existing knote `ModifyKnote` sets `EV_ONESHOT` and marks the knote triggered. The test now pins both halves: `EV_ADD | EV_FORCEONESHOT` delivers as a normal level knote twice, then the same change on the existing knote fires once and the knote is gone (`EV_DELETE` -> `ENOENT`). - The `EV_ONESHOT | EV_CLEAR | EV_DISPATCH` OR on modify is dropped; a modify now touches only `udata`, enable/disable, `EV_FORCEONESHOT` and the filter's touch/fflags, matching `kqueue_register`. No `EV_CLEAR` can reach a socket knote through modify any more. PR body and the `libkernel.md` debt entry updated to describe the new behaviour. `guest_kqueue` green locally (WSL).
github-actions[bot] commented 2026-10-15 06:42:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T06:42:45Z.


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 5973 docs/dev/debt/libkernel.md L111-112
PR 6343 docs/dev/debt/libkernel.md L111-112
PR 6510 core/libs/prx/libkernel/Equeue/Equeue.cpp L52-53, L68-69, L84-85, L101-102, L123, L130, L155, L167-168
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp L225, L244-252
core/libs/tests/GuestKqueue.cpp L59, L252, L534-535
docs/dev/debt/libkernel.md L111-112
PR 6542 docs/dev/debt/libkernel.md L110-112

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 3891 docs/dev/debt/libkernel.md
PR 4156 docs/dev/debt/libkernel.md
PR 4396 docs/dev/debt/libkernel.md
PR 4397 docs/dev/debt/libkernel.md
PR 4422 docs/dev/debt/libkernel.md
PR 4423 docs/dev/debt/libkernel.md
PR 4424 docs/dev/debt/libkernel.md
PR 4520 docs/dev/debt/libkernel.md
PR 4521 docs/dev/debt/libkernel.md
PR 4522 docs/dev/debt/libkernel.md
PR 4523 docs/dev/debt/libkernel.md
PR 4566 docs/dev/debt/libkernel.md
PR 4599 docs/dev/debt/libkernel.md
PR 4718 docs/dev/debt/libkernel.md
PR 4740 docs/dev/debt/libkernel.md
PR 4749 docs/dev/debt/libkernel.md
PR 4760 docs/dev/debt/libkernel.md
PR 4813 docs/dev/debt/libkernel.md
PR 5021 docs/dev/debt/libkernel.md
PR 5835 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestKqueue.cpp
PR 6222 docs/dev/debt/libkernel.md
PR 6447 core/libs/prx/libkernel/Equeue/Equeue.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6186172820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5847#issuecomment-6186172820). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T06:42:45Z. --- <!-- 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 5973](https://www.github.com/boykopovar/AnyPS5/pull/5973) | `docs/dev/debt/libkernel.md` [L111-112](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/docs/dev/debt/libkernel.md#L111-L112) | | | | [PR 6343](https://www.github.com/boykopovar/AnyPS5/pull/6343) | `docs/dev/debt/libkernel.md` [L111-112](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/docs/dev/debt/libkernel.md#L111-L112) | | | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `core/libs/prx/libkernel/Equeue/Equeue.cpp` [L52-53](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L52-L53), [L68-69](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L68-L69), [L84-85](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L84-L85), [L101-102](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L101-L102), [L123](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L123), [L130](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L130), [L155](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L155), [L167-168](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/Equeue.cpp#L167-L168)<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp` [L225](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L225), [L244-252](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L244-L252)<br>`core/libs/tests/GuestKqueue.cpp` [L59](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/tests/GuestKqueue.cpp#L59), [L252](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/tests/GuestKqueue.cpp#L252), [L534-535](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/core/libs/tests/GuestKqueue.cpp#L534-L535)<br>`docs/dev/debt/libkernel.md` [L111-112](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/docs/dev/debt/libkernel.md#L111-L112) | | | | [PR 6542](https://www.github.com/boykopovar/AnyPS5/pull/6542) | `docs/dev/debt/libkernel.md` [L110-112](https://github.com/boykopovar/AnyPS5/blob/ce991f1ec2eb71a1f30459b4442a0730a0a4861b/docs/dev/debt/libkernel.md#L110-L112) | | | 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 3891](https://www.github.com/boykopovar/AnyPS5/pull/3891) | `docs/dev/debt/libkernel.md` | | [PR 4156](https://www.github.com/boykopovar/AnyPS5/pull/4156) | `docs/dev/debt/libkernel.md` | | [PR 4396](https://www.github.com/boykopovar/AnyPS5/pull/4396) | `docs/dev/debt/libkernel.md` | | [PR 4397](https://www.github.com/boykopovar/AnyPS5/pull/4397) | `docs/dev/debt/libkernel.md` | | [PR 4422](https://www.github.com/boykopovar/AnyPS5/pull/4422) | `docs/dev/debt/libkernel.md` | | [PR 4423](https://www.github.com/boykopovar/AnyPS5/pull/4423) | `docs/dev/debt/libkernel.md` | | [PR 4424](https://www.github.com/boykopovar/AnyPS5/pull/4424) | `docs/dev/debt/libkernel.md` | | [PR 4520](https://www.github.com/boykopovar/AnyPS5/pull/4520) | `docs/dev/debt/libkernel.md` | | [PR 4521](https://www.github.com/boykopovar/AnyPS5/pull/4521) | `docs/dev/debt/libkernel.md` | | [PR 4522](https://www.github.com/boykopovar/AnyPS5/pull/4522) | `docs/dev/debt/libkernel.md` | | [PR 4523](https://www.github.com/boykopovar/AnyPS5/pull/4523) | `docs/dev/debt/libkernel.md` | | [PR 4566](https://www.github.com/boykopovar/AnyPS5/pull/4566) | `docs/dev/debt/libkernel.md` | | [PR 4599](https://www.github.com/boykopovar/AnyPS5/pull/4599) | `docs/dev/debt/libkernel.md` | | [PR 4718](https://www.github.com/boykopovar/AnyPS5/pull/4718) | `docs/dev/debt/libkernel.md` | | [PR 4740](https://www.github.com/boykopovar/AnyPS5/pull/4740) | `docs/dev/debt/libkernel.md` | | [PR 4749](https://www.github.com/boykopovar/AnyPS5/pull/4749) | `docs/dev/debt/libkernel.md` | | [PR 4760](https://www.github.com/boykopovar/AnyPS5/pull/4760) | `docs/dev/debt/libkernel.md` | | [PR 4813](https://www.github.com/boykopovar/AnyPS5/pull/4813) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libkernel.md` | | [PR 5835](https://www.github.com/boykopovar/AnyPS5/pull/5835) | `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) | `docs/dev/debt/libkernel.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel/Equeue/Equeue.cpp` |
adriadam10 commented 2026-10-15 13:40:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:40:44Z.

Review: APPROVED


Both points are fixed: EV_FORCEONESHOT is a no-op on add and sets EV_ONESHOT and triggers on an existing knote, as in kqueue_register, and a modify no longer adopts flags. Checked the build and ctest on the PR merged onto main, guest_kqueue passes and fails without the change; merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5534046606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5847#pullrequestreview-5534046606). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:40:44Z. **Review:** APPROVED --- Both points are fixed: `EV_FORCEONESHOT` is a no-op on add and sets `EV_ONESHOT` and triggers on an existing knote, as in `kqueue_register`, and a modify no longer adopts flags. Checked the build and ctest on the PR merged onto main, `guest_kqueue` passes and fails without the change; merging once the full Build is green.
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!5847
No description provided.