xref: /dflybsd-src/lib/libc/sys/sched_setaffinity.2 (revision 476c884a573292e93796bc5fccec91d43c1a37a1)
1907281d1SSepherosa Ziehau.\" Copyright (c) 2017 The DragonFly Project.  All rights reserved.
2907281d1SSepherosa Ziehau.\"
3907281d1SSepherosa Ziehau.\" This code is derived from software contributed to The DragonFly Project
4907281d1SSepherosa Ziehau.\" by Sepherosa Ziehau <sepherosa@gmail.com>.
5907281d1SSepherosa Ziehau.\"
6907281d1SSepherosa Ziehau.\" Redistribution and use in source and binary forms, with or without
7907281d1SSepherosa Ziehau.\" modification, are permitted provided that the following conditions
8907281d1SSepherosa Ziehau.\" are met:
9907281d1SSepherosa Ziehau.\"
10907281d1SSepherosa Ziehau.\" 1. Redistributions of source code must retain the above copyright
11907281d1SSepherosa Ziehau.\"    notice, this list of conditions and the following disclaimer.
12907281d1SSepherosa Ziehau.\" 2. Redistributions in binary form must reproduce the above copyright
13907281d1SSepherosa Ziehau.\"    notice, this list of conditions and the following disclaimer in
14907281d1SSepherosa Ziehau.\"    the documentation and/or other materials provided with the
15907281d1SSepherosa Ziehau.\"    distribution.
16907281d1SSepherosa Ziehau.\" 3. Neither the name of The DragonFly Project nor the names of its
17907281d1SSepherosa Ziehau.\"    contributors may be used to endorse or promote products derived
18907281d1SSepherosa Ziehau.\"    from this software without specific, prior written permission.
19907281d1SSepherosa Ziehau.\"
20907281d1SSepherosa Ziehau.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21907281d1SSepherosa Ziehau.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22907281d1SSepherosa Ziehau.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23907281d1SSepherosa Ziehau.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24907281d1SSepherosa Ziehau.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25907281d1SSepherosa Ziehau.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26907281d1SSepherosa Ziehau.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27907281d1SSepherosa Ziehau.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28907281d1SSepherosa Ziehau.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29907281d1SSepherosa Ziehau.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30907281d1SSepherosa Ziehau.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31907281d1SSepherosa Ziehau.\" SUCH DAMAGE.
32907281d1SSepherosa Ziehau.\"
33907281d1SSepherosa Ziehau.Dd January 14, 2017
34907281d1SSepherosa Ziehau.Dt SCHED_SETAFFINITY 2
35907281d1SSepherosa Ziehau.Os
36907281d1SSepherosa Ziehau.Sh NAME
3725e1dde1SSascha Wildner.Nm CPU_AND ,
3825e1dde1SSascha Wildner.Nm CPU_CLR ,
3925e1dde1SSascha Wildner.Nm CPU_COUNT ,
4025e1dde1SSascha Wildner.Nm CPU_EQUAL ,
4125e1dde1SSascha Wildner.Nm CPU_ISSET ,
4225e1dde1SSascha Wildner.Nm CPU_OR ,
4325e1dde1SSascha Wildner.Nm CPU_SET ,
4425e1dde1SSascha Wildner.Nm CPU_XOR ,
4525e1dde1SSascha Wildner.Nm CPU_ZERO ,
46907281d1SSepherosa Ziehau.Nm sched_setaffinity ,
47907281d1SSepherosa Ziehau.Nm sched_getaffinity
48907281d1SSepherosa Ziehau.Nd set and get a process's CPU affinity mask
49907281d1SSepherosa Ziehau.Sh LIBRARY
50907281d1SSepherosa Ziehau.Lb libc
51907281d1SSepherosa Ziehau.Sh SYNOPSIS
52907281d1SSepherosa Ziehau.In sys/types.h
53907281d1SSepherosa Ziehau.In sys/sched.h
54907281d1SSepherosa Ziehau.Ft int
55fe54de69SSepherosa Ziehau.Fn sched_setaffinity "pid_t pid" "size_t cpusetsize" "const cpu_set_t *mask"
56907281d1SSepherosa Ziehau.Ft int
57907281d1SSepherosa Ziehau.Fn sched_getaffinity "pid_t pid" "size_t cpusetsize" "cpu_set_t *mask"
58907281d1SSepherosa Ziehau.Fn CPU_ZERO &mask
59907281d1SSepherosa Ziehau.Fn CPU_SET cpu &mask
60907281d1SSepherosa Ziehau.Fn CPU_CLR cpu &mask
61907281d1SSepherosa Ziehau.Fn CPU_ISSET cpu &mask
62907281d1SSepherosa Ziehau.Fn CPU_COUNT &mask
63907281d1SSepherosa Ziehau.Fn CPU_AND &dstmask &srcmask1 &srcmask2
64907281d1SSepherosa Ziehau.Fn CPU_OR &dstmask &srcmask1 srcmask2
65907281d1SSepherosa Ziehau.Fn CPU_XOR &dstmask &srcmask1 &srcmask2
66907281d1SSepherosa Ziehau.Fn CPU_EQUAL &mask1 &mask2
67907281d1SSepherosa Ziehau.Sh DESCRIPTION
68907281d1SSepherosa ZiehauThe
69907281d1SSepherosa Ziehau.Fn sched_setaffinity
70907281d1SSepherosa Ziehausets the CPU affinity mask of the process,
71907281d1SSepherosa Ziehauwhich is identified by the
72907281d1SSepherosa Ziehau.Fa pid
73907281d1SSepherosa Ziehauto the value specified by the
74907281d1SSepherosa Ziehau.Fa mask .
75907281d1SSepherosa ZiehauThe
76907281d1SSepherosa Ziehau.Fa cpusetsize
77907281d1SSepherosa Ziehauis the length (in bytes) of the data pointed to by
78907281d1SSepherosa Ziehau.Fa mask .
79907281d1SSepherosa ZiehauNormally this argument would be specified as sizeof(cpu_set_t).
80907281d1SSepherosa ZiehauIf the
81907281d1SSepherosa Ziehau.Fa pid
82907281d1SSepherosa Ziehauis zero,
83907281d1SSepherosa Ziehauthen the pid of the calling process is used.
84907281d1SSepherosa ZiehauAll threads of the process identified by
85907281d1SSepherosa Ziehau.Fa pid
86907281d1SSepherosa Ziehauare affected.
87907281d1SSepherosa ZiehauIf the calling thread is one of the target process's threads,
88907281d1SSepherosa Ziehauthen the calling thread will be migrated immediately,
89907281d1SSepherosa Ziehauif necessary,
90907281d1SSepherosa Ziehauwhile other threads of the targt process will be migrated
91907281d1SSepherosa Ziehauby the scheduler later.
92907281d1SSepherosa Ziehau.Pp
93907281d1SSepherosa ZiehauA process created by
94907281d1SSepherosa Ziehau.Xr fork 2 ,
95907281d1SSepherosa Ziehau.Xr vfork 2 ,
96907281d1SSepherosa Ziehauand
97907281d1SSepherosa Ziehau.Xr rfork 2
98907281d1SSepherosa Ziehauinherits the calling thread's CPU affinity mask.
99907281d1SSepherosa ZiehauSame applies to the threads created by
100907281d1SSepherosa Ziehau.Xr lwp_create 2 ,
101907281d1SSepherosa Ziehauand the threads created by
102907281d1SSepherosa Ziehau.Xr pthread_create 3 .
103907281d1SSepherosa Ziehau.Pp
104907281d1SSepherosa Ziehau.Fn sched_getaffinity
105907281d1SSepherosa Ziehauwrites the affinity mask of the process
106907281d1SSepherosa Ziehauidentified by the
107907281d1SSepherosa Ziehau.Fa pid
108907281d1SSepherosa Ziehauto the cpu_set_t structure pointed to by
109907281d1SSepherosa Ziehau.Fa mask .
110907281d1SSepherosa ZiehauIf the
111907281d1SSepherosa Ziehau.Fa pid
112907281d1SSepherosa Ziehauis zero,
113907281d1SSepherosa Ziehauthen the pid of the calling process is used.
114907281d1SSepherosa ZiehauIf the process is multithreaded,
115907281d1SSepherosa Ziehauthen the CPU affinity mask of the first thread will be returned.
116907281d1SSepherosa Ziehau.Pp
117907281d1SSepherosa ZiehauThe cpu_set_t data structure represents a set of CPUs.
118907281d1SSepherosa ZiehauThe first available CPU on the system corresponds to a cpu value of 0,
119907281d1SSepherosa Ziehauthe next CPU corresponds to a cpu value of 1,
120907281d1SSepherosa Ziehauand so on and so forth.
121907281d1SSepherosa ZiehauThe constant
12262a84585SSascha Wildner.Dv CPU_SETSIZE
123907281d1SSepherosa Ziehauspecifies a value one greater than the maximum
124907281d1SSepherosa ZiehauCPU number that can be stored in cpu_set_t.
125907281d1SSepherosa ZiehauThe cpu_set_t should be treated as opaque data structure;
126907281d1SSepherosa Ziehauall manipulation of cpu_set_t should be done via the following macros:
127907281d1SSepherosa Ziehau.Bl -tag -width "CPU_COUNTxxx"
128907281d1SSepherosa Ziehau.It Fn CPU_ZERO
129907281d1SSepherosa ZiehauReset the
130907281d1SSepherosa Ziehau.Fa mask ,
131907281d1SSepherosa Ziehauso that it contains no CPUs.
132907281d1SSepherosa Ziehau.It Fn CPU_SET
133907281d1SSepherosa ZiehauAdd the
134907281d1SSepherosa Ziehau.Fa cpu
135907281d1SSepherosa Ziehauto the
136907281d1SSepherosa Ziehau.Fa mask .
137907281d1SSepherosa Ziehau.It Fn CPU_CLR
138907281d1SSepherosa ZiehauRemove the
139907281d1SSepherosa Ziehau.Fa cpu
140907281d1SSepherosa Ziehaufrom the
141907281d1SSepherosa Ziehau.Fa mask .
142907281d1SSepherosa Ziehau.It Fn CPU_ISSET
143907281d1SSepherosa ZiehauTest to see whether the
144907281d1SSepherosa Ziehau.Fa cpu
145907281d1SSepherosa Ziehauis a member of the
146907281d1SSepherosa Ziehau.Fa mask .
147907281d1SSepherosa Ziehau.It Fn CPU_COUNT
148907281d1SSepherosa ZiehauReturn the number of CPUs in the
149907281d1SSepherosa Ziehau.Fa mask .
150907281d1SSepherosa Ziehau.It Fn CPU_AND
151907281d1SSepherosa ZiehauStore the intersection of the
152907281d1SSepherosa Ziehau.Fa srcmask1
153907281d1SSepherosa Ziehauand the
154907281d1SSepherosa Ziehau.Fa srcmask2
155907281d1SSepherosa Ziehauin the
156907281d1SSepherosa Ziehau.Fa dstmask .
157907281d1SSepherosa ZiehauThe
158907281d1SSepherosa Ziehau.Fa dstmask
159907281d1SSepherosa Ziehaucould be one of the source masks.
160907281d1SSepherosa Ziehau.It Fn CPU_OR
161907281d1SSepherosa ZiehauStore the union of the
162907281d1SSepherosa Ziehau.Fa srcmask1
163907281d1SSepherosa Ziehauand the
164907281d1SSepherosa Ziehau.Fa srcmask2
165907281d1SSepherosa Ziehauin the
166907281d1SSepherosa Ziehau.Fa dstmask .
167907281d1SSepherosa ZiehauThe
168907281d1SSepherosa Ziehau.Fa dstmask
169907281d1SSepherosa Ziehaucould be one of the source masks.
170907281d1SSepherosa Ziehau.It Fn CPU_XOR
171907281d1SSepherosa ZiehauStore the XOR of the
172907281d1SSepherosa Ziehau.Fa srcmask1
173907281d1SSepherosa Ziehauand the
174907281d1SSepherosa Ziehau.Fa srcmask2
175907281d1SSepherosa Ziehauin the
176907281d1SSepherosa Ziehau.Fa dstmask .
177907281d1SSepherosa ZiehauThe
178907281d1SSepherosa Ziehau.Fa dstmask
179907281d1SSepherosa Ziehaucould be one of the source masks.
180907281d1SSepherosa Ziehau.It Fn CPU_EQUAL
181907281d1SSepherosa ZiehauTest whether the
182907281d1SSepherosa Ziehau.Fa mask1
183907281d1SSepherosa Ziehauand the
184907281d1SSepherosa Ziehau.Fa mask2
185907281d1SSepherosa Ziehaucontain the same CPUs.
186907281d1SSepherosa Ziehau.El
187907281d1SSepherosa Ziehau.Sh RETURN VALUES
188907281d1SSepherosa ZiehauThese system calls return \-1 on error and
189907281d1SSepherosa Ziehau0 upon successful completion.
190907281d1SSepherosa Ziehau.Sh ERRORS
191907281d1SSepherosa ZiehauThe
192907281d1SSepherosa Ziehau.Fn sched_setaffinity
193907281d1SSepherosa Ziehauand
194907281d1SSepherosa Ziehau.Fn sched_getaffinity
195907281d1SSepherosa Ziehauwill fail if:
196907281d1SSepherosa Ziehau.Bl -tag -width Er
197907281d1SSepherosa Ziehau.It Bq Er EFAULT
198907281d1SSepherosa ZiehauThe
199907281d1SSepherosa Ziehau.Fa mask
200907281d1SSepherosa Ziehauparameter is outside the process's allocated address space.
201907281d1SSepherosa Ziehau.It Bq Er EINVAL
202907281d1SSepherosa ZiehauThe
203907281d1SSepherosa Ziehau.Fa pid
204907281d1SSepherosa Ziehauparameter is negative.
205907281d1SSepherosa Ziehau.It Bq Er ESRCH
206907281d1SSepherosa ZiehauThe process identified by the
207907281d1SSepherosa Ziehau.Fa pid
208907281d1SSepherosa Ziehaudoes not exist.
209907281d1SSepherosa Ziehau.It Bq Er EPERM
210907281d1SSepherosa ZiehauThe
211907281d1SSepherosa Ziehau.Fa mask
212907281d1SSepherosa Ziehaudoes not contain a valid CPU.
213907281d1SSepherosa Ziehau.El
214907281d1SSepherosa Ziehau.Sh SEE ALSO
215*476c884aSSascha Wildner.Xr fork 2 ,
216*476c884aSSascha Wildner.Xr lwp_create 2 ,
217*476c884aSSascha Wildner.Xr lwp_getaffinity 2 ,
218*476c884aSSascha Wildner.Xr lwp_setaffinity 2 ,
219*476c884aSSascha Wildner.Xr rfork 2 ,
220*476c884aSSascha Wildner.Xr vfork 2 ,
221*476c884aSSascha Wildner.Xr pthread_create 3 ,
222*476c884aSSascha Wildner.Xr pthread_getaffinity_np 3 ,
223a0c14455SSepherosa Ziehau.Xr pthread_setaffinity_np 3
224907281d1SSepherosa Ziehau.Sh HISTORY
225907281d1SSepherosa ZiehauThe
226907281d1SSepherosa Ziehau.Fn sched_setaffinity
227907281d1SSepherosa Ziehauand
228907281d1SSepherosa Ziehau.Fn sched_getaffinity
229907281d1SSepherosa Ziehaufunctions first appeared in
230907281d1SSepherosa Ziehau.Dx 4.7 .
231