fix(libkernel): move every knote kevent reports behind the waiting ones #9780
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9780"
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 Retr0G28 on 2026-10-22T14:43:48Z.
What
keventcould keep returning the same knote and never reach the ones after it whenneventswas smaller than the number of ready knotes. In FreeBSD 11.4,kqueue_scan(sys/kern/kern_event.c) puts a reported knote withoutEV_CLEARorEV_DISPATCHback at the tail of the queue. It takes anEV_CLEARorEV_DISPATCHknote off the queue, andknote_enqueue(fromknoteor fromkqueue_registeronEV_ENABLE) puts it back at the tail when it fires again. AnEV_ONESHOTknote is dropped.CollectOncePerWait, the collection loop behindkevent, moved a reported knote to the tail only if it was still triggered after its reset. A levelEVFILT_READorEVFILT_WRITEknote on a socket or pipe clearstriggereduntil the next poll, and anEV_CLEARorEV_DISPATCHknote clears it until it fires again. These knotes kept their registration position, so withneventssmaller than the number of ready knotes, the first of them was reported on every call. Now every reported knote that is not deleted moves behind the knotes that were not reported, as inkqueue_scan. A knote is still reported at most once per call, andEV_ONESHOTknotes are still deleted.There is no gap sentence about this order in
docs/dev/debt/libkernel.md. The kqueue entry already says that a reported level event moves behind the other events, and that is now true for socket and pipe knotes too.#9127 is the companion change for
sceKernelWaitEqueue(CollectTriggered). The two PRs are independent and merge without conflicts (git merge-treeof both branches is clean).Test changes:
guest_kqueue(ReportedKnotesMoveToTail): levelEVFILT_READknotes on two pipes and a socketpair, all readable, are reported one perkevent(nevents = 1)call, each in turn, over two rounds. TwoEV_CLEARuser knotes: after the first one is reported and triggered again, the second one comes first. TwoEV_DISPATCHuser knotes: after the first one is reported and then enabled and triggered in one change, the second one comes first.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, rebased onmain11f976b27c.guest_kqueuewith the new test fails (exit 0xc0000409 from the failedRequire). With temporary logging, each of the three cases fails onmain: the level knotes return the first pipe on every call (expected 4, 6, 8; got 4, 4, 4), theEV_CLEARcase returns 11 where 12 is expected, and theEV_DISPATCHcase returns 21 where 22 is expected. With this PR it passes.guest_kqueue,guest_equeue_events,guest_socket_events,guest_poll,guest_selectandguest_select_wait: 6 of 6 pass when run serially. After the rebase onto11f976b27c,guest_kqueuepasses again.python tools/check_conventions.py --base origin/mainreports no errors.3383d303a7(CachyOS, kernel 7.3.0-4, GCC 16.2.1, Release), alone and merged intomaine2b9700a98.guest_kqueuepasses 3 of 3 on both trees, including the Linux-onlyEdgeTriggered*andSocketWriteLowWaterWhileFillingcases, andguest_equeue_eventspasses 3 of 3. With only this PR'sEqueue.cppchange reverted,guest_kqueueaborts inReportedKnotesMoveToTail. The full suite on the merge has 3 failures, theagc_driver_sample_order*tests on an RTX 3080 Ti, and they fail on plainmaintoo.Overlap:
tools/pr_overlap.pycould not compare #6044, #7088, #7509 and #7653, which conflict withmain. I checked their diffs. #6044 reorganizes the test tree, #7088 adds kevent events on regular files, #7509 bounds pending equeue events inAddEventandTriggerEvent, and #7653 changes kevent timer re-adds and adds filters. None of them changesCollectOncePerWaitor the order in which knotes are reported. #9127 changesCollectTriggeredand thesceKernelWaitEqueuedebt entry, andgit merge-treewith this branch is clean. #9823 changessceKernelDeleteAmprSystemEventinEqueue.cpp, not the kqueue collection loop.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 MarcZX10 on 2026-10-22T16:34:03Z.
Review: DISMISSED
The collection-loop change moves each returned, non-deleted knote behind events that were not returned, matching the queue-order behavior described for FreeBSD
kqueue_scan. The new tests cover level-triggered pipe/socket reads over multiplenevents=1calls, plus retriggeredEV_CLEARand reenabledEV_DISPATCHuser events. Current-main conventions andgit diff --checkpass. I did not rerunguest_kqueuelocally. The PR reports the before/after failures and Windows test suite; upstream product jobs are skipped, and Linux is not reported as tested.This branch is 13 commits behind live
main(499b1cf9fc44da935fe6d63813675ad5810e8402). CONTRIBUTING.md requires branches to be based on and kept up to date withmain. Please sync it, then rerunguest_kqueueon Linux as well as Windows on the final head; the changed event-collection loop is shared across platforms.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:57:37Z.
Review: COMMENTED
The exact head
c3e795b7daf659335617ada2c0ea4870aafbc5d3has a clean merge tree with currentmain(11f976b27c16ed91633f00039dba5dfd97dd7cc1); conventions and diff-check pass. The queue-order change is covered by level-triggered pipe/socket and retriggered EV_CLEAR/EV_DISPATCH cases. The PR reports Windows tests but no Linux run; hosted product builds are skipped. The branch is 21 commits behind current main, so please rebase and rerunguest_kqueueon a supported host before merge. I did not rerun libkernel tests locally because this VM’s CPU lacks the repository-required feature set.