feat(libkernel): implement EV_DISABLE, EV_DISPATCH and EV_FORCEONESHOT in kevent #6510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6510"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Nawasfadili on 2026-10-15T18:07:53Z.
What
Implement EV_DISABLE, EV_DISPATCH, and EV_FORCEONESHOT flags in kevent for libkernel.
Tested
Windows 11 x64, guest_kqueue tests (passed 5/5 repeats with 0 errors). Multi-threaded worker stress test for EV_DISPATCH.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T18:27:16Z.
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.
docs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/FileEvent.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/FileEvent.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/prx/libkernel/Equeue/src/FileEvent.cppcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/Equeue.hppcore/libs/prx/libkernel/Equeue/src/FileEvent.cppcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/Equeue.hppcore/libs/prx/libkernel/Equeue/src/FileEvent.cppcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/prx/libkernel/Equeue/Equeue.hppcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/tests/GuestKqueue.cppcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/prx/libkernel/Equeue/Equeue.hppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/FileEvent.cppcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T19:04:53Z.
Review: COMMENTED
Linux run, plus three places where the new flags diverge from the FreeBSD 11
kern_event.cthat the debt entry cites.Setup: Ubuntu 26.04, i7-8700, GCC 15.2, Release, full build with
BUILD_TESTING=ON. Head709c63698merged onto main44df21632.Results
guest_kqueuepasses, and passes 5/5 with--repeat until-fail:5, StressTest included.ctest -E "^agc"): 668/670, the same as plain main. The two failures arefile_writer_binaryandfile_writer_text, which also fail on main on this host.Equeuesource files: aborts withkevent: EV_DISABLE not implemented. So the test does cover the new paths.Divergences from FreeBSD 11 (commit
34bd347, the one the debt entry links)EV_FORCEONESHOTtogether withEV_ADD.kqueue_registerdrops the flag when it creates the knote (kn_kevent.flags &= ~(EV_ADD | EV_DELETE | EV_ENABLE | EV_DISABLE | EV_FORCEONESHOT)) and jumps todone_ev_add, so the new knote is not one-shot. On FreeBSD the event keeps firing and a laterEV_DELETEreturns 0. With this PR the knote is deleted after the first delivery, the returnedflagsis0x100, andEV_DELETEgetsENOENT.ForceOneshotandEdgeCaseFlagsassert the PR's version. RemovingEV_DISABLE | EV_FORCEONESHOTfromKNOTE_CLEARED_FLAGSis what lets0x100reach the caller; main matched FreeBSD there.EV_FORCEONESHOTon an existing knote. FreeBSD runskn->kn_flags |= EV_ONESHOT; KNOTE_ACTIVATE(kn, 1);. The event is delivered on the next scan even if its condition never triggered, comes back withEV_ONESHOT, and the knote is then dropped. With this PR nothing is delivered until a trigger arrives.EVFILT_USERdata.filt_usertouch(EVENT_REGISTER)setskn_sdata = kev->dataon every touch, not only withNOTE_TRIGGER. Main follows that; this PR moves the assignment inside theNOTE_TRIGGERbranch. The fourth step ofEdgeCaseFlagsdepends on the PR's behaviour.Smaller differences:
EV_ADD | EV_FORCEONESHOTbecomes one-shot here. On FreeBSD,filt_timerattachonly seesEV_ONESHOT, so the period becomes 1.EV_ENABLE | EV_DISABLEin the same change returnsEINVALon FreeBSD (start ofkqueue_register). Here the knote is disabled.Probe on the same build. Each scenario was appended to
GuestKqueue.cpp, using its own helpers:44df21632EV_ADD,NOTE_TRIGGERdata 100, then touch with data 7, pollEV_ADD | EV_FORCEONESHOT, trigger, poll, poll,EV_DELETEflags=0x100, then 0, deleteENOENTflags=0, then 1 again (EV_CLEARis not set), delete 0EV_ADD(no trigger), thenEV_FORCEONESHOT, pollflags=EV_ONESHOT, knote droppedThe FreeBSD column comes from reading the source; I did not run FreeBSD. If the console is meant to follow FreeBSD here, the knote probably needs a separate disabled state and the flags masked as in
kqueue_register. If not, it would help to record these differences in the debt entry: as written, it sayskqueue_registeris followed.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Nawasfadili on 2026-10-15T23:10:19Z.
Thanks a lot for the thorough review and FreeBSD 11 analysis, @jotitadev!
I've updated the PR to strictly match FreeBSD 11 (
kern_event.c):bool disabledfield toKernelEqueueEventsoevent.flagsis no longer mutated or polluted withEV_DISABLEuponEV_DISPATCHdelivery, mirroring FreeBSD's separation ofkn_status(KN_DISABLED) andkn_kevent.flags.EV_FORCEONESHOTsemantics:KNOTE_CLEARED_FLAGSonEV_ADDso a newly added knote remains persistent.EV_ONESHOTand activates it immediately (triggered = true), matchingkern_event.c:1340-1341(kn->kn_flags |= EV_ONESHOT; KNOTE_ACTIVATE(kn, 1);), returning withEV_ONESHOTand auto-dropping.EVFILT_USERdata touch:TouchUserKnotenow updatesevent.event.data = change.dataunconditionally on every register touch, exactly asfilt_usertouch(EVENT_REGISTER)does.GuestKqueue.cppto verify all three probe scenarios from your table (guest_kqueuepasses 5/5 repeats, and conventions check passes cleanly).Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T14:13:55Z.
Review: COMMENTED
A heads-up on where this PR stands. #5847, which implements the same
EV_DISABLE,EV_DISPATCHandEV_FORCEONESHOThandling inKqueue.cppandEqueue.cpp, was merged by adriadam10 on 2026-10-15 at 21:01 UTC, a few hours after this PR opened. Head522969b0cnow conflicts withmain5d9dcc42din five files (Equeue.cpp,Equeue.hpp,Kqueue.cpp,GuestKqueue.cppand the libkernel debt doc), all from that overlap. The merged version's debt entry already describes the three flags.The one part that isn't on
mainis theFileEvent.cppchange:IsDeletedalso treating a path under$Deletedas deleted, andNOTE_DELETEraised on that transition. That's a separate topic from the kevent flags. If it fixes a casemainmisses, for example a delete where neitherdeletePendingnor the link count changes in the snapshot, it could stand on its own as a small PR with a test that shows the missedNOTE_DELETE. If any of jotitadev's FreeBSD 11 points (the separatedisabledstate and so on) still differ from what #5847 merged, those would fit a follow-up againstmaintoo.AI-assisted: yes. I checked the merge with
mainand compared the diff with the merged #5847.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-16T17:13:31Z.
Heads-up before more rebase effort goes in:
mainalready implements this feature. PR #5847 landedb32c5a50c("feat(libkernel): implement kevent EV_DISABLE, EV_DISPATCH and EV_FORCEONESHOT", Oct 14) with follow-upa7da412a7("follow kqueue_register for EV_FORCEONESHOT and modify flags"), so this PR is now a parallel implementation of merged work.mainalso renamed the event field this PR uses (disabled→enabled, inverted default).What I find genuinely additive here, on top of #5847:
deleteEventFuncinvocation when anEV_ONESHOTnote retires inCollectTriggered(Equeue.cpp) — mirrors the patternmainalready uses inCollectOncePerWait$Deletedpath detection inFileEvent.cpp(IsDeleted(before) != IsDeleted(after)transitions) — not covered bymain'sNOTE_DELETEreporting as far as I can tellGuestKqueue.cpp— with one caveat:EdgeCaseFlagsappliesEV_DISPATCHon modify and asserts it lands in the knote flags, whicha7da412a7deliberately removed (it follows FreeBSDkqueue_register, which does not OR dispatch flags into a note on modify), so that test contradictsmain's semantics as-isSo the practical options are reducing this PR to the additive deltas (the delete-once and
$Deletedpieces plus the compatible tests), or closing it in favor of #5847 — that's a call for you and the maintainers. I can carry the reduction as a rebase handoff if that's the wanted direction; the semantics question (EV_DISPATCH reset behavior — this PR resets viaresetFunc/EV_CLEAR conditionally,mainclears unconditionally) may also be worth reconciling against FreeBSD in whichever piece survives.Imported from boykopovar/AnyPS5. Originally posted by Nawasfadili on 2026-10-16T20:13:19Z.
Thanks @blawesom and @karimibrahim07 for the thorough review and heads-up!
Since the kevent flags were already merged via #5847, I'll close this PR.
@blawesom If you'd like to carry over the additive pieces (
deleteEventFuncinCollectTriggered, the Windows$Deletedhandling inFileEvent, and the extra tests) as a follow-up rebase handoff, please feel free to do so! Thanks again for your guidance.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T02:43:36Z.
Closing:
mainalready implements this feature. #5847 (plusa7da412a7) landedEV_DISABLE,EV_DISPATCHandEV_FORCEONESHOTinKqueue.cpp/Equeue.cpp, so this PR is a parallel implementation and conflicts withmainin five files. You also said on 2026-10-16 that you would close it.The pieces not on
main(deleteEventFuncwhen anEV_ONESHOTknote retires inCollectTriggered, the Windows$Deletedhandling inFileEvent.cpp, and the extra tests) are welcome as a small follow-up PR rebased on currentmain, one topic each.Pull request closed