feat(libkernel): support kevent timer reconfiguration #5361

Closed
AaravMehta-07 wants to merge 1 commit from upstream-pr/5361 into main
AaravMehta-07 commented 2026-10-13 17:58:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-13T17:58:06Z.


What

Implement reconfiguration of an existing EVFILT_TIMER through kevent. Main currently throws kevent: changing an existing EVFILT_TIMER not implemented, including an EV_ADD that changes an existing timer's period.

This uses FreeBSD 11.4's filt_timertouch and kqueue_register behavior as the reference. An EV_ADD discards old undelivered expiry state and restarts with the new period/precision; changes without EV_ADD update only udata. Existing persistent flags are retained. Invalid replacement parameters disarm the timer and produce an EV_ERROR/EINVAL event rather than a registration error.

Lookup, insert, update and delete selection are one queue-mutex transaction. This matters when a concurrent wait consumes a one-shot registration: separating HasEvent from EditEvent can otherwise return ENOENT for a valid re-add. The inline template avoids adding an out-of-line helper to the library's auto-exported symbols.

The reference choice is explicit: FreeBSD 11.0 retained the old armed expiry, whereas 11.4 restarts it. This is a public-source contract implementation, not console-measured PS5 behavior. The debt entry records that distinction and retains the other unsupported cases. No ABI signature, export name or NID was changed, and no proprietary firmware was used. No title was tested or claimed unblocked.

The unchanged progress scanner reports 3214/3646 (88.15%) before and after: kevent remains partial because other cases still throw. No coverage-counter claim is made.

Tested

Windows, supported WinLibs MinGW-w64 GCC 15.2.0 r7, Release with BUILD_TESTING=ON and recursively initialized submodules:

cmake --build <full-build> --parallel 6
cmake --build <full-build> --target libs --parallel 6
ctest --test-dir <full-build> --output-on-failure --parallel 4
  1097 registered: 1089 passed, 8 skipped, 0 failed (206.54 s)
ctest --test-dir <full-build> -R ^guest_kqueue$ --repeat until-fail:5 --output-on-failure
  5/5 passed, about 2.05 s each
python tools/check_conventions.py --base upstream/main
  Passed
python tools/check_test_registration.py <full-build>
  785 executables, 0 built but unregistered
git diff upstream/main --check
  Passed
python tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch codex/kevent-timer-reconfiguration
  No overlap with open pull requests

The eight Windows skips were agc_driver_stencil_ref_export, the five video_out_flip_{lifetime,reopen,controls,overlay,unopened} tests, guest_video_out_wqhd_detection_no_vulkan, and long_paths. They are not counted as passes. Wider GPU tests ran with ANYPS5_GPU=4060 on NVIDIA RTX 4060 Laptop, driver 610.88. No test timeout was increased.

Linux/WSL Ubuntu, GCC 15.2.0: the bundled-dependency full configuration succeeded; built the affected guest_kqueue_tests target and kernel/libc dependencies. Focused guest_kqueue passed 3/3 (2.28-2.29 s each). The full Linux build and full Linux suite were not run.

The guest-export regression covers discarded materialized expiry/count state, changed deadline/precision and udata, preserved periodic/one-shot flags, no-EV_ADD touches, a waiting thread, invalid-update error delivery and recovery, fresh registration after one-shot deletion, and 2000 concurrent re-add/delivery iterations. Compile-time checks pin the existing x64 event/timespec layouts.

The updated regression was compiled against the saved original unpatched runtime from 0214069 and failed with the original timer-change exception (exit -1073740791). Kqueue.cpp is unchanged between that upstream revision and the PR base. Five isolated Linux mutants compiled and failed the regression: stale trigger, stale count, replacement flags, missing waiter notification, and non-atomic lookup/update. Mutation copies and logs were kept outside the repository. This is not a sanitizer run; waiter scheduling is exercised with a start flag/delay, not a formal blocked-state proof.

