feat(libkernel): implement cpuset_setaffinity for the calling thread or process #3323
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3323"
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 TheAggie on 2026-10-11T07:36:59Z.
What
Implements
cpuset_setaffinity(libkernel, NID0Ma-LQjv6So) for the calling thread and the calling process.XPSemu (PPSA97358, catalog ZIP sha256-checked) stops on it on
main5c7ceb07, now thatsceKernelGetAppInfo(#3056) is merged:The title calls it at
0xC7944Bascpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, 8, &mask). OnERANGEit retries with sizes 16 and 32. Any other failure takes its error path.The checks follow FreeBSD 11
sys_cpuset_setaffinity(sys/kern/kern_cpuset.c), in the same order:ERANGEoutside 8 to 32 bytes, the same rangecpuset_getaffinityalready uses.EFAULTwhen it is null.EINVAL.CPU_WHICH_TID, id -1): sets that thread's mask.CPU_WHICH_PID, id -1 orgetpid()): sets the mask of every guest thread that is alive.sceKernelGetAvailableCpumask. If nothing is left,EDEADLK.NotImplemented_nid_no_patch).FreeBSD gives the process one cpuset that later threads join. Here, a thread created after a process-level call still starts with its attribute's mask. That gap is listed in TechnicalDebt (Functional).
Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, on
main5c7ceb07.guest_available_cpumask: extended with a thread that:EINVALfor a nonzero high byte,ERANGEfor 4 and 33 bytes,EFAULTfor a null mask, andEDEADLKfor a mask with no available CPU;If the process path only sets the calling thread, the test fails.
Related tests:
guest_pthread*,guest_thread*andcpu_topologyall pass (18/18).XPSemu: with this PR, the next stop is
sigsetjmp(aRo9AhFUXcM).Not tested on Linux.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T07:37:19Z.
Progress report (
2bb78d2→bb4b938)📉 System libraries: 85.8% (-0.03%, +1 declared functions)
🆕 1 declared as stubs
cpuset_setaffinity_nid_postfixImported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:52:27Z.
Additional platform validation of standalone PR head
bb4b938e34b704aec4030945caa91bad73de1997(2026-10-11):Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.19 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
guest_thread_callback_abi,cpu_topology,guest_thread_atexit,guest_pthread_barrier,guest_thread_self,guest_pthread_getname,guest_pthread_attr,guest_pthread_mutexattr,guest_pthread_start,guest_pthread_stack,guest_thread_cpu_clock,guest_pthread_sem,guest_pthread_cancel,guest_pthread_cancel_recovery,guest_pthread_cancel_recovery_coarse,guest_pthread_rwlock,guest_pthread_key,guest_available_cpumask,guest_pthread_rename.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(guest_available_cpumask$|guest_pthread|guest_thread|cpu_topology$)".No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:57:13Z.
Checked the build and ctest on Linux (
guest_available_cpumaskpasses; without the change it doesn't link), the error order against FreeBSDkern_cpuset_setaffinity, and the TechnicalDebt entry (Functional, gap documented). Linux validation by @Mouhand-Kaddo also noted. Merging.