fix(libkernel): take the console's 8- to 16-byte sets in pthread_setaffinity_np #15219
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15219"
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 EagleBearerYS on 2026-11-02T21:08:07Z.
What
pthread_setaffinity_npfollows the set sizes measured on a PS5:ERANGE;Before, only FreeBSD's 32-byte
cpuset_twas accepted, so the console's 8- and 16-byte sets returnedERANGE, and a 32-byte set succeeded where the console returnsERANGE.Sources:
ERANGE.cpuset_setaffinity(comment on #9156): any size from 8 to 16 bytes is accepted, andERANGEis returned below 8 and from 24 (0, 1, 4, 7, 8, 9, 12, 16, 24, 32, 64 and 128 tried). FreeBSD 11.4's libthr passes the setter's size straight to that call.pthread_getaffinity_npgot the same rule in #14039, where @B-Howell pointed out that the setter had been measured too (comment).Still throws: 17 to 23 bytes, which weren't measured, as in the getter.
Not measured on a PS5: a set longer than 8 bytes with a bit set past the first 8 bytes returns
EINVAL, askern_cpuset_setaffinitydoes, and ascpuset_setaffinityalready does here. The test doesn't assert it.Debt: this builds on #15179, which gives these sizes their own entry in
docs/dev/debt/libkernel.md. It takespthread_setaffinity_npout of that entry, which now coverscpuset_getaffinityandcpuset_setaffinityonly, and rewrites the setter's own entry: the gap first, the sources, and the unmeasuredEINVAL.Overlap: #7135 (AlexOfTheForest) and #14885 (@oneandonlydean) change
cpuset_setaffinity's levels and ids in the same file. Neither touches the setter's size check.Thread.cppmerges cleanly with #14885.docs/dev/debt/libkernel.md, #14885 rewrites thecpuset_setaffinityandcpuset_getaffinityentries just above the setter's entry, which this PR rewrites, so the two touch adjacent lines. Whichever merges second keeps #14885's two entries and this PR's setter entry.mainitself incpuset_getaffinity, not in the setter.Claim check (open PRs, and PRs closed or merged since 10-19): no other PR changes
pthread_setaffinity_np's set sizes. #14039 (merged) did the getter, and #15179 (open, this PR's base) only corrects the debt entry.Tested
guest_available_cpumask's setter cases now use the measured sizes:ERANGEand change nothing;EDEADLKandEFAULTcases now use 8 or 16 bytes instead of 32;EINVALandESRCHthread cases are unchanged, since a thread error comes before the size check.GitHub's runners (run),
guest_available_cpumask:Thread.cppwith the new test, 3 runsbf4f7b7239, a merge ofmaind1ae628bc2. The only conflict was indocs/dev/debt/libkernel.md: #14885 rewrote thecpuset_setaffinityandcpuset_getaffinityentries next to this PR'spthread_setaffinity_npentry, and the merge keepsmain's two entries and this PR's.Thread.cppand the test merge without a conflict, since #14885 changes thecpuset_*functions and this PR the setter, and this PR's diff overmainis unchanged. On GitHub's runners (run),guest_available_cpumaskpasses 10 of 10 on Linux and on Windows, and fails on both withmain's implementation. The libc and libkernel suites pass: 297 and 321 run on Linux, 324 and 342 on Windows, 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.Checks:
tools/check_conventions.py: all passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-03T23:08:12Z.
Review: APPROVED
@EagleBearerYS approved at
bf4f7b7239.What I ran: this head merged onto
main(merge0504cfbc3b; onlydocs/dev/debt/libkernel.mdneeded git's auto-merge) on Windows 11 with WinLibs GCC, Release.guest_available_cpumaskpasses (1 of 1).main'score/libs/prx/libkernel/Pthread/Posix/Thread.cppput back and this branch's test kept, the test aborts (1 of 1 failed). So the new size cases check the change.Read in the diff:
EINVALfor a null thread,ESRCH) still come before the size check, as the PR says.ERANGE;Thread.cpp:362); those sizes weren't in the sweep;pthread_getaffinity_npand the setter now shareGUEST_AFFINITY_ERANGE_BYTES.GUEST_CPUSET_BYTESis still used by the getter's buffer atThread.cpp:349.EDEADLKandEFAULTcases moved to 8- and 16-byte sets.outside's second word is now 0 inGuestAvailableCpumask.cpp; with a nonzero second word its 16-byte call would hit the newEINVALbeforeEDEADLK.EINVALfor a bit past the first 8 bytes isn't asserted, and the debt entry says it's unmeasured. That matches the description. If a console run ever settles it, a row with a nonzero byte at offset 8 to 15 and a 16-byte size would cover it.The debt change reads right:
pthread_setaffinity_npleaves the shared size entry, and its own entry now states the gap first (17 to 23 bytes throw, the unmeasuredEINVAL).