feat(libkernel): implement setpriority #5545
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5545"
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 Nixitov on 2026-10-13T23:20:30Z.
What
Implement
setpriorityin libkernel next to thegetpriorityadded in #4374.PPSA50011 imports it and stops at start-up on
main(its stop moved here oncegetprioritymerged):Behaviour follows FreeBSD's
sys_setpriorityfor the only guest process:PRIO_PROCESS,PRIO_PGRPandPRIO_USERwith 0 or the guest's own pid (its user id 0 forPRIO_USER) return 0, any other id fails withESRCHand any otherwhichwithEINVAL. errno is left unchanged on success, as in FreeBSD's libc. The value is not applied: the guest nice is not the host's scheduling class, sogetprioritykeeps reporting 0. That is recorded indocs/dev/debt/libkernel.md.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.
guest_sched_priorityis extended:setpriorityaccepts the same target ids asgetpriority, leaves errno unchanged on success and rejects the same ids (ESRCH) andwhich(EINVAL); it passes.eboot.binunwrapped and relinked with the built relinker--windows: onmainit stops atTUC9xC1YQjs(setpriority); with this change it resolves it and runs the title's own boot ([X360] BOOT main entered), then stops later on an unrelated guest-arena mapping error, not a missing import.python tools/check_conventions.py --base origin/mainpasses.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 github-actions[bot] on 2026-10-13T23:21:11Z.
Progress report (
6d03255→afc04c7)➖ System libraries: 88.19% (+0.0%, +1 implemented functions)
✅ 1 implemented
setpriority_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T23:30:05Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL187Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:13:41Z.
Review: COMMENTED
The target-id and
whichchecks mirrorgetpriority, which is good. The value itself, though, is accepted and dropped.setpriority(PRIO_PROCESS, 0, 10)returns 0, and a followinggetpriority(PRIO_PROCESS, 0)still reports 0. So the pair is observably inconsistent, which the repository's exact-or-throw rule doesn't allow. It is effectively a silent stub, and those are only allowed for UI-only effects.Not changing the host scheduling is fine. The guest nice value doesn't need to reach the host. What's missing is the guest-visible state. Two options that stay exact:
setpriorityclampsnicevalto[PRIO_MIN, PRIO_MAX](-20..20) as FreeBSD'sdonicedoes and stores it, andgetpriorityreturns it. On FreeBSD, lowering the value below the current one needs privilege (EACCESotherwise). Whether a title process on the console holds that privilege is unverified, so the lowering case could throw until it's known.niceval == 0(the valuegetpriorityalready reports) and throwNotImplementedfor anything else, with the value PPSA50011 actually passes noted in the debt entry.Which value does PPSA50011 pass? If it's 0, the second option unblocks it with no new state.
Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-14T01:26:12Z.
Same-file overlaps only, no shared logic:
getdtablesizeincore/libs/prx/libkernel/System/src/Process.cppnext to where this addssetpriority.docs/dev/debt/libkernel.md.Whoever lands second needs a small rebase; nothing here depends on either, and this does not change their behaviour.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-14T01:35:36Z.
Thanks — fixed following your first option. There is now one guest nice value:
setpriorityclampsnicevaltoPRIO_MIN–PRIO_MAX(-20..20, as FreeBSD'sdonicedoes) and stores it, andgetpriorityreturns it, so a succeeding set is observable through the getter and nothing is dropped. The host scheduling class is still left alone. The target-id andwhichchecks are unchanged, and the debt entry now records that whether a title process may lower the value without privilege is unverified.I kept the general model rather than accepting only
niceval == 0: this machine can't show what PPSA50011 passes (its stop issetpriority, so it never reaches the call before loading), and the stored value is consistent for any caller. The test now checks the round trip and the clamp (10→10,99→20,-99→-20).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:58:29Z.
Checked the
which/id validation againstgetpriority, the -20..20 clamp against FreeBSD'sdonice, and the set/get round trip.guest_sched_prioritypasses in the build + ctest of the PR merged onto main, and the test no longer links without the change. The PR body still saysgetprioritykeeps reporting 0; the code and the debt entry are right. Merging.