fix(libkernel): check and keep the scheduling policy of a thread #4086

Merged
hugodearaujo merged 1 commit from upstream-pr/4086 into main 2026-10-13 12:29:16 +00:00
hugodearaujo commented 2026-10-11 22:58:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-11T22:58:48Z.


What

Follows #4077, which fixed sched_get_priority_max/min and left this in TechnicalDebt: pthread_setschedparam and scePthreadSetschedparam ignored the policy and stored any priority, and pthread_getschedparam always reported SCHED_FIFO. I called the console's exports from a homebrew payload on a PS5 (firmware 13.60), on a created thread:

setschedparam(self, policy, priority) Console main
SCHED_FIFO (1) or SCHED_RR (3), priority 256 to 767 0 0
same policies, priority 896 to 959 0 0
same policies, priority -2 to 255, 768 to 895, 960 to 2100, 4095, 4096, 8191, 65535, 65536, INT_MAX EINVAL, nothing changes 0, priority stored
any priority with policy 0, 2 (SCHED_OTHER), 4 EINVAL, nothing changes 0, priority stored
getschedparam after SCHED_RR was set 3 1

Both APIs answer the same (0x80020016 for the SCE one, 22 for the POSIX one). A thread created with explicit scheduling attributes starts with the attributes' policy (SCHED_RR gives 3); one that inherits starts with its creator's (1 here, even when the attributes say SCHED_RR).

So both set calls now check the policy and the priority and keep the policy, both get calls report it, and scePthreadCreate sets it from the attributes or the creator. A null parameter still returns EINVAL; on the console it crashed the payload.

Title: Propagation: Paradise Hotel (PPSA15878) calls pthread_setschedparam from three places in eboot.bin: with SCHED_FIFO and a priority from the engine (0xffe6b3), and twice with the policy pthread_getschedparam reported (0xffebe2, and 0x4b75df0, the priority mapping described in #4077). It ignores the result.

What is still different is in TechnicalDebt: a created thread that inherits scheduling takes the priority of its attributes, where the console gives it its creator's (measured: 700 with the attributes at 300).

Tested

  • PS5 firmware 13.60: the table above, scanned priority by priority from -2 to 2100 for SCHED_FIFO, and four attribute combinations at creation.
  • Linux: full CTest 907/907. The new guest_pthread_schedparam covers the accepted bands and their edges, the rejected policies, both APIs, the policy kept after SCHED_RR, and the policy of created threads; it aborts on main.
  • Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: current main does not build on Windows (HostPoll in Socket.cpp, fixed by #4021), so I built this branch with #4021 merged: 907/909, guest_pthread_schedparam, guest_sched_priority and guest_pthread_attr pass. agc_write_tracking and guest_kernel_stack_protect fail the same way on main with #4021 in this VM.

Until #4077 is merged this branch also carries its commit; the change of this PR is the second commit.

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 in TechnicalDebt
  • 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: #4077
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823033206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4086). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-11T22:58:48Z. --- ### What Follows #4077, which fixed `sched_get_priority_max/min` and left this in TechnicalDebt: `pthread_setschedparam` and `scePthreadSetschedparam` ignored the policy and stored any priority, and `pthread_getschedparam` always reported `SCHED_FIFO`. I called the console's exports from a homebrew payload on a PS5 (firmware 13.60), on a created thread: | `setschedparam(self, policy, priority)` | Console | `main` | |---|---|---| | `SCHED_FIFO` (1) or `SCHED_RR` (3), priority 256 to 767 | 0 | 0 | | same policies, priority 896 to 959 | 0 | 0 | | same policies, priority -2 to 255, 768 to 895, 960 to 2100, 4095, 4096, 8191, 65535, 65536, `INT_MAX` | **`EINVAL`**, nothing changes | 0, priority stored | | any priority with policy 0, 2 (`SCHED_OTHER`), 4 | **`EINVAL`**, nothing changes | 0, priority stored | | `getschedparam` after `SCHED_RR` was set | **3** | 1 | Both APIs answer the same (`0x80020016` for the SCE one, 22 for the POSIX one). A thread created with explicit scheduling attributes starts with the attributes' policy (`SCHED_RR` gives 3); one that inherits starts with its creator's (1 here, even when the attributes say `SCHED_RR`). So both set calls now check the policy and the priority and keep the policy, both get calls report it, and `scePthreadCreate` sets it from the attributes or the creator. A null parameter still returns `EINVAL`; on the console it crashed the payload. Title: Propagation: Paradise Hotel (PPSA15878) calls `pthread_setschedparam` from three places in `eboot.bin`: with `SCHED_FIFO` and a priority from the engine (`0xffe6b3`), and twice with the policy `pthread_getschedparam` reported (`0xffebe2`, and `0x4b75df0`, the priority mapping described in #4077). It ignores the result. What is still different is in TechnicalDebt: a created thread that inherits scheduling takes the priority of its attributes, where the console gives it its creator's (measured: 700 with the attributes at 300). ### Tested - PS5 firmware 13.60: the table above, scanned priority by priority from -2 to 2100 for `SCHED_FIFO`, and four attribute combinations at creation. - Linux: full CTest 907/907. The new `guest_pthread_schedparam` covers the accepted bands and their edges, the rejected policies, both APIs, the policy kept after `SCHED_RR`, and the policy of created threads; it aborts on `main`. - Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: current `main` does not build on Windows (`HostPoll` in `Socket.cpp`, fixed by #4021), so I built this branch with #4021 merged: 907/909, `guest_pthread_schedparam`, `guest_sched_priority` and `guest_pthread_attr` pass. `agc_write_tracking` and `guest_kernel_stack_protect` fail the same way on `main` with #4021 in this VM. Until #4077 is merged this branch also carries its commit; the change of this PR is the second commit. ### 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`); silent stubs are listed in TechnicalDebt - [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: #4077 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-13 10:55:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:55:50Z.


Rebased onto current main (the TechnicalDebt entry moved to docs/dev/debt/libkernel.md; same text). Checked: scoped build and ctest, guest_pthread_schedparam fails without the change and passes with it, both APIs and the policy of created threads covered. Merging once the full build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143992645 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4086#issuecomment-6143992645). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T10:55:50Z. --- Rebased onto current `main` (the TechnicalDebt entry moved to `docs/dev/debt/libkernel.md`; same text). Checked: scoped build and ctest, `guest_pthread_schedparam` fails without the change and passes with it, both APIs and the policy of created threads covered. Merging once the full build is green.
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!4086
No description provided.