Repository navigation
feat(libkernel): implement EV_DISABLE, EV_DISPATCH and EV_FORCEONESHOT in kevent - #6510
Nawasfadili wants to merge 1 commit into
Conversation
|
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.
|
jotitadev
left a comment
There was a problem hiding this comment.
Linux run, plus three places where the new flags diverge from the FreeBSD 11 kern_event.c that the debt entry cites.
Setup: Ubuntu 26.04, i7-8700, GCC 15.2, Release, full build with BUILD_TESTING=ON. Head 709c63698 merged onto main 44df21632.
Results
guest_kqueuepasses, and passes 5/5 with--repeat until-fail:5, StressTest included.- Non-GPU suite (
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. - Test only, without the three
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:
- A zero-period timer with
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:
| Scenario | main 44df21632 |
this PR | FreeBSD 11 (from source) |
|---|---|---|---|
user knote: EV_ADD, NOTE_TRIGGER data 100, then touch with data 7, poll |
data 7 | data 100 | data 7 |
EV_ADD | EV_FORCEONESHOT, trigger, poll, poll, EV_DELETE |
throws | 1 event flags=0x100, then 0, delete ENOENT |
flag dropped; 1 event flags=0, then 1 again (EV_CLEAR is not set), delete 0 |
EV_ADD (no trigger), then EV_FORCEONESHOT, poll |
throws | 0 events | 1 event flags=EV_ONESHOT, knote dropped |
The 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 says kqueue_register is followed.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
709c636 to
522969b
Compare
|
Thanks a lot for the thorough review and FreeBSD 11 analysis, @jotitadev! I've updated the PR to strictly match FreeBSD 11 (
|
karimibrahim07
left a comment
There was a problem hiding this comment.
A heads-up on where this PR stands. #5847, which implements the same EV_DISABLE, EV_DISPATCH and EV_FORCEONESHOT handling in Kqueue.cpp and Equeue.cpp, was merged by adriadam10 on 2026-10-15 at 21:01 UTC, a few hours after this PR opened. Head 522969b0c now conflicts with main 5d9dcc42d in five files (Equeue.cpp, Equeue.hpp, Kqueue.cpp, GuestKqueue.cpp and 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 main is the FileEvent.cpp change: IsDeleted also treating a path under $Deleted as deleted, and NOTE_DELETE raised on that transition. That's a separate topic from the kevent flags. If it fixes a case main misses, for example a delete where neither deletePending nor the link count changes in the snapshot, it could stand on its own as a small PR with a test that shows the missed NOTE_DELETE. If any of jotitadev's FreeBSD 11 points (the separate disabled state and so on) still differ from what #5847 merged, those would fit a follow-up against main too.
AI-assisted: yes. I checked the merge with main and compared the diff with the merged #5847.
|
Heads-up before more rebase effort goes in: What I find genuinely additive here, on top of #5847:
So the practical options are reducing this PR to the additive deltas (the delete-once and |
|
Thanks @blawesom and @karimibrahim07 for the thorough review and heads-up! @blawesom If you'd like to carry over the additive pieces ( |
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
|
Closing: The pieces not on |
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
…perseded kevent tests - RecycleBinDeleteWatchedFile now runs on Windows: its call moves out of the #ifndef _WIN32 block so the $Extend$Deleted$ path is exercised - InotifyWatchCount and the two leak assertions gate on __linux__ (macOS has no /proc; the count was always 0 and the assertion vacuous) - DisableAndEnable, Dispatch, ForceOneshot and StressTest drop with their main() calls: they belong to the superseded boykopovar#6510 feature, and StressTest asserts strict arrival order across 4 threads with 1-2 ms sleeps (CI flake risk)
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
…perseded kevent tests - RecycleBinDeleteWatchedFile now runs on Windows: its call moves out of the #ifndef _WIN32 block so the $Extend$Deleted$ path is exercised - InotifyWatchCount and the two leak assertions gate on __linux__ (macOS has no /proc; the count was always 0 and the assertion vacuous) - DisableAndEnable, Dispatch, ForceOneshot and StressTest drop with their main() calls: they belong to the superseded boykopovar#6510 feature, and StressTest asserts strict arrival order across 4 threads with 1-2 ms sleeps (CI flake risk)
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
…perseded kevent tests - RecycleBinDeleteWatchedFile now runs on Windows: its call moves out of the #ifndef _WIN32 block so the $Extend$Deleted$ path is exercised - InotifyWatchCount and the two leak assertions gate on __linux__ (macOS has no /proc; the count was always 0 and the assertion vacuous) - DisableAndEnable, Dispatch, ForceOneshot and StressTest drop with their main() calls: they belong to the superseded boykopovar#6510 feature, and StressTest asserts strict arrival order across 4 threads with 1-2 ms sleeps (CI flake risk)
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
…perseded kevent tests - RecycleBinDeleteWatchedFile now runs on Windows: its call moves out of the #ifndef _WIN32 block so the $Extend$Deleted$ path is exercised - InotifyWatchCount and the two leak assertions gate on __linux__ (macOS has no /proc; the count was always 0 and the assertion vacuous) - DisableAndEnable, Dispatch, ForceOneshot and StressTest drop with their main() calls: they belong to the superseded boykopovar#6510 feature, and StressTest asserts strict arrival order across 4 threads with 1-2 ms sleeps (CI flake risk)
… and follow Windows $Deleted paths Carries the additive pieces of boykopovar#6510 onto main after its feature was superseded by boykopovar#5847: the deleteEventFunc invocation when an EV_ONESHOT note retires in CollectTriggered, the Windows $Deleted path detection in FileEvent (IsDeleted transitions), the relaxed timer-modify and SetVnodeNotes guards, and the compatible kevent tests.
…perseded kevent tests - RecycleBinDeleteWatchedFile now runs on Windows: its call moves out of the #ifndef _WIN32 block so the $Extend$Deleted$ path is exercised - InotifyWatchCount and the two leak assertions gate on __linux__ (macOS has no /proc; the count was always 0 and the assertion vacuous) - DisableAndEnable, Dispatch, ForceOneshot and StressTest drop with their main() calls: they belong to the superseded boykopovar#6510 feature, and StressTest asserts strict arrival order across 4 threads with 1-2 ms sleeps (CI flake risk)
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)