All PE export names, including 620 guest-style names, matched the original runtime. No new timer helper was exported. Research, implementation, tests and critical review were AI-assisted; the independent reviewer was an AI agent, not a human reviewer.

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); remaining gaps are recorded in library technical debt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a (libkernel timer change)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4847328519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5361). Originally posted by [AaravMehta-07](https://github.com/AaravMehta-07) on 2026-10-13T17:58:06Z. --- ### What Implement reconfiguration of an existing `EVFILT_TIMER` through `kevent`. Main currently throws `kevent: changing an existing EVFILT_TIMER not implemented`, including an `EV_ADD` that changes an existing timer's period. This uses FreeBSD 11.4's [`filt_timertouch`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/kern_event.c#L744-L810) and `kqueue_register` behavior as the reference. An `EV_ADD` discards old undelivered expiry state and restarts with the new period/precision; changes without `EV_ADD` update only `udata`. Existing persistent flags are retained. Invalid replacement parameters disarm the timer and produce an `EV_ERROR`/`EINVAL` event rather than a registration error. Lookup, insert, update and delete selection are one queue-mutex transaction. This matters when a concurrent wait consumes a one-shot registration: separating `HasEvent` from `EditEvent` can otherwise return `ENOENT` for a valid re-add. The inline template avoids adding an out-of-line helper to the library's auto-exported symbols. The reference choice is explicit: FreeBSD 11.0 retained the old armed expiry, whereas 11.4 restarts it. This is a public-source contract implementation, **not console-measured PS5 behavior**. The debt entry records that distinction and retains the other unsupported cases. No ABI signature, export name or NID was changed, and no proprietary firmware was used. No title was tested or claimed unblocked. The unchanged progress scanner reports 3214/3646 (88.15%) before and after: `kevent` remains partial because other cases still throw. No coverage-counter claim is made. ### Tested Windows, supported WinLibs MinGW-w64 GCC 15.2.0 r7, Release with `BUILD_TESTING=ON` and recursively initialized submodules: ```text cmake --build <full-build> --parallel 6 cmake --build <full-build> --target libs --parallel 6 ctest --test-dir <full-build> --output-on-failure --parallel 4 1097 registered: 1089 passed, 8 skipped, 0 failed (206.54 s) ctest --test-dir <full-build> -R ^guest_kqueue$ --repeat until-fail:5 --output-on-failure 5/5 passed, about 2.05 s each python tools/check_conventions.py --base upstream/main Passed python tools/check_test_registration.py <full-build> 785 executables, 0 built but unregistered git diff upstream/main --check Passed python tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch codex/kevent-timer-reconfiguration No overlap with open pull requests ``` The eight Windows skips were `agc_driver_stencil_ref_export`, the five `video_out_flip_{lifetime,reopen,controls,overlay,unopened}` tests, `guest_video_out_wqhd_detection_no_vulkan`, and `long_paths`. They are not counted as passes. Wider GPU tests ran with `ANYPS5_GPU=4060` on NVIDIA RTX 4060 Laptop, driver 610.88. No test timeout was increased. Linux/WSL Ubuntu, GCC 15.2.0: the bundled-dependency full configuration succeeded; built the affected `guest_kqueue_tests` target and kernel/libc dependencies. Focused `guest_kqueue` passed 3/3 (2.28-2.29 s each). **The full Linux build and full Linux suite were not run.** The guest-export regression covers discarded materialized expiry/count state, changed deadline/precision and `udata`, preserved periodic/one-shot flags, no-`EV_ADD` touches, a waiting thread, invalid-update error delivery and recovery, fresh registration after one-shot deletion, and 2000 concurrent re-add/delivery iterations. Compile-time checks pin the existing x64 event/timespec layouts. The updated regression was compiled against the saved original unpatched runtime from `0214069` and failed with the original timer-change exception (exit `-1073740791`). `Kqueue.cpp` is unchanged between that upstream revision and the PR base. Five isolated Linux mutants compiled and failed the regression: stale trigger, stale count, replacement flags, missing waiter notification, and non-atomic lookup/update. Mutation copies and logs were kept outside the repository. This is not a sanitizer run; waiter scheduling is exercised with a start flag/delay, not a formal blocked-state proof. All PE export names, including 620 guest-style names, matched the original runtime. No new timer helper was exported. Research, implementation, tests and critical review were AI-assisted; the independent reviewer was an AI agent, not a human reviewer. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); remaining gaps are recorded in library technical debt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a (libkernel timer change) - [x] AI-assisted: yes
CnRJay commented 2026-10-14 01:16:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:16:42Z.

Review: COMMENTED


Making the lookup, insert, update and delete one transaction under the queue mutex is a good catch. A separate HasEvent/EditEvent check really can race with a consumed one-shot timer.

On the semantics: the description says FreeBSD 11.0 keeps the armed expiry on a re-EV_ADD while 11.4 restarts it, and the PR picks 11.4. Which FreeBSD release the console kernel tracks isn't settled, and this is exactly the case where the two disagree. Under the repository's exact-or-throw rule, the disputed case (an EV_ADD that changes the period of a timer that is still armed) would keep throwing until it's measured. The unambiguous cases, a udata-only change and a re-add of a timer that has already fired or been disarmed, behave the same in both versions and can go in now.

Measuring it is practical: #5230 measured scheduling behaviour from a homebrew payload on a PS5 (firmware 13.60). The same kind of payload could arm a 1 s timer, re-add it with 3 s after 0.5 s, and record when it first fires: 3.5 s from the start means 11.4 behaviour, and 1 s or 3 s means otherwise. That would settle it for this PR and for the debt entry.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511946873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5361#pullrequestreview-5511946873). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T01:16:42Z. **Review:** COMMENTED --- Making the lookup, insert, update and delete one transaction under the queue mutex is a good catch. A separate `HasEvent`/`EditEvent` check really can race with a consumed one-shot timer. On the semantics: the description says FreeBSD 11.0 keeps the armed expiry on a re-`EV_ADD` while 11.4 restarts it, and the PR picks 11.4. Which FreeBSD release the console kernel tracks isn't settled, and this is exactly the case where the two disagree. Under the repository's exact-or-throw rule, the disputed case (an `EV_ADD` that changes the period of a timer that is still armed) would keep throwing until it's measured. The unambiguous cases, a `udata`-only change and a re-add of a timer that has already fired or been disarmed, behave the same in both versions and can go in now. Measuring it is practical: #5230 measured scheduling behaviour from a homebrew payload on a PS5 (firmware 13.60). The same kind of payload could arm a 1 s timer, re-add it with 3 s after 0.5 s, and record when it first fires: 3.5 s from the start means 11.4 behaviour, and 1 s or 3 s means otherwise. That would settle it for this PR and for the debt entry.
oneandonlydean commented 2026-10-14 02:28:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:28:12Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159532828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5361#issuecomment-6159532828). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:28:12Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!5361
No description provided.