1 .\" Copyright (c) 2017 The DragonFly Project. All rights reserved.
3 .\" This code is derived from software contributed to The DragonFly Project
4 .\" by Sepherosa Ziehau <sepherosa@gmail.com>.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in
14 .\" the documentation and/or other materials provided with the
16 .\" 3. Neither the name of The DragonFly Project nor the names of its
17 .\" contributors may be used to endorse or promote products derived
18 .\" from this software without specific, prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .Dt SCHED_SETAFFINITY 2
46 .Nm sched_setaffinity ,
48 .Nd set and get a process's CPU affinity mask
55 .Fn sched_setaffinity "pid_t pid" "size_t cpusetsize" "const cpu_set_t *mask"
57 .Fn sched_getaffinity "pid_t pid" "size_t cpusetsize" "cpu_set_t *mask"
61 .Fn CPU_ISSET cpu &mask
63 .Fn CPU_AND &dstmask &srcmask1 &srcmask2
64 .Fn CPU_OR &dstmask &srcmask1 srcmask2
65 .Fn CPU_XOR &dstmask &srcmask1 &srcmask2
66 .Fn CPU_EQUAL &mask1 &mask2
70 sets the CPU affinity mask of the process,
71 which is identified by the
73 to the value specified by the
77 is the length (in bytes) of the data pointed to by
79 Normally this argument would be specified as sizeof(cpu_set_t).
83 then the pid of the calling process is used.
84 All threads of the process identified by
87 If the calling thread is one of the target process's threads,
88 then the calling thread will be migrated immediately,
90 while other threads of the targt process will be migrated
91 by the scheduler later.
98 inherits the calling thread's CPU affinity mask.
99 Same applies to the threads created by
101 and the threads created by
102 .Xr pthread_create 3 .
104 .Fn sched_getaffinity
105 writes the affinity mask of the process
108 to the cpu_set_t structure pointed to by
113 then the pid of the calling process is used.
114 If the process is multithreaded,
115 then the CPU affinity mask of the first thread will be returned.
117 The cpu_set_t data structure represents a set of CPUs.
118 The first available CPU on the system corresponds to a cpu value of 0,
119 the next CPU corresponds to a cpu value of 1,
120 and so on and so forth.
123 specifies a value one greater than the maximum
124 CPU number that can be stored in cpu_set_t.
125 The cpu_set_t should be treated as opaque data structure;
126 all manipulation of cpu_set_t should be done via the following macros:
127 .Bl -tag -width "CPU_COUNTxxx"
131 so that it contains no CPUs.
143 Test to see whether the
148 Return the number of CPUs in the
151 Store the intersection of the
159 could be one of the source masks.
161 Store the union of the
169 could be one of the source masks.
179 could be one of the source masks.
185 contain the same CPUs.
188 These system calls return \-1 on error and
189 0 upon successful completion.
192 .Fn sched_setaffinity
194 .Fn sched_getaffinity
200 parameter is outside the process's allocated address space.
204 parameter is negative.
206 The process identified by the
212 does not contain a valid CPU.
217 .Xr lwp_getaffinity 2 ,
218 .Xr lwp_setaffinity 2 ,
221 .Xr pthread_create 3 ,
222 .Xr pthread_getaffinity_np 3 ,
223 .Xr pthread_setaffinity_np 3
226 .Fn sched_setaffinity
228 .Fn sched_getaffinity
229 functions first appeared in