fix(libkernel): move events reported by sceKernelWaitEqueue behind the waiting ones #9127
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9127"
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-21T12:42:30Z.
What
sceKernelWaitEqueuescanned the event list in place, so whennumwas smaller than the number of ready events, the first ones in the list were reported on every call and the later ones were never reported. In FreeBSD 11kqueue_scan(sys/kern/kern_event.c), a reported knote withoutEV_CLEARorEV_DISPATCHgoes back in at the tail ofkq_head. A knote withEV_CLEARorEV_DISPATCHleaves the queue, and when it fires againknote_enqueueputs it at the tail. Either way, the next scan starts with the knotes that were waiting and not yet reported.KernelEqueuePrivate::CollectTriggerednow moves each event it reports to a separate list and appends that list to the end of the event list after the scan, the same wayCollectOncePerWaitdoes for kqueues. Events that were not reported keep their order. AnEV_ONESHOTevent is still removed. Edge events (EV_CLEAR) are moved too: this list keeps every registered event, so the tail is where FreeBSD would put the event when it fires again. Without the move, an edge event that fires before every call is reported each time and the others starve. Each event is visited at most once per call, so none is reported twice by mistake. Several pending AMPR or VideoOut completions are still returned in one call, as before.The sentence about the missing rotation is cut from the
sceKernelWaitEqueueentry indocs/dev/debt/libkernel.md. It is replaced by the gap that remains: events that fire between two calls are reported in registration order, not in the order they fired.Test change:
guest_equeue_eventsgetsVerifyReportedEventsMoveBehindWaitingOnes:num1 give ids 1, 2, then 1;num2 give {1, 2}, {3, 1}, then {2, 3};Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, onmain2f161d4f33(rebased on7280a17ec0afterwards; the two new commits do not touch these files).guest_equeue_eventswith the new test fails (exit 0xc0000409 from the failedRequire). Every section fails: the level pair gives 1, 1, 1; the three events give {1, 2} three times; the edge pair gives 7, 7, 8. With this PR it passes.guest_equeue_events,guest_kqueue,guest_socket_events,guest_kernel_errors,np_uds_events,guest_ampr_markers,guest_ampr_threads,guest_http2andguest_video_out_hdr: 9 of 9 pass when run serially.video_out_flip_*:video_out_flip_decodepasses; the other 13 skip on this machine (exit code 77). The AGC driver tests, which also wait on equeues, were not run.python tools/check_conventions.py --base origin/mainreports no errors.guest_equeue_eventspasses, and fails withmain'sEqueue.cpp(comment below). Not run on bare-metal Linux.Overlap:
tools/pr_overlap.pycould not compare some open PRs, so I checked the ones that touch the same code files. #7049 adds a delete callback inside theEV_ONESHOTbranch ofCollectTriggered. #7509 caps the pending events of one entry and adds a test. #7492 changesNotifyOnetoNotifyAlland adds a test afterVerifyEdgeUserEventReportedOnce; the new test here goes afterVerifyRepeatedAmprCompletionsAreNotLost, away from that insertion. #6044 moves the test file. None of them changes the order in which events are reported. The rest touch only other lines ofdocs/dev/debt/libkernel.md.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 xXPBSXx on 2026-10-21T16:44:31Z.
Linux data point for
41709ae50e: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain; its merge-base is7280a17ec).ctest -R '^guest_equeue_events$'passes 3 of 3.libkernel/Equeue/Equeue.cpprestored to the merge-base (the PR's tests kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:56:21Z.
Review: COMMENTED
Checked against main
99feaf0eb8and FreeBSD 11.4 sys/kern/kern_event.c (8c639945):CollectTriggered(Equeue.cpp:185-227) is unchanged from your base, so the rotation isn't on main yet; onlyCollectOncePerWaithas it.EV_CLEAR/EV_DISPATCHknotes are reinserted at the tail (L1815), clear/dispatch ones are dequeued (L1801-1812), andknote_enqueueappends at the tail (L2542). Tracingkqueue_scangives the same {1,2},{3,1},{2,3} and 7, 8, 7 sequences your test expects.knote_enqueuequeues them in the order they fire".Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:16:26Z.
Review: APPROVED
Re-checked head
f389bcce9cagainst main6cd36e6517:knote_enqueuefiring order is stated correctly.docs/dev/debt/libkernel.md; the code and tests are unchanged from the version I traced before.Equeue.cppor the tests since, and it still merges cleanly. Thanks, LGTM.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.