feat(libkernel_sys): implement scheduler policy query #9369

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/9369 into main
MarcZX10 commented 2026-10-21 19:30:41 +00:00 (Migrated from github.com)

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


What

Implements sched_getparam and sched_getscheduler for the current guest process. Both accept pid 0 or the current process ID; the former returns the calling guest thread's tracked priority and the latter its tracked FIFO/round-robin policy. Invalid process IDs return ESRCH, null output returns EFAULT, and an unsupported tracked policy returns EINVAL. The debt entry records the scope and that console behavior remains unverified.

Tested

Linux x86-64: libkernel_sys and guest_kernel_sys_tests built successfully. ctest -R '^guest_kernel_sys$' could not start because this VM's Intel Xeon E5-1620 v2 lacks required guest-execution CPU features (LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA). Convention checks passed. No overlap with open PRs.

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:4957212868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9369). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T19:30:41Z. --- ### What Implements `sched_getparam` and `sched_getscheduler` for the current guest process. Both accept pid 0 or the current process ID; the former returns the calling guest thread's tracked priority and the latter its tracked FIFO/round-robin policy. Invalid process IDs return `ESRCH`, null output returns `EFAULT`, and an unsupported tracked policy returns `EINVAL`. The debt entry records the scope and that console behavior remains unverified. ### Tested Linux x86-64: `libkernel_sys` and `guest_kernel_sys_tests` built successfully. `ctest -R '^guest_kernel_sys$'` could not start because this VM's Intel Xeon E5-1620 v2 lacks required guest-execution CPU features (LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA). Convention checks passed. No overlap with open PRs. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 19:31:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T19:31:29Z.


Progress report (584c5a8 → afe568e)

