mirror of https://github.com/mkerrisk/man-pages
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>
This commit is contained in:
parent
cf486e4aa9
commit
310ac27840
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue