1 .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2014 Peter Zijlstra <peterz@infradead.org>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH SCHED_SETATTR 2 2021-03-22 "Linux" "Linux Programmer's Manual"
28 sched_setattr, sched_getattr \-
29 set and get scheduling policy and attributes
34 .BI "int sched_setattr(pid_t " pid ", struct sched_attr *" attr ,
35 .BI " unsigned int " flags );
36 .BI "int sched_getattr(pid_t " pid ", struct sched_attr *" attr ,
37 .BI " unsigned int " size ", unsigned int " flags );
39 .\" FIXME . Add feature test macro requirements
42 There are no glibc wrappers for these system calls; see NOTES.
47 system call sets the scheduling policy and
48 associated attributes for the thread whose ID is specified in
53 the scheduling policy and attributes of the calling thread will be set.
55 Currently, Linux supports the following "normal"
56 (i.e., non-real-time) scheduling policies as values that may be specified in
60 the standard round-robin time-sharing policy;
61 .\" In the 2.6 kernel sources, SCHED_OTHER is actually called
65 for "batch" style execution of processes; and
70 low priority background jobs.
72 Various "real-time" policies are also supported,
73 for special time-critical applications that need precise control over
74 the way in which runnable threads are selected for execution.
75 For the rules governing when a process may use these policies, see
77 The real-time policies that may be specified in
82 a first-in, first-out policy; and
87 Linux also provides the following policy:
90 a deadline scheduling policy; see
96 argument is a pointer to a structure that defines
97 the new scheduling policy and attributes for the specified thread.
98 This structure has the following form:
103 u32 size; /* Size of this structure */
104 u32 sched_policy; /* Policy (SCHED_*) */
105 u64 sched_flags; /* Flags */
106 s32 sched_nice; /* Nice value (SCHED_OTHER,
108 u32 sched_priority; /* Static priority (SCHED_FIFO,
110 /* Remaining fields are for SCHED_DEADLINE */
120 structure are as follows:
123 This field should be set to the size of the structure in bytes, as in
124 .IR "sizeof(struct sched_attr)" .
125 If the provided structure is smaller than the kernel structure,
126 any additional fields are assumed to be '0'.
127 If the provided structure is larger than the kernel structure,
128 the kernel verifies that all additional fields are 0;
135 to contain the size of the kernel structure.
137 The above behavior when the size of the user-space
139 structure does not match the size of the kernel structure
140 allows for future extensibility of the interface.
141 Malformed applications that pass oversize structures
142 won't break in the future if the size of the kernel
144 structure is increased.
146 it could also allow applications that know about a larger user-space
148 structure to determine whether they are running on an older kernel
149 that does not support the larger structure.
152 This field specifies the scheduling policy, as one of the
157 This field contains zero or more of the following flags
158 that are ORed together to control scheduling behavior:
161 .BR SCHED_FLAG_RESET_ON_FORK
164 do not inherit privileged scheduling policies.
169 .BR SCHED_FLAG_RECLAIM " (since Linux 4.13)"
170 .\" 2d4283e9d583a3ee8cfb1cbb9c1270614df4c29d
173 thread to reclaim bandwidth unused by other real-time threads.
174 .\" Bandwidth reclaim is done via the GRUB algorithm; see
175 .\" Documentation/scheduler/sched-deadline.txt
177 .BR SCHED_FLAG_DL_OVERRUN " (since Linux 4.16)"
178 .\" commit 34be39305a77b8b1ec9f279163c7cdb6cc719b91
179 This flag allows an application to get informed about run-time overruns in
182 Such overruns may be caused by (for example) coarse execution time accounting
183 or incorrect parameter assignment.
184 Notification takes the form of a
186 signal which is generated on each overrun.
194 rather than thread-directed.
195 This is probably a bug.
198 is being used to set a per-thread attribute.
199 On the other hand, if the process-directed signal is delivered to
200 a thread inside the process other than the one that had a run-time overrun,
201 the application has no way of knowing which thread overran.
205 This field specifies the nice value to be set when specifying
211 The nice value is a number in the range \-20 (high priority)
212 to +19 (low priority); see
216 This field specifies the static priority to be set when specifying
222 The allowed range of priorities for these policies can be determined using
223 .BR sched_get_priority_min (2)
225 .BR sched_get_priority_max (2).
226 For other policies, this field must be specified as 0.
229 This field specifies the "Runtime" parameter for deadline scheduling.
230 The value is expressed in nanoseconds.
231 This field, and the next two fields,
234 scheduling; for further details, see
238 This field specifies the "Deadline" parameter for deadline scheduling.
239 The value is expressed in nanoseconds.
242 This field specifies the "Period" parameter for deadline scheduling.
243 The value is expressed in nanoseconds.
247 argument is provided to allow for future extensions to the interface;
248 in the current implementation it must be specified as 0.
254 system call fetches the scheduling policy and the
255 associated attributes for the thread whose ID is specified in
260 the scheduling policy and attributes of the calling thread
265 argument should be set to the size of the
267 structure as known to user space.
268 The value must be at least as large as the size of the initially published
270 structure, or the call fails with the error
273 The retrieved scheduling attributes are placed in the fields of the
275 structure pointed to by
283 If the caller-provided
285 buffer is larger than the kernel's
288 the additional bytes in the user-space structure are not touched.
289 If the caller-provided structure is smaller than the kernel
291 structure, the kernel will silently not return any values which would be stored
292 outside the provided space.
294 .BR sched_setattr (),
295 these semantics allow for future extensibility of the interface.
299 argument is provided to allow for future extensions to the interface;
300 in the current implementation it must be specified as 0.
307 On error, \-1 is returned, and
309 is set to indicate the error.
314 can both fail for the following reasons:
325 The thread whose ID is
331 can fail for the following reasons:
334 The buffer specified by
342 is invalid; that is, it is smaller than the initial version of the
344 structure (48 bytes) or larger than the system page size.
348 can fail for the following reasons:
351 The buffer specified by
355 is larger than the kernel structure,
356 and one or more of the excess bytes is nonzero.
360 admission control failure, see
365 is not one of the recognized policies;
367 contains a flag other than
368 .BR SCHED_FLAG_RESET_ON_FORK ;
370 .I attr.sched_priority
375 and the deadline scheduling parameters in
380 The caller does not have appropriate privileges.
383 The CPU affinity mask of the thread specified by
385 does not include all CPUs in the system
387 .BR sched_setaffinity (2)).
389 These system calls first appeared in Linux 3.14.
390 .\" FIXME . Add glibc version
392 These system calls are nonstandard Linux extensions.
394 Glibc does not provide wrappers for these system calls; call them using
398 provides a superset of the functionality of
399 .BR sched_setscheduler (2),
400 .BR sched_setparam (2),
402 and (other than the ability to set the priority of all processes
403 belonging to a specified user or all processes in a specified group)
407 provides a superset of the functionality of
408 .BR sched_getscheduler (2),
409 .BR sched_getparam (2),
413 In Linux versions up to
414 .\" FIXME . patch sent to Peter Zijlstra
417 failed with the error
421 for the case described in ERRORS.
423 In Linux versions up to 5.3,
425 failed with the error
429 structure was larger than the
431 passed by user space.
432 .\" In Linux versions up to up 3.15,
433 .\" FIXME . patch from Peter Zijlstra pending
434 .\" .BR sched_setattr ()
435 .\" allowed a negative
436 .\" .I attr.sched_policy
443 .BR sched_get_priority_max (2),
444 .BR sched_get_priority_min (2),
445 .BR sched_getaffinity (2),
446 .BR sched_getparam (2),
447 .BR sched_getscheduler (2),
448 .BR sched_rr_get_interval (2),
449 .BR sched_setaffinity (2),
450 .BR sched_setparam (2),
451 .BR sched_setscheduler (2),
454 .BR pthread_getschedparam (3),
455 .BR pthread_setschedparam (3),
456 .BR pthread_setschedprio (3),
457 .BR capabilities (7),