cpuset: Fix sched_[g|s]etaffinity() for better compatibility with Linux.
authorDmitry Chagin <dchagin@FreeBSD.org>
Sun, 29 Jan 2023 13:17:33 +0000 (16:17 +0300)
committerDmitry Chagin <dchagin@FreeBSD.org>
Sun, 29 Jan 2023 13:17:33 +0000 (16:17 +0300)
commitc21b080f3dc2f5e91ada608d4385b7ed6538ba9b
tree90dbfdc1dc1e64f276fd0b89437f5e75ba647336
parentf8660ea4b14d8ef8beefd4699d79098c738dddd8
cpuset: Fix sched_[g|s]etaffinity() for better compatibility with Linux.

Under Linux to sched_[g|s]etaffinity() functions the value returned from a call
to gettid(2) (thread id) can be passed in the argument pid. Specifying pid as 0
will set the attribute for the calling thread, and passing the value returned
from a call to getpid(2) (process id) will set the attribute for the main thread
of the thread group.

Native cpuset(2) family of system calls has "which" argument to determine how
the value of id argument is interpreted, i.e., CPU_WHICH_TID is used to pass
a thread id and CPU_WHICH_PID - to pass a process id.

For now native sched_[g|s]etaffinity() implementation is wrong as uses "which"
CPU_WHICH_PID to pass both (process and thread id) to the kernel. To fix this
adding a new "which" CPU_WHICH_TIDPID intended to handle both id's.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D38209
MFC after: 1 week
lib/libc/gen/sched_getaffinity.c
lib/libc/gen/sched_setaffinity.c
lib/libc/sys/cpuset.2
sys/kern/kern_cpuset.c
sys/sys/cpuset.h