Index: head/lib/libc/sys/cpuset.2 =================================================================== --- head/lib/libc/sys/cpuset.2 (revision 289667) +++ head/lib/libc/sys/cpuset.2 (revision 289668) @@ -1,229 +1,230 @@ .\" Copyright (c) 2008 Christian Brueffer .\" Copyright (c) 2008 Jeffrey Roberson .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd January 8, 2015 +.Dd October 20, 2015 .Dt CPUSET 2 .Os .Sh NAME .Nm cpuset , .Nm cpuset_getid , .Nm cpuset_setid .Nd manage CPU affinity sets .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/param.h .In sys/cpuset.h .Ft int .Fn cpuset "cpusetid_t *setid" .Ft int .Fn cpuset_setid "cpuwhich_t which" "id_t id" "cpusetid_t setid" .Ft int .Fn cpuset_getid "cpulevel_t level" "cpuwhich_t which" "id_t id" "cpusetid_t *setid" .Sh DESCRIPTION The .Nm family of system calls allow applications to control sets of processors and assign processes and threads to these sets. Processor sets contain lists of CPUs that members may run on and exist only as long as some process is a member of the set. All processes in the system have an assigned set. The default set for all processes in the system is the set numbered 1. Threads belong to the same set as the process which contains them, however, they may further restrict their set with the anonymous per-thread mask. .Pp Sets are referenced by a number of type .Ft 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 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. .Pp The anonymous set is a further thread-specific refinement on the assigned set. It is intended that administrators will manipulate numbered sets using .Xr cpuset 1 while application developers will manipulate anonymous sets using .Xr cpuset_setaffinity 2 . .Pp To select the correct set a value of type .Ft cpulevel_t is used. The following values for .Fa level are supported: .Bl -column CPU_LEVEL_CPUSET -offset indent .It Dv CPU_LEVEL_ROOT Ta "Root set" .It Dv CPU_LEVEL_CPUSET Ta "Assigned set" .It Dv CPU_LEVEL_WHICH Ta "Set specified by which argument" .El .Pp The .Fa which argument determines how the value of .Fa id is interpreted and is of type .Ft cpuwhich_t . The .Fa which argument may have the following values: .Bl -column CPU_WHICH_CPUSET -offset indent .It Dv CPU_WHICH_TID Ta "id is lwpid_t (thread id)" .It Dv CPU_WHICH_PID Ta "id is pid_t (process id)" .It Dv CPU_WHICH_JAIL Ta "id is jid (jail id)" .It Dv CPU_WHICH_CPUSET Ta "id is a cpusetid_t (cpuset id)" .It Dv CPU_WHICH_IRQ Ta "id is an irq number" .It Dv CPU_WHICH_DOMAIN Ta "id is a NUMA domain" .El .Pp An .Fa id of '-1' may be used with a .Fa which of .Dv CPU_WHICH_TID , .Dv CPU_WHICH_PID , or .Dv CPU_WHICH_CPUSET to mean the current thread, process, or current thread's cpuset. All cpuset syscalls allow this usage. .Pp A .Fa level argument of .Dv CPU_LEVEL_WHICH combined with a .Fa which argument other than .Dv CPU_WHICH_CPUSET refers to the anonymous mask of the object. This mask does not have an id and may only be manipulated with .Xr cpuset_setaffinity 2 . .Pp .Fn cpuset creates a new set containing the same CPUs as the root set of the current process and stores its id in the space provided by .Fa setid . On successful completion the calling process joins the set and is the only member. Children inherit this set after a call to .Xr fork 2 . .Pp .Fn cpuset_setid attempts to set the id of the object specified by the .Fa which argument. Currently .Dv CPU_WHICH_PID is the only acceptable value for which as threads do not have an id distinct from their process and the API does not permit changing the id of an existing set. Upon successful completion all of the threads in the target process will be running on CPUs permitted by the set. .Pp .Fn cpuset_getid retrieves a set id from the object indicated by .Fa which and stores it in the space pointed to by .Fa setid . The retrieved id may be that of either the root or assigned set depending on the value of .Fa level . .Fa level should be .Dv CPU_LEVEL_CPUSET or .Dv CPU_LEVEL_ROOT to get the set id from the process or thread specified by the .Fa id argument. Specifying .Dv CPU_LEVEL_WHICH with a process or thread is unsupported since this references the unnumbered anonymous mask. .Pp The actual contents of the sets may be retrieved or manipulated using .Xr cpuset_getaffinity 2 and .Xr cpuset_setaffinity 2 . See those manual pages for more detail. .Sh RETURN VALUES .Rv -std .Sh ERRORS The following error codes may be set in .Va errno : .Bl -tag -width Er .It Bq Er EINVAL The .Fa which or .Fa level argument was not a valid value. .It Bq Er EDEADLK The .Fn cpuset_setid call would leave a thread without a valid CPU to run on because the set does not overlap with the thread's anonymous mask. .It Bq Er EFAULT The setid pointer passed to .Fn cpuset_getid or .Fn cpuset was invalid. .It Bq Er ESRCH The object specified by the .Fa id and .Fa which arguments could not be found. .It Bq Er EPERM The calling process did not have the credentials required to complete the operation. .It Bq Er ENFILE There was no free .Ft cpusetid_t for allocation. .El .Sh SEE ALSO .Xr cpuset 1 , .Xr cpuset_getaffinity 2 , .Xr cpuset_setaffinity 2 , .Xr pthread_affinity_np 3 , -.Xr pthread_attr_affinity_np 3 +.Xr pthread_attr_affinity_np 3 , +.Xr cpuset 9 .Sh HISTORY The .Nm family of system calls first appeared in .Fx 7.1 . .Sh AUTHORS .An Jeffrey Roberson Aq Mt jeff@FreeBSD.org Index: head/lib/libc/sys/cpuset_getaffinity.2 =================================================================== --- head/lib/libc/sys/cpuset_getaffinity.2 (revision 289667) +++ head/lib/libc/sys/cpuset_getaffinity.2 (revision 289668) @@ -1,163 +1,164 @@ .\" Copyright (c) 2008 Christian Brueffer .\" Copyright (c) 2008 Jeffrey Roberson .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd September 10, 2010 +.Dd October 20, 2015 .Dt CPUSET_GETAFFINITY 2 .Os .Sh NAME .Nm cpuset_getaffinity , .Nm cpuset_setaffinity .Nd manage CPU affinity .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/param.h .In sys/cpuset.h .Ft int .Fn cpuset_getaffinity "cpulevel_t level" "cpuwhich_t which" "id_t id" "size_t setsize" "cpuset_t *mask" .Ft int .Fn cpuset_setaffinity "cpulevel_t level" "cpuwhich_t which" "id_t id" "size_t setsize" "const cpuset_t *mask" .Sh DESCRIPTION .Fn cpuset_getaffinity and .Fn cpuset_setaffinity allow the manipulation of sets of CPUs available to processes, threads, interrupts, jails and other resources. These functions may manipulate sets of CPUs that contain many processes or per-object anonymous masks that effect only a single object. .Pp The valid values for the .Fa level and .Fa which arguments are documented in .Xr cpuset 2 . These arguments specify which object and which set of the object we are referring to. Not all possible combinations are valid. For example, only processes may belong to a numbered set accessed by a .Fa level argument of .Dv CPU_LEVEL_CPUSET . All resources, however, have a mask which may be manipulated with .Dv CPU_LEVEL_WHICH . .Pp Masks of type .Ft cpuset_t are composed using the .Dv CPU_SET macros. The kernel tolerates large sets as long as all CPUs specified in the set exist. Sets smaller than the kernel uses generate an error on calls to .Fn cpuset_getaffinity even if the result set would fit within the user supplied set. Calls to .Fn cpuset_setaffinity tolerate small sets with no restrictions. .Pp The supplied mask should have a size of .Fa setsize bytes. This size is usually provided by calling .Li sizeof(mask) which is ultimately determined by the value of .Dv CPU_SETSIZE as defined in .In sys/cpuset.h . .Pp .Fn cpuset_getaffinity retrieves the mask from the object specified by .Fa level , .Fa which and .Fa id and stores it in the space provided by .Fa mask . .Pp .Fn cpuset_setaffinity attempts to set the mask for the object specified by .Fa level , .Fa which and .Fa id to the value in .Fa mask . .Sh RETURN VALUES .Rv -std .Sh ERRORS The following error codes may be set in .Va errno : .Bl -tag -width Er .It Bq Er EINVAL The .Fa level or .Fa which argument was not a valid value. .It Bq Er EINVAL The .Fa mask argument specified when calling .Fn cpuset_setaffinity was not a valid value. .It Bq Er EDEADLK The .Fn cpuset_setaffinity call would leave a thread without a valid CPU to run on because the set does not overlap with the thread's anonymous mask. .It Bq Er EFAULT The mask pointer passed was invalid. .It Bq Er ESRCH The object specified by the .Fa id and .Fa which arguments could not be found. .It Bq Er ERANGE The .Fa cpusetsize was either preposterously large or smaller than the kernel set size. .It Bq Er EPERM The calling process did not have the credentials required to complete the operation. .El .Sh SEE ALSO .Xr cpuset 1 , .Xr cpuset 2 , .Xr cpuset_getid 2 , .Xr cpuset_setid 2 , .Xr pthread_affinity_np 3 , -.Xr pthread_attr_affinity_np 3 +.Xr pthread_attr_affinity_np 3 , +.Xr cpuset 9 .Sh HISTORY The .Nm family of system calls first appeared in .Fx 7.1 . .Sh AUTHORS .An Jeffrey Roberson Aq Mt jeff@FreeBSD.org Index: head/share/man/man9/cpuset.9 =================================================================== --- head/share/man/man9/cpuset.9 (revision 289667) +++ head/share/man/man9/cpuset.9 (revision 289668) @@ -1,350 +1,352 @@ .\" Copyright (c) 2015 Conrad Meyer .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd October 20, 2015 .Dt CPUSET 9 .Os .Sh NAME .Nm cpuset(9) \(em .Nm CPUSET_T_INITIALIZER , .Nm CPUSET_FSET , .Nm CPU_CLR , .Nm CPU_COPY , .Nm CPU_ISSET , .Nm CPU_SET , .Nm CPU_ZERO , .Nm CPU_FILL , .Nm CPU_SETOF , .Nm CPU_EMPTY , .Nm CPU_ISFULLSET , .Nm CPU_FFS , .Nm CPU_COUNT , .Nm CPU_SUBSET , .Nm CPU_OVERLAP , .Nm CPU_CMP , .Nm CPU_OR , .Nm CPU_AND , .Nm CPU_NAND , .Nm CPU_CLR_ATOMIC , .Nm CPU_SET_ATOMIC , .Nm CPU_SET_ATOMIC_ACQ , .Nm CPU_AND_ATOMIC , .Nm CPU_OR_ATOMIC , .Nm CPU_COPY_STORE_REL .Nd cpuset manipulation macros .Sh SYNOPSIS .In sys/_cpuset.h .In sys/cpuset.h .\" .Fn CPUSET_T_INITIALIZER "ARRAY_CONTENTS" .Vt CPUSET_FSET .\" .Fn CPU_CLR "size_t cpu_idx" "cpuset_t *cpuset" .Fn CPU_COPY "cpuset_t *from" "cpuset_t *to" .Ft bool .Fn CPU_ISSET "size_t cpu_idx" "cpuset_t *cpuset" .Fn CPU_SET "size_t cpu_idx" "cpuset_t *cpuset" .Fn CPU_ZERO "cpuset_t *cpuset" .Fn CPU_FILL "cpuset_t *cpuset" .Fn CPU_SETOF "size_t cpu_idx" "cpuset_t *cpuset" .Ft bool .Fn CPU_EMPTY "cpuset_t *cpuset" .Ft bool .Fn CPU_ISFULLSET "cpuset_t *cpuset" .Ft size_t .Fn CPU_FFS "cpuset_t *cpuset" .Ft size_t .Fn CPU_COUNT "cpuset_t *cpuset" .\" .Ft bool .Fn CPU_SUBSET "cpuset_t *haystack" "cpuset_t *needle" .Ft bool .Fn CPU_OVERLAP "cpuset_t *cpuset1" "cpuset_t *cpuset2" .Ft bool .Fn CPU_CMP "cpuset_t *cpuset1" "cpuset_t *cpuset2" .Fn CPU_OR "cpuset_t *dst" "cpuset_t *src" .Fn CPU_AND "cpuset_t *dst" "cpuset_t *src" .Fn CPU_NAND "cpuset_t *dst" "cpuset_t *src" .\" .Fn CPU_CLR_ATOMIC "size_t cpu_idx" "cpuset_t *cpuset" .Fn CPU_SET_ATOMIC "size_t cpu_idx" "cpuset_t *cpuset" .Fn CPU_SET_ATOMIC_ACQ "size_t cpu_idx" "cpuset_t *cpuset" .\" .Fn CPU_AND_ATOMIC "cpuset_t *dst" "cpuset_t *src" .Fn CPU_OR_ATOMIC "cpuset_t *dst" "cpuset_t *src" .Fn CPU_COPY_STORE_REL "cpuset_t *from" "cpuset_t *to" .Sh DESCRIPTION The .Nm family of macros provide a flexible and efficient CPU set implementation, backed by the .Xr bitset 9 macros. Each CPU is represented by a single bit. The maximum number of CPUs representable by .Vt cpuset_t is .Va MAXCPU . Individual CPUs in cpusets are referenced with indices zero through .Fa MAXCPU - 1 . .Pp The .Fn CPUSET_T_INITIALIZER macro allows one to initialize a .Vt cpuset_t with a compile time literal value. .Pp The .Fn CPUSET_FSET macro defines a compile time literal, usable by .Fn CPUSET_T_INITIALIZER , representing a full cpuset (all CPUs present). For examples of .Fn CPUSET_T_INITIALIZER and .Fn CPUSET_FSET usage, see the .Sx CPUSET_T_INITIALIZER EXAMPLE section. .Pp The .Fn CPU_CLR macro removes CPU .Fa cpu_idx from the cpuset pointed to by .Fa cpuset . The .Fn CPU_CLR_ATOMIC macro is identical, but the bit representing the CPU is cleared with atomic machine instructions. .Pp The .Fn CPU_COPY macro copies the contents of the cpuset .Fa from to the cpuset .Fa to . .Fn CPU_COPY_STORE_REL is similar, but copies component machine words from .Fa from and writes them to .Fa to with atomic store with release semantics. (That is, if .Fa to is composed of multiple machine words, .Fn CPU_COPY_STORE_REL performs multiple individually atomic operations.) .Pp The .Fn CPU_SET macro adds CPU .Fa cpu_idx to the cpuset pointed to by .Fa cpuset , if it is not already present. The .Fn CPU_SET_ATOMIC macro is identical, but the bit representing the CPU is set with atomic machine instructions. The .Fn CPU_SET_ATOMIC_ACQ macro sets the bit representing the CPU with atomic acquire semantics. .Pp The .Fn CPU_ZERO macro removes all CPUs from .Fa cpuset . .Pp The .Fn CPU_FILL macro adds all CPUs to .Fa cpuset . .Pp The .Fn CPU_SETOF macro removes all CPUs in .Fa cpuset before adding only CPU .Fa cpu_idx . .Pp The .Fn CPU_EMPTY macro returns .Dv true if .Fa cpuset is empty. .Pp The .Fn CPU_ISFULLSET macro returns .Dv true if .Fa cpuset is full (the set of all CPUs). .Pp The .Fn CPU_FFS macro returns the 1-index of the first (lowest) CPU in .Fa cpuset , or zero if .Fa cpuset is empty. Like with .Xr ffs 3 , to use the non-zero result of .Fn CPU_FFS as a .Fa cpu_idx index parameter to any other .Nm macro, you must subtract one from the result. .Pp The .Fn CPU_COUNT macro returns the total number of CPUs in .Fa cpuset . .Pp The .Fn CPU_SUBSET macro returns .Dv true if .Fa needle is a subset of .Fa haystack . .Pp The .Fn CPU_OVERLAP macro returns .Dv true if .Fa cpuset1 and .Fa cpuset2 have any common CPUs. (That is, if .Fa cpuset1 AND .Fa cpuset2 is not the empty set.) .Pp The .Fn CPU_CMP macro returns .Dv true if .Fa cpuset1 is NOT equal to .Fa cpuset2 . .Pp The .Fn CPU_OR macro adds CPUs present in .Fa src to .Fa dst . (It is the .Nm equivalent of the scalar: .Fa dst |= .Fa src . ) .Fn CPU_OR_ATOMIC is similar, but sets the bits representing CPUs in the component machine words in .Fa dst with atomic machine instructions. (That is, if .Fa dst is composed of multiple machine words, .Fn CPU_OR_ATOMIC performs multiple individually atomic operations.) .Pp The .Fn CPU_AND macro removes CPUs absent from .Fa src from .Fa dst . (It is the .Nm equivalent of the scalar: .Fa dst &= .Fa src . ) .Fn CPU_AND_ATOMIC is similar, with the same atomic semantics as .Fn CPU_OR_ATOMIC . .Pp The .Fn CPU_NAND macro removes CPUs in .Fa src from .Fa dst . (It is the .Nm equivalent of the scalar: .Fa dst &= .Fa ~ src . ) .Sh CPUSET_T_INITIALIZER EXAMPLE .Bd -literal cpuset_t myset; /* Initialize myset to filled (all CPUs) */ myset = CPUSET_T_INITIALIZER(CPUSET_FSET); /* Initialize myset to only the lowest CPU */ myset = CPUSET_T_INITIALIZER(0x1); .Ed .Sh SEE ALSO +.Xr cpuset 1 , +.Xr cpuset 2 , .Xr bitset 9 .Sh HISTORY .In sys/cpuset.h first appeared in .Fx 7.1 , released in January 2009, and in .Fx 8.0 , released in November 2009. .Pp This manual page first appeared in .Fx 11.0 . .Sh AUTHORS .An -nosplit The .Nm macros were written by .An Jeff Roberson Aq Mt jeff@FreeBSD.org . This manual page was written by .An Conrad Meyer Aq Mt cem@FreeBSD.org . .Sh CAVEATS Unlike every other reference to individual set members, which are zero-indexed, .Fn CPU_FFS returns a one-indexed result (or zero if the cpuset is empty).