Skip to content

fix(libkernel): report a thread's class and priority from rtprio_thread as measured on a PS5 - #7853

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
ionut27001:fix/libkernel-rtprio-thread-lookup
Oct 24, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
ionut27001:fix/libkernel-rtprio-thread-lookup

Conversation

@ionut27001

@ionut27001 ionut27001 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

rtprio_thread threw NotImplemented for every thread made with the sce attributes, which allow only SCHED_FIFO and SCHED_RR, because the console's mapping from a scheduling priority to the rtprio prio was unmeasured. The debt entry names Morrowind (mshivam019/morrowind-ps5) as an importer at start-up.

Measured in a payload process on a PS5 (firmware 12.70; payload SDK v0.44, clang 18.1.8), calling rtprio_thread resolved from libkernel_sys.sprx with an rtprio of the probe's own, on its main thread and on threads it created with scePthreadCreate and an explicit policy and priority (probe p79_libkernel, source and log attached: p79-rtprio-equeue.zip; lines quoted unchanged with a p79: prefix; policy/prio are what scePthreadGetschedparam reported inside the thread, type/rtprio what RTP_LOOKUP with lwpid 0 reported there, rtprio_other is the lookup by the thread's id from the main thread):

p79: case rtprio_thread who=main requested_policy=-1 requested_prio=-1 create_ret=0 getsched_ret=0 policy=1 prio=700 lookup_ret=0 errno=0 type=10 rtprio=700
p79: case rtprio_set who=main set_type=2 set_prio=0 ret=-1 errno=22 policy_after=1 prio_after=700 lookup_after_type=10 lookup_after_prio=700
p79: case rtprio_self_by_id lookup_ret=0 errno=0 type=10 rtprio=700
p79: case rtprio_unknown_id id=1 lookup_ret=-1 errno=3
p79: case rtprio_unknown_id id=999999 lookup_ret=-1 errno=3
p79: case rtprio_bad_function function=2 ret=-1 errno=3
p79: case rtprio_null_rtp ret=-1 errno=14
p79: case rtprio_other who=fifo256 from_main lookup_ret=0 errno=0 type=10 rtprio=256
p79: case rtprio_thread who=fifo256 requested_policy=1 requested_prio=256 create_ret=0 getsched_ret=0 policy=1 prio=256 lookup_ret=0 errno=0 type=10 rtprio=256
p79: case rtprio_thread who=fifo384 requested_policy=1 requested_prio=384 create_ret=0 getsched_ret=0 policy=1 prio=384 lookup_ret=0 errno=0 type=10 rtprio=384
p79: case rtprio_thread who=fifo512 requested_policy=1 requested_prio=512 create_ret=0 getsched_ret=0 policy=1 prio=512 lookup_ret=0 errno=0 type=10 rtprio=512
p79: case rtprio_thread who=fifo640 requested_policy=1 requested_prio=640 create_ret=0 getsched_ret=0 policy=1 prio=640 lookup_ret=0 errno=0 type=10 rtprio=640
p79: case rtprio_thread who=fifo767 requested_policy=1 requested_prio=767 create_ret=0 getsched_ret=0 policy=1 prio=767 lookup_ret=0 errno=0 type=10 rtprio=767
p79: case rtprio_other who=rr512 from_main lookup_ret=0 errno=0 type=2 rtprio=512
p79: case rtprio_thread who=rr512 requested_policy=3 requested_prio=512 create_ret=0 getsched_ret=0 policy=3 prio=512 lookup_ret=0 errno=0 type=2 rtprio=512
p79: case rtprio_set who=rr512 set_type=2 set_prio=15 ret=-1 errno=22 policy_after=3 prio_after=512 lookup_after_type=2 lookup_after_prio=512
p79: case rtprio_attr who=other700 setinherit_ret=0 setpolicy_ret=0x8002002d setparam_ret=0 create_ret=0
p79: case rtprio_thread who=other700 requested_policy=2 requested_prio=700 create_ret=0 getsched_ret=0 policy=1 prio=700 lookup_ret=0 errno=0 type=10 rtprio=700
p79: case rtprio_attr who=fifo896 setinherit_ret=0 setpolicy_ret=0 setparam_ret=0x8002002d create_ret=0
p79: case rtprio_thread who=fifo896 requested_policy=1 requested_prio=896 create_ret=0 getsched_ret=0 policy=1 prio=700 lookup_ret=0 errno=0 type=10 rtprio=700

So RTP_LOOKUP reports type 10 (RTP_PRIO_FIFO) for a SCHED_FIFO thread and 2 (RTP_PRIO_REALTIME) for a SCHED_RR thread, with prio equal to the thread's scheduling priority (700, 256, 384, 512, 640, 767), for the calling thread and for another live thread by its id; an id that is no thread fails with ESRCH, function 2 with ESRCH, a null rtprio with EFAULT. RTP_SET with type 2 and prio 0, 15 or 31 failed with EINVAL on both classes and changed nothing. SCHED_OTHER was refused by scePthreadAttrSetschedpolicy (0x8002002d) and priorities 896 and 959 by scePthreadAttrSetschedparam, so those threads ran as SCHED_FIFO at their default or requested priority (700; 512 for other512) and are not measurements of those requests.

The change:

  • rtprio_thread_nid_postfix reports RTP_LOOKUP for the calling thread and, through a new GetLiveGuestThreadSched_nid_no_patch, for another live guest thread by its id: type 10 or 2 by the thread's policy and prio its priority; a thread that is not real-time keeps reporting RTP_PRIO_NORMAL (3) with 0 as before (the payload process refused SCHED_OTHER through scePthreadAttrSetschedpolicy; the POSIX pthread_attr_setschedpolicy path was not probed, and here it stores SCHED_OTHER). An unknown function fails with ESRCH instead of EINVAL (measured for function 2 only). RTP_SET keeps throwing for a real-time thread and for another thread, since no accepted value was measured; the measured EINVALs are recorded in the debt entry.
  • guest_rtprio_thread (new): lookups on the main thread, on itself by id, inside and from outside SCHED_FIFO threads at 512 and 256 and a SCHED_RR thread at 600, ESRCH after the thread is joined, ESRCH for function 2 and ids 1 and 999999, EFAULT for a null rtprio, and that RTP_SET still throws for the calling thread and for another thread. guest_sched_priority now expects the lookup to succeed with type 10 and prio 700 on its main thread and ESRCH for function 2.
  • Debt: the entry now states the open gaps (RTP_SET on real-time and other threads, non-real-time threads) with what was measured for them, and the lookup and error codes in one sentence each.

