xref: /netbsd-src/lib/librt/sched.3 (revision cac8e449158efc7261bebc8657cbb0125a2cfdde)
1.\"	$NetBSD: sched.3,v 1.5 2008/06/22 08:24:26 wiz Exp $
2.\"
3.\" Copyright (c) 2008 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Mindaugas Rasiukevicius <rmind at NetBSD org>.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\"
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.
29.\"
30.Dd June 16, 2008
31.Dt SCHED 3
32.Os
33.Sh NAME
34.Nm sched_setparam ,
35.Nm sched_getparam ,
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 ,
41.Nm sched_yield
42.Nd process scheduling
43.Sh LIBRARY
44.Lb librt
45.Sh SYNOPSIS
46.In sched.h
47.Ft int
48.Fn sched_setparam "pid_t pid" "const struct sched_param *param"
49.Ft int
50.Fn sched_getparam "pid_t pid" "struct sched_param *param"
51.Ft int
52.Fn sched_setscheduler "pid_t pid" "int policy" "const struct sched_param *param"
53.Ft int
54.Fn sched_getscheduler "pid_t pid"
55.Ft int
56.Fn sched_get_priority_max "int policy"
57.Ft int
58.Fn sched_get_priority_min "int policy"
59.Ft int
60.Fn sched_rr_get_interval "pid_t pid" "struct timespec *interval"
61.Ft int
62.Fn sched_yield "void"
63.Sh DESCRIPTION
64This section describes the functions used to get the scheduling
65information about the processes, and control the scheduling of the process.
66.Pp
67Available scheduling policies (classes) are:
68.Bl -tag -width SCHED_OTHER
69.It Dv SCHED_OTHER
70Time-sharing (TS) scheduling policy.
71The default policy in
72.Nx .
73.It Dv SCHED_FIFO
74First in, first out (FIFO) scheduling policy.
75.It Dv SCHED_RR
76Round robin scheduling policy.
77.El
78.Pp
79The
80.Fa struct sched_param
81contains at least one member:
82.Bl -tag -width flags
83.It Fa sched_priority
84Specifies the priority of the process.
85.El
86.Ss FUNCTIONS
87.Bl -tag -width compact
88.It Fn sched_setparam pid param
89Sets the scheduling parameters for the process specified by
90.Fa pid
91to
92.Fa param .
93If the value of
94.Fa pid
95is equal to zero, then the calling process is used.
96.It Fn sched_getparam pid param
97Gets the scheduling parameters of the process specified by
98.Fa pid
99into the structure
100.Fa param .
101If the value of
102.Fa pid
103is equal to zero, then the calling process is used.
104.It Fn sched_setscheduler pid policy param
105Set the scheduling policy and parameters for the process specified by
106.Fa pid .
107If the value of
108.Fa pid
109is equal to zero, then the calling process is used.
110.It Fn sched_getscheduler pid
111Returns the scheduling policy of the process specified by
112.Fa pid .
113If the value of
114.Fa pid
115is equal to zero, then the calling process is used.
116.It Fn sched_get_priority_max policy
117Returns the maximal priority which may be used for the scheduling policy
118specified by
119.Fa policy .
120.It Fn sched_get_priority_min policy
121Returns the minimal priority which may be used for the scheduling policy
122specified by
123.Fa policy .
124.It Fn sched_rr_get_interval pid interval
125Returns the time quantum into the structure
126.Fa interval
127of the process specified by
128.Fa pid .
129If the value of
130.Fa pid
131is equal to zero, then the calling process is used.
132The process must be running at
133.Fa SCHED_RR
134scheduling policy.
135.It Fn sched_yield
136Yields a processor voluntarily and gives other threads a chance to run
137without waiting for an involuntary preemptive switch.
138.El
139.Sh RETURN VALUES
140.Fn sched_setparam ,
141.Fn sched_getparam ,
142.Fn sched_rr_get_interval ,
143and
144.Fn sched_yield
145return 0 on success.
146Otherwise, \-1 is returned and
147.Va errno
148is set to indicate the error.
149.Pp
150.Fn sched_setscheduler
151returns the previously used scheduling policy on success.
152Otherwise, \-1 is returned and
153.Va errno
154is set to indicate the error.
155.Pp
156.Fn sched_getscheduler
157returns the scheduling policy on success.
158Otherwise, \-1 is returned and
159.Va errno
160is set to indicate the error.
161.Pp
162The
163.Fn sched_get_priority_max
164and
165.Fn sched_get_priority_min
166return the maximal/minimal priority value on success.
167Otherwise, \-1 is returned and
168.Va errno
169is set to indicate the error.
170.Sh ERRORS
171The
172.Fn sched_setparam
173and
174.Fn sched_setscheduler
175functions fail if:
176.Bl -tag -width Er
177.It Bq Er EINVAL
178At least one of the specified scheduling parameters was invalid.
179.It Bq Er EPERM
180The calling process has no appropriate privileges to perform the operation.
181.It Bq Er ESRCH
182No process can be found corresponding to that specified by
183.Fa pid ,
184and value of
185.Fa pid
186is not zero.
187.El
188.Pp
189The
190.Fn sched_getparam
191and
192.Fn sched_getscheduler
193functions fail if:
194.Bl -tag -width Er
195.It Bq Er EPERM
196The calling process is not a super-user and its effective user id does not
197match the effective user-id of the specified process.
198.It Bq Er ESRCH
199No process can be found corresponding to that specified by
200.Fa pid ,
201and value of
202.Fa pid
203is not zero.
204.El
205.Pp
206The
207.Fn sched_get_priority_max
208and
209.Fn sched_get_priority_min
210functions fail if:
211.Bl -tag -width Er
212.It Bq Er EINVAL
213The specified scheduling policy is invalid.
214.El
215.Pp
216The
217.Fn sched_rr_get_interval
218function fails if:
219.Bl -tag -width Er
220.It Bq Er ESRCH
221No process can be found corresponding to that specified by
222.Fa pid ,
223and value of
224.Fa pid
225is not zero.
226.El
227.Sh SEE ALSO
228.Xr affinity 3 ,
229.Xr cpuset 3 ,
230.Xr pset 3 ,
231.Xr schedctl 8
232.Sh STANDARDS
233These functions conform to
234.St -p1003.1-2001
235standard.
236.Sh HISTORY
237The scheduling functions appeared in
238.Nx 5.0 .
239