1.\" $NetBSD: sched.3,v 1.10 2011/04/25 23:14:33 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 May 6, 2010 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 scheduling information 65about processes, and control the scheduling of processes. 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.Sh 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.It Fn sched_setaffinity_np pid size cpuset 139Set the affinity mask specified by 140.Fa cpuset 141for the process specified by 142.Fa pid . 143At least one valid CPU must be set in the mask. 144.It Fn sched_getaffinity_np pid size cpuset 145Get the affinity mask of the process specified by 146.Fa pid 147into the 148.Fa cpuset . 149.El 150.Sh IMPLEMENTATION NOTES 151Portable applications should not use the 152.Fn sched_setaffinity_np 153and 154.Fn sched_getaffinity_np 155functions. 156.Sh RETURN VALUES 157.Fn sched_setparam , 158.Fn sched_getparam , 159.Fn sched_rr_get_interval , 160and 161.Fn sched_yield 162return 0 on success. 163Otherwise, \-1 is returned and 164.Va errno 165is set to indicate the error. 166.Pp 167.Fn sched_setscheduler 168returns the previously used scheduling policy on success. 169Otherwise, \-1 is returned and 170.Va errno 171is set to indicate the error. 172.Pp 173.Fn sched_getscheduler 174returns the scheduling policy on success. 175Otherwise, \-1 is returned and 176.Va errno 177is set to indicate the error. 178.Pp 179.Fn sched_get_priority_max 180and 181.Fn sched_get_priority_min 182return the maximal/minimal priority value on success. 183Otherwise, \-1 is returned and 184.Va errno 185is set to indicate the error. 186.Pp 187.Fn sched_setaffinity_np 188and 189.Fn sched_getaffinity_np 190return 0 on success. 191Otherwise, \-1 is returned and 192.Va errno 193is set to indicate the error. 194.Sh ERRORS 195The 196.Fn sched_setparam 197and 198.Fn sched_setscheduler 199functions fail if: 200.Bl -tag -width Er 201.It Bq Er EINVAL 202At least one of the specified scheduling parameters was invalid. 203.It Bq Er EPERM 204The calling process has no appropriate privileges to perform the operation. 205.It Bq Er ESRCH 206No process can be found corresponding to the PID specified by 207.Fa pid , 208and the value of 209.Fa pid 210is not zero. 211.El 212.Pp 213The 214.Fn sched_getparam 215and 216.Fn sched_getscheduler 217functions fail if: 218.Bl -tag -width Er 219.It Bq Er EPERM 220The calling process is not a super-user and its effective user id does not 221match the effective user-id of the specified process. 222.It Bq Er ESRCH 223No process can be found corresponding to that specified by 224.Fa pid , 225and the value of 226.Fa pid 227is not zero. 228.El 229.Pp 230The 231.Fn sched_get_priority_max 232and 233.Fn sched_get_priority_min 234functions fail if: 235.Bl -tag -width Er 236.It Bq Er EINVAL 237The specified scheduling policy is invalid. 238.El 239.Pp 240The 241.Fn sched_rr_get_interval 242function fails if: 243.Bl -tag -width Er 244.It Bq Er ESRCH 245No process can be found corresponding to that specified by 246.Fa pid , 247and the value of 248.Fa pid 249is not zero. 250.El 251.Sh SEE ALSO 252.Xr affinity 3 , 253.Xr cpuset 3 , 254.Xr pset 3 , 255.Xr schedctl 8 256.Sh STANDARDS 257These functions, except 258.Fn sched_setaffinity_np 259and 260.Fn sched_getaffinity_np , 261are expected to conform the 262.St -p1003.1-2001 263standard. 264.Sh HISTORY 265The scheduling functions appeared in 266.Nx 5.0 . 267