xref: /dflybsd-src/lib/libc/sys/sched_setaffinity.2 (revision fe54de69b61a9ee6e80c15042575b71ae23c7b1b)
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
37907281d1SSepherosa Ziehau.Nm sched_setaffinity,
38907281d1SSepherosa Ziehau.Nm sched_getaffinity
39907281d1SSepherosa Ziehau.Nd set and get a process's CPU affinity mask
40907281d1SSepherosa Ziehau.Sh LIBRARY
41907281d1SSepherosa Ziehau.Lb libc
42907281d1SSepherosa Ziehau.Sh SYNOPSIS
43907281d1SSepherosa Ziehau.In sys/types.h
44907281d1SSepherosa Ziehau.In sys/sched.h
45907281d1SSepherosa Ziehau.Ft int
46*fe54de69SSepherosa Ziehau.Fn sched_setaffinity "pid_t pid" "size_t cpusetsize" "const cpu_set_t *mask"
47907281d1SSepherosa Ziehau.Ft int
48907281d1SSepherosa Ziehau.Fn sched_getaffinity "pid_t pid" "size_t cpusetsize" "cpu_set_t *mask"
49907281d1SSepherosa Ziehau.Fn CPU_ZERO &mask
50907281d1SSepherosa Ziehau.Fn CPU_SET cpu &mask
51907281d1SSepherosa Ziehau.Fn CPU_CLR cpu &mask
52907281d1SSepherosa Ziehau.Fn CPU_ISSET cpu &mask
53907281d1SSepherosa Ziehau.Fn CPU_COUNT &mask
54907281d1SSepherosa Ziehau.Fn CPU_AND &dstmask &srcmask1 &srcmask2
55907281d1SSepherosa Ziehau.Fn CPU_OR &dstmask &srcmask1 srcmask2
56907281d1SSepherosa Ziehau.Fn CPU_XOR &dstmask &srcmask1 &srcmask2
57907281d1SSepherosa Ziehau.Fn CPU_EQUAL &mask1 &mask2
58907281d1SSepherosa Ziehau.Sh DESCRIPTION
59907281d1SSepherosa Ziehau.Pp
60907281d1SSepherosa ZiehauThe
61907281d1SSepherosa Ziehau.Fn sched_setaffinity
62907281d1SSepherosa Ziehausets the CPU affinity mask of the process,
63907281d1SSepherosa Ziehauwhich is identified by the
64907281d1SSepherosa Ziehau.Fa pid
65907281d1SSepherosa Ziehauto the value specified by the
66907281d1SSepherosa Ziehau.Fa mask .
67907281d1SSepherosa ZiehauThe
68907281d1SSepherosa Ziehau.Fa cpusetsize
69907281d1SSepherosa Ziehauis the length (in bytes) of the data pointed to by
70907281d1SSepherosa Ziehau.Fa mask .
71907281d1SSepherosa ZiehauNormally this argument would be specified as sizeof(cpu_set_t).
72907281d1SSepherosa ZiehauIf the
73907281d1SSepherosa Ziehau.Fa pid
74907281d1SSepherosa Ziehauis zero,
75907281d1SSepherosa Ziehauthen the pid of the calling process is used.
76907281d1SSepherosa ZiehauAll threads of the process identified by
77907281d1SSepherosa Ziehau.Fa pid
78907281d1SSepherosa Ziehauare affected.
79907281d1SSepherosa ZiehauIf the calling thread is one of the target process's threads,
80907281d1SSepherosa Ziehauthen the calling thread will be migrated immediately,
81907281d1SSepherosa Ziehauif necessary,
82907281d1SSepherosa Ziehauwhile other threads of the targt process will be migrated
83907281d1SSepherosa Ziehauby the scheduler later.
84907281d1SSepherosa Ziehau.Pp
85907281d1SSepherosa ZiehauA process created by
86907281d1SSepherosa Ziehau.Xr fork 2 ,
87907281d1SSepherosa Ziehau.Xr vfork 2 ,
88907281d1SSepherosa Ziehauand
89907281d1SSepherosa Ziehau.Xr rfork 2
90907281d1SSepherosa Ziehauinherits the calling thread's CPU affinity mask.
91907281d1SSepherosa ZiehauSame applies to the threads created by
92907281d1SSepherosa Ziehau.Xr lwp_create 2 ,
93907281d1SSepherosa Ziehauand the threads created by
94907281d1SSepherosa Ziehau.Xr pthread_create 3 .
95907281d1SSepherosa Ziehau.Pp
96907281d1SSepherosa Ziehau.Fn sched_getaffinity
97907281d1SSepherosa Ziehauwrites the affinity mask of the process
98907281d1SSepherosa Ziehauidentified by the
99907281d1SSepherosa Ziehau.Fa pid
100907281d1SSepherosa Ziehauto the cpu_set_t structure pointed to by
101907281d1SSepherosa Ziehau.Fa mask .
102907281d1SSepherosa ZiehauIf the
103907281d1SSepherosa Ziehau.Fa pid
104907281d1SSepherosa Ziehauis zero,
105907281d1SSepherosa Ziehauthen the pid of the calling process is used.
106907281d1SSepherosa ZiehauIf the process is multithreaded,
107907281d1SSepherosa Ziehauthen the CPU affinity mask of the first thread will be returned.
108907281d1SSepherosa Ziehau.Pp
109907281d1SSepherosa ZiehauThe cpu_set_t data structure represents a set of CPUs.
110907281d1SSepherosa ZiehauThe first available CPU on the system corresponds to a cpu value of 0,
111907281d1SSepherosa Ziehauthe next CPU corresponds to a cpu value of 1,
112907281d1SSepherosa Ziehauand so on and so forth.
113907281d1SSepherosa ZiehauThe constant
114907281d1SSepherosa Ziehau.Va CPU_SETSIZE
115907281d1SSepherosa Ziehauspecifies a value one greater than the maximum
116907281d1SSepherosa ZiehauCPU number that can be stored in cpu_set_t.
117907281d1SSepherosa ZiehauThe cpu_set_t should be treated as opaque data structure;
118907281d1SSepherosa Ziehauall manipulation of cpu_set_t should be done via the following macros:
119907281d1SSepherosa Ziehau.Bl -tag -width "CPU_COUNTxxx"
120907281d1SSepherosa Ziehau.It Fn CPU_ZERO
121907281d1SSepherosa ZiehauReset the
122907281d1SSepherosa Ziehau.Fa mask ,
123907281d1SSepherosa Ziehauso that it contains no CPUs.
124907281d1SSepherosa Ziehau.It Fn CPU_SET
125907281d1SSepherosa ZiehauAdd the
126907281d1SSepherosa Ziehau.Fa cpu
127907281d1SSepherosa Ziehauto the
128907281d1SSepherosa Ziehau.Fa mask .
129907281d1SSepherosa Ziehau.It Fn CPU_CLR
130907281d1SSepherosa ZiehauRemove the
131907281d1SSepherosa Ziehau.Fa cpu
132907281d1SSepherosa Ziehaufrom the
133907281d1SSepherosa Ziehau.Fa mask .
134907281d1SSepherosa Ziehau.It Fn CPU_ISSET
135907281d1SSepherosa ZiehauTest to see whether the
136907281d1SSepherosa Ziehau.Fa cpu
137907281d1SSepherosa Ziehauis a member of the
138907281d1SSepherosa Ziehau.Fa mask .
139907281d1SSepherosa Ziehau.It Fn CPU_COUNT
140907281d1SSepherosa ZiehauReturn the number of CPUs in the
141907281d1SSepherosa Ziehau.Fa mask .
142907281d1SSepherosa Ziehau.It Fn CPU_AND
143907281d1SSepherosa ZiehauStore the intersection of the
144907281d1SSepherosa Ziehau.Fa srcmask1
145907281d1SSepherosa Ziehauand the
146907281d1SSepherosa Ziehau.Fa srcmask2
147907281d1SSepherosa Ziehauin the
148907281d1SSepherosa Ziehau.Fa dstmask .
149907281d1SSepherosa ZiehauThe
150907281d1SSepherosa Ziehau.Fa dstmask
151907281d1SSepherosa Ziehaucould be one of the source masks.
152907281d1SSepherosa Ziehau.It Fn CPU_OR
153907281d1SSepherosa ZiehauStore the union of the
154907281d1SSepherosa Ziehau.Fa srcmask1
155907281d1SSepherosa Ziehauand the
156907281d1SSepherosa Ziehau.Fa srcmask2
157907281d1SSepherosa Ziehauin the
158907281d1SSepherosa Ziehau.Fa dstmask .
159907281d1SSepherosa ZiehauThe
160907281d1SSepherosa Ziehau.Fa dstmask
161907281d1SSepherosa Ziehaucould be one of the source masks.
162907281d1SSepherosa Ziehau.It Fn CPU_XOR
163907281d1SSepherosa ZiehauStore the XOR of the
164907281d1SSepherosa Ziehau.Fa srcmask1
165907281d1SSepherosa Ziehauand the
166907281d1SSepherosa Ziehau.Fa srcmask2
167907281d1SSepherosa Ziehauin the
168907281d1SSepherosa Ziehau.Fa dstmask .
169907281d1SSepherosa ZiehauThe
170907281d1SSepherosa Ziehau.Fa dstmask
171907281d1SSepherosa Ziehaucould be one of the source masks.
172907281d1SSepherosa Ziehau.It Fn CPU_EQUAL
173907281d1SSepherosa ZiehauTest whether the
174907281d1SSepherosa Ziehau.Fa mask1
175907281d1SSepherosa Ziehauand the
176907281d1SSepherosa Ziehau.Fa mask2
177907281d1SSepherosa Ziehaucontain the same CPUs.
178907281d1SSepherosa Ziehau.El
179907281d1SSepherosa Ziehau.Sh RETURN VALUES
180907281d1SSepherosa ZiehauThese system calls return \-1 on error and
181907281d1SSepherosa Ziehau0 upon successful completion.
182907281d1SSepherosa Ziehau.Sh ERRORS
183907281d1SSepherosa ZiehauThe
184907281d1SSepherosa Ziehau.Fn sched_setaffinity
185907281d1SSepherosa Ziehauand
186907281d1SSepherosa Ziehau.Fn sched_getaffinity
187907281d1SSepherosa Ziehauwill fail if:
188907281d1SSepherosa Ziehau.Bl -tag -width Er
189907281d1SSepherosa Ziehau.It Bq Er EFAULT
190907281d1SSepherosa ZiehauThe
191907281d1SSepherosa Ziehau.Fa mask
192907281d1SSepherosa Ziehauparameter is outside the process's allocated address space.
193907281d1SSepherosa Ziehau.It Bq Er EINVAL
194907281d1SSepherosa ZiehauThe
195907281d1SSepherosa Ziehau.Fa pid
196907281d1SSepherosa Ziehauparameter is negative.
197907281d1SSepherosa Ziehau.It Bq Er ESRCH
198907281d1SSepherosa ZiehauThe process identified by the
199907281d1SSepherosa Ziehau.Fa pid
200907281d1SSepherosa Ziehaudoes not exist.
201907281d1SSepherosa Ziehau.It Bq Er EPERM
202907281d1SSepherosa ZiehauThe
203907281d1SSepherosa Ziehau.Fa mask
204907281d1SSepherosa Ziehaudoes not contain a valid CPU.
205907281d1SSepherosa Ziehau.El
206907281d1SSepherosa Ziehau.Sh SEE ALSO
207907281d1SSepherosa Ziehau.Xr fork 2
208907281d1SSepherosa Ziehau.Xr lwp_create 2
209907281d1SSepherosa Ziehau.Xr lwp_getaffinity 2
210907281d1SSepherosa Ziehau.Xr lwp_setaffinity 2
211907281d1SSepherosa Ziehau.Xr pthread_create 3
212907281d1SSepherosa Ziehau.Xr rfork 2
213907281d1SSepherosa Ziehau.Xr vfork 2
214907281d1SSepherosa Ziehau.Sh HISTORY
215907281d1SSepherosa ZiehauThe
216907281d1SSepherosa Ziehau.Fn sched_setaffinity
217907281d1SSepherosa Ziehauand
218907281d1SSepherosa Ziehau.Fn sched_getaffinity
219907281d1SSepherosa Ziehaufunctions first appeared in
220907281d1SSepherosa Ziehau.Dx 4.7 .
221