xref: /freebsd-src/lib/libsys/rtprio.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"-
2*8269e767SBrooks Davis.\" Copyright (c) 1994, Henrik Vestergaard Draboel
3*8269e767SBrooks Davis.\" All rights reserved.
4*8269e767SBrooks Davis.\"
5*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
6*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
7*8269e767SBrooks Davis.\" are met:
8*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
9*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
10*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
11*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
12*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
13*8269e767SBrooks Davis.\" 3. All advertising materials mentioning features or use of this software
14*8269e767SBrooks Davis.\"    must display the following acknowledgement:
15*8269e767SBrooks Davis.\" 	This product includes software developed by Henrik Vestergaard Draboel.
16*8269e767SBrooks Davis.\" 4. The name of the author may not be used to endorse or promote products
17*8269e767SBrooks Davis.\"    derived from this software without specific prior written permission.
18*8269e767SBrooks Davis.\"
19*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*8269e767SBrooks Davis.\" SUCH DAMAGE.
30*8269e767SBrooks Davis.\"-
31*8269e767SBrooks Davis.\" Copyright (c) 2011 Xin LI <delphij@FreeBSD.org>
32*8269e767SBrooks Davis.\"
33*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
34*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
35*8269e767SBrooks Davis.\" are met:
36*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
37*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
38*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
39*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
40*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
41*8269e767SBrooks Davis.\"
42*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52*8269e767SBrooks Davis.\" SUCH DAMAGE.
53*8269e767SBrooks Davis.\"
54*8269e767SBrooks Davis.Dd December 8, 2021
55*8269e767SBrooks Davis.Dt RTPRIO 2
56*8269e767SBrooks Davis.Os
57*8269e767SBrooks Davis.Sh NAME
58*8269e767SBrooks Davis.Nm rtprio ,
59*8269e767SBrooks Davis.Nm rtprio_thread
60*8269e767SBrooks Davis.Nd examine or modify realtime or idle priority
61*8269e767SBrooks Davis.Sh LIBRARY
62*8269e767SBrooks Davis.Lb libc
63*8269e767SBrooks Davis.Sh SYNOPSIS
64*8269e767SBrooks Davis.In sys/types.h
65*8269e767SBrooks Davis.In sys/rtprio.h
66*8269e767SBrooks Davis.Ft int
67*8269e767SBrooks Davis.Fn rtprio "int function" "pid_t pid" "struct rtprio *rtp"
68*8269e767SBrooks Davis.Ft int
69*8269e767SBrooks Davis.Fn rtprio_thread "int function" "lwpid_t lwpid" "struct rtprio *rtp"
70*8269e767SBrooks Davis.Sh DESCRIPTION
71*8269e767SBrooks DavisThe
72*8269e767SBrooks Davis.Fn rtprio
73*8269e767SBrooks Davissystem call
74*8269e767SBrooks Davisis used to lookup or change the realtime or idle priority of a process,
75*8269e767SBrooks Davisor the calling thread.
76*8269e767SBrooks DavisThe
77*8269e767SBrooks Davis.Fn rtprio_thread
78*8269e767SBrooks Davissystem call
79*8269e767SBrooks Davisis used to lookup or change the realtime or idle priority of a thread.
80*8269e767SBrooks Davis.Pp
81*8269e767SBrooks DavisThe
82*8269e767SBrooks Davis.Fa function
83*8269e767SBrooks Davisargument
84*8269e767SBrooks Davisspecifies the operation to be performed.
85*8269e767SBrooks DavisRTP_LOOKUP to lookup the current priority,
86*8269e767SBrooks Davisand RTP_SET to set the priority.
87*8269e767SBrooks Davis.Pp
88*8269e767SBrooks DavisFor the
89*8269e767SBrooks Davis.Fn rtprio
90*8269e767SBrooks Davissystem call,
91*8269e767SBrooks Davisthe
92*8269e767SBrooks Davis.Fa pid
93*8269e767SBrooks Davisargument
94*8269e767SBrooks Davisspecifies the process to operate on,
95*8269e767SBrooks Davis0 for the calling thread.
96*8269e767SBrooks DavisWhen
97*8269e767SBrooks Davis.Fa pid
98*8269e767SBrooks Davisis non-zero,
99*8269e767SBrooks Davisthe system call reports the highest priority in the process,
100*8269e767SBrooks Davisor sets all threads' priority in the process,
101*8269e767SBrooks Davisdepending on value of the
102*8269e767SBrooks Davis.Fa function
103*8269e767SBrooks Davisargument.
104*8269e767SBrooks Davis.Pp
105*8269e767SBrooks DavisFor the
106*8269e767SBrooks Davis.Fn rtprio_thread
107*8269e767SBrooks Davissystem call,
108*8269e767SBrooks Davisthe
109*8269e767SBrooks Davis.Fa lwpid
110*8269e767SBrooks Davisspecifies the thread to operate on,
111*8269e767SBrooks Davis0 for the calling thread.
112*8269e767SBrooks Davis.Pp
113*8269e767SBrooks DavisThe
114*8269e767SBrooks Davis.Fa *rtp
115*8269e767SBrooks Davisargument
116*8269e767SBrooks Davisis a pointer to a struct rtprio which is used to specify the priority and priority type.
117*8269e767SBrooks DavisThis structure has the following form:
118*8269e767SBrooks Davis.Bd -literal
119*8269e767SBrooks Davisstruct rtprio {
120*8269e767SBrooks Davis	u_short	type;
121*8269e767SBrooks Davis	u_short prio;
122*8269e767SBrooks Davis};
123*8269e767SBrooks Davis.Ed
124*8269e767SBrooks Davis.Pp
125*8269e767SBrooks DavisThe value of the
126*8269e767SBrooks Davis.Va type
127*8269e767SBrooks Davisfield may be RTP_PRIO_REALTIME for realtime priorities,
128*8269e767SBrooks DavisRTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities.
129*8269e767SBrooks DavisThe priority specified by the
130*8269e767SBrooks Davis.Va prio
131*8269e767SBrooks Davisfield ranges between 0 and
132*8269e767SBrooks Davis.Dv RTP_PRIO_MAX
133*8269e767SBrooks Davis.Pq usually 31 .
134*8269e767SBrooks Davis0 is the highest possible priority.
135*8269e767SBrooks Davis.Pp
136*8269e767SBrooks DavisRealtime and idle priority is inherited through
137*8269e767SBrooks Davis.Fn fork
138*8269e767SBrooks Davisand
139*8269e767SBrooks Davis.Fn exec .
140*8269e767SBrooks Davis.Pp
141*8269e767SBrooks DavisA realtime thread can only be preempted by a thread of equal or
142*8269e767SBrooks Davishigher priority, or by an interrupt; idle priority threads will run only
143*8269e767SBrooks Daviswhen no other real/normal priority thread is runnable.
144*8269e767SBrooks DavisHigher real/idle priority threads
145*8269e767SBrooks Davispreempt lower real/idle priority threads.
146*8269e767SBrooks DavisThreads of equal real/idle priority are run round-robin.
147*8269e767SBrooks Davis.Sh RETURN VALUES
148*8269e767SBrooks Davis.Rv -std rtprio rtprio_thread
149*8269e767SBrooks Davis.Sh ERRORS
150*8269e767SBrooks DavisThe
151*8269e767SBrooks Davis.Fn rtprio
152*8269e767SBrooks Davisand
153*8269e767SBrooks Davis.Fn rtprio_thread
154*8269e767SBrooks Davissystem calls
155*8269e767SBrooks Daviswill fail if:
156*8269e767SBrooks Davis.Bl -tag -width Er
157*8269e767SBrooks Davis.It Bq Er EFAULT
158*8269e767SBrooks DavisThe rtp pointer passed to
159*8269e767SBrooks Davis.Fn rtprio
160*8269e767SBrooks Davisor
161*8269e767SBrooks Davis.Fn rtprio_thread
162*8269e767SBrooks Daviswas invalid.
163*8269e767SBrooks Davis.It Bq Er EINVAL
164*8269e767SBrooks DavisThe specified
165*8269e767SBrooks Davis.Fa prio
166*8269e767SBrooks Daviswas out of range.
167*8269e767SBrooks Davis.It Bq Er EPERM
168*8269e767SBrooks DavisThe calling thread is not allowed to set the priority.
169*8269e767SBrooks DavisOnly
170*8269e767SBrooks Davisroot is allowed to change the realtime or idle priority of any thread.
171*8269e767SBrooks DavisExceptional privileges can be granted through the
172*8269e767SBrooks Davis.Xr mac_priority 4
173*8269e767SBrooks Davispolicy and the realtime and idletime user groups.
174*8269e767SBrooks DavisThe
175*8269e767SBrooks Davis.Xr sysctl 8
176*8269e767SBrooks Davisvariable
177*8269e767SBrooks Davis.Va security.bsd.unprivileged_idprio
178*8269e767SBrooks Davisis deprecated.
179*8269e767SBrooks DavisIf set to non-zero, it lets any user change the idle priority of threads
180*8269e767SBrooks Davisthey own.
181*8269e767SBrooks Davis.It Bq Er ESRCH
182*8269e767SBrooks DavisThe specified process or thread was not found or visible.
183*8269e767SBrooks Davis.El
184*8269e767SBrooks Davis.Sh SEE ALSO
185*8269e767SBrooks Davis.Xr nice 1 ,
186*8269e767SBrooks Davis.Xr ps 1 ,
187*8269e767SBrooks Davis.Xr rtprio 1 ,
188*8269e767SBrooks Davis.Xr setpriority 2 ,
189*8269e767SBrooks Davis.Xr nice 3 ,
190*8269e767SBrooks Davis.Xr mac_priority 4 ,
191*8269e767SBrooks Davis.Xr renice 8 ,
192*8269e767SBrooks Davis.Xr p_cansee 9
193*8269e767SBrooks Davis.Sh AUTHORS
194*8269e767SBrooks Davis.An -nosplit
195*8269e767SBrooks DavisThe original author was
196*8269e767SBrooks Davis.An Henrik Vestergaard Draboel Aq Mt hvd@terry.ping.dk .
197*8269e767SBrooks DavisThis implementation in
198*8269e767SBrooks Davis.Fx
199*8269e767SBrooks Daviswas substantially rewritten by
200*8269e767SBrooks Davis.An David Greenman .
201*8269e767SBrooks DavisThe
202*8269e767SBrooks Davis.Fn rtprio_thread
203*8269e767SBrooks Davissystem call was implemented by
204*8269e767SBrooks Davis.An David Xu .
205