1.\" $NetBSD: sched.3,v 1.1 2008/03/10 14:47:06 rmind 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.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd March 10, 2008 38.Dt SCHED 3 39.Os 40.Sh NAME 41.Nm sched_setparam , 42.Nm sched_getparam , 43.Nm sched_setscheduler , 44.Nm sched_getscheduler , 45.Nm sched_get_priority_max , 46.Nm sched_get_priority_min , 47.Nm sched_rr_get_interval , 48.Nm sched_yield 49.Nd process scheduling 50.Sh LIBRARY 51.Lb librt 52.Sh SYNOPSIS 53.In sched.h 54.Ft int 55.Fn sched_setparam "pid_t pid" "const struct sched_param *param" 56.Ft int 57.Fn sched_getparam "pid_t pid" "struct sched_param *param" 58.Ft int 59.Fn sched_setscheduler "pid_t pid" "int policy" "const struct sched_param *param" 60.Ft int 61.Fn sched_getscheduler "pid_t pid" 62.Ft int 63.Fn sched_get_priority_max "int policy" 64.Ft int 65.Fn sched_get_priority_min "int policy" 66.Ft int 67.Fn sched_rr_get_interval "pid_t pid" "struct timespec *interval" 68.Ft int 69.Fn sched_yield "void" 70.Sh DESCRIPTION 71This section describes the functions used to get the scheduling 72information about the processes, and control the scheduling of the process. 73.Pp 74Available scheduling policies (classes) are: 75.Bl -tag -width SCHED_OTHER 76.It Dv SCHED_OTHER 77Time-sharing (TS) scheduling policy. 78The default policy in 79.Nx . 80.It Dv SCHED_FIFO 81First in, first out (FIFO) scheduling policy. 82.It Dv SCHED_RR 83Round robin scheduling policy. 84.El 85.Pp 86The 87.Fa struct sched_param 88contains at least one member: 89.Bl -tag -width flags 90.It Fa sched_priority 91Specifies the priority of the process. 92.El 93.Ss FUNCTIONS 94.Bl -tag -width compact 95.It Fn sched_setparam pid param 96Sets the scheduling parameters for the process specified by 97.Fa pid 98to 99.Fa param . 100If the value of 101.Fa pid 102is equal to zero, then the calling process is used. 103.It Fn sched_getparam pid param 104Gets the scheduling parameters of the process specified by 105.Fa pid 106into the structure 107.Fa param . 108If the value of 109.Fa pid 110is equal to zero, then the calling process is used. 111.It Fn sched_setscheduler pid policy param 112Set the scheduling policy and parameters for the process specified by 113.Fa pid . 114If the value of 115.Fa pid 116is equal to zero, then the calling process is used. 117.It Fn sched_getscheduler pid 118Returns the scheduling policy of the process specified by 119.Fa pid . 120If the value of 121.Fa pid 122is equal to zero, then the calling process is used. 123.It Fn sched_get_priority_max policy 124Returns the maximal priority which may be used for the scheduling policy 125specified by 126.Fa policy . 127.It Fn sched_get_priority_min policy 128Returns the minimal priority which may be used for the scheduling policy 129specified by 130.Fa policy . 131.It Fn sched_rr_get_interval pid interval 132Returns the time quantum into the structure 133.Fa interval 134of the process specified by 135.Fa pid . 136If the value of 137.Fa pid 138is equal to zero, then the calling process is used. 139The process must be running at 140.Fa SCHED_RR 141scheduling policy. 142.It Fn sched_yield 143Yields a processor voluntarily and gives other threads a chance to run 144without waiting for an involuntary preemptive switch. 145.El 146.Sh RETURN VALUES 147.Fn sched_setparam , 148.Fn sched_getparam , 149.Fn sched_rr_get_interval , 150and 151.Fn sched_yield 152return 0 on success. 153Otherwise, \-1 is returned and 154.Va errno 155is set to indicate the error. 156.Pp 157.Fn sched_setscheduler 158returns the previously used scheduling policy on success. 159Otherwise, \-1 is returned and 160.Va errno 161is set to indicate the error. 162.Pp 163.Fn sched_getscheduler 164returns the scheduling policy on success. 165Otherwise, \-1 is returned and 166.Va errno 167is set to indicate the error. 168.Pp 169The 170.Fn sched_get_priority_max 171and 172.Fn sched_get_priority_min 173return the maximal/minimal priority value on success. 174Otherwise, \-1 is returned and 175.Va errno 176is set to indicate the error. 177.Sh ERRORS 178The 179.Fn sched_setparam 180and 181.Fn sched_setscheduler 182functions fail if: 183.Bl -tag -width Er 184.It Bq Er EINVAL 185At least one of the specified scheduling parameters was invalid. 186.It Bq Er EPERM 187The calling process has no appropriate privileges to perform the operation. 188.It Bq Er ESRCH 189No process can be found corresponding to that specified by 190.Fa pid , 191and value of 192.Fa pid 193is not zero. 194.El 195.Pp 196The 197.Fn sched_getparam 198and 199.Fn sched_getscheduler 200functions fail if: 201.Bl -tag -width Er 202.It Bq Er EPERM 203The calling process is not a super-user and its effective user id does not 204match the effective user-id of the specified process. 205.It Bq Er ESRCH 206No process can be found corresponding to that specified by 207.Fa pid , 208and value of 209.Fa pid 210is not zero. 211.El 212.Pp 213The 214.Fn sched_get_priority_max 215and 216.Fn sched_get_priority_min 217functions fail if: 218.Bl -tag -width Er 219.It Bq Er EINVAL 220The specified scheduling policy is invalid. 221.El 222.Pp 223The 224.Fn sched_rr_get_interval 225function fails if: 226.Bl -tag -width Er 227.It Bq Er ESRCH 228No process can be found corresponding to that specified by 229.Fa pid , 230and value of 231.Fa pid 232is not zero. 233.El 234.Sh SEE ALSO 235.Xr pset 3 , 236.Xr schedctl 8 237.Sh STANDARDS 238These functions conform to 239.St -p1003.1-2001 240standard. 241.Sh HISTORY 242The scheduling functions appeared in 243.Nx 5.0 . 244.Sh BUGS 245Currently, these functions are valid and work correctly only with the 246SCHED_M2 thread scheduler implementation. 247