libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel.
authorDmitry Chagin <dchagin@FreeBSD.org>
Sun, 29 Jan 2023 12:35:18 +0000 (15:35 +0300)
committerDmitry Chagin <dchagin@FreeBSD.org>
Sun, 29 Jan 2023 12:35:18 +0000 (15:35 +0300)
commit01f74ccd5a0d1a444703e931339709c7de5296b5
tree61d6a4150b2b068858ad651853462d2a1bc58f96
parent02f7670ed243498aea96150962c2c9916bab7c98
libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel.

Since f35093f8 semantics of a thread affinity functions is changed to be a
compatible with Linux:

In case of getaffinity(), the minimum cpuset_t size that the kernel permits is
the maximum CPU id, present in the system, / NBBY bytes, the maximum size is not
limited.
In case of setaffinity(), the kernel does not limit the size of the user-provided
cpuset_t, internally using only the meaningful part of the set, where the upper
bound is the maximum CPU id, present in the system, no larger than the size of
the kernel cpuset_t.

To match pthread_attr_[g|s]etaffinity_np checks of the user-provided cpusets to
the kernel behavior export the minimum cpuset_t size allowed by running kernel
via new sysctl kern.sched.cpusetsizemin and use it in checks.

Reviewed by:
Differential Revision: https://reviews.freebsd.org/D38112
MFC after: 1 week
lib/libthr/thread/thr_attr.c
sys/kern/kern_cpuset.c
sys/kern/subr_smp.c
sys/sys/cpuset.h