feat(libkernel): implement pthread_setaffinity_np #4514

Merged
kallmek3nny merged 1 commit from upstream-pr/4514 into main 2026-10-13 21:20:34 +00:00
kallmek3nny commented 2026-10-12 14:05:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kallmek3nny on 2026-10-12T14:05:15Z.


What

Carries screamm's standalone pthread_setaffinity_np commit from #4463 unchanged, preserving the original commit and authorship.

The implementation follows the FreeBSD-style affinity behavior described and tested in #4463: validate another thread before the cpuset size, require the 32-byte guest cpuset_t, reject a null set, clip the requested mask to sceKernelGetAvailableCpumask(), reject an empty result, and store the affinity through the existing guest-thread path. The accompanying guest_available_cpumask coverage exercises the caller, another live thread, unavailable bits, invalid sizes/pointers, unknown threads, and joined threads.

This addresses the pthread_setaffinity_np half of #4463. The sys_siglist / sys_nsig half is already carried separately in #4469.

Tested

Not rerun locally in this carry checkout. The original author reports Windows 11 / WinLibs GCC 15.2.0 Release testing with guest_available_cpumask 3/3, the non-GPU suite 607/607, tools/check_conventions.py --base main, and git diff --check passing; details are in #4463.

GitHub's PR workflows passed on the unchanged carried commit before the branch sync. The branch now merge-syncs upstream main at 8fa5cc486687471840d232e18d58dbdb2a68a660 while preserving screamm's original commit 018524d5295de79e174494286b620a2d8d7d8d30 unchanged in history.

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; no new silent stub is added
  • No notes, investigation .md files or images added to the repository
  • No third-party code added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PS5CEMU-HAR after #3787
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4830557956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4514). Originally posted by [kallmek3nny](https://github.com/kallmek3nny) on 2026-10-12T14:05:15Z. --- ### What Carries screamm's standalone `pthread_setaffinity_np` commit from #4463 unchanged, preserving the original commit and authorship. The implementation follows the FreeBSD-style affinity behavior described and tested in #4463: validate another thread before the cpuset size, require the 32-byte guest `cpuset_t`, reject a null set, clip the requested mask to `sceKernelGetAvailableCpumask()`, reject an empty result, and store the affinity through the existing guest-thread path. The accompanying `guest_available_cpumask` coverage exercises the caller, another live thread, unavailable bits, invalid sizes/pointers, unknown threads, and joined threads. This addresses the `pthread_setaffinity_np` half of #4463. The `sys_siglist` / `sys_nsig` half is already carried separately in #4469. ### Tested Not rerun locally in this carry checkout. The original author reports Windows 11 / WinLibs GCC 15.2.0 Release testing with `guest_available_cpumask` 3/3, the non-GPU suite 607/607, `tools/check_conventions.py --base main`, and `git diff --check` passing; details are in #4463. GitHub's PR workflows passed on the unchanged carried commit before the branch sync. The branch now merge-syncs upstream `main` at `8fa5cc486687471840d232e18d58dbdb2a68a660` while preserving screamm's original commit `018524d5295de79e174494286b620a2d8d7d8d30` unchanged in history. ### 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 - [x] Unimplemented paths throw; no new silent stub is added - [x] No notes, investigation `.md` files or images added to the repository - [x] No third-party code added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PS5CEMU-HAR after #3787 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-12 14:06:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T14:06:23Z.


Progress report (8fa5cc4 → dee2b0e)

📈 System libraries: 86.34% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel pthread_setaffinity_np_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125915846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4514#issuecomment-6125915846). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T14:06:23Z. --- <!-- progress-report --> ### Progress report (8fa5cc4 → dee2b0e) 📈 **System libraries**: 86.34% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `pthread_setaffinity_np_nid_postfix` | </details>
LeandroLP23 commented 2026-10-12 14:29:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T14:29:37Z.


I ran the carried commit 018524d52 locally, since the PR body says it wasn't rerun. I'd prepared the same carry, so I'll leave it to this PR. Windows 11 (26300), WinLibs GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON, with the commit merged onto main c6efe068a.

Tests

  • guest_available_cpumask: 3/3.
  • ctest -E '^agc_' -j 4: 533/533. The change doesn't touch AGC, so the GPU tests weren't run.
  • Mutation checks, each change made only inside pthread_setaffinity_np; each one makes guest_available_cpumask fail:
    • drop the clip to sceKernelGetAvailableCpumask();
    • drop the ERANGE size check;
    • drop the ESRCH live-thread check.
  • Fork CI on the commit (run): Linux 956/957, Windows 950/951, the three relinker jobs 128/129, 123/124 and 119/120. The one failure in every job is conventions_ci_gate, because my fork runs the old build.yml without file filters. It is not this change.

Title. PS5CEMU-HAR (PPSA99360, catalog 3.5.0), relinked with --windows --trap-sdk-syscall-stubs. Each row adds one change onto the row above:

Build Stop
main unresolved ELF import avvJ3J0H0EY from libkernel.prx (sceKernelJitCreateSharedMemory, #3787)
+ #3787 (its two File/src conflicts with main resolved by keeping both sides) unresolved ELF import 5KWrg7-ZqvE from libkernel.prx (pthread_setaffinity_np)
+ this commit unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx (swscanf, #4467)
+ #4467 unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx (__umodti3, #4462)

So this PR moves the title past pthread_setaffinity_np once #3787 is in. The checklist could say Depends on: #3787 and Unblocks: PPSA99360. sys_siglist/sys_nsig (#4469) are not a stop for this title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126316145 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4514#issuecomment-6126316145). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-12T14:29:37Z. --- I ran the carried commit `018524d52` locally, since the PR body says it wasn't rerun. I'd prepared the same carry, so I'll leave it to this PR. Windows 11 (26300), WinLibs GCC 15.2.0, Ninja, Release, `BUILD_TESTING=ON`, with the commit merged onto `main` `c6efe068a`. **Tests** - `guest_available_cpumask`: 3/3. - `ctest -E '^agc_' -j 4`: 533/533. The change doesn't touch AGC, so the GPU tests weren't run. - Mutation checks, each change made only inside `pthread_setaffinity_np`; each one makes `guest_available_cpumask` fail: - drop the clip to `sceKernelGetAvailableCpumask()`; - drop the `ERANGE` size check; - drop the `ESRCH` live-thread check. - Fork CI on the commit ([run](https://github.com/LeandroLP23/AnyPS5/actions/runs/38259198257)): Linux 956/957, Windows 950/951, the three relinker jobs 128/129, 123/124 and 119/120. The one failure in every job is `conventions_ci_gate`, because my fork runs the old `build.yml` without file filters. It is not this change. **Title.** PS5CEMU-HAR (PPSA99360, catalog 3.5.0), relinked with `--windows --trap-sdk-syscall-stubs`. Each row adds one change onto the row above: | Build | Stop | |---|---| | `main` | `unresolved ELF import avvJ3J0H0EY from libkernel.prx` (`sceKernelJitCreateSharedMemory`, #3787) | | + #3787 (its two `File/src` conflicts with `main` resolved by keeping both sides) | `unresolved ELF import 5KWrg7-ZqvE from libkernel.prx` (`pthread_setaffinity_np`) | | + this commit | `unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx` (`swscanf`, #4467) | | + #4467 | `unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx` (`__umodti3`, #4462) | So this PR moves the title past `pthread_setaffinity_np` once #3787 is in. The checklist could say `Depends on: #3787` and `Unblocks: PPSA99360`. `sys_siglist`/`sys_nsig` (#4469) are not a stop for this title. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-13 00:20:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:20:55Z.


Please rebase onto main and drop the merge commit (dee2b0e67); branches here carry none. It conflicts now in Pthread/include/Pthread.hpp, Pthread/src/Thread.cpp and the debt entry, which goes in docs/dev/debt/libkernel.md since the split. #3787 has merged, so this no longer waits on anything else.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135182999 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4514#issuecomment-6135182999). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:20:55Z. --- Please rebase onto main and drop the merge commit (`dee2b0e67`); branches here carry none. It conflicts now in `Pthread/include/Pthread.hpp`, `Pthread/src/Thread.cpp` and the debt entry, which goes in `docs/dev/debt/libkernel.md` since the split. #3787 has merged, so this no longer waits on anything else.
screamm commented 2026-10-13 10:55:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-13T10:55:47Z.


Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs; base main d379bfd0 with #5025 applied for the title runs (without it current main cannot load libkernel_sys.prx on Windows, #4877)): dee2b0e6 merged onto d379bfd0 (two trivial conflicts: main already has GuestThreadIsLive, identical to the PR's IsLiveGuestThread, so keep main's and rename the one call; the debt bullet moves to docs/dev/debt/libkernel.md after cpuset_getaffinity). The commit is my 018524d5 unchanged. guest_available_cpumask 3/3; suite 687/688 (only patched_libraries, main's #4877 failure); conventions and git diff --check pass.

PS5CEMU-HAR (PPSA99360, relinked with --trap-sdk-syscall-stubs): before FAIL: unresolved ELF import 5KWrg7-ZqvE from libkernel.prx; after FAIL: unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx (swscanf, #4467). Stacked with #4469 and #4467 the title runs the whole minute at PS5CEMU-HAR | FPS: 59.93 (3483), its launcher logging [ui] frames=3001 avg=16.68 ms.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143991685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4514#issuecomment-6143991685). Originally posted by [screamm](https://github.com/screamm) on 2026-10-13T10:55:47Z. --- Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`; base `main` `d379bfd0` with #5025 applied for the title runs (without it current `main` cannot load `libkernel_sys.prx` on Windows, #4877)): `dee2b0e6` merged onto `d379bfd0` (two trivial conflicts: `main` already has `GuestThreadIsLive`, identical to the PR's `IsLiveGuestThread`, so keep `main`'s and rename the one call; the debt bullet moves to `docs/dev/debt/libkernel.md` after `cpuset_getaffinity`). The commit is my `018524d5` unchanged. `guest_available_cpumask` 3/3; suite 687/688 (only `patched_libraries`, `main`'s #4877 failure); conventions and `git diff --check` pass. PS5CEMU-HAR (PPSA99360, relinked with `--trap-sdk-syscall-stubs`): before `FAIL: unresolved ELF import 5KWrg7-ZqvE from libkernel.prx`; after `FAIL: unresolved ELF import HNnWdT43ues from libSceLibcInternal.prx` (swscanf, #4467). Stacked with #4469 and #4467 the title runs the whole minute at `PS5CEMU-HAR | FPS: 59.93 (3483)`, its launcher logging `[ui] frames=3001 avg=16.68 ms`.
p3n1cillin commented 2026-10-13 14:38:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:38:37Z.


Title run with this PR: Windows 11, MinGW GCC 15.2.0 (WinLibs), Release, on main 3faa9cb40 merged with this PR and the other open PRs the catalog titles need; PS5CEMU-HAR (PPSA99360) from its catalog release, converted with --trap-sdk-syscall-stubs (it has a forbidden inline syscall otherwise), eboot.bin kept in app0.

  • With this PR, #4467 and #4469, tools/import_audit.py lists no absent import for PS5CEMU-HAR and it runs the whole 60 s with no exception.
  • This head conflicts with main: main added GuestThreadIsLive in Pthread.hpp/Thread.cpp, which does what this PR's IsLiveGuestThread does, so a rebase can drop the new helper and use main's; docs/dev/TechnicalDebt.md is now split into docs/dev/debt/<library>.md. For the run above I kept both helpers.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148069558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4514#issuecomment-6148069558). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T14:38:37Z. --- Title run with this PR: Windows 11, MinGW GCC 15.2.0 (WinLibs), Release, on `main` `3faa9cb40` merged with this PR and the other open PRs the catalog titles need; PS5CEMU-HAR (PPSA99360) from its catalog release, converted with `--trap-sdk-syscall-stubs` (it has a forbidden inline syscall otherwise), `eboot.bin` kept in `app0`. - With this PR, #4467 and #4469, `tools/import_audit.py` lists no absent import for PS5CEMU-HAR and it runs the whole 60 s with no exception. - This head conflicts with `main`: `main` added `GuestThreadIsLive` in `Pthread.hpp`/`Thread.cpp`, which does what this PR's `IsLiveGuestThread` does, so a rebase can drop the new helper and use `main`'s; `docs/dev/TechnicalDebt.md` is now split into `docs/dev/debt/<library>.md`. For the run above I kept both helpers. AI-assisted (Claude Code).
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!4514
No description provided.