1 .\" $NetBSD: sched.3,v 1.7 2008/10/31 18:07:18 snj Exp $
3 .\" Copyright (c) 2008 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Mindaugas Rasiukevicius <rmind at NetBSD org>.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nm sched_setscheduler ,
37 .Nm sched_getscheduler ,
38 .Nm sched_get_priority_max ,
39 .Nm sched_get_priority_min ,
40 .Nm sched_rr_get_interval ,
42 .Nd process scheduling
48 .Fn sched_setparam "pid_t pid" "const struct sched_param *param"
50 .Fn sched_getparam "pid_t pid" "struct sched_param *param"
52 .Fn sched_setscheduler "pid_t pid" "int policy" "const struct sched_param *param"
54 .Fn sched_getscheduler "pid_t pid"
56 .Fn sched_get_priority_max "int policy"
58 .Fn sched_get_priority_min "int policy"
60 .Fn sched_rr_get_interval "pid_t pid" "struct timespec *interval"
62 .Fn sched_yield "void"
64 This section describes the functions used to get scheduling information
65 about processes, and control the scheduling of processes.
67 Available scheduling policies (classes) are:
68 .Bl -tag -width SCHED_OTHER
70 Time-sharing (TS) scheduling policy.
74 First in, first out (FIFO) scheduling policy.
76 Round robin scheduling policy.
80 .Fa struct sched_param
81 contains at least one member:
84 Specifies the priority of the process.
87 .Bl -tag -width compact
88 .It Fn sched_setparam pid param
89 Sets the scheduling parameters for the process specified by
95 is equal to zero, then the calling process is used.
96 .It Fn sched_getparam pid param
97 Gets the scheduling parameters of the process specified by
103 is equal to zero, then the calling process is used.
104 .It Fn sched_setscheduler pid policy param
105 Set the scheduling policy and parameters for the process specified by
109 is equal to zero, then the calling process is used.
110 .It Fn sched_getscheduler pid
111 Returns the scheduling policy of the process specified by
115 is equal to zero, then the calling process is used.
116 .It Fn sched_get_priority_max policy
117 Returns the maximal priority which may be used for the scheduling policy
120 .It Fn sched_get_priority_min policy
121 Returns the minimal priority which may be used for the scheduling policy
124 .It Fn sched_rr_get_interval pid interval
125 Returns the time quantum into the structure
127 of the process specified by
131 is equal to zero, then the calling process is used.
132 The process must be running at
136 Yields a processor voluntarily and gives other threads a chance to run
137 without waiting for an involuntary preemptive switch.
138 .It Fn sched_setaffinity_np pid size cpuset
139 Set the affinity mask specified by
141 for the process specified by
143 At least one valid CPU must be set in the mask.
144 .It Fn sched_getaffinity_np pid size cpuset
145 Get the affinity mask of the process specified by
153 .Fn sched_rr_get_interval ,
157 Otherwise, \-1 is returned and
159 is set to indicate the error.
161 .Fn sched_setscheduler
162 returns the previously used scheduling policy on success.
163 Otherwise, \-1 is returned and
165 is set to indicate the error.
167 .Fn sched_getscheduler
168 returns the scheduling policy on success.
169 Otherwise, \-1 is returned and
171 is set to indicate the error.
173 .Fn sched_get_priority_max
175 .Fn sched_get_priority_min
176 return the maximal/minimal priority value on success.
177 Otherwise, \-1 is returned and
179 is set to indicate the error.
181 .Fn sched_setaffinity_np
183 .Fn sched_getaffinity_np
185 Otherwise, \-1 is returned and
187 is set to indicate the error.
192 .Fn sched_setscheduler
196 At least one of the specified scheduling parameters was invalid.
198 The calling process has no appropriate privileges to perform the operation.
200 No process can be found corresponding to the PID specified by
210 .Fn sched_getscheduler
214 The calling process is not a super-user and its effective user id does not
215 match the effective user-id of the specified process.
217 No process can be found corresponding to that specified by
225 .Fn sched_get_priority_max
227 .Fn sched_get_priority_min
231 The specified scheduling policy is invalid.
235 .Fn sched_rr_get_interval
239 No process can be found corresponding to that specified by
246 Portable applications should not use the
247 .Fn sched_setaffinity_np
249 .Fn sched_getaffinity_np
257 These functions, except
258 .Fn sched_setaffinity_np
260 .Fn sched_getaffinity_np ,
261 are expected to conform the
265 The scheduling functions appeared in