diff options
author | Michael Kerrisk <mtk.manpages@gmail.com> | 2016-03-10 16:43:52 +0100 |
---|---|---|
committer | Michael Kerrisk <mtk.manpages@gmail.com> | 2016-03-10 21:04:55 +0100 |
commit | 310ac278405a063c48265b8706b08de300080fc2 (patch) | |
tree | 59986a75ab1ddbe0672237ea169a8d27cfa3641b | |
parent | cf486e4aa9dfdf5c3faf7ecfbe287e3d9e0048dd (diff) | |
download | man-pages-310ac278405a063c48265b8706b08de300080fc2.tar.gz |
sched_setaffinity.2: Warn that CPU_ALLOC() may allocate a slightly CPU set than requested
Reported-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r-- | man2/sched_setaffinity.2 | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/man2/sched_setaffinity.2 b/man2/sched_setaffinity.2 index fd3298645f..39f80b0a48 100644 --- a/man2/sched_setaffinity.2 +++ b/man2/sched_setaffinity.2 @@ -276,6 +276,21 @@ of the required mask using .BR sched_getaffinity () calls with increasing mask sizes (until the call does not fail with the error .BR EINVAL ). + +Be aware that +.BR CPU_ALLOC (3) +may allocate a slightly larger CPU set than requested +(because CPU sets are implemented as bit masks allocated in units of +.IR sizeof(long) ). +Consequently, +.BR sched_getaffinity () +can set bits beyond the requested allocation size, because the kernel +sees a few additional bits. +Therefore, the caller should iterate over the bits in the returned set, +counting those which are set, and stop upon reaching the value returned by +.BR CPU_COUNT (3) +(rather than iterating over the number of bits +requested to be allocated). .SH EXAMPLE The program below creates a child process. The parent and child then each assign themselves to a specified CPU |