Skip to content

fix(libkernel): bound equeue pending events - #7509

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Pouare514:fix/equeue-bound-pending-events
Nov 2, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Pouare514:fix/equeue-bound-pending-events

Conversation

@Pouare514

Copy link
Copy Markdown
Contributor

What

Bound pendingEvents per equeue registration to the armed event plus at most 64 queued events. A trigger past the cap drops the oldest queued event and keeps the latest payload; an AddEvent carrying more than 64 keeps the latest 64. Drained bursts report exactly as before. The cap lives in KernelEqueuePrivate::kMaxPendingEvents and is enforced centrally in TriggerEvent/AddEvent, so it covers every producer with the queue-behind pattern (VideoOut flip/vblank, AMPR completions) instead of patching one filter. AddEvent builds the stored event field-by-field and copies at most 64 queued entries, so it never copies an unbounded host queue.

Tested

Release Ninja BUILD_TESTING=ON (MinGW GCC 15.2) on Windows.

  • ctest -R "guest_equeue_events|guest_kqueue|guest_socket_events": 3/3 pass (equeue 0.48s, kqueue 3.06s, socket_events 0.21s).
  • New guest_equeue_events cases: 100k undrained AMPR triggers stay bounded (deliver exactly 65 = 1 + 64, last payload is the latest) and an AddEvent seeded with 20k queued events is truncated to 65 with the latest preserved; small bursts (existing 2- and 3-completion AMPR tests) still deliver every event.
  • Fail-without: with only Equeue.cpp reverted (new tests kept), guest_equeue_event_tests aborts on Require(total <= kBound) after the flood (unbounded 100k deliveries). Pass-with: same binary passes after restoring the fix (exit 0).
  • git diff --check clean; python3 tools/check_conventions.py --base origin/main passes; no // in added C++ lines.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Undrained triggers queued without limit and AddEvent copied the whole queue, so a flip/vblank flood could exhaust the host heap while guest memory stayed free. Keep the armed event plus at most 64 queued events per registration, dropping the oldest queued event past the cap and keeping the latest payload; an AddEvent carrying more keeps the latest 64. Drained bursts report as before.
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 11215 docs/dev/debt/libkernel.md L365
PR 12970 docs/dev/debt/libkernel.md L365
PR 13582 docs/dev/debt/libkernel.md L365
PR 13587 docs/dev/debt/libkernel.md L365
PR 14128 docs/dev/debt/libkernel.md L365
PR 14264 docs/dev/debt/libkernel.md L365
PR 14497 docs/dev/debt/libkernel.md L365

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.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 core/libs/prx/libkernel/Equeue/Equeue.hpp
docs/dev/debt/libkernel.md
PR 7121 core/libs/prx/libkernel/Equeue/Equeue.hpp
docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7804 docs/dev/debt/libkernel.md
PR 9156 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9293 core/libs/prx/libkernel/Equeue/Equeue.cpp
docs/dev/debt/libkernel.md
PR 9297 core/libs/prx/libkernel/Equeue/Equeue.cpp
docs/dev/debt/libkernel.md
PR 9302 core/libs/prx/libkernel/Equeue/Equeue.cpp
docs/dev/debt/libkernel.md
PR 9389 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9843 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 9947 docs/dev/debt/libkernel.md
PR 10025 docs/dev/debt/libkernel.md
PR 10319 docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 11625 docs/dev/debt/libkernel.md
PR 11896 docs/dev/debt/libkernel.md
PR 11939 docs/dev/debt/libkernel.md
PR 12104 docs/dev/debt/libkernel.md
PR 12560 docs/dev/debt/libkernel.md
PR 14212 docs/dev/debt/libkernel.md

@akkadbakkad89

akkadbakkad89 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Linux datapoint at head c170bba422 (author ran Windows): guest_equeue_events, guest_kqueue, guest_socket_events - 3/3 pass on Ubuntu 24.04 (WSL2), GCC, Release. The bounded-AMPR cases build and run clean here.

@MarcZX10

Copy link
Copy Markdown
Contributor

Thanks for the Linux run. That independently confirms the bounded AMPR flood and the seeded AddEvent queue pass on the current head, complementing the Windows focused run in the description.

@wachi35676

Copy link
Copy Markdown
Contributor

Confirmed on Ubuntu 24.04 (GCC 13.3) as well as Windows, with this PR merged onto main 9f25d0bf5.

AI-assisted: yes (Claude Code); results above were run on this machine.

@screamm

screamm commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Windows run of head c170bba42, merged onto main 0d078f75d together with #7492 (fd2eb3521) and #7090 (17d9e0a51); the merges are clean, so this is the stack.

  • Host: Windows 11 Pro 26220, Ryzen 7 5700X, RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON.
  • Build: the full build and libs pass, no warning in Equeue.cpp or GuestEqueueEvents.cpp.
  • guest_equeue_events (with the 100k-trigger flood and the 20k-seed AddEvent cases) passes 3/3 on a quiet host (0.70-0.89 s) and 15/15 with --repeat until-fail:15 under load from other builds (0.77-2.27 s, mean 1.30 s). The other 34 equeue/kqueue/socket/poll/select/rudp tests pass 3x, 105/105 in total.
  • Negative control: with Equeue.cpp taken from fix(libkernel): wake every thread waiting on an equeue or kqueue when an event fires #7492's head (your three cap hunks removed, header and tests kept) guest_equeue_events aborts after 1.27 s at the bound check, while guest_kqueue still passes. With the stack restored it passes.
  • Non-GPU suite (ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): 936 tests, 929 pass, 2 skipped, 5 load timeouts (conventions_function_bodies, configure_seed, hardware_oracle_compare, guest_none_relocations, tls_function_coverage_register_address_loads) that pass serially.
  • tools/check_conventions.py --base origin/main and git diff origin/main --check pass; no env var added.

Titles: VideoOut is the only producer that queues behind an armed event. PPSA99169 (RetroArch), PPSA01153 (OliSe Player) and PPSA74126 (Stremio Plus), 60 s each against the same build with Equeue.cpp, Equeue.hpp and Udp.cpp from main: no stop line, frames 5494 / 3457 / 3387 before and 5914 / 3486 / 3487 after. A local diagnostic print (reverted) in TriggerEvent for a cap drop did not fire in 45 s on PPSA74126, PPSA99082 or PPSA99169 (app.exe only), so none of these titles reaches the 64 limit; I did not log the AddEvent truncation.

On the limit itself: FreeBSD 11.4 has no per-knote queue (repeated activations of an EV_CLEAR knote accumulate in kn_data and are reported once), so 1 + 64 is this project's own bound. The debt entry says the console's depth is unknown, which is accurate; I have nothing that measures it.

Not checked: Linux, macOS, a console, the AddEvent truncation in a title, #6510 and #7129 merged with this.

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 18, 2026
@blawesom

Copy link
Copy Markdown
Contributor

Rebase handoff — rebased onto current main (authorship unchanged). One docs-debt conflict, unioned.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the two known main regressions (agc_driver_tessellation — Mesa, #5444; agc_driver_bda_device — #7584), neither from this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7509
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 6dd4d5d5c.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@blawesom

Copy link
Copy Markdown
Contributor

Rebase handoff — rebased onto current main (f075f91737, authorship unchanged). Two conflicts, both add/add:

  • GuestEqueueEvents.cpp: main added a local SCE_KERNEL_ERROR_*/EVFILT_*/EV_* constant block after SCE_OK; your version takes them from Equeue.hpp (now via KernelErrors.hpp), so the merged file keeps your include and drops main's block — otherwise both define them and the test does not compile.
  • docs/dev/debt/libkernel.md: main added five new entries at the spot yours lands; both kept, your equeue pending-event bound entry after them.

Verified on Linux (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, Ryzen 7 9800X3D) — the host your Tested section leaves open:

  • Builds; conventions pass.
  • Your tested set: guest_equeue_events (0.4 s), guest_kqueue (3.8 s), guest_socket_events — 3/3 pass, including the new flood cases (the 100k-trigger AMPR burst and the 20k-seeded AddEvent truncation).
  • Fail-without, your methodology: with only Equeue.cpp from main (your tests and Equeue.hpp kept), guest_equeue_events aborts on the unbounded flood; restoring the fix passes.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7509
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 15db90adfe.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@Pouare514 thanks for this. Main still has an unbounded pending-event queue, so this is still wanted. It needs a rebase: the library change applies cleanly, and the only conflicts are add/add in core/libs/tests/GuestEqueueEvents.cpp and docs/dev/debt/libkernel.md. One question while you're there: where do 64 and drop-oldest come from? A dropped completion is a silent loss for a guest that drains later expecting every event. If it's a chosen bound rather than a console measurement, please say so in the debt entry, and say how many in-flight completions you've seen titles actually queue.

# Conflicts:
#	core/libs/prx/libkernel/Equeue/Equeue.cpp
#	core/libs/tests/GuestEqueueEvents.cpp
#	docs/dev/debt/libkernel.md
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 1, 2026
@oneandonlydean oneandonlydean self-assigned this Nov 1, 2026
@oneandonlydean
oneandonlydean merged commit 83e1447 into boykopovar:main Nov 2, 2026
10 of 11 checks passed
oneandonlydean pushed a commit that referenced this pull request Nov 14, 2026
…dropping them silently

Triggers and AddEvent past the 64-event pending cap dropped the oldest queued
events with no record. Each dropped-oldest batch is now counted per queue
(DroppedPendingEvents()) and logged, gated on APS5_TRACE_EQUEUE and
rate-limited to the first drop and each power-of-two of the cumulative total,
so a long burst reports in log2 lines rather than one per drop. The cap value
and the drop-oldest (keep-newest) semantics are unchanged, pending the console
queue-depth / keep-newest-vs-oldest question on #7509.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants