1*8269e767SBrooks Davis.\" Copyright (c) 2008 Christian Brueffer 2*8269e767SBrooks Davis.\" Copyright (c) 2008 Jeffrey Roberson 3*8269e767SBrooks Davis.\" All rights reserved. 4*8269e767SBrooks Davis.\" 5*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 6*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 7*8269e767SBrooks Davis.\" are met: 8*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 9*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 10*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 11*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 12*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 13*8269e767SBrooks Davis.\" 14*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*8269e767SBrooks Davis.\" SUCH DAMAGE. 25*8269e767SBrooks Davis.\" 26*8269e767SBrooks Davis.Dd April 27, 2022 27*8269e767SBrooks Davis.Dt CPUSET_GETAFFINITY 2 28*8269e767SBrooks Davis.Os 29*8269e767SBrooks Davis.Sh NAME 30*8269e767SBrooks Davis.Nm cpuset_getaffinity , 31*8269e767SBrooks Davis.Nm cpuset_setaffinity 32*8269e767SBrooks Davis.Nd manage CPU affinity 33*8269e767SBrooks Davis.Sh LIBRARY 34*8269e767SBrooks Davis.Lb libc 35*8269e767SBrooks Davis.Sh SYNOPSIS 36*8269e767SBrooks Davis.In sys/param.h 37*8269e767SBrooks Davis.In sys/cpuset.h 38*8269e767SBrooks Davis.Ft int 39*8269e767SBrooks Davis.Fn cpuset_getaffinity "cpulevel_t level" "cpuwhich_t which" "id_t id" "size_t setsize" "cpuset_t *mask" 40*8269e767SBrooks Davis.Ft int 41*8269e767SBrooks Davis.Fn cpuset_setaffinity "cpulevel_t level" "cpuwhich_t which" "id_t id" "size_t setsize" "const cpuset_t *mask" 42*8269e767SBrooks Davis.Sh DESCRIPTION 43*8269e767SBrooks Davis.Fn cpuset_getaffinity 44*8269e767SBrooks Davisand 45*8269e767SBrooks Davis.Fn cpuset_setaffinity 46*8269e767SBrooks Davisallow the manipulation of sets of CPUs available to processes, threads, 47*8269e767SBrooks Davisinterrupts, jails and other resources. 48*8269e767SBrooks DavisThese functions may manipulate sets of CPUs that contain many processes 49*8269e767SBrooks Davisor per-object anonymous masks that effect only a single object. 50*8269e767SBrooks Davis.Pp 51*8269e767SBrooks DavisThe valid values for the 52*8269e767SBrooks Davis.Fa level 53*8269e767SBrooks Davisand 54*8269e767SBrooks Davis.Fa which 55*8269e767SBrooks Davisarguments are documented in 56*8269e767SBrooks Davis.Xr cpuset 2 . 57*8269e767SBrooks DavisThese arguments specify which object and which set of the object we are 58*8269e767SBrooks Davisreferring to. 59*8269e767SBrooks DavisNot all possible combinations are valid. 60*8269e767SBrooks DavisFor example, only processes may belong to a numbered set accessed by a 61*8269e767SBrooks Davis.Fa level 62*8269e767SBrooks Davisargument of 63*8269e767SBrooks Davis.Dv CPU_LEVEL_CPUSET . 64*8269e767SBrooks DavisAll resources, however, have a mask which may be manipulated with 65*8269e767SBrooks Davis.Dv CPU_LEVEL_WHICH . 66*8269e767SBrooks Davis.Pp 67*8269e767SBrooks DavisMasks of type 68*8269e767SBrooks Davis.Ft cpuset_t 69*8269e767SBrooks Davisare composed using the 70*8269e767SBrooks Davis.Dv CPU_SET 71*8269e767SBrooks Davismacros. 72*8269e767SBrooks DavisIf the user-supplied mask is not large enough to fit all of the matching CPUs, 73*8269e767SBrooks Davis.Fn cpuset_getaffinity 74*8269e767SBrooks Davisfails with 75*8269e767SBrooks Davis.Er ERANGE . 76*8269e767SBrooks DavisCalls to 77*8269e767SBrooks Davis.Fn cpuset_setaffinity 78*8269e767SBrooks Davistolerate masks of any size with no restrictions. 79*8269e767SBrooks DavisThe kernel uses the meaningful part of the mask, where the upper bound is 80*8269e767SBrooks Davisthe maximum CPU id present in the system. 81*8269e767SBrooks DavisIf bits for non-existing CPUs are set, calls to 82*8269e767SBrooks Davis.Fn cpuset_setaffinity 83*8269e767SBrooks Davisfail with 84*8269e767SBrooks Davis.Er EINVAL . 85*8269e767SBrooks Davis.Pp 86*8269e767SBrooks DavisThe supplied mask should have a size of 87*8269e767SBrooks Davis.Fa setsize 88*8269e767SBrooks Davisbytes. 89*8269e767SBrooks DavisThis size is usually provided by calling 90*8269e767SBrooks Davis.Li sizeof(mask) 91*8269e767SBrooks Daviswhich is ultimately determined by the value of 92*8269e767SBrooks Davis.Dv CPU_SETSIZE 93*8269e767SBrooks Davisas defined in 94*8269e767SBrooks Davis.In sys/cpuset.h . 95*8269e767SBrooks Davis.Pp 96*8269e767SBrooks Davis.Fn cpuset_getaffinity 97*8269e767SBrooks Davisretrieves the 98*8269e767SBrooks Davismask from the object specified by 99*8269e767SBrooks Davis.Fa level , 100*8269e767SBrooks Davis.Fa which 101*8269e767SBrooks Davisand 102*8269e767SBrooks Davis.Fa id 103*8269e767SBrooks Davisand stores it in the space provided by 104*8269e767SBrooks Davis.Fa mask . 105*8269e767SBrooks Davis.Pp 106*8269e767SBrooks Davis.Fn cpuset_setaffinity 107*8269e767SBrooks Davisattempts to set the mask for the object specified by 108*8269e767SBrooks Davis.Fa level , 109*8269e767SBrooks Davis.Fa which 110*8269e767SBrooks Davisand 111*8269e767SBrooks Davis.Fa id 112*8269e767SBrooks Davisto the value in 113*8269e767SBrooks Davis.Fa mask . 114*8269e767SBrooks Davis.Sh RETURN VALUES 115*8269e767SBrooks Davis.Rv -std 116*8269e767SBrooks Davis.Sh ERRORS 117*8269e767SBrooks DavisThe following error codes may be set in 118*8269e767SBrooks Davis.Va errno : 119*8269e767SBrooks Davis.Bl -tag -width Er 120*8269e767SBrooks Davis.\" When changing this list, consider updating share/man/man3/pthread_create.3, 121*8269e767SBrooks Davis.\" since that function can return any of these errors. 122*8269e767SBrooks Davis.It Bq Er EINVAL 123*8269e767SBrooks DavisThe 124*8269e767SBrooks Davis.Fa level 125*8269e767SBrooks Davisor 126*8269e767SBrooks Davis.Fa which 127*8269e767SBrooks Davisargument was not a valid value. 128*8269e767SBrooks Davis.It Bq Er EINVAL 129*8269e767SBrooks DavisThe 130*8269e767SBrooks Davis.Fa mask 131*8269e767SBrooks Davisargument specified when calling 132*8269e767SBrooks Davis.Fn cpuset_setaffinity 133*8269e767SBrooks Daviswas not a valid value. 134*8269e767SBrooks Davis.It Bq Er EDEADLK 135*8269e767SBrooks DavisThe 136*8269e767SBrooks Davis.Fn cpuset_setaffinity 137*8269e767SBrooks Daviscall would leave a thread without a valid CPU to run on because the set 138*8269e767SBrooks Davisdoes not overlap with the thread's anonymous mask. 139*8269e767SBrooks Davis.It Bq Er EFAULT 140*8269e767SBrooks DavisThe mask pointer passed was invalid. 141*8269e767SBrooks Davis.It Bq Er ESRCH 142*8269e767SBrooks DavisThe object specified by the 143*8269e767SBrooks Davis.Fa id 144*8269e767SBrooks Davisand 145*8269e767SBrooks Davis.Fa which 146*8269e767SBrooks Davisarguments could not be found. 147*8269e767SBrooks Davis.It Bq Er ERANGE 148*8269e767SBrooks DavisThe 149*8269e767SBrooks Davis.Fa cpusetsize 150*8269e767SBrooks Daviswas smaller than needed to fit all of the matching CPUs. 151*8269e767SBrooks Davis.It Bq Er EPERM 152*8269e767SBrooks DavisThe calling process did not have the credentials required to complete the 153*8269e767SBrooks Davisoperation. 154*8269e767SBrooks Davis.It Bq Er ECAPMODE 155*8269e767SBrooks DavisThe calling process attempted to act on a process other than itself, while 156*8269e767SBrooks Davisin capability mode. 157*8269e767SBrooks DavisSee 158*8269e767SBrooks Davis.Xr capsicum 4 . 159*8269e767SBrooks Davis.El 160*8269e767SBrooks Davis.Sh SEE ALSO 161*8269e767SBrooks Davis.Xr cpuset 1 , 162*8269e767SBrooks Davis.Xr cpuset 2 , 163*8269e767SBrooks Davis.Xr cpuset_getdomain 2 , 164*8269e767SBrooks Davis.Xr cpuset_getid 2 , 165*8269e767SBrooks Davis.Xr cpuset_setdomain 2 , 166*8269e767SBrooks Davis.Xr cpuset_setid 2 , 167*8269e767SBrooks Davis.Xr pthread_affinity_np 3 , 168*8269e767SBrooks Davis.Xr pthread_attr_affinity_np 3 , 169*8269e767SBrooks Davis.Xr capsicum 4 , 170*8269e767SBrooks Davis.Xr cpuset 9 171*8269e767SBrooks Davis.Sh HISTORY 172*8269e767SBrooks DavisThe 173*8269e767SBrooks Davis.Nm 174*8269e767SBrooks Davisfamily of system calls first appeared in 175*8269e767SBrooks Davis.Fx 7.1 . 176*8269e767SBrooks Davis.Sh AUTHORS 177*8269e767SBrooks Davis.An Jeffrey Roberson Aq Mt jeff@FreeBSD.org 178