feat(libkernel): implement sched_getparam, sched_getscheduler and sched_setparam for the calling thread #9187
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9187"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by slider on 2026-10-21T14:43:01Z.
What
Implements
sched_getparam,sched_getschedulerandsched_setparamin libkernel for the calling thread (pid 0), following FreeBSD 11.4'ssys/kern/p1003_1b.c:sched_getparam(0, param)andsched_getscheduler(0)report the calling thread's priority and policy, the valuespthread_getschedparamreports. They use the 256-767 scale that the PS5-measuredsched_get_priority_maxandsched_get_priority_minreport.sched_setparam(0, param)keeps the thread's policy and sets its priority throughscePthreadSetprio, as FreeBSD'sksched_setparamkeeps the policy and callsksched_setscheduler. It accepts the priority rangespthread_setschedparamaccepts.sched_setparamcopies the parameter in first, so a null pointer givesEFAULTbefore the pid is checked.ESRCH, asgetpriorityalready does here.NotImplementedplaceholders fromlibkernel_sys/Export.Discovery.cpp(duplicate-export rule). Imports bind by NID.docs/dev/debt/libkernel.md), each case throwing instead of guessing:EPERM, the PS5's pthread layerEINVAL, and the console's answer is unverified.Left out on purpose:
sched_setscheduler: FreeBSD requiresPRIV_SCHED_SET, and whether a title holds it on the console is unverified.sched_rr_get_interval: the value depends on the console's scheduler tuning.Merges cleanly (
git merge-tree) with the open boykopovar/AnyPS5#8373, boykopovar/AnyPS5#8890, boykopovar/AnyPS5#8987, boykopovar/AnyPS5#9141 and boykopovar/AnyPS5#9167, which edit the same files.Tested
Linux (Ubuntu 24.04, GCC 13.3, Release):
guest_sched_paramspasses. It covers agreement withpthread_getschedparam, the policy kept acrosssched_setparam, and both priority ranges and their edges. It also checks that a change made by another thread does not affect the caller,ESRCHfor foreign pids,EFAULTand its order, and the throws.guest_pthread_schedparamandguest_kernel_syspass.tools/check_conventions.py --base origin/mainpasses.Windows: the changed sources and the test pass a syntax-only check with MinGW-w64 GCC 13 (not the supported 15.2); not built or run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T04:12:32Z.
Review: COMMENTED
Checked against main
6ef5a1c4cand FreeBSD 11.4sys/kern/ksched.c/p1003_1b.c:sched_setparamaccepts 896-959 (Pthread/Posix/Thread.cpp:243reuses the pthread-layerAcceptsSchedParamfrom line 48). In FreeBSD,ksched_setparamgoes toksched_setscheduler, which for FIFO/RR accepts onlyP1B_PRIO_MIN..P1B_PRIO_MAXand returns EPERM otherwise (ksched.c:178-188). Those are the constantsksched_get_priority_min/maxreport, and main'ssched_get_priority_maxreturns 767 (System/src/Process.cpp:474-479). Sosched_setparam(0, {896})reporting success contradicts both the source and the PR's own debt text ("on the 256-767 scale ofsched_get_priority_max").sched_setparambysched_get_priority_min_nid_postfix(policy)/sched_get_priority_max_nid_postfix(policy)and throw for 896-959 like 255/768, since the console's answer is unverified. Then move 896 and 959 inGuestSchedParams.cpp:55from the success loop to the throw loop.rtprio_threaddebt entry treats the pthread-priority-to-kernel mapping as unmeasured. By the same reasoning,sched_getparamfor a thread at 896-959 (set viapthread_setschedparam) reports a value outside the kernel range, and could throw rather than pass it through.sched_setparam, pid-first in the getters, ESRCH for foreign pids consistent withgetpriority, the throw for the own pid (FIRST_THREAD_IN_PROCis not tracked), and the policy kept acrosssched_setparam.BUILD_TESTING=ONbuild) merged onto main6ef5a1c4c; the only failing step is the existingImageArrayWindowPastLayerLimit.cppalignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T07:49:26Z.
Review: CHANGES_REQUESTED
I independently reviewed this head and agree with the priority-range concern already raised above. The implementation's
AcceptsSchedParamaccepts 896–959, andGuestSchedParams.cppasserts thatsched_setparam(0,...)succeeds for 896 and 959. On currentmain,sched_get_priority_min/maxreports 256–767. The PR describes that same 256–767 scale, while FreeBSD 11.4'sksched_setparamvalidates throughksched_setschedulerand rejects priorities outside the reported policy range. Please either provide console evidence that establishes 896–959 as valid for this API and align the documented range, or keep those values out of the success path (and test them as unverified/rejected). The separate pthread API accepting a value does not establish thatsched_setparammust accept it. I builtguest_sched_params_testsfrom this head in Release mode successfully. I then ranctest --test-dir build -R '^guest_sched_params$' --output-on-failure; it aborts before test assertions because this host's Intel Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, and FMA required by the project. The hosted product build/test jobs are also skipped, so there is no passing execution of this PR's focused test available in the checks I could run. One repository item also needs attention before this is merge-ready: this branch is 596 commits behind currentmain. Please update it and rerun the overlap/conventions checks; the existing overlap report still lists closed #9369 and should be refreshed. I did not approve because the success-path range remains unsupported and the required test has not executed on a capable host.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by slider on 2026-10-22T09:16:45Z.
Thanks @harisibrar1 and @MarcZX10. In https://github.com/boykopovar/AnyPS5/pull/9187/commits/679f42be111946d2ad70993a82caf840341ee31f:
sched_setparamnow accepts onlysched_get_priority_min..sched_get_priority_max(256-767) and throws outside it, 896-959 included, where FreeBSD's ksched answers EPERM.sched_getparamthrows for a threadpthread_setschedparamput in 896-959, rather than reporting a value outside the reported scale.guest_sched_params,guest_pthread_schedparamandguest_kernel_syspass on Linux; the changed files pass a MinGW syntax check. I don't have a title that calls these, soUnblocksstays none. Fine with it waiting behind title work per #5239.