feat(libkernel): wait for the low water mark in the kqueue descriptor events #4908
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4908"
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 VitzS7 on 2026-10-13T03:28:12Z.
What
kevent'sNOTE_LOWATand thesizeargument ofsceKernelAddReadEventandsceKernelAddWriteEventare the same thing: a low water mark that holds the event until the socket has that many bytes, or that much free space. Both threw, so a title that waits for a number of bytes could not register the event at all.A mark is now kept per knote (
KernelEqueueEvent::lowat) and the descriptor filter compares the count it polls against it:keventwithEV_ADDandNOTE_LOWATregisters the mark, whose value iskn_sdata;NOTE_LOWATclears it, askqueue_registercopies the whole kevent over the knote it re-adds;filt_soreadandfilt_sowritereturn before they comparekn_dataagainstkn_sdata;sceKernelAddReadEventandsceKernelAddWriteEventtakesizeas that mark, where 0 and 1 are the readiness the default knote reports.A mark is not something poll readiness can express: a socket below it is already readable, so a wait that has one returns to its caller every millisecond instead of spinning on the readable socket, the slice
GuestSockets::WaitAnyalready uses for pipes.Tested
Linux (Fedora 44, GCC 16.2.1, release with
BUILD_TESTING), full build,ctest --test-dir build -E "agc_|video_out|lds_|msaa"534/534,python3 tools/check_conventions.py --base origin/mainclean.New cases in
GuestKqueue.cpp: a registered mark reports only at the fourth byte, a re-add withoutNOTE_LOWATclears it, raising it above what the socket holds holds the knote again, and the write filter of the other end keeps its own mark (a mark above the send buffer size it reports never triggers).GuestSocketEvents.cppdoes the same through thesizeofsceKernelAddReadEventand the same write case; that file used to assert the old throw there.Not tested on the console, and not reached at run time yet: PS5MC (PPSA99420) and XPSemu (PPSA97358) both import
kevent(NIDRW-GEfpnsqg) and both calls, andtools/import_audit.pyon their relinked registries reports them as stubs, but each stops earlier on an absent import (ixrw0h2tWuI,chflags, andx7g7Ebeo8-U,mlockall) that this PR does not touch. The semantics follow the FreeBSD 11 sources the existing filter was written from (kern_event.c, andfilt_soread/filt_sowrite).EV_CLEARon a socket still throws, deliberately: reporting once is easy, but re-arming needs a sign that the socket's state changed, and a write event reports the constantSO_SNDBUFas its data, so a title that writes and waits again underEV_CLEARwould never be woken.EVFILT_READon a kqueue,EVFILT_READ/EVFILT_WRITEon a non-socket descriptor and the timer changes also still throw; those are separate paths.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)keventand these calls; neither reaches them yetImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:30:04Z.
Coordination note with open #4391: that PR moves guest sockets to low ordinary descriptors and changes kqueue socket detection from
FirstDescriptorrange checks toGuestSockets::IsOpen. This PR currently keeps range checks inKqueue.cpp(includingAddDescriptorKnote), so after #4391 merges the low-watermark path would treat valid socket descriptors as non-sockets. Could you carry the membership check when rebasing/merging, or coordinate the merge order with #4391? The watermark changes themselves are separate.Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-13T03:42:22Z.
Thanks, yes — I'll carry it.
To be precise about what is at risk here: the watermark code itself classifies nothing.
EqueueDescriptorEventand the mark compare the count the filter polls, and the range check the note points at is the pre-existing one that #4391 already rewrites (the bot's line range,Equeue.cppL599-602, is that same check). Nothing in this PR introduces a new descriptor-number test, so whichever of the two lands first, the rebase is the membership check as you wrote it.The follow-up I'm preparing touches those same lines and takes the membership check with it:
keventread and write events on pipes (FreeBSD'sfilt_pipereadandfilt_pipewrite),EINVALfor a file and a directory (filt_fileattachattaches the vnode filter only) and a throw for a descriptor whose filters are not modelled, all classified by socket-table membership first and then by the host descriptor type rather than by a number range. I'll list this PR under its Depends on, so the merge order stays visible.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T06:15:51Z.
Windows test: head
79648ee85merged onto currentmainea2bbefb2(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_kqueue|guest_socket_event: guest_kqueue passed, guest_socket_events passed (2 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-13T06:28:57Z.
Thanks for the Windows run — that is the one platform I cannot check here, so it closes half of the checklist.
The other half, which your note says you did not run: the cases this PR adds or rewrites do fail on
mainwithout it, so they are not passing on their own.GuestKqueue.cppasserted a throw for a read or write event on a pipe and now asserts the filter instead, andGuestSocketEvents.cppreplaced its expected rejection of a non-socket descriptor with thesizethe calls take. Onmainthe low water mark and the non-socket descriptor both throw, so the first of those cases aborts rather than passing silently — the same shape your merge would have shown had it been run againstmainalone.Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-13T19:49:16Z.
Rebased on current
main(dacd78525), which now carries #4391.The conflict was in
Equeue.cpp(AddDescriptorEvent) andKqueue.cpp. The resolution keeps your socket-table membership checks —isSocketwhere the call already computes it,GuestSockets::IsOpeninDescriptorFilterError— and puts this PR's low water mark on top, so nothing here decides what a descriptor is from its number. Nothing else in the PR changed.Local verification on
dacd78525+ this branch (cmake→python3 tools/check_test_registration.py build→cmake --build build→cmake --build build --target libs):ctest --test-dir build -E "agc_|video_out|lds_|msaa"570/570, andtools/check_conventions.py --base origin/mainclean.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:50:57Z.
Thanks for rebasing on
dacd78525and carrying theGuestSockets::IsOpenchecks through the conflict. That resolves the interaction I flagged with #4391, and your 570/570 local CTest result plus clean conventions check is useful evidence. I have no further request on the overlap; I will keep #4391/#4908 dependency and merge-order notes aligned.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T04:41:37Z.
Closing: no title is known to reach this. With the queue at 480+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed