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