From dde6d764a3f03c9d59d74dd2b2d735e4a643bbcd Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Tue, 21 Jul 2015 17:00:40 +0200 Subject: [PATCH] sched_setaffinity.2: Rework text about dealing with systems with more than 1024 CPUs After comments from Florian Weimer, who pointed out various confusions in the earlier text. Reported-by: Florian Weimer Signed-off-by: Michael Kerrisk --- man2/sched_setaffinity.2 | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/man2/sched_setaffinity.2 b/man2/sched_setaffinity.2 index c00a8c0df..8b5b96db2 100644 --- a/man2/sched_setaffinity.2 +++ b/man2/sched_setaffinity.2 @@ -242,7 +242,10 @@ system call returns the size (in bytes) of the data type that is used internally by the kernel to represent the CPU set bit mask. .SS Handling systems with more than 1024 CPUs -The +The underlying system calls (which represent CPU masks as bit masks of type +.IR "unsigned long\ *" ) +impose no restriction on the size of the CPU mask. +However, the .I cpu_set_t data type used by glibc has a fixed size of 128 bytes, meaning that the maximum CPU number that can be represented is 1023. @@ -260,29 +263,15 @@ size specified in .I cpusetsize is smaller than the size of the affinity mask used by the kernel. .PP -The underlying system calls (which represent CPU masks as bit masks of type -.IR "unsigned long\ *" ) -impose no restriction on the size of the mask. -To handle systems with more than 1024 CPUs, one must dynamically allocate the +When working on systems with more than 1024 CPUs, +one must dynamically allocate the .I mask -argument using -.BR CPU_ALLOC (3) -and manipulate the mask using the "_S" macros described in -.BR CPU_ALLOC (3). -Using an allocation based on the number of online CPUs: - - cpu_set_t *mask = CPU_ALLOC(CPU_ALLOC_SIZE( - sysconf(_SC_NPROCESSORS_CONF))); - -is probably sufficient, although the value returned by the -.BR sysconf () -call can in theory change during the lifetime of the process. -Alternatively, one can obtain a value that is guaranteed to be -stable for the lifetime of the process by probing for the size +argument. +Currently, the only way to do this is by probing for the size of the required mask using .BR sched_getaffinity () -calls with increasing mask sizes until the call does not fail with the error -.BR EINVAL . +calls with increasing mask sizes (until the call does not fail with the error +.BR EINVAL ). .SH EXAMPLE The program below creates a child process. The parent and child then each assign themselves to a specified CPU