📈 System libraries: 42.12% (+0.02%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel_sys sched_getparam_nid_postfix
libkernel_sys sched_getscheduler_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324732830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9369#issuecomment-6324732830). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T19:31:29Z. --- <!-- progress-report --> ### Progress report (584c5a8 → afe568e) 📈 **System libraries**: 42.12% (+0.02%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `sched_getparam_nid_postfix` | | libkernel_sys | `sched_getscheduler_nid_postfix` | </details>
github-actions[bot] commented 2026-10-21 19:52:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T19:52:35Z.


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 9131 docs/dev/debt/libkernel_sys.md L7-8
PR 9187 core/libs/prx/libkernel_sys/Export.Discovery.cpp L2451-2460 sched_getparam
sched_getscheduler
PR 9423 core/libs/tests/GuestKernelSys.cpp L1-2, L61

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 5528 core/libs/tests/GuestKernelSys.cpp
PR 6044 core/libs/tests/GuestKernelSys.cpp
PR 6525 core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel_sys.md
PR 8457 core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel_sys.md
PR 8531 docs/dev/debt/libkernel_sys.md
PR 8987 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
PR 9019 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
PR 9040 core/libs/prx/libkernel_sys/Export.Discovery.cpp
core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel_sys.md
PR 9095 core/libs/tests/GuestKernelSys.cpp
PR 9103 core/libs/prx/libkernel_sys/Export.Discovery.cpp
core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel_sys.md
PR 9141 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
PR 9294 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325134632 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9369#issuecomment-6325134632). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T19:52:35Z. --- <!-- 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 | |---|---|---|---| | [PR 9131](https://www.github.com/boykopovar/AnyPS5/pull/9131) | `docs/dev/debt/libkernel_sys.md` [L7-8](https://github.com/boykopovar/AnyPS5/blob/d6eafa54d0464258574fd2f71889754d05a5bc93/docs/dev/debt/libkernel_sys.md#L7-L8) | | | | [PR 9187](https://www.github.com/boykopovar/AnyPS5/pull/9187) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp` [L2451-2460](https://github.com/boykopovar/AnyPS5/blob/d6eafa54d0464258574fd2f71889754d05a5bc93/core/libs/prx/libkernel_sys/Export.Discovery.cpp#L2451-L2460) | `sched_getparam`<br>`sched_getscheduler` | | | [PR 9423](https://www.github.com/boykopovar/AnyPS5/pull/9423) | `core/libs/tests/GuestKernelSys.cpp` [L1-2](https://github.com/boykopovar/AnyPS5/blob/d6eafa54d0464258574fd2f71889754d05a5bc93/core/libs/tests/GuestKernelSys.cpp#L1-L2), [L61](https://github.com/boykopovar/AnyPS5/blob/d6eafa54d0464258574fd2f71889754d05a5bc93/core/libs/tests/GuestKernelSys.cpp#L61) | | | 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 5528](https://www.github.com/boykopovar/AnyPS5/pull/5528) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 6525](https://www.github.com/boykopovar/AnyPS5/pull/6525) | `core/libs/tests/GuestKernelSys.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 8457](https://www.github.com/boykopovar/AnyPS5/pull/8457) | `core/libs/tests/GuestKernelSys.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 8531](https://www.github.com/boykopovar/AnyPS5/pull/8531) | `docs/dev/debt/libkernel_sys.md` | | [PR 8987](https://www.github.com/boykopovar/AnyPS5/pull/8987) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9019](https://www.github.com/boykopovar/AnyPS5/pull/9019) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9040](https://www.github.com/boykopovar/AnyPS5/pull/9040) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp`<br>`core/libs/tests/GuestKernelSys.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9095](https://www.github.com/boykopovar/AnyPS5/pull/9095) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 9103](https://www.github.com/boykopovar/AnyPS5/pull/9103) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp`<br>`core/libs/tests/GuestKernelSys.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9141](https://www.github.com/boykopovar/AnyPS5/pull/9141) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9294](https://www.github.com/boykopovar/AnyPS5/pull/9294) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp`<br>`docs/dev/debt/libkernel_sys.md` |
xXPBSXx commented 2026-10-21 20:41:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T20:41:30Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_kernel_sys_tests; ctest -N -R guest_kernel_sys lists exactly one test.

PR head tested: afe568e9e1d812ce69927ef144ae3619d09936c5.

Results (3 runs each):

  • PR head: guest_kernel_sys passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libkernel_sys/Export.Discovery.cpp with the version from the PR's merge base (1896871ba7), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

GPU: the run output has no Selected GPU line; no GPU claim is made.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326088833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9369#issuecomment-6326088833). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T20:41:30Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_kernel_sys_tests`; `ctest -N -R guest_kernel_sys` lists exactly one test. **PR head tested:** `afe568e9e1d812ce69927ef144ae3619d09936c5`. **Results (3 runs each):** - PR head: `guest_kernel_sys` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libkernel_sys/Export.Discovery.cpp` with the version from the PR's merge base (`1896871ba7`), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards. **GPU:** the run output has no `Selected GPU` line; no GPU claim is made. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
wachi35676 commented 2026-10-21 23:39:40 +00:00 (Migrated from github.com)

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


Linux run, and one difference from FreeBSD that a guest can reach.

Head afe568e9e1 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.

  • guest_kernel_sys: 3/3 on Linux (the description has no Linux test run), 3/3 on Windows. With Export.Discovery.cpp from main: sched_getparam_nid_postfix not implemented.
  • check_conventions.py --base a6dcea927: passes.

SCHED_OTHER threads get EINVAL. pthread_attr_setschedpolicy accepts 1 to 3 (Posix/Attr.cpp:141), and with PTHREAD_EXPLICIT_SCHED the new thread stores that policy (Pthread/src/Thread.cpp:390). Probe: create a thread with an explicit policy, then call sched_getscheduler(0) in it. Same on Windows and Linux:

main thread sched_getscheduler(0)=1
attr policy 1: thread sched_getscheduler(0)=1 errno=0
attr policy 2: thread sched_getscheduler(0)=-1 errno=22
attr policy 3: thread sched_getscheduler(0)=3 errno=0

FreeBSD 11.4's getscheduler cannot fail: anything that is not FIFO or round-robin reports SCHED_OTHER (ksched.c L106-L125). Returning 2 for policy 2 matches that. The test's schedPolicy.store(0) case would then need a different expectation.

sched_getparam/sched_getscheduler (O6gKl8uvGyE, SD7oNCIQWvE) are exported by PS5 3.20 libkernel as well as libkernel_sys (libkernel.c L8843-L8844). On Windows a libkernel import does not search libkernel_sys (WindowsEntryStubBuilder.cpp:175-177), so titles that import them from libkernel will not reach this code.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329011938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9369#issuecomment-6329011938). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:39:40Z. --- Linux run, and one difference from FreeBSD that a guest can reach. Head `afe568e9e1` 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. - `guest_kernel_sys`: 3/3 on Linux (the description has no Linux test run), 3/3 on Windows. With `Export.Discovery.cpp` from main: `sched_getparam_nid_postfix not implemented`. - `check_conventions.py --base a6dcea927`: passes. **`SCHED_OTHER` threads get `EINVAL`.** `pthread_attr_setschedpolicy` accepts 1 to 3 (`Posix/Attr.cpp:141`), and with `PTHREAD_EXPLICIT_SCHED` the new thread stores that policy (`Pthread/src/Thread.cpp:390`). Probe: create a thread with an explicit policy, then call `sched_getscheduler(0)` in it. Same on Windows and Linux: ``` main thread sched_getscheduler(0)=1 attr policy 1: thread sched_getscheduler(0)=1 errno=0 attr policy 2: thread sched_getscheduler(0)=-1 errno=22 attr policy 3: thread sched_getscheduler(0)=3 errno=0 ``` FreeBSD 11.4's `getscheduler` cannot fail: anything that is not FIFO or round-robin reports `SCHED_OTHER` ([ksched.c L106-L125](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/ksched.c#L106-L125)). Returning 2 for policy 2 matches that. The test's `schedPolicy.store(0)` case would then need a different expectation. `sched_getparam`/`sched_getscheduler` (`O6gKl8uvGyE`, `SD7oNCIQWvE`) are 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) L8843-L8844). On Windows a libkernel import does not search libkernel_sys (`WindowsEntryStubBuilder.cpp:175-177`), so titles that import them from libkernel will not reach this code. AI-assisted: yes (Claude Code); results above were run on this machine.
MarcZX10 commented 2026-10-22 07:44:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T07:44:59Z.


Closing this PR to avoid duplicate export work under CONTRIBUTING.md and the duplicate-export convention. Earlier open #9187 covers sched_getparam and sched_getscheduler, adds sched_setparam, and moves these exports to libkernel while removing the libkernel_sys copies. The overlap check also flagged the same exports. I have not transferred any code. Please continue scheduler work through the single coordinated implementation and resolve the independent findings there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335542592 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9369#issuecomment-6335542592). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T07:44:59Z. --- Closing this PR to avoid duplicate export work under CONTRIBUTING.md and the duplicate-export convention. Earlier open #9187 covers sched_getparam and sched_getscheduler, adds sched_setparam, and moves these exports to libkernel while removing the libkernel_sys copies. The overlap check also flagged the same exports. I have not transferred any code. Please continue scheduler work through the single coordinated implementation and resolve the independent findings there.

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