feat(libkernel): add pipe write events and socket low watermarks to sceKernelAdd*Event #10645
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10645"
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 rocklouis055 on 2026-10-24T14:23:28Z.
What
Builds on #9099 (@aarushkha's regular-file events, merged). It extends
sceKernelAddReadEventandsceKernelAddWriteEventwith the two caseskeventalready handles and these still throw on:Write end of a pipe:
sceKernelAddWriteEventtakes it throughGuestSockets::PipeWriteState, withEV_EOFonce the read end closes andSCE_KERNEL_ERROR_EPIPEfor a new event added after that, asAddDescriptorKnoteinKqueue.cppdoes; adding an existing one again succeeds and replaces itsudata, askeventdoes. A read event on the write end and a write event on the read end still throw, as inkevent.Socket low watermark: a
sizeabove 1 on a stream socket becomes the event'slowWater, asNOTE_LOWATdoes inkevent(DescriptorLowWater); above 1 on a socket that is not a stream throws, as there. Adding the event again replaces the mark, asModifyKnotedoes, and a size aboveINT64_MAX, which askn_sdatawould be a mark below 1, throws asDescriptorLowWaterdoes. The size stays ignored on pipes, as inkevent, and a size above 1 on a regular file keeps #9099's throw.Datagram size on Windows:
GuestSockets::Readyreads a datagram socket'sdatafrom an overlappedMSG_PEEKreceive, cancelled without waiting if it would pend (itsOVERLAPPED, event and buffer stay in a never-freed pool until the kernel completes it), so it reports the next datagram's size as Linux and macOS do; Winsock'sFIONREADreports 1 for a zero-length datagram (traced by @ycbuzi).The debt entries for these calls are updated: the pipe entry now covers both ends, the socket entry states the low watermark (still above the 1000-character warning it already triggers on
main), and a new entry covers the Windows datagram size.#9823 also edits these lines, replacing
NotImplemented_nid_no_patchwiththrow; it does not add either case.Order with overlapping PRs
#12296 has merged. The remaining overlap is with @Felipebmaitan's #12682 → #12688 → #12700 stack: both sides add an
#includeat the same place inSocket/src/Udp.cpp, and nothing else conflicts or calls the other side's code (composed and run on Linux and Windows by @B-Howell). Proposed: this PR first, then that stack, keeping both includes; if its author prefers the reverse, this PR will declareDepends on: #12700and rebase. Asked here; not yet agreed.Tested
Linux x86-64 (Ubuntu 26.04, GCC 15), Release, on
bf70e27f7d(rebased onmainba8dcc6ae8).guest_socket_eventscovers: a pipe write event withEV_EOF,EPIPEfor a new event after the read end closed and a successful re-add with newudata; stream read marks of 6 andINT64_MAXthat time out at 3 bytes, a re-add fromINT64_MAXto 1 that fires withdata3 and from 1 to 6 that times out again; a write mark of 64; and a connected loopback datagram socket with an empty queue (times out), a zero-length datagram (data0), and a zero-length then a 3-byte datagram (data0, then 3), and a sender and a racing reader on that socket while the read event is polled (everydata0 or 3, then each late datagram read until the event times out).guest_socket_submitted_recordschecks the peek pool: a submitted record is not handed out again before completion and is reused after it, and a failed event creation is retried on the next acquire. It,guest_equeue_events,guest_kqueueandguest_udppass 20 times withctest --repeat until-fail:20. Reverting the re-add mark update, or returningEPIPEon every re-add, makesguest_socket_eventsabort. The WindowsUdp.cpppasses a syntax check with clang forx86_64-windows-gnu(no diagnostics in the new code), and @ycbuzi ran8e19a7affcon Windows (the four tests pass; with onlymain'sUdp.cppthe zero-length datagram check fails), and @B-Howell ranb1d851bf47on Windows 11 and WSL2 (the seven socket and event tests pass 3 of 3; withmain'sEqueue.cppandUdp.cpp,guest_socket_eventsaborts); @tkcm01 ranb1d851bf47on macOS (Apple M4, x86_64 under Rosetta 2):guest_socket_eventspasses 30/30 andguest_socket_submitted_records5/5, and with only this PR's testsguest_socket_eventsaborts on the missing low watermark. The pipe write-event cases are skipped there, since the pipe write state throws on macOS, as forkevent.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T14:31:53Z.
Review: APPROVED
Reviewed the exact head
e673953786a79b3252b673438e45956daad61253. The added pipe-write path matcheskeventhandling for writable readiness,EV_EOF, andEPIPEafter the read end closes; the low-watermark path uses the same stream-socket restriction and poll threshold asDescriptorLowWater. The added tests exercise both wrong pipe ends, closed-reader behavior, stream thresholds, and rejection on datagram sockets. The hosted conventions check passes, with the existing overlong debt-entry warning; the repository-local convention check reports the same warning and no errors. The PR correctly declares its dependency on #9099, which remains open. I did not independently run the product build.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T16:26:18Z.
Review: COMMENTED
Reviewed head
84da0e33070cmerged ontomain0119103fa9ed(clean merge), Linux x86-64 (WSL2 Ubuntu 24.04, GCC 13.3), Release.What I ran:
guest_socket_eventson the merge: passes, 20/20 with--repeat until-fail:20.guest_equeue_eventsandguest_kqueuepass too.Equeue.cppaborts withsceKernelAddWriteEvent: descriptor that is neither a socket nor a regular file not implemented; the54ffdb28c5assignment (watermark for every size) fails (hangs to the 20 s ctest timeout); an uncheckedstatic_cast<std::int64_t>(size)aborts. So the new checks catch all three.Two things I think are worth fixing, one minor:
Re-adding a socket event keeps the old watermark.
AddDescriptorEventpasses the newlowWatertoKernelEqueuePrivate::AddEvent, but for an event that already exists that only updates deadline, interval and udata (Equeue.cpp:475-477). kevent goes throughModifyKnote, which replaceslowWater(Kqueue.cpp:415), matching the kevent debt entry ("a later change of the knote replaces it askqueue_registerreplaceskn_sdata"). Before this PR the mark was always 0 on this path, so this is new. Probe on the merge, stream socket with 3 bytes queued:sceKernelAddReadEvent(eq, reader, 6, …)thensceKernelAddReadEvent(eq, reader, 1, …): the wait times out (mark is still 6)data3 (mark is still 1)Updating
lowWaterfor an existing socket event (asModifyKnotedoes) fixes it, and an add-6-then-add-1 check would cover it.Sizes above
INT64_MAXare capped, where kevent throws.DescriptorLowWaterthrows on aNOTE_LOWATmark below 1 (Kqueue.cpp:167), and a size aboveINT64_MAXis exactly such a negative mark if it reacheskn_sdatathe way this PR models it. The kevent measurements entry also records the console firing at once for a mark of -1 on a drained stream socket. So under the PR's own modelsceKernelAddReadEvent(eq, s, SIZE_MAX, …)would fire at once on the console, while here it never fires short of EOF. Throwing for those sizes, as kevent does, fits the throw-on-unknown rule better than picking a behaviour. TheINT64_MAX + 1andSIZE_MAXchecks would then becomeRejects-style or go away.Minor: a write event re-added on a pipe after the read end closed returns
EPIPE(Equeue.cpp:836 runs before the existing-event lookup) and keeps the old udata. kevent checksEPIPEonly for a new knote (Kqueue.cpp:475 toAddDescriptorKnote), as FreeBSD 11.4 runspipe_kqfilteronly on attach. Example:sceKernelAddWriteEvent(eq, p[1], 1, a),close(p[0]),sceKernelAddWriteEvent(eq, p[1], 1, b)givesEPIPEhere and success throughkevent. (Read from the code, not run.)Not run: Windows, macOS.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:41:49Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The current implementation still needs a deterministic event test and an explicit integration order with the newer socket work. The latest macOS run of head
459808d639reportsguest_socket_eventsaborting in 5 of 6 runs at theETIMEDOUTcheck after the racing sender and reader join; the probe found a datagram still queued on the failing runs. This is a platform-specific test failure that needs to be resolved or isolated with a supported deterministic test before relying on the suite.The current heads also conflict when composed: #10645 with #12688 conflicts in
Udp.cppand the kernel debt file; #10645 with #12700 has the same conflicts. #12688/#12700 are part of the replacement transport/write stack, so the earlier #11872 order needs to be reconsidered against those current heads.What I ran
459808d639d933e070dd37115367317657461313against currentmain52c09d567d2fa453494dd720fcf53a98149468e4.git diff --check.git merge-tree --write-treepreviews for #10645 with #12688 and #12700.Results
Udp.cppanddocs/dev/debt/libkernel.mdUdp.cppanddocs/dev/debt/libkernel.mdguest_socket_eventsPlease stabilize the macOS event test and coordinate an order with the authors of the overlapping socket changes, then record the agreed dependencies and rerun focused event/datagram tests on the integrated head. I have no preferred order based on the current evidence and am not asking anyone to close or abandon work.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T11:07:08Z.
Review: COMMENTED
Re-checked — new head, no blocking findings
The new head changes only the final check after the racing threads join, and I found no blocking defect, but that check no longer fails when a datagram stays queued without an event, which was the symptom the earlier changes-requested review cited.
What I ran
Exact head
bf70e27f7db6fe20e56d788ee44c0de1c9266ed9, previously reviewed head459808d639d933e070dd37115367317657461313, currentmaine67cc818696fd6e6c58ac80adc6550c54aed68e8(merge preview clean, no declared dependencies). Environment: Debian 12, Python 3.11.2, git 2.39.5. No build, no compiler, no CTest.The precheck's ABI and test-quality helpers could not find their scripts in its isolated head tree, so I ran both helpers by hand as listed. The changed-line comparison was run on the PR's own patches at both heads.
Results
git diff --check(precheck)main(precheck)core/libs/tests/GuestSocketEvents.cpp. The product files (Equeue.cpp,Udp.cpp,SubmittedRecords.hpp, libkernelCMakeLists.txt) have identical changed lines at both heads.pr_abi_audit.py(by hand)pr_test_quality.py(by hand)possible-unregistered-cpp-test. Both files are registered incore/libs/prx/libkernel/CMakeLists.txtthrough${LIBS_INCLUDE_DIR}/tests/...paths, so these are false positives.Unedited command output
Findings
Blocking: None.
Non-blocking:
recvwith flag0x80meaning "empty", so an emptiness check can use the same convention. Suggested addition after line 365:Sources
recvloop at the new headNot verified
bf70e27f7db6fe20e56d788ee44c0de1c9266ed9that the description requests is still needed; this review cannot provide it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T16:22:28Z.
Review: DISMISSED
Re-checked — new head, changes requested
The new head adds the missing final queue-empty assertion, but the required merge order with three open overlapping PRs is still explicitly unagreed.
What I ran
Reviewed head
b1d851bf4752c6cb42f4aba29bc4004fbd666ba1, based one6f57307fa7f47165d7fc1bee945abdb2f6816e7; the live preview onto currentmainf2d874c1fdccf781c0fa5d86619bb5dd8894b958is clean. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. No compiler or build was run.Results
${LIBS_INCLUDE_DIR}paths.main.Selected raw check output
Negative control
Findings
Blocking
Udp.cppseam with #10645 and says the second PR must rebase. The repository requires overlapping authors to agree on order and declare it withDepends on. Please coordinate the order with the affected authors and update the PR order/dependency declaration to reflect that agreement.Non-blocking
Sources
Not verified
No local build, CTest, macOS rerun, or console behavior was verified. The negative control is author-reported only.
To get this to a good state
Please reach and record an order agreement with the overlapping PR authors, then update the relevant
Depends ondeclarations. I will rerun the same no-build checks on the new head.