cpu_foreach(3)cpu_foreach(3)NAMEcpu_foreach - enumerate members of a CPU set (libc library)
cpu_cursor_t cursor = SET_CURSOR_INIT;
unsigned int flags,
cpu_cursor_t *cursor );
Specifies a CPU set whose members are to be enumerated. Control the
processing of set members. The flags parameter can be one or more (a
logical OR operation) of the following flags: Initializes the cursor to
the first member of the set before scanning. Wraps around to the
beginning of the set when scanning for members. Consumes the set mem‐
bers; that is, removes the member from the set when found. As shown in
the SYNOPSIS, a cursor variable may be initialized to the value
SET_CURSOR_INIT. Initialization of this variable is equivalent to set‐
ting the SET_CURSOR_FIRST flag on the initial call to cpu_foreach().
Points to an opaque type that records the position in a set for subse‐
quent invocations of the cpu_foreach() function.
The cpu_foreach() function scans the specified cpuset, starting at the
position saved in the cursor parameter, for members of the set and
returns the first member found. If the SET_CURSOR_FIRST flag is set,
the cursor is initialized to the beginning of the set before starting
the scan. If no members are found, the cpu_foreach() function will
If the SET_CURSOR_WRAP flag is set, the scan will wrap from the end of
the set to the beginning searching for a member to return. Otherwise,
a one pass scan is performed, and when the end of the set is reached,
the cursor is positioned at the end of the set. From then on, the
cpu_foreach() function will continue to return CPU_NONE until the cur‐
sor is reinitialized (by specifying the SET_CURSOR_FIRST orSET_CUR‐
If the SET_CURSOR_CONSUME flag is set, the member returned, if any,
will be removed from the set.
Although the preceding description discusses the “beginning” and “end”
of the set, and wrapping from the end to the beginning, CPU sets are
conceptually unordered. Thus, these end points are arbitrary points in
the set that exist to ensure that each member is returned only once per
pass through the set. Therefore, applications should not depend on a
specific numeric order of the returned member IDs.
The cpu_foreach() function returns the next member in the set starting
at the position of the cursor. If no more members are found, CPU_NONE
is returned. This function always completes successfully.
No errors are defined for the cpu_foreach() function.
See the EXAMPLES section of cpusetops(3) for a sample program that uses
the cpu_foreach() function.
Functions: cpusetops(3), numa_intro(3)