fix(libkernel): report the console's scheduling priority range #4077

Merged
hugodearaujo merged 1 commit from upstream-pr/4077 into main 2026-10-12 08:38:56 +00:00
hugodearaujo commented 2026-10-11 22:48:26 +00:00 (Migrated from github.com)

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


What

sched_get_priority_max returned 256 and sched_get_priority_min 767 for policies 1 to 3, and other policies threw. TechnicalDebt said the console's answer was unverified. I called the console's exports from a homebrew payload on a PS5 (firmware 13.60):

Policy Console max / min main max / min
1 (SCHED_FIFO) 767 / 256 256 / 767
3 (SCHED_RR) 767 / 256 256 / 767
2 (SCHED_OTHER) -1, errno 22 / -1, errno 22 256 / 767
-1, 0, 4, 5 -1, errno 22 / -1, errno 22 throws

So the range was swapped, and every policy without a range fails with EINVAL instead of a host exception. A second check agrees: on the console a mutex attribute set to PTHREAD_PRIO_PROTECT reports a default ceiling of 767, the highest SCHED_RR priority in FreeBSD libthr. pthread_mutexattr_setprotocol here takes that ceiling from sched_get_priority_max(SCHED_RR), so on main it is 256; this change fixes it too.

Title: Propagation: Paradise Hotel (PPSA15878) sets its thread priorities this way (eboot.bin 0x4b75d60):

pthread_getschedparam(thread, &policy, &param)
max = sched_get_priority_max(policy); min = sched_get_priority_min(policy)
priority = max == min ? 0 : min + roundf((4 - level) * (max - min) * 0.25f)
pthread_setschedparam(thread, policy, &param)

Threads report SCHED_FIFO both on the console and here, so with the swapped range each level got the mirrored priority: level 4 gave 767 instead of 256.

The SCHED_OTHER range was accepted for SDL titles (#1908). SDL now gets -1 and EINVAL, as on the console, instead of an exception or a range.

The TechnicalDebt entry gives the measurements. It also notes what is still different and left for a separate change: pthread_setschedparam ignores the policy and does not check the priority, where the console rejects SCHED_OTHER and priorities below 256 with EINVAL.

Tested

  • PS5 firmware 13.60: the table, the mutex ceiling, and pthread_getschedparam on the main thread and on a created thread (both SCHED_FIFO).
  • Linux: full CTest 906/906. guest_sched_priority now checks both ranges and the EINVAL cases; it aborts on main. guest_pthread_mutexattr already compares the ceiling with sched_get_priority_max(SCHED_RR) and passes.
  • 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: 903/905, guest_sched_priority and guest_pthread_mutexattr pass. agc_write_tracking and guest_kernel_stack_protect fail the same way on main with #4021 in this VM.

Overlap: #3654 adds its getpriority TechnicalDebt entry right below the entry this PR rewrites, so whichever lands second needs a one-line rebase. #3654 already conflicts with main elsewhere.

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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822978645 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4077). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-11T22:48:26Z. --- ### What `sched_get_priority_max` returned 256 and `sched_get_priority_min` 767 for policies 1 to 3, and other policies threw. TechnicalDebt said the console's answer was unverified. I called the console's exports from a homebrew payload on a PS5 (firmware 13.60): | Policy | Console max / min | `main` max / min | |---|---|---| | 1 (`SCHED_FIFO`) | **767 / 256** | 256 / 767 | | 3 (`SCHED_RR`) | **767 / 256** | 256 / 767 | | 2 (`SCHED_OTHER`) | **-1, errno 22 / -1, errno 22** | 256 / 767 | | -1, 0, 4, 5 | -1, errno 22 / -1, errno 22 | throws | So the range was swapped, and every policy without a range fails with `EINVAL` instead of a host exception. A second check agrees: on the console a mutex attribute set to `PTHREAD_PRIO_PROTECT` reports a default ceiling of 767, the highest `SCHED_RR` priority in FreeBSD libthr. `pthread_mutexattr_setprotocol` here takes that ceiling from `sched_get_priority_max(SCHED_RR)`, so on `main` it is 256; this change fixes it too. Title: Propagation: Paradise Hotel (PPSA15878) sets its thread priorities this way (`eboot.bin` `0x4b75d60`): ``` pthread_getschedparam(thread, &policy, &param) max = sched_get_priority_max(policy); min = sched_get_priority_min(policy) priority = max == min ? 0 : min + roundf((4 - level) * (max - min) * 0.25f) pthread_setschedparam(thread, policy, &param) ``` Threads report `SCHED_FIFO` both on the console and here, so with the swapped range each level got the mirrored priority: level 4 gave 767 instead of 256. The `SCHED_OTHER` range was accepted for SDL titles (#1908). SDL now gets -1 and `EINVAL`, as on the console, instead of an exception or a range. The TechnicalDebt entry gives the measurements. It also notes what is still different and left for a separate change: `pthread_setschedparam` ignores the policy and does not check the priority, where the console rejects `SCHED_OTHER` and priorities below 256 with `EINVAL`. ### Tested - PS5 firmware 13.60: the table, the mutex ceiling, and `pthread_getschedparam` on the main thread and on a created thread (both `SCHED_FIFO`). - Linux: full CTest 906/906. `guest_sched_priority` now checks both ranges and the `EINVAL` cases; it aborts on `main`. `guest_pthread_mutexattr` already compares the ceiling with `sched_get_priority_max(SCHED_RR)` and passes. - 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: 903/905, `guest_sched_priority` and `guest_pthread_mutexattr` pass. `agc_write_tracking` and `guest_kernel_stack_protect` fail the same way on `main` with #4021 in this VM. Overlap: #3654 adds its `getpriority` TechnicalDebt entry right below the entry this PR rewrites, so whichever lands second needs a one-line rebase. #3654 already conflicts with `main` elsewhere. ### 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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!4077
No description provided.