![]() |
![]()
| ![]() |
![]()
NAME
LIBRARYStandard C Library (libc, -lc) SYNOPSIS
int
int
int
DESCRIPTIONThe Sets are referenced by a number of type cpuset_id_t. Each thread has a root set, an assigned set, and an anonymous mask. Only the root and assigned sets are numbered. The root set is the set of all CPUs and memory domains available in the system or in the system partition the thread is running in. The assigned set is a subset of the root set and is administratively assignable on a per-process basis. Many processes and threads may be members of a numbered set. The anonymous set is a further thread-specific refinement on the assigned set. It is intended that administrators will manipulate numbered sets using cpuset(1) while application developers will manipulate anonymous sets using cpuset_setaffinity(2) and cpuset_setdomain(2). To select the correct set a value of type cpulevel_t is used. The following values for level are supported:
The which argument determines how the value of id is interpreted and is of type cpuwhich_t. The which argument may have the following values:
An id of '-1' may be used with a
which of A level argument of
The actual contents of the sets may be retrieved or manipulated using cpuset_getaffinity(2), cpuset_setaffinity(2), cpuset_getdomain(2), and cpuset_setdomain(2). The cpuset(9) macros may be used to manipulate masks of type cpuset_t get and set using those APIs. See those manual pages for more detail. RETURN VALUESUpon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error. EXAMPLESIn this example, a CPU set mask is configured to limit execution to the first CPU using CPU_ZERO(9) and CPU_SET(9), members of the cpuset(9) programming interface. Then, the mask is applied to a new anonymous CPU set associated with the current process using cpuset_setaffinity(2). This mask will be used by the current process, and inherited by any new child processes. #include <sys/param.h> #include <sys/cpuset.h> #include <sysexits.h> cpuset_t cpuset_mask; /* Initialize a CPU mask and enable CPU 0. */ CPU_ZERO(&cpuset_mask); CPU_SET(0, &cpuset_mask); /* Set affinity for the CPU set for the current process. */ if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset_mask), &cpuset_mask) < 0) err(EX_OSERR, "cpuset_setaffinity"); In the next example, a named CPU set is created containing the current process, and its affinity similarly configured. The resulting CPU set ID can then be used for further external management of the affinity of the set. #include <sys/param.h> #include <sys/cpuset.h> #include <sysexits.h> cpusetid_t cpuset_id; cpuset_t cpuset_mask; /* Create new cpuset for the current process. */ if (cpuset(&cpuset_id) < 0) err(EX_OSERR, "cpuset"); /* Initialize a CPU mask and enable CPU 0. */ CPU_ZERO(&cpuset_mask); CPU_SET(0, &cpuset_mask); /* Set affinity for the CPU set for the current process. */ if (cpuset_setaffinity(CPU_LEVEL_SET, CPU_WHICH_CPUSET, cpuset_id, sizeof(cpuset_mask), &cpuset_mask) < 0) err(EX_OSERR, "cpuset_setaffinity"); ERRORSThe following error codes may be set in errno:
SEE ALSOcpuset(1), cpuset_getaffinity(2), cpuset_getdomain(2), cpuset_setaffinity(2), cpuset_setdomain(2), pthread_affinity_np(3), pthread_attr_affinity_np(3), CPU_SET(9), CPU_ZERO(9), cpuset(9) HISTORYThe AUTHORSJeffrey Roberson <jeff@FreeBSD.org>
|