fix(libkernel): bound equeue pending events #7509

Merged
Pouare514 merged 2 commits from upstream-pr/7509 into main 2026-11-02 07:56:08 +00:00
Pouare514 commented 2026-10-18 10:15:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-18T10:15:31Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4908239220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7509). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-18T10:15:31Z. --- ### 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - Depends on: none - Fixes: none - Unblocks: none - GPUs tested: n/a - AI-assisted: yes
akkadbakkad89 commented 2026-10-18 11:28:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T11:28:15Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249369598 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7509#issuecomment-6249369598). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-18T11:28:15Z. --- 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 commented 2026-10-18 12:06:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:06:14Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249711390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7509#issuecomment-6249711390). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T12:06:14Z. --- 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 commented 2026-10-18 12:20:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:20:14Z.


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

  • With Equeue.cpp reverted to main, guest_equeue_events aborts on both platforms; with the PR it passes.
  • The socket/equeue set passes (Linux 26/26, Windows 38/38 serial).
  • It merges cleanly with #7492 (NotifyAll in the same functions), and the combined build passes guest_equeue_events and guest_kqueue 5/5.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249840817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7509#issuecomment-6249840817). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-18T12:20:14Z. --- Confirmed on Ubuntu 24.04 (GCC 13.3) as well as Windows, with this PR merged onto `main` `9f25d0bf5`. - With `Equeue.cpp` reverted to `main`, `guest_equeue_events` aborts on both platforms; with the PR it passes. - The socket/equeue set passes (Linux 26/26, Windows 38/38 serial). - It merges cleanly with #7492 (`NotifyAll` in the same functions), and the combined build passes `guest_equeue_events` and `guest_kqueue` 5/5. AI-assisted: yes (Claude Code); results above were run on this machine.
screamm commented 2026-10-18 13:53:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-18T13:53:26Z.


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 #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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250728190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7509#issuecomment-6250728190). Originally posted by [screamm](https://github.com/screamm) on 2026-10-18T13:53:26Z. --- 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 #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).
blawesom commented 2026-10-18 16:27:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T16:27:24Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252283808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7509#issuecomment-6252283808). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-18T16:27:24Z. --- **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`.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7509
No description provided.