From: Dmitry V. Levin Date: Mon, 5 Dec 2016 02:31:52 +0000 (+0000) Subject: affinity: document the method of finding out the cpuset size X-Git-Tag: v4.15~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cec2dc2ab50e25db7057eb2fbc521ac7e0ce85b7;p=strace affinity: document the method of finding out the cpuset size * affinity.c (get_cpuset_size): Add a comment about sched_getaffinity. --- diff --git a/affinity.c b/affinity.c index 24d5edba..6e347ddd 100644 --- a/affinity.c +++ b/affinity.c @@ -35,6 +35,18 @@ get_cpuset_size(void) static unsigned int cpuset_size; if (!cpuset_size) { + /* + * If the cpuset size passed to sched_getaffinity is less + * than necessary to store the bitmask, the kernel does not + * look at the mask pointer and fails with EINVAL. + * + * If the cpuset size is large enough, the kernel fails with + * EFAULT on inaccessible mask pointers. + * + * This undocumented kernel feature can be used to probe + * the kernel and find out the minimal valid cpuset size + * without allocating any memory for the CPU affinity mask. + */ pid_t pid = getpid(); cpuset_size = 128; while (cpuset_size &&