1SCHED_SETATTR(2)           Linux Programmer's Manual          SCHED_SETATTR(2)
2
3
4

NAME

6       sched_setattr,  sched_getattr  -  set  and  get  scheduling  policy and
7       attributes
8

SYNOPSIS

10       #include <sched.h>
11
12       int sched_setattr(pid_t pid, struct sched_attr *attr,
13                         unsigned int flags);
14
15       int sched_getattr(pid_t pid, struct sched_attr *attr,
16                         unsigned int size, unsigned int flags);
17

DESCRIPTION

19   sched_setattr()
20       The sched_setattr() system call sets the scheduling policy and  associ‐
21       ated  attributes  for  the thread whose ID is specified in pid.  If pid
22       equals zero, the scheduling policy and attributes of the calling thread
23       will be set.
24
25       Currently,  Linux supports the following "normal" (i.e., non-real-time)
26       scheduling policies as values that may be specified in policy:
27
28       SCHED_OTHER   the standard round-robin time-sharing policy;
29
30       SCHED_BATCH   for "batch" style execution of processes; and
31
32       SCHED_IDLE    for running very low priority background jobs.
33
34       Various "real-time" policies are also supported, for special time-crit‐
35       ical  applications  that  need  precise  control  over the way in which
36       runnable threads are selected for execution.  For the  rules  governing
37       when  a  process  may  use these policies, see sched(7).  The real-time
38       policies that may be specified in policy are:
39
40       SCHED_FIFO    a first-in, first-out policy; and
41
42       SCHED_RR      a round-robin policy.
43
44       Linux also provides the following policy:
45
46       SCHED_DEADLINE
47                     a deadline scheduling policy; see sched(7) for details.
48
49       The attr argument is a pointer to a  structure  that  defines  the  new
50       scheduling policy and attributes for the specified thread.  This struc‐
51       ture has the following form:
52
53           struct sched_attr {
54               u32 size;              /* Size of this structure */
55               u32 sched_policy;      /* Policy (SCHED_*) */
56               u64 sched_flags;       /* Flags */
57               s32 sched_nice;        /* Nice value (SCHED_OTHER,
58                                         SCHED_BATCH) */
59               u32 sched_priority;    /* Static priority (SCHED_FIFO,
60                                         SCHED_RR) */
61               /* Remaining fields are for SCHED_DEADLINE */
62               u64 sched_runtime;
63               u64 sched_deadline;
64               u64 sched_period;
65           };
66
67       The fields of this structure are as follows:
68
69       size   This field should be set to the size of the structure in  bytes,
70              as  in  sizeof(struct sched_attr).  If the provided structure is
71              smaller than the kernel structure,  any  additional  fields  are
72              assumed to be '0'.  If the provided structure is larger than the
73              kernel structure, the kernel verifies that all additional fields
74              are  0;  if  they  are not, sched_setattr() fails with the error
75              E2BIG and updates size to contain the size of the kernel  struc‐
76              ture.
77
78              The  above  behavior  when the size of the user-space sched_attr
79              structure does not match the size of the kernel structure allows
80              for  future  extensibility of the interface.  Malformed applica‐
81              tions that pass oversize structures won't break in the future if
82              the  size  of  the kernel sched_attr structure is increased.  In
83              the future, it could also allow applications that know  about  a
84              larger user-space sched_attr structure to determine whether they
85              are running on an older kernel that does not support the  larger
86              structure.
87
88       sched_policy
89              This  field  specifies  the  scheduling  policy,  as  one of the
90              SCHED_* values listed above.
91
92       sched_flags
93              This field contains flags controlling scheduling behavior.  Only
94              one  such  flag  is currently defined: SCHED_FLAG_RESET_ON_FORK.
95              As a result of including this flag, children created by  fork(2)
96              do not inherit privileged scheduling policies.  See sched(7) for
97              details.
98
99       sched_nice
100              This field specifies the nice value to be  set  when  specifying
101              sched_policy as SCHED_OTHER or SCHED_BATCH.  The nice value is a
102              number in the range -20 (high priority) to +19  (low  priority);
103              see sched(7).
104
105       sched_priority
106              This field specifies the static priority to be set when specify‐
107              ing sched_policy as SCHED_FIFO or SCHED_RR.  The  allowed  range
108              of  priorities  for  these  policies  can  be  determined  using
109              sched_get_priority_min(2)  and  sched_get_priority_max(2).   For
110              other policies, this field must be specified as 0.
111
112       sched_runtime
113              This field specifies the "Runtime" parameter for deadline sched‐
114              uling.  The value is expressed in nanoseconds.  This field,  and
115              the  next  two fields, are used only for SCHED_DEADLINE schedul‐
116              ing; for further details, see sched(7).
117
118       sched_deadline
119              This field  specifies  the  "Deadline"  parameter  for  deadline
120              scheduling.  The value is expressed in nanoseconds.
121
122       sched_period
123              This  field specifies the "Period" parameter for deadline sched‐
124              uling.  The value is expressed in nanoseconds.
125
126       The flags argument is provided to allow for future  extensions  to  the
127       interface; in the current implementation it must be specified as 0.
128
129   sched_getattr()
130       The  sched_getattr()  system call fetches the scheduling policy and the
131       associated attributes for the thread whose ID is specified in pid.   If
132       pid  equals  zero,  the scheduling policy and attributes of the calling
133       thread will be retrieved.
134
135       The size argument should be set to the size of the sched_attr structure
136       as  known  to  user  space.  The value must be at least as large as the
137       size of the initially published sched_attr structure, or the call fails
138       with the error EINVAL.
139
140       The  retrieved  scheduling  attributes  are placed in the fields of the
141       sched_attr structure pointed to by attr.  The kernel sets attr.size  to
142       the size of its sched_attr structure.
143
144       If  the  caller-provided  attr  buffer  is  larger  than  the  kernel's
145       sched_attr structure, the additional bytes in the user-space  structure
146       are  not touched.  If the caller-provided structure is smaller than the
147       kernel sched_attr structure and the kernel needs to return values  out‐
148       side  the  provided  space, sched_getattr() fails with the error E2BIG.
149       As with sched_setattr(), these semantics allow for future extensibility
150       of the interface.
151
152       The  flags  argument  is provided to allow for future extensions to the
153       interface; in the current implementation it must be specified as 0.
154

