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 2014-05-13 "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 ", const struct sched_attr *" attr ,
35 .BI " unsigned int " flags );
37 .BI "int sched_getattr(pid_t " pid ", const struct sched_attr *" attr ,
38 .BI " unsigned int " size ", unsigned int " flags );
40 .\" FIXME . Add feature test macro requirements
45 system call sets the scheduling policy and
46 associated attributes for the thread whose ID is specified in
51 the scheduling policy and attributes of the calling thread will be set.
53 Currently, Linux supports the following "normal"
54 (i.e., non-real-time) scheduling policies as values that may be specified in
58 the standard round-robin time-sharing policy;
59 .\" In the 2.6 kernel sources, SCHED_OTHER is actually called
63 for "batch" style execution of processes; and
68 low priority background jobs.
70 Various "real-time" policies are also supported,
71 for special time-critical applications that need precise control over
72 the way in which runnable threads are selected for execution.
73 For the rules governing when a process may use these policies, see
75 The real-time policies that may be specified in
80 a first-in, first-out policy; and
85 Linux also provides the following policy:
88 a deadline scheduling policy; see
94 argument is a pointer to a structure that defines
95 the new scheduling policy and attributes for the specified thread.
96 This structure has the following form:
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,
106 u32 sched_priority; /* Static priority (SCHED_FIFO,
108 /* Remaining fields are for SCHED_DEADLINE */
116 The fields of this structure are as follows:
119 This field should be set to the size of the structure in bytes, as in
120 .IR "sizeof(struct sched_attr)" .
121 If the provided structure is smaller than the kernel structure,
122 any additional fields are assumed to be '0'.
123 If the provided structure is larger than the kernel structure,
124 the kernel verifies that all additional fields are 0;
131 to contain the size of the kernel structure.
133 The above behavior when the size of the user-space
135 structure does not match the size of the kernel structure
136 allows for future extensibility of the interface.
137 Malformed applications that pass oversize structures
138 won't break in the future if the size of the kernel
140 structure is increased.
142 it could also allow applications that know about a larger user-space
144 structure to determine whether they are running on an older kernel
145 that does not support the larger structure.
148 This field specifies the scheduling policy, as one of the
153 This field contains flags controlling scheduling behavior.
154 Only one such flag is currently defined:
155 .BR SCHED_FLAG_RESET_ON_FORK .
156 As a result of including this flag, children created by
158 do not inherit privileged scheduling policies.
164 This field specifies the nice value to be set when specifying
170 The nice value is a number in the range \-20 (high priority)
171 to +19 (low priority); see
175 This field specifies the static priority to be set when specifying
181 The allowed range of priorities for these policies can be determined using
182 .BR sched_get_priority_min (2)
184 .BR sched_get_priority_max (2).
185 For other policies, this field must be specified as 0.
188 This field specifies the "Runtime" parameter for deadline scheduling.
189 The value is expressed in nanoseconds.
190 This field, and the next two fields,
193 scheduling; for further details, see
197 This field specifies the "Deadline" parameter for deadline scheduling.
198 The value is expressed in nanoseconds.
201 This field specifies the "Period" parameter for deadline scheduling.
202 The value is expressed in nanoseconds.
206 argument is provided to allow for future extensions to the interface;
207 in the current implementation it must be specified as 0.
213 system call fetches the scheduling policy and the
214 associated attributes for the thread whose ID is specified in
219 the scheduling policy and attributes of the calling thread
224 argument should be set to the size of the
226 structure as known to user space.
227 The value must be at least as large as the size of the initially published
229 structure, or the call fails with the error
232 The retrieved scheduling attributes are placed in the fields of the
234 structure pointed to by
242 If the caller-provided
244 buffer is larger than the kernel's
247 the additional bytes in the user-space structure are not touched.
248 If the caller-provided structure is smaller than the kernel
250 structure and the kernel needs to return values outside the provided space,
255 .BR sched_setattr (),
256 these semantics allow for future extensibility of the interface.
260 argument is provided to allow for future extensions to the interface;
261 in the current implementation it must be specified as 0.
268 On error, \-1 is returned, and
270 is set to indicate the cause of the error.
275 can both fail for the following reasons:
286 The thread whose ID is
292 can fail for the following reasons:
295 The buffer specified by
303 is invalid; that is, it is smaller than the initial version of the
305 structure (48 bytes) or larger than the system page size.
309 can fail for the following reasons:
312 The buffer specified by
316 is larger than the kernel structure,
317 and one or more of the excess bytes is nonzero.
321 admission control failure, see
326 is not one of the recognized policies;
328 contains a flag other than
329 .BR SCHED_FLAG_RESET_ON_FORK ;
331 .I attr.sched_priority
336 and the deadline scheduling parameters in
341 The caller does not have appropriate privileges.
344 The caller's CPU affinity mask
345 does not include all CPUs in the system
347 .BR sched_setaffinity (2)).
349 These system calls first appeared in Linux 3.14.
350 .\" FIXME . Add glibc version
352 These system calls are nonstandard Linux extensions.
355 provides a superset of the functionality of
356 .BR sched_setscheduler (2),
357 .BR sched_setparam (2),
359 and (other than the ability to set the priority of all processes
360 belonging to a specified user or all processes in a specified group)
364 provides a superset of the functionality of
365 .BR sched_getscheduler (2),
366 .BR sched_getparam (2),
370 In Linux versions up to
371 .\" FIXME . patch sent to Peter Zijlstra
373 .BR sched_settattr ()
374 failed with the error
378 for the case described in ERRORS.
379 .\" In Linux versions up to up 3.15,
380 .\" FIXME . patch from Peter Zijlstra pending
381 .\" .BR sched_setattr ()
382 .\" allowed a negative
383 .\" .I attr.sched_policy
389 .BR sched_get_priority_max (2),
390 .BR sched_get_priority_min (2),
391 .BR sched_getaffinity (2),
392 .BR sched_getscheduler (2),
393 .BR sched_getparam (2),
394 .BR sched_rr_get_interval (2),
395 .BR sched_setaffinity (2),
396 .BR sched_setscheduler (2),
397 .BR sched_setparam (2),
400 .BR pthread_getschedparam (3),
401 .BR pthread_setschedparam (3),
402 .BR pthread_setschedprio (3),
403 .BR capabilities (7),