Not measured: RTP_SET with type 10 or with a prio in 256-767 (the probe restores each thread's looked-up type and prio with one such set but does not record its result), RTP_SET by another thread's id (none issued), a non-real-time thread, a thread of another process, and a game process; Morrowind was not run.

Overlaps: tools/pr_overlap.py reports one open PR that changes the same lines: #7658 turns the three NotImplemented_nid_no_patch calls of rtprio_thread (and cpuset's) into std::runtime_error throws; it adds no lookup, so whichever lands second rebases the throw lines. It could not compare 27 PRs that conflict with main and share a file with this branch (Pthread/src/Thread.cpp, Pthread.hpp, Posix/Thread.cpp, the libkernel CMakeLists.txt, GuestSchedPriority.cpp or the libkernel debt file): #3986, #4972, #5021, #6044, #6149, #6226, #6446, #6469, #6519, #6879, #6908, #6936, #6942, #6977, #7039, #7049, #7075, #7088, #7105, #7121, #7129, #7149, #7192, #7201, #7299, #7332 and #7509; of those, the ones that touch the three thread files (#3986, #5021, #6879, #6908, #7149, #7201, #7332) change no rtprio_thread line. No open PR implements the lookup.

Tested

Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0 r7 (posix, UCRT), Ninja, Release, -DBUILD_TESTING=ON, branch built and tested on main 36f60df, then rebased on f72c7aa; of the touched files, main meanwhile changed other lines of the libkernel CMakeLists.txt and debt file (#7813), with no conflict; the two tests rebuilt and rerun after the rebase, passed.

  • guest_rtprio_thread (new), guest_sched_priority and guest_pthread_schedparam pass (3 of 3; the first two twice).
  • Revert check: with Pthread/Posix/Thread.cpp, Pthread/src/Thread.cpp and Pthread/include/Pthread.hpp from main and the tests kept, guest_rtprio_thread and guest_sched_priority both abort with "unhandled exception 'St13runtime_error' ... what(): rtprio_thread: a guest thread's real-time class not implemented"; restored, both pass.
  • python tools/check_conventions.py --base origin/main passes.
  • Probe p79_libkernel built with the payload SDK v0.44 and clang 18.1.8 (-target x86_64-sie-ps5), launched once through the payload manager; its equeue section is not used by this PR.

Not tested: Linux (the change has no host-specific code; GetLiveGuestThreadSched_nid_no_patch reads the same registry as the affinity helpers next to it), Morrowind or any title.

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

…ad as measured on a PS5

RTP_LOOKUP threw for every thread made with the sce attributes, which
allow only SCHED_FIFO and SCHED_RR, since the rtprio mapping was
unmeasured. In a payload process on a PS5 (firmware 12.70) the lookup
reports type 10 for SCHED_FIFO and 2 for SCHED_RR with prio equal to the
scheduling priority, for the calling thread and for another live thread
by its id; an unknown id fails with ESRCH, and so did function 2. Report
that, and keep RTP_SET throwing for real-time and other threads, where no
accepted value was measured.
@ionut27001
ionut27001 force-pushed the fix/libkernel-rtprio-thread-lookup branch from da00182 to 4f004b0 Compare October 19, 2026 11:04
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

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 3986 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 4563 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 6149 docs/dev/debt/libkernel.md
PR 6830 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 7509 docs/dev/debt/libkernel.md
PR 7511 docs/dev/debt/libkernel.md
PR 8010 docs/dev/debt/libkernel.md
PR 8592 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 8605 docs/dev/debt/libkernel.md
PR 9133 docs/dev/debt/libkernel.md
PR 9160 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9284 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9293 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9297 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9302 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9378 docs/dev/debt/libkernel.md
PR 9447 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp
PR 9499 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9509 docs/dev/debt/libkernel.md
PR 9557 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9561 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9566 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9575 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9669 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9693 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9823 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp
PR 9947 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10061 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
docs/dev/debt/libkernel.md
PR 10350 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md

@fogydes fogydes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff, hardware probe evidence, and test fixtures:

  • Author provides direct hardware oracle logs (p79_libkernel on firmware 12.70) establishing that rtprio_thread RTP_LOOKUP returns type 10 (RTP_PRIO_FIFO) for SCHED_FIFO threads and type 2 (RTP_PRIO_REALTIME) for SCHED_RR threads with priority values in the 256–767 range, while an unrecognized function returns ESRCH (3) rather than FreeBSD's EINVAL.
  • Pthread/Posix/Thread.cpp and Pthread/src/Thread.cpp: GetLiveGuestThreadSched_nid_no_patch queries live thread scheduling state cleanly under the registry lock, enabling lookups across threads by LWP ID.
  • GuestRtprioThread.cpp: Covers self-lookups, target LWP lookups across FIFO/RR priorities, joined-thread lifecycle error assertions (ESRCH), null pointer guards (EFAULT), and verifies that RTP_SET continues throwing.
  • CMake configuration correctly includes configure_windows_unwind and the Windows DLL search path modification.
  • Zero comments added in code; Conventional Commits title; debt documentation in docs/dev/debt/libkernel.md updated with measured values.

AI-assisted: yes

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@DavidSamir

Copy link
Copy Markdown
Contributor

Morrowind (PPSA99630, the morrowind-ps5 catalog release) reaches the set half of rtprio_thread. I ran it on Windows with OpenMW's public-domain game template staged as its data (template.omwgame and the_hub.omwaddon from gitlab.com/OpenMW/example-suite, in place of the commercial files).

A local trace of the arguments shows one call before it stops, on main and with this PR's head merged:

rtprio_thread(function=1 (RTP_SET), lwpid=0, {type=4 (RTP_PRIO_IDLE), prio=31}) on a thread whose policy is 1 (SCHED_FIFO)

It then throws rtprio_thread: a guest thread's real-time class not implemented. Your p79 log measures RTP_SET only with type 2, where every thread class gets EINVAL and keeps its priority. The console's answer for type 4 with priority 31 would settle this call. If you can add that case to the probe, I can run the title against the result.

AI-assisted: yes

@ntamas94

Copy link
Copy Markdown
Contributor

Console rows that overlap the attribute part of p79, measured on a PS4 Pro (firmware 10.71, 10.710.001) with a user-mode homebrew PRX loaded by a small watcher app; one line per call as function[label] | arguments | return | errno | output. rtprio_thread itself was not measured.

scePthreadAttrSetschedpolicy[fifo] | &$attr, 1 | 0x00000000 | - |
scePthreadAttrSetschedpolicy[rr] | &$attr, 3 | 0x00000000 | - |
scePthreadAttrSetschedpolicy[other] | &$attr, 2 | 0x8002002d | - |
scePthreadAttrSetschedpolicy[0] | &$attr, 0 | 0x8002002d | - |
scePthreadAttrSetschedpolicy[99] | &$attr, 99 | 0x8002002d | - |
scePthreadAttrSetschedparam[prio256] | &$attr, buf0:4:00010000 | 0x00000000 | - |
scePthreadAttrSetschedparam[prio700] | &$attr, buf0:4:bc020000 | 0x00000000 | - |
scePthreadAttrSetschedparam[prio767] | &$attr, buf0:4:ff020000 | 0x00000000 | - |
scePthreadAttrSetschedparam[prio255] | &$attr, buf0:4:ff000000 | 0x8002002d | - |
scePthreadAttrSetschedparam[prio768] | &$attr, buf0:4:00030000 | 0x8002002d | - |
scePthreadAttrSetschedparam[prio0] | &$attr, buf0:4:00000000 | 0x8002002d | - |
scePthreadAttrSetschedparam[prio-1] | &$attr, buf0:4:ffffffff | 0x8002002d | - |
scePthreadGetschedparam | (void *)$self, buf0:4, buf1:4 | 0x00000000 | - | buf0=01000000 buf1=bc020000

The PS4 matches the PS5 log on these points: only SCHED_FIFO (1) and SCHED_RR (3) are accepted for an attribute, SCHED_OTHER (2) answers 0x8002002d as in your other700 line, the priority range is 256..767, and the main thread reports policy 1 with priority 700.

@adriadam10
adriadam10 merged commit 137a8fa into boykopovar:main Oct 24, 2026
11 of 12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked against current main (3fcb5e4): the change merges cleanly with the new libkernel CMakeLists entries and the Pthread changes, and none of the lines it touches moved. The members it uses are present, the RTP_LOOKUP types and priorities match the p79 console log, the debt entry describes what is measured, and both tests fail on main; RTP_SET still throws for real-time and other threads, as the entry states. Merged.

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.

5 participants