feat(libkernel): implement setpriority #5545

Merged
Nixitov merged 1 commit from upstream-pr/5545 into main 2026-10-14 12:46:16 +00:00
Nixitov commented 2026-10-13 23:20:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-13T23:20:30Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4850722542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-13T23:20:30Z. --- ### 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA50011 - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 23:21:11 +00:00 (Migrated from github.com)

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
Library Name
libkernel setpriority_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157282155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545#issuecomment-6157282155). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T23:21:11Z. --- <!-- progress-report --> ### Progress report (6d03255 → afc04c7) ➖ **System libraries**: 88.19% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `setpriority_nid_postfix` | </details>
github-actions[bot] commented 2026-10-13 23:30:05 +00:00 (Migrated from github.com)

Imported 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.

Pull request Conflicting files (lines on main) Same exports Same new files
#5611 docs/dev/debt/libkernel.md L187
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157393655 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545#issuecomment-6157393655). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T23:30:05Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/fce397b509d4769c2d11833cd6d7cbfa6a3cf1bf/docs/dev/debt/libkernel.md#L187) | | |
CnRJay commented 2026-10-14 01:13:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:13:41Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511929628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545#pullrequestreview-5511929628). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T01:13:41Z. **Review:** COMMENTED --- 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 commented 2026-10-14 01:26:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-14T01:26:12Z.


Same-file overlaps only, no shared logic:

  • #5061 adds getdtablesize in core/libs/prx/libkernel/System/src/Process.cpp next to where this adds setpriority.
  • #5611 adds a technical-debt entry near ours in 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158806195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545#issuecomment-6158806195). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-14T01:26:12Z. --- Same-file overlaps only, no shared logic: - **#5061** adds `getdtablesize` in `core/libs/prx/libkernel/System/src/Process.cpp` next to where this adds `setpriority`. - **#5611** adds a technical-debt entry near ours in `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
Nixitov commented 2026-10-14 01:35:36 +00:00 (Migrated from github.com)

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: 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158916494 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545#issuecomment-6158916494). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-14T01:35:36Z. --- 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
adriadam10 commented 2026-10-14 11:58:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:58:29Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167809036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5545#issuecomment-6167809036). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:58:29Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5545
No description provided.