]> granicus.if.org Git - strace/commitdiff
affinity: document the method of finding out the cpuset size
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Dec 2016 02:31:52 +0000 (02:31 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Dec 2016 03:56:17 +0000 (03:56 +0000)
* affinity.c (get_cpuset_size): Add a comment about sched_getaffinity.

affinity.c

index 24d5edbaf6d9cff049e62ca55c0ed0bfbcc83236..6e347dddded1c328e529d6153bf79b1d30997eb9 100644 (file)
@@ -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 &&