]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sched_setattr.2
sched_setattr.2: Minor tweaks to Claudio Scordino's patch
[thirdparty/man-pages.git] / man2 / sched_setattr.2
CommitLineData
225d97f2
MK
1.\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
2.\" and Copyright (C) 2014 Peter Zijlstra <peterz@infradead.org>
3.\"
4.\" %%%LICENSE_START(VERBATIM)
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\" %%%LICENSE_END
25.\"
4b8c67d9 26.TH SCHED_SETATTR 2 2017-09-15 "Linux" "Linux Programmer's Manual"
225d97f2
MK
27.SH NAME
28sched_setattr, sched_getattr \-
29set and get scheduling policy and attributes
30.SH SYNOPSIS
31.nf
32.B #include <sched.h>
dbfe9c70 33.PP
c3529e3b 34.BI "int sched_setattr(pid_t " pid ", struct sched_attr *" attr ,
225d97f2 35.BI " unsigned int " flags );
dbfe9c70 36.PP
4b081d8d 37.BI "int sched_getattr(pid_t " pid ", struct sched_attr *" attr ,
225d97f2
MK
38.BI " unsigned int " size ", unsigned int " flags );
39.fi
bea08fec 40.\" FIXME . Add feature test macro requirements
225d97f2
MK
41.SH DESCRIPTION
42.SS sched_setattr()
43The
44.BR sched_setattr ()
45system call sets the scheduling policy and
46associated attributes for the thread whose ID is specified in
47.IR pid .
48If
49.I pid
50equals zero,
51the scheduling policy and attributes of the calling thread will be set.
efeece04 52.PP
225d97f2
MK
53Currently, Linux supports the following "normal"
54(i.e., non-real-time) scheduling policies as values that may be specified in
55.IR policy :
56.TP 14
57.BR SCHED_OTHER
58the standard round-robin time-sharing policy;
59.\" In the 2.6 kernel sources, SCHED_OTHER is actually called
60.\" SCHED_NORMAL.
61.TP
62.BR SCHED_BATCH
63for "batch" style execution of processes; and
64.TP
65.BR SCHED_IDLE
66for running
67.I very
68low priority background jobs.
69.PP
70Various "real-time" policies are also supported,
71for special time-critical applications that need precise control over
72the way in which runnable threads are selected for execution.
73For the rules governing when a process may use these policies, see
74.BR sched (7).
75The real-time policies that may be specified in
76.IR policy
77are:
78.TP 14
79.BR SCHED_FIFO
80a first-in, first-out policy; and
81.TP
82.BR SCHED_RR
83a round-robin policy.
84.PP
85Linux also provides the following policy:
86.TP 14
87.B SCHED_DEADLINE
88a deadline scheduling policy; see
89.BR sched (7)
90for details.
91.PP
92The
93.I attr
94argument is a pointer to a structure that defines
95the new scheduling policy and attributes for the specified thread.
96This structure has the following form:
efeece04 97.PP
225d97f2 98.in +4n
b8302363 99.EX
225d97f2
MK
100struct sched_attr {
101 u32 size; /* Size of this structure */
102 u32 sched_policy; /* Policy (SCHED_*) */
103 u64 sched_flags; /* Flags */
104 s32 sched_nice; /* Nice value (SCHED_OTHER,
105 SCHED_BATCH) */
106 u32 sched_priority; /* Static priority (SCHED_FIFO,
107 SCHED_RR) */
108 /* Remaining fields are for SCHED_DEADLINE */
109 u64 sched_runtime;
110 u64 sched_deadline;
111 u64 sched_period;
112};
b8302363 113.EE
225d97f2 114.in
efeece04 115.PP
225d97f2
MK
116The fields of this structure are as follows:
117.TP
118.B size
119This field should be set to the size of the structure in bytes, as in
120.IR "sizeof(struct sched_attr)" .
121If the provided structure is smaller than the kernel structure,
122any additional fields are assumed to be '0'.
123If the provided structure is larger than the kernel structure,
124the kernel verifies that all additional fields are 0;
125if they are not,
126.BR sched_setattr ()
127fails with the error
128.BR E2BIG
129and updates
130.I size
131to contain the size of the kernel structure.
132.IP
133The above behavior when the size of the user-space
134.I sched_attr
135structure does not match the size of the kernel structure
136allows for future extensibility of the interface.
137Malformed applications that pass oversize structures
138won't break in the future if the size of the kernel
139.I sched_attr
140structure is increased.
141In the future,
142it could also allow applications that know about a larger user-space
143.I sched_attr
144structure to determine whether they are running on an older kernel
145that does not support the larger structure.
146.TP
147.I sched_policy
148This field specifies the scheduling policy, as one of the
149.BR SCHED_*
150values listed above.
151.TP
152.I sched_flags
c7456cdd
MK
153This field contains contains zero or more of the following flags
154that are ORed together to control scheduling behavior:
155.RS
156.TP
157.BR SCHED_FLAG_RESET_ON_FORK
158Children created by
225d97f2
MK
159.BR fork (2)
160do not inherit privileged scheduling policies.
161See
162.BR sched (7)
163for details.
c7456cdd
MK
164.TP
165.BR SCHED_FLAG_RECLAIM " (since Linux 4.13)"
166.\" 2d4283e9d583a3ee8cfb1cbb9c1270614df4c29d
167This flag allows a
87b4fd4b
CS
168.BR SCHED_DEADLINE
169task to reclaim bandwidth unused by other real-time tasks through the GRUB
c7456cdd
MK
170algorithm.
171.TP
172.BR SCHED_FLAG_DL_OVERRUN " (since Linux 4.16)"
173.\" commit 34be39305a77b8b1ec9f279163c7cdb6cc719b91
174This flag allows a
87b4fd4b 175.BR SCHED_DEADLINE
c7456cdd
MK
176task to get informed about run-time overruns through the delivery of
177.B SIGXCPU
178signals.
179.RE
225d97f2
MK
180.TP
181.I sched_nice
182This field specifies the nice value to be set when specifying
183.IR sched_policy
184as
185.BR SCHED_OTHER
186or
187.BR SCHED_BATCH .
188The nice value is a number in the range \-20 (high priority)
189to +19 (low priority); see
9b7b2ea5 190.BR sched (7).
225d97f2
MK
191.TP
192.I sched_priority
193This field specifies the static priority to be set when specifying
194.IR sched_policy
195as
196.BR SCHED_FIFO
197or
198.BR SCHED_RR .
199The allowed range of priorities for these policies can be determined using
200.BR sched_get_priority_min (2)
201and
202.BR sched_get_priority_max (2).
203For other policies, this field must be specified as 0.
204.TP
205.I sched_runtime
206This field specifies the "Runtime" parameter for deadline scheduling.
207The value is expressed in nanoseconds.
208This field, and the next two fields,
209are used only for
0da5e58a 210.BR SCHED_DEADLINE
225d97f2
MK
211scheduling; for further details, see
212.BR sched (7).
213.TP
214.I sched_deadline
215This field specifies the "Deadline" parameter for deadline scheduling.
216The value is expressed in nanoseconds.
217.TP
218.I sched_period
219This field specifies the "Period" parameter for deadline scheduling.
220The value is expressed in nanoseconds.
221.PP
222The
223.I flags
224argument is provided to allow for future extensions to the interface;
225in the current implementation it must be specified as 0.
226.\"
227.\"
228.SS sched_getattr()
229The
230.BR sched_getattr ()
231system call fetches the scheduling policy and the
232associated attributes for the thread whose ID is specified in
233.IR pid .
234If
235.I pid
236equals zero,
237the scheduling policy and attributes of the calling thread
238will be retrieved.
efeece04 239.PP
225d97f2
MK
240The
241.I size
242argument should be set to the size of the
243.I sched_attr
244structure as known to user space.
245The value must be at least as large as the size of the initially published
246.I sched_attr
247structure, or the call fails with the error
248.BR EINVAL .
efeece04 249.PP
225d97f2
MK
250The retrieved scheduling attributes are placed in the fields of the
251.I sched_attr
252structure pointed to by
253.IR attr .
254The kernel sets
255.I attr.size
256to the size of its
257.I sched_attr
258structure.
efeece04 259.PP
225d97f2
MK
260If the caller-provided
261.I attr
262buffer is larger than the kernel's
263.I sched_attr
264structure,
265the additional bytes in the user-space structure are not touched.
266If the caller-provided structure is smaller than the kernel
267.I sched_attr
268structure and the kernel needs to return values outside the provided space,
269.BR sched_getattr ()
270fails with the error
271.BR E2BIG .
272As with
273.BR sched_setattr (),
274these semantics allow for future extensibility of the interface.
efeece04 275.PP
225d97f2
MK
276The
277.I flags
278argument is provided to allow for future extensions to the interface;
279in the current implementation it must be specified as 0.
280.SH RETURN VALUE
281On success,
282.BR sched_setattr ()
283and
284.BR sched_getattr ()
285return 0.
286On error, \-1 is returned, and
287.I errno
288is set to indicate the cause of the error.
289.SH ERRORS
290.BR sched_getattr ()
291and
292.BR sched_setattr ()
293can both fail for the following reasons:
294.TP
295.B EINVAL
296.I attr
297is NULL; or
298.I pid
299is negative; or
300.I flags
301is not zero.
302.TP
303.B ESRCH
304The thread whose ID is
305.I pid
306could not be found.
307.PP
308In addition,
309.BR sched_getattr ()
310can fail for the following reasons:
311.TP
312.B E2BIG
313The buffer specified by
314.I size
315and
316.I attr
317is too small.
318.TP
319.B EINVAL
320.I size
321is invalid; that is, it is smaller than the initial version of the
322.I sched_attr
323structure (48 bytes) or larger than the system page size.
324.PP
325In addition,
326.BR sched_setattr ()
327can fail for the following reasons:
328.TP
329.B E2BIG
330The buffer specified by
331.I size
332and
333.I attr
334is larger than the kernel structure,
335and one or more of the excess bytes is nonzero.
336.TP
337.B EBUSY
338.B SCHED_DEADLINE
339admission control failure, see
340.BR sched (7).
341.TP
342.B EINVAL
343.I attr.sched_policy
344is not one of the recognized policies;
345.I attr.sched_flags
346contains a flag other than
347.BR SCHED_FLAG_RESET_ON_FORK ;
348or
349.I attr.sched_priority
350is invalid; or
351.I attr.sched_policy
352is
353.BR SCHED_DEADLINE
354and the deadline scheduling parameters in
355.I attr
356are invalid.
357.TP
358.B EPERM
359The caller does not have appropriate privileges.
360.TP
361.B EPERM
4a6f17b5
MK
362The CPU affinity mask of the thread specified by
363.I pid
225d97f2
MK
364does not include all CPUs in the system
365(see
366.BR sched_setaffinity (2)).
367.SH VERSIONS
368These system calls first appeared in Linux 3.14.
bea08fec 369.\" FIXME . Add glibc version
225d97f2
MK
370.SH CONFORMING TO
371These system calls are nonstandard Linux extensions.
372.SH NOTES
373.BR sched_setattr ()
374provides a superset of the functionality of
375.BR sched_setscheduler (2),
376.BR sched_setparam (2),
377.BR nice (2),
378and (other than the ability to set the priority of all processes
379belonging to a specified user or all processes in a specified group)
380.BR setpriority (2).
381Analogously,
1b05b97a 382.BR sched_getattr ()
225d97f2
MK
383provides a superset of the functionality of
384.BR sched_getscheduler (2),
385.BR sched_getparam (2),
386and (partially)
387.BR getpriority (2).
388.SH BUGS
389In Linux versions up to
bea08fec 390.\" FIXME . patch sent to Peter Zijlstra
225d97f2
MK
3913.15,
392.BR sched_settattr ()
393failed with the error
394.BR EFAULT
395instead of
396.BR E2BIG
397for the case described in ERRORS.
398.\" In Linux versions up to up 3.15,
bea08fec 399.\" FIXME . patch from Peter Zijlstra pending
225d97f2
MK
400.\" .BR sched_setattr ()
401.\" allowed a negative
402.\" .I attr.sched_policy
403.\" value.
404.SH SEE ALSO
405.ad l
406.nh
ac30de07 407.BR chrt (1),
225d97f2
MK
408.BR nice (2),
409.BR sched_get_priority_max (2),
410.BR sched_get_priority_min (2),
411.BR sched_getaffinity (2),
225d97f2 412.BR sched_getparam (2),
03768726 413.BR sched_getscheduler (2),
225d97f2
MK
414.BR sched_rr_get_interval (2),
415.BR sched_setaffinity (2),
225d97f2 416.BR sched_setparam (2),
03768726 417.BR sched_setscheduler (2),
225d97f2
MK
418.BR sched_yield (2),
419.BR setpriority (2),
420.BR pthread_getschedparam (3),
421.BR pthread_setschedparam (3),
422.BR pthread_setschedprio (3),
423.BR capabilities (7),
424.BR cpuset (7),
425.BR sched (7)
426.ad