Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
hugodearaujo:fix/sched-priority-range
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
hugodearaujo:fix/sched-priority-range

Conversation

@hugodearaujo

Copy link
Copy Markdown
Contributor

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

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

On a PS5 (firmware 13.60) sched_get_priority_max returns 767 and
sched_get_priority_min 256 for SCHED_FIFO and SCHED_RR; the two were
swapped. Every other policy, SCHED_OTHER included, returns -1 with
EINVAL instead of a range or a host exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit 10aff1c into boykopovar:main Oct 12, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants