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