cpu_foreach(3) [osf1 man page]
cpu_foreach(3) Library Functions Manual cpu_foreach(3) NAME
cpu_foreach - enumerate members of a CPU set (libc library) SYNOPSIS
#include <cpuset.h> cpu_cursor_t cursor = SET_CURSOR_INIT; cpuid_t cpu_foreach( cpuset_t cpuset, int flags, cpu_cursor_t *cursor ); PARAMETERS
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 members; 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 sub- sequent invocations of the cpu_foreach() function. DESCRIPTION
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 return CPU_NONE. 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. Other- wise, 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 cursor is reinitialized (by specifying the SET_CURSOR_FIRST orSET_CURSOR_WRAP flag). If the SET_CURSOR_CONSUME flag is set, the member returned, if any, will be removed from the set. NOTES
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. RETURN VALUES
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. ERRORS
No errors are defined for the cpu_foreach() function. EXAMPLES
See the EXAMPLES section of cpusetops(3) for a sample program that uses the cpu_foreach() function. SEE ALSO
Functions: cpusetops(3), numa_intro(3) Files: numa_types(4) cpu_foreach(3)
Check Out this Related Man Page
cpusetops(3) Library Functions Manual cpusetops(3) NAME
cpusetops, cpuaddset, cpuandset, cpucopyset, cpucountset, cpudelset, cpudiffset, cpuemptyset, cpufillset, cpuisemptyset, cupismember, cpuorset, cpusetcreate, cpusetdestroy, cpuxorset - Perform operations on CPU sets (libc library) SYNOPSIS
#include <cpuset.h> int cpuaddset( cpuset_t set, cpuid_t cpuid ); int cpuandset( cpuset_t set_src1, cpuset_t set_src2, cpuset_t set_dst ); int cpucopyset( cpuset_t set_src, cpuset_t set_dst ); int cpucountset( cpuset_t set ); int cpudelset( cpuset_t set, cpuid_t cpuid ); int cpudiffset( cpuset_t set_src1, cpuset_t set_src2, cpuset_t set_dst ); int cpuemptyset( cpuset_t set ); int cpufillset( cpuset_t set ); int cpuisemptyset( cpuset_t set ); int cpuismember( cpuset_t set, cpuid_t cpuid ); int cpuorset( cpuset_t set_src1, cpuset_t set_src2, cpuset_t set_dst ); int cpusetcreate( cpuset_t *set ); int cpusetdestroy( cpuset_t *set ); int cpuxorset( cpuset_t set_src1, cpuset_t set_src2, cpuset_t set_dst ); PARAMETERS
Identifies a CPU. Specifies or points to a CPU set. Specifies a CPU set that is being copied to or that is the result of a logical OR, XOR, or AND operation on two other CPU sets. Specifies a CPU set that is being copied to another CPU set or that is part of a logical OR, XOR, or AND operation with another CPU set. DESCRIPTION
The cpusetops primitives manipulate sets of CPUs, by operating on data objects (of type cpuset_t) that are created by cpusetcreate(). The cpusetcreate() function allocates, and sets to empty, a CPU set pointed to by set. The cpusetdestroy() function releases the memory that was obtained by cpusetcreate() for the specified CPU set pointed to by set. The cpucountset() function returns the number of members in the CPU set specified by set. The cpuemptyset() function initializes the CPU set specified by set, such that no CPUs are included in the set. The cpufillset() function initializes the CPU set specified by set, such that all CPUs that are currently configured in the caller's parti- tion are included in the set. The cpuismember() function tests whether the CPU specified by the value of cpuid is a member of the CPU set specified by set. The cpuisemptyset() function tests whether the CPU set specified by the set is empty. The cpucopyset() function copies the contents of the CPU set specified by set_src to the CPU set specified by set_dst. The cpuaddset() and cpudelset() functions respectively add or delete the individual CPU specified by the value of cpuid to or from the CPU set specified by set. The cpuandset(), cpuorset(), and cpuxorset() functions perform a logical AND, OR, or XOR operation, respectively, on the CPU sets specified by set_src1 and set_src2, storing the result in the CPU set specified by set_dst. The cpudiffset() function finds the logical difference between the CPU sets specified by set_src1 and set_src2, storing the result in the CPU set specified by set_dst. (The result is made up of members that are included in set_src1 but not in set_src2.) RETURN VALUES
These functions return the following values: Success (returned by all functions). For cpuisemptyset() and cpuismember() only, 0 also means the condition being tested is false; that is, the specified CPU set is not empty or does not contain the specified member. Success (returned by cpuisemptyset() and cpuismember()only). This return value also means the condition being tested is true; that is, the specified CPU set is empty or contains the specified member. Failure (returned by all functions). In this case, errno is set to indicate the error. ERRORS
The cpuaddset(), cpuandset(), cpucopyset(), cpucountset(), cpudelset(), cpudiffset(), cpuemptyset(), cpufillset(), cpuisemptyset(), cpuis- member(), cpuorset(), and cpuxorset() functions set errno to the following value for the corresponding condition: The value of a set or set_* argument is invalid (possibly is not a CPU set created bycpusetcreate()). The cpusetcreate() and cpusetdestroy() functions set errno to one of the the following values for the corresponding condition: The address of the specified CPU set is invalid. For cpusetcreate() only, no memory could be allocated for the specified CPU set. If the cpuaddset(), cpudelset(), and cpuismember() functions fail, they set errno to the following value for the reason specified: The value of cpuid is an invalid or unsupported CPU identifier. EXAMPLES
The following example demonstrates a variety of CPU set operations: #include <cpuset.h> int main() { cpuset_t cpuset, cpuset2; /* Create cpusets - initialized as empty */ cpusetcreate(&cpuset); cpusetcreate(&cpuset2); /* demonstrate cpuset operations */ /* add cpu 0 to cpuset */ if (cpuaddset(cpuset, 0) == -1) { perror("cpuaddset"); return 0; } /* copy cpuset to cpuset2 */ if (cpucopyset(cpuset, cpuset2) == -1) { perror("cpucopyset"); return 0; } if (cpuaddset(cpuset, 1) == -1) { /* add cpu 1 to cpuset */ perror("cpuaddset"); return 0; } /* difference of cpuset and cpuset2, store in cpuset */ if (cpudiffset(cpuset, cpuset2, cpuset) == -1) { perror("cpudiffset"); return 0; } /* Enumerate cpuset. */ while (1) { cpuid_t id; int flags = SET_CURSOR_CONSUME; cpu_cursor_t cpu_cursor = SET_CURSOR_INIT; id = cpu_foreach(cpuset, flags, &cpu_cursor); if (id == CPU_NONE) { printf(" "); break; } else { printf("%3d ", id); } } /* Destroy cpuset */ cpusetdestroy(&cpuset); cpusetdestroy(&cpuset2); return 0; } SEE ALSO
Functions: cpu_foreach(3), numa_intro(3) Files: numa_types(4) cpusetops(3)