Skip to content

feat(libkernel): implement setpriority - #5545

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Nixitov:feat/setpriority
Oct 14, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Nixitov:feat/setpriority

Conversation

@Nixitov

@Nixitov Nixitov commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

What

Implement setpriority in libkernel next to the getpriority added in #4374.

PPSA50011 imports it and stops at start-up on main (its stop moved here once getpriority merged):

FAIL: unresolved ELF import TUC9xC1YQjs from libkernel.prx

Behaviour follows FreeBSD's sys_setpriority for the only guest process: PRIO_PROCESS, PRIO_PGRP and PRIO_USER with 0 or the guest's own pid (its user id 0 for PRIO_USER) return 0, any other id fails with ESRCH and any other which with EINVAL. 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, so getpriority keeps reporting 0. That is recorded in docs/dev/debt/libkernel.md.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.

  • guest_sched_priority is extended: setpriority accepts the same target ids as getpriority, leaves errno unchanged on success and rejects the same ids (ESRCH) and which (EINVAL); it passes.
  • PPSA50011 (an Xbox 360 emulator port), eboot.bin unwrapped and relinked with the built relinker --windows: on main it stops at TUC9xC1YQjs (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/main passes.

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
  • Unblocks: PPSA50011
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Progress report (6d03255 → afc04c7)

➖ System libraries: 88.19% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel setpriority_nid_postfix

@github-actions github-actions Bot mentioned this pull request Oct 13, 2026
10 tasks done
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#5611 docs/dev/debt/libkernel.md L187

@CnRJay CnRJay 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.

The target-id and which checks mirror getpriority, which is good. The value itself, though, is accepted and dropped. setpriority(PRIO_PROCESS, 0, 10) returns 0, and a following getpriority(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:

  • Keep one guest nice value (there is only one guest process). setpriority clamps niceval to [PRIO_MIN, PRIO_MAX] (-20..20) as FreeBSD's donice does and stores it, and getpriority returns it. On FreeBSD, lowering the value below the current one needs privilege (EACCES otherwise). Whether a title process on the console holds that privilege is unverified, so the lowering case could throw until it's known.
  • Or accept only niceval == 0 (the value getpriority already reports) and throw NotImplemented for 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.

@Nixitov

Nixitov commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Same-file overlaps only, no shared logic:

Whoever lands second needs a small rebase; nothing here depends on either, and this does not change their behaviour.

AI-assisted: yes

@Nixitov

Nixitov commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — fixed following your first option. There is now one guest nice value: setpriority clamps niceval to PRIO_MIN–PRIO_MAX (-20..20, as FreeBSD's donice does) and stores it, and getpriority returns 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 and which checks 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 is setpriority, 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

@Nixitov
Nixitov force-pushed the feat/setpriority branch 2 times, most recently from eae354a to 34096bd Compare October 14, 2026 01:50
PPSA50011 imports setpriority and stops at start-up once getpriority is implemented. Accept PRIO_PROCESS, PRIO_PGRP and PRIO_USER for the guest's own process and fail with ESRCH for any other id and EINVAL for any other which, leaving errno unchanged on success like FreeBSD's libc; the value is not applied, since the guest nice is not the host's scheduling class.
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the which/id validation against getpriority, the -20..20 clamp against FreeBSD's donice, and the set/get round trip. guest_sched_priority passes in the build + ctest of the PR merged onto main, and the test no longer links without the change. The PR body still says getpriority keeps reporting 0; the code and the debt entry are right. Merging.

@adriadam10
adriadam10 merged commit 4e0cb18 into boykopovar:main Oct 14, 2026
8 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.

3 participants