feat(libkernel): add setitimer on the alarm timer #3800

Merged
YossiYad merged 2 commits from upstream-pr/3800 into main 2026-10-12 20:19:39 +00:00
YossiYad commented 2026-10-11 16:48:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-11T16:48:23Z.


What

Carries screamm's screamm/AnyPS5:feat/libkernel-setitimer commit from #3735 unchanged onto current main, preserving its author:

  • Implement setitimer on the existing alarm timer thread, after FreeBSD 11.4 kern_time.c and alarm.c: EINVAL for an unknown timer or a value/interval with a negative field, tv_usec >= 1000000 or more than INT32_MAX/2 seconds; a null value reads the timer (EFAULT when the output is null too, after the timer check); a zero value disarms and returns the previous remaining time and interval; a non-zero value arms, re-armed by it_interval on expiry. alarm now clears the interval as FreeBSD's does.
  • It never reports success for a signal it cannot deliver, which is why the earlier #3293 was closed. Expiry with a guest SIGALRM handler or while SIGALRM is blocked throws with the reason, as alarm already does; ITIMER_VIRTUAL/ITIMER_PROF throw when armed (no CPU time accounting) and read as zero; an interval below 1 ms throws (the kernel's tick rounding is not known). Recorded in TechnicalDebt.
  • PS5MC (PPSA99420) imports setitimer, as reported in #3735.

getitimer is in the open #3572 and touches the same Signals.cpp; whichever merges second should read the interval this PR stores (alarms.interval), since #3572 reports it as always 0.

The library progress moves from 2903/3383 (85.81%) to 2904/3384 (85.82%). The total rises by one because setitimer was not exported before.

Closes #3735.

Tested

Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, -DBUILD_TESTING=ON), based on main a11c8f7f:

  • Full build, libs, and full ctest: 825 pass, 8 skip, no failures (833 registered tests).
  • The new guest_itimer and guest_signals pass 10 consecutive runs side by side. This is the first Linux run of the commit; the author reported Windows only.
  • tools/check_conventions.py --base upstream/main and git diff --check pass.
  • The original author reported Windows testing in #3735. PS5MC was not run on this machine.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820680650 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-11T16:48:23Z. --- ### What Carries screamm's `screamm/AnyPS5:feat/libkernel-setitimer` commit from #3735 unchanged onto current `main`, preserving its author: - Implement `setitimer` on the existing `alarm` timer thread, after FreeBSD 11.4 `kern_time.c` and `alarm.c`: `EINVAL` for an unknown timer or a value/interval with a negative field, `tv_usec >= 1000000` or more than `INT32_MAX/2` seconds; a null value reads the timer (`EFAULT` when the output is null too, after the timer check); a zero value disarms and returns the previous remaining time and interval; a non-zero value arms, re-armed by `it_interval` on expiry. `alarm` now clears the interval as FreeBSD's does. - It never reports success for a signal it cannot deliver, which is why the earlier #3293 was closed. Expiry with a guest `SIGALRM` handler or while `SIGALRM` is blocked throws with the reason, as `alarm` already does; `ITIMER_VIRTUAL`/`ITIMER_PROF` throw when armed (no CPU time accounting) and read as zero; an interval below 1 ms throws (the kernel's tick rounding is not known). Recorded in TechnicalDebt. - PS5MC (PPSA99420) imports `setitimer`, as reported in #3735. `getitimer` is in the open #3572 and touches the same `Signals.cpp`; whichever merges second should read the interval this PR stores (`alarms.interval`), since #3572 reports it as always 0. The library progress moves from 2903/3383 (85.81%) to 2904/3384 (85.82%). The total rises by one because `setitimer` was not exported before. Closes #3735. ### Tested Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, `-DBUILD_TESTING=ON`), based on `main` `a11c8f7f`: - Full build, `libs`, and full `ctest`: 825 pass, 8 skip, no failures (833 registered tests). - The new `guest_itimer` and `guest_signals` pass 10 consecutive runs side by side. This is the first Linux run of the commit; the author reported Windows only. - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - The original author reported Windows testing in #3735. PS5MC was not run on this machine. ### 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; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 16:48:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T16:48:54Z.


Progress report (0142215 → 5e1ffc2)

➖ System libraries: 86.46% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel setitimer_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111345780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6111345780). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T16:48:54Z. --- <!-- progress-report --> ### Progress report (0142215 → 5e1ffc2) ➖ **System libraries**: 86.46% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `setitimer_nid_postfix` | </details>
YossiYad commented 2026-10-11 22:20:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-11T22:20:39Z.


Rebased onto current main (33067ca0c). main gained getitimer in 1fc9b4d93, which declares the same GuestItimerval in Signals.cpp; the carried commit now keeps the one copy from main, with no other change to it.

One follow-up commit: getitimer on main always reported a zero it_interval, which was true while alarm was the only writer. With setitimer arming a periodic ITIMER_REAL, it read back as one-shot. ec642b222 reports the interval and extends guest_itimer to read the timer through getitimer after re-arming; the new check fails without the fix (getitimer did not report the setitimer interval).

Linux, GCC, Release: full ctest 901/901 before the follow-up; after it guest_itimer, guest_getitimer, guest_signals and guest_signal_sets pass. tools/check_conventions.py --base upstream/main passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114531331 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6114531331). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-11T22:20:39Z. --- Rebased onto current `main` (`33067ca0c`). `main` gained `getitimer` in 1fc9b4d93, which declares the same `GuestItimerval` in `Signals.cpp`; the carried commit now keeps the one copy from `main`, with no other change to it. One follow-up commit: `getitimer` on `main` always reported a zero `it_interval`, which was true while `alarm` was the only writer. With `setitimer` arming a periodic `ITIMER_REAL`, it read back as one-shot. ec642b222 reports the interval and extends `guest_itimer` to read the timer through `getitimer` after re-arming; the new check fails without the fix (`getitimer did not report the setitimer interval`). Linux, GCC, Release: full ctest 901/901 before the follow-up; after it `guest_itimer`, `guest_getitimer`, `guest_signals` and `guest_signal_sets` pass. `tools/check_conventions.py --base upstream/main` passes.
oneandonlydean commented 2026-10-11 23:17:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:17:24Z.


Same as #3781: conflicts with main in docs/dev/TechnicalDebt.md; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115009192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6115009192). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:17:24Z. --- Same as #3781: conflicts with main in `docs/dev/TechnicalDebt.md`; please rebase.
MarcZX10 commented 2026-10-11 23:56:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T23:56:59Z.


I independently rebuilt the carried implementation on current main (bca7a29d) with GCC 12.2, Release/Ninja, and BUILD_TESTING=ON. The guest_itimer and guest_signals CTest cases passed (2/2), including the getitimer interval regression check, and tools/check_conventions.py --base upstream/main passed. This validates the rebase integration locally; it does not change the PR branch or replace its CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115335903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6115335903). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T23:56:59Z. --- I independently rebuilt the carried implementation on current `main` (`bca7a29d`) with GCC 12.2, Release/Ninja, and `BUILD_TESTING=ON`. The `guest_itimer` and `guest_signals` CTest cases passed (2/2), including the `getitimer` interval regression check, and `tools/check_conventions.py --base upstream/main` passed. This validates the rebase integration locally; it does not change the PR branch or replace its CI.
github-actions[bot] commented 2026-10-12 08:33:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T08:33:39Z.


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
#4382 core/libs/prx/libkernel/System/src/Signals.cpp L92, L101, L107, L113, L126, L128, L138-142, L183
core/libs/tests/GuestItimer.cpp
setitimer_nid_postfix core/libs/tests/GuestItimer.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120656806 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6120656806). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T08:33:39Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #4382 | `core/libs/prx/libkernel/System/src/Signals.cpp` [L92](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L92), [L101](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L101), [L107](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L107), [L113](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L113), [L126](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L126), [L128](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L128), [L138-142](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L138-L142), [L183](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libkernel/System/src/Signals.cpp#L183)<br>`core/libs/tests/GuestItimer.cpp` | `setitimer_nid_postfix` | `core/libs/tests/GuestItimer.cpp` |
ArekatlaNishanthchowdary commented 2026-10-12 19:25:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArekatlaNishanthchowdary on 2026-10-12T19:25:04Z.


Rebase handoff: the two commits rebased onto current main, authorship unchanged: ArekatlaNishanthchowdary:carry/libkernel-setitimer-rebased (638bc3df3, base d53960612).

The only conflict was docs/dev/TechnicalDebt.md, which main split into one file per library in 342a8c459. The setitimer entry is now the last line of docs/dev/debt/libkernel.md, with its link changed to ../../../core/...; TechnicalDebt.md is left as on main. The code applied without conflict.

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: full build passes, full ctest 996/996 passed, tools/check_conventions.py --base origin/main passes. Linux not run.

To pick it up: git fetch https://github.com/ArekatlaNishanthchowdary/AnyPS5 carry/libkernel-setitimer-rebased && git reset --hard FETCH_HEAD, then force-push.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131101259 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6131101259). Originally posted by [ArekatlaNishanthchowdary](https://github.com/ArekatlaNishanthchowdary) on 2026-10-12T19:25:04Z. --- Rebase handoff: the two commits rebased onto current `main`, authorship unchanged: [`ArekatlaNishanthchowdary:carry/libkernel-setitimer-rebased`](https://github.com/ArekatlaNishanthchowdary/AnyPS5/tree/carry/libkernel-setitimer-rebased) (`638bc3df3`, base `d53960612`). The only conflict was `docs/dev/TechnicalDebt.md`, which `main` split into one file per library in 342a8c459. The `setitimer` entry is now the last line of `docs/dev/debt/libkernel.md`, with its link changed to `../../../core/...`; `TechnicalDebt.md` is left as on `main`. The code applied without conflict. Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: full build passes, full `ctest` 996/996 passed, `tools/check_conventions.py --base origin/main` passes. Linux not run. To pick it up: `git fetch https://github.com/ArekatlaNishanthchowdary/AnyPS5 carry/libkernel-setitimer-rebased && git reset --hard FETCH_HEAD`, then force-push. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-12 20:11:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:11:09Z.


Rebased onto current main; the only conflict was the TechnicalDebt entry, now in docs/dev/debt/libkernel.md (author and code unchanged). Checked on Linux: build, guest_itimer, guest_signals and guest_signal_sets pass. Merging once CI is green. #4382 carries the same commit and becomes redundant.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131807649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3800#issuecomment-6131807649). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:11:09Z. --- Rebased onto current `main`; the only conflict was the TechnicalDebt entry, now in `docs/dev/debt/libkernel.md` (author and code unchanged). Checked on Linux: build, `guest_itimer`, `guest_signals` and `guest_signal_sets` pass. Merging once CI is green. #4382 carries the same commit and becomes redundant.
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!3800
No description provided.