feat(libkernel): support cpuset affinity by guest thread ID #6540
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6540"
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 JJenkx on 2026-10-15T19:25:37Z.
What
With
CPU_LEVEL_WHICH/CPU_WHICH_TID,cpuset_getaffinityandcpuset_setaffinitycurrently throw when the requested TID belongs to another live guest thread. Resolve that guest TID in the live-thread registry and read or update the selected thread's affinity. Lookup and access hold the registry lock so removal and release cannot pass between them; a thread that exits before the setter's final lookup returnsESRCH.The worker observes the new affinity,
sceKernelGetCurrentCpureports a CPU within it, and a subsequently created child inherits it. The calling thread's mask stays intact. Existing mask validation, process-wide operations and unsupported ROOT/CPUSET levels remain covered.Thread selection follows FreeBSD 11.4 cpuset_which and kern_cpuset_getaffinity/kern_cpuset_setaffinity. This expands the existing guest affinity model: affinity is recorded for guest CPU reporting and inheritance, not applied to host scheduler affinity. PS5 hardware behavior is unmeasured; the library debt entries record the remaining limits. No new exports or title/FPS gain is claimed.
Tested
Arch Linux, Ryzen 9 7950X, Release, bundled dependencies, main
44df21632125dbe3113a19173e7ebb879da53003.libsbuild passed. Seven checks passed, zero skips:guest_available_cpumask,guest_current_cpu,guest_pthread_start,guest_thread_cpu_clock,guest_pthread_join_self,guest_pthread_destructor_lifetime,guest_pthread_attr.ESRCHwith an untouched output after join. Existing self/process, invalid argument and unsupported-level checks remain.cpuset_getaffinity other than the calling thread or process not implemented.60798920d5b6c0d174f72ad27b17f7d62806b9891b2c40f5d52b35161f78d452.External Windows validation
screamm’s independent report tests head
7777219eemerged onto main5d9dcc42d, using Windows11, Ryzen75700X, RTX4070 and MinGW GCC15.2. Runtime libraries build, and the seven affinity/thread checks pass three repetitions (21runs). Parent-source and no-op-setter negative controls fail; restoration passes. Their broader build still encounters main’s known MinGW64KiB-alignment AGC test issue. Reported load-related non-GPU test failures pass on serial reruns; this is not a new full-suite pass claimed here.Their diagnostic title runs reach only the calling-thread query path. No title exercises another-thread affinity, and the timed runs end by termination. No title unblock, ordinary-close stability or FPS improvement is established. These are contributor-reported Windows results, separate from our Linux checks above.
Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T20:24:06Z.
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.
main)docs/dev/debt/libkernel.mdL149-151core/libs/prx/libkernel/Pthread/Posix/Thread.cppL63-69, L76-80, L101-106, L119-120core/libs/prx/libkernel/Pthread/include/Pthread.hppL165core/libs/tests/GuestAvailableCpumask.cppL319-321docs/dev/debt/libkernel.mdL150-151Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/include/Pthread.hppcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestAvailableCpumask.cppcore/libs/prx/libkernel/Pthread/include/Pthread.hppcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/Posix/Thread.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/src/Thread.cppImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T11:10:48Z.
Windows run of head
7777219ee, merged alone ontomain5d9dcc42d(clean merge).alignasAGC test (#6452/#6478), andlibspasses. The only warning inPosix/Thread.cpp(rtprio_thread,-Wreturn-type) also appears onmain.--repeat until-fail:3, 21/21 runs:guest_available_cpumask,guest_current_cpu,guest_pthread_start,guest_thread_cpu_clock,guest_pthread_join_self,guest_pthread_destructor_lifetime,guest_pthread_attr.mainand the test kept, the test aborts withcpuset_getaffinity other than the calling thread or process not implemented.Require.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): the host was heavily loaded by other builds, so 19 tests timed out or aborted on the first pass. All 19 passed on serial reruns.guest_kqueue,guest_file_lock_processandguest_video_out_high_frame_ratepassed on the first rerun, and theconventions_function_bodiesshards andhardware_oracle_compareon the second.tools/check_conventions.py --base 5d9dcc42dandgit diff --checkpass. There are no new exports.Titles. In the relinked titles I have,
cpuset_getaffinityis imported by PPSA99002, PPSA99008 and PPSA99082, andcpuset_setaffinityby PPSA68091, PPSA97358, PPSA99002, PPSA99008 and PPSA99203. I ran all six for 45 s with a local diagnosticlibkernelthat logs these calls. Only OpenNOW PPSA99082 callscpuset_getaffinity, 6 times, all withlevel=3 which=1 id=-1(the calling thread). No title callscpuset_setaffinityin that window, and none passes another thread's TID, so the new path is not reached by any title here. The calling-thread path now goes through the registry lookup, so I ran before/after on PPSA99082, and on PPSA99008, which imports both. Each run was 130 s, with 2 alternating runs per side. Neither side has a stop line, and every run was killed at the time limit:mainr1 / r2PPSA99082's logs are the same on both sides apart from pointers and paths.
Not checked: Linux, PS5 hardware, and any title that sets or queries another thread's affinity (none available here). #6447 edits the same
cpuset_*lines inPosix/Thread.cpp.Written with Claude Code assistance (validation by a subagent, reviewed in this session).