feat(libkernel_sys): implement sched_rr_get_interval #9382

Merged
MarcZX10 merged 3 commits from upstream-pr/9382 into main 2026-10-23 09:47:27 +00:00
MarcZX10 commented 2026-10-21 19:54:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T19:54:56Z.


What

Implement sched_rr_get_interval for the guest's current process. It reports the FreeBSD 11 ULE default time slice for usual AMD64 clock rates (94 ms), accepts pid 0 or the current guest pid, and returns ESRCH for other pids and EFAULT for a null output pointer. The emulator does not model per-process scheduling quantum changes; that limitation is recorded in technical debt.

Tested

  • Linux: cmake --build build --target guest_sched_priority_tests -j2 passed.
  • python3 tools/check_conventions.py --base upstream/main passed.
  • python3 tools/pr_overlap.py --base main --branch codex/libkernel-sys-sched-interval --jobs 2 reported no overlap with open PRs.
  • ctest --test-dir build -R '^guest_sched_priority$' --output-on-failure could not enter the test: this host's Intel Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, and FMA required by AnyPS5's CPU guard.

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 or investigation files added to the repository
  • 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:4957507079 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9382). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T19:54:56Z. --- ### What Implement `sched_rr_get_interval` for the guest's current process. It reports the FreeBSD 11 ULE default time slice for usual AMD64 clock rates (94 ms), accepts pid 0 or the current guest pid, and returns `ESRCH` for other pids and `EFAULT` for a null output pointer. The emulator does not model per-process scheduling quantum changes; that limitation is recorded in technical debt. ### Tested - Linux: `cmake --build build --target guest_sched_priority_tests -j2` passed. - `python3 tools/check_conventions.py --base upstream/main` passed. - `python3 tools/pr_overlap.py --base main --branch codex/libkernel-sys-sched-interval --jobs 2` reported no overlap with open PRs. - `ctest --test-dir build -R '^guest_sched_priority$' --output-on-failure` could not enter the test: this host's Intel Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, and FMA required by AnyPS5's CPU guard. ### 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 or investigation files added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
ycbuzi commented 2026-10-21 22:41:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T22:41:47Z.


Windows run of 76178efc32 merged onto main a6dcea9279 (6cd718d449, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libkernel, libkernel_sys and guest_sched_priority_tests with no errors or warnings. ctest --repeat until-fail:2 on guest_sched_priority: passes on both repeats. Not run: a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328164430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9382#issuecomment-6328164430). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T22:41:47Z. --- Windows run of 76178efc32 merged onto `main` a6dcea9279 (6cd718d449, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libkernel`, `libkernel_sys` and `guest_sched_priority_tests` with no errors or warnings. `ctest --repeat until-fail:2` on `guest_sched_priority`: passes on both repeats. Not run: a title.
wachi35676 commented 2026-10-21 23:39:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:39:36Z.


Windows layout problem: the guest's tv_nsec is not fully written.

Head 76178efc32 merged onto main a6dcea927 (clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON; WSL2 Ubuntu 24.04, GCC 13.3.0, Release.

sched_rr_get_interval_nid_postfix takes the host struct timespec*. On MinGW the host timespec is a 64-bit tv_sec and a 32-bit long tv_nsec, so the store writes only the low 4 bytes of the guest's 64-bit tv_nsec. The test uses the same host struct, so it cannot see this. Probe: a 16-byte guest timespec filled with 0xff, then sched_rr_get_interval(0, &value):

  • Windows: ret=0 tv_sec=0 tv_nsec=-4200967296 (0xffffffff059a5380)
  • Linux: ret=0 tv_sec=0 tv_nsec=94000000 (0x00000000059a5380)

Using KernelTimespec (or two std::int64_t fields), as #9388 had to for timespec_get, and pre-filling the output in the test fixes it and makes it observable.

Other results:

  • guest_sched_priority: 3/3 on Windows, 3/3 on Linux. With Export.cpp and Export.Discovery.cpp from main: sched_rr_get_interval_nid_postfix not implemented.
  • 94 ms checks out against FreeBSD 11.4: ksched_attach stores 1000000000 / hz * sched_rr_interval() (ksched.c L66) and ULE's sched_rr_interval() is (sched_slice * hz + realstathz / 2) / realstathz (sched_ule.c L1705), 94 with hz 1000, stathz 127, slice 12. The ESRCH-before-EFAULT order matches sys_sched_rr_get_interval.
  • sched_rr_get_interval (PrsRaaSO-X0) is exported by PS5 3.20 libkernel as well as libkernel_sys (libkernel.c L8845). On Windows a libkernel import does not search libkernel_sys (WindowsEntryStubBuilder.cpp:175-177 adds libkernel only for libkernel_sys/libkernel_web imports), so a title that imports it from libkernel will not reach this implementation.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329011025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9382#issuecomment-6329011025). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:39:36Z. --- Windows layout problem: the guest's `tv_nsec` is not fully written. Head `76178efc32` merged onto main `a6dcea927` (clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release, `BUILD_TESTING=ON`; WSL2 Ubuntu 24.04, GCC 13.3.0, Release. `sched_rr_get_interval_nid_postfix` takes the host `struct timespec*`. On MinGW the host `timespec` is a 64-bit `tv_sec` and a 32-bit `long tv_nsec`, so the store writes only the low 4 bytes of the guest's 64-bit `tv_nsec`. The test uses the same host struct, so it cannot see this. Probe: a 16-byte guest timespec filled with `0xff`, then `sched_rr_get_interval(0, &value)`: - Windows: `ret=0 tv_sec=0 tv_nsec=-4200967296 (0xffffffff059a5380)` - Linux: `ret=0 tv_sec=0 tv_nsec=94000000 (0x00000000059a5380)` Using `KernelTimespec` (or two `std::int64_t` fields), as #9388 had to for `timespec_get`, and pre-filling the output in the test fixes it and makes it observable. Other results: - `guest_sched_priority`: 3/3 on Windows, 3/3 on Linux. With `Export.cpp` and `Export.Discovery.cpp` from main: `sched_rr_get_interval_nid_postfix not implemented`. - 94 ms checks out against FreeBSD 11.4: `ksched_attach` stores `1000000000 / hz * sched_rr_interval()` ([ksched.c L66](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/ksched.c#L66)) and ULE's `sched_rr_interval()` is `(sched_slice * hz + realstathz / 2) / realstathz` ([sched_ule.c L1705](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sched_ule.c#L1705)), 94 with hz 1000, stathz 127, slice 12. The ESRCH-before-EFAULT order matches `sys_sched_rr_get_interval`. - `sched_rr_get_interval` (`PrsRaaSO-X0`) is exported by PS5 3.20 libkernel as well as libkernel_sys ([libkernel.c](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel.c) L8845). On Windows a libkernel import does not search libkernel_sys (`WindowsEntryStubBuilder.cpp:175-177` adds libkernel only for libkernel_sys/libkernel_web imports), so a title that imports it from libkernel will not reach this implementation. AI-assisted: yes (Claude Code); results above were run on this machine.
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!9382
No description provided.