RETURN VALUE

156       On success, sched_setattr() and sched_getattr() return 0.  On error, -1
157       is returned, and errno is set to indicate the cause of the error.
158

ERRORS

160       sched_getattr()  and  sched_setattr()  can  both fail for the following
161       reasons:
162
163       EINVAL attr is NULL; or pid is negative; or flags is not zero.
164
165       ESRCH  The thread whose ID is pid could not be found.
166
167       In addition, sched_getattr() can fail for the following reasons:
168
169       E2BIG  The buffer specified by size and attr is too small.
170
171       EINVAL size is invalid; that is, it is smaller than the initial version
172              of the sched_attr structure (48 bytes) or larger than the system
173              page size.
174
175       In addition, sched_setattr() can fail for the following reasons:
176
177       E2BIG  The buffer specified by size and attr is larger than the  kernel
178              structure, and one or more of the excess bytes is nonzero.
179
180       EBUSY  SCHED_DEADLINE admission control failure, see sched(7).
181
182       EINVAL attr.sched_policy   is  not  one  of  the  recognized  policies;
183              attr.sched_flags     contains     a     flag     other      than
184              SCHED_FLAG_RESET_ON_FORK;  or attr.sched_priority is invalid; or
185              attr.sched_policy is SCHED_DEADLINE and the deadline  scheduling
186              parameters in attr are invalid.
187
188       EPERM  The caller does not have appropriate privileges.
189
190       EPERM  The  CPU  affinity  mask of the thread specified by pid does not
191              include all CPUs in the system (see sched_setaffinity(2)).
192

VERSIONS

194       These system calls first appeared in Linux 3.14.
195

CONFORMING TO

197       These system calls are nonstandard Linux extensions.
198

NOTES

200       sched_setattr()  provides  a   superset   of   the   functionality   of
201       sched_setscheduler(2),  sched_setparam(2), nice(2), and (other than the
202       ability to set the priority of all processes belonging to  a  specified
203       user  or  all  processes  in a specified group) setpriority(2).  Analo‐
204       gously, sched_getattr() provides a superset  of  the  functionality  of
205       sched_getscheduler(2),  sched_getparam(2),  and  (partially)  getprior‐
206       ity(2).
207

BUGS

209       In Linux versions up to 3.15, sched_settattr() failed  with  the  error
210       EFAULT instead of E2BIG for the case described in ERRORS.
211

SEE ALSO

213       chrt(1), nice(2), sched_get_priority_max(2), sched_get_priority_min(2),
214       sched_getaffinity(2), sched_getparam(2), sched_getscheduler(2),
215       sched_rr_get_interval(2), sched_setaffinity(2), sched_setparam(2),
216       sched_setscheduler(2), sched_yield(2), setpriority(2),
217       pthread_getschedparam(3), pthread_setschedparam(3),
218       pthread_setschedprio(3), capabilities(7), cpuset(7), sched(7)
219

COLOPHON

221       This page is part of release 4.16 of the Linux  man-pages  project.   A
222       description  of  the project, information about reporting bugs, and the
223       latest    version    of    this    page,    can     be     found     at
224       https://www.kernel.org/doc/man-pages/.
225
226
227
228Linux                             2017-09-15                  SCHED_SETATTR(2)
Impressum