Skip to content

feat(libkernel): implement pthread_setaffinity_np - #4514

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
kallmek3nny:feat/libkernel-pthread-setaffinity
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
kallmek3nny:feat/libkernel-pthread-setaffinity

Conversation

@kallmek3nny

@kallmek3nny kallmek3nny commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(libkernel): implement the JIT shared memory calls #3787
  • AI-assisted: yes

@kallmek3nny
kallmek3nny marked this pull request as draft October 12, 2026 14:05
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Progress report (8fa5cc4 → dee2b0e)

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

✅ 1 implemented
Library Name
libkernel pthread_setaffinity_np_nid_postfix

@kallmek3nny
kallmek3nny marked this pull request as ready for review October 12, 2026 14:10
@kallmek3nny
kallmek3nny marked this pull request as draft October 12, 2026 14:11
@kallmek3nny
kallmek3nny marked this pull request as ready for review October 12, 2026 14:23
@LeandroLP23

Copy link
Copy Markdown
Contributor

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)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

screamm commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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.

danielradosa added a commit to danielradosa/AnyPS5 that referenced this pull request Oct 13, 2026
Uses the existing GuestThreadIsLive, rejects masks outside sceKernelGetAvailableCpumask (bits 64-255 included) or empty with EDEADLK per FreeBSD cpuset_shadow instead of clipping, stores another thread's affinity under the registry lock; debt entry moved to docs/dev/debt/libkernel.md.
@p3n1cillin

Copy link
Copy Markdown

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, feat(libc): implement swscanf #4467 and feat(libSceLibcInternal): export sys_siglist and sys_nsig #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).

PS5CEMU-HAR (PPSA99360, ps5-payload-dev build, relinks with
--trap-sdk-syscall-stubs) imports pthread_setaffinity_np (5KWrg7-ZqvE)
from libkernel.prx. babyhuey's run with boykopovar#3787 merged onto main e7c70a2
(PR boykopovar#3787, 2026-10-12T10:54:44Z) stops at it:

  Windows: FAIL: unresolved ELF import 5KWrg7-ZqvE (pthread_setaffinity_np) from libkernel.prx
  Linux: undefined symbol: 5KWrg7-ZqvE (pthread_setaffinity_np)

It follows FreeBSD 11.4 libthr thr_affinity.c (8c639945) over
kern_cpuset_setaffinity: another thread is looked up first (EINVAL for
null, ESRCH when unknown or finished, as _thr_find_thread without dead
threads), a size other than the 32-byte cpuset_t returns ERANGE, the
mask is clipped to sceKernelGetAvailableCpumask and an empty result
returns EDEADLK, as cpuset_setaffinity does. The affinity is stored on
the guest thread through scePthreadSetaffinity, for the caller and for
any live guest thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions
github-actions Bot force-pushed the feat/libkernel-pthread-setaffinity branch from 87283af to 74c3fb6 Compare October 13, 2026 16:39
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@oneandonlydean
oneandonlydean merged commit ea2b2d3 into boykopovar:main Oct 13, 2026
7 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.

5 participants