-
Notifications
You must be signed in to change notification settings - Fork 0
/
sched_getattr.html
584 lines (437 loc) · 16.6 KB
/
sched_getattr.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:27:15 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>SCHED_SETATTR</title>
</head>
<body>
<h1 align="center">SCHED_SETATTR</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">sched_setattr,
sched_getattr - set and get scheduling policy and
attributes</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sched.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
sched_setattr(pid_t</b> <i>pid</i><b>, struct sched_attr
*</b><i>attr</i><b>, <br>
unsigned int</b> <i>flags</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
sched_getattr(pid_t</b> <i>pid</i><b>, struct sched_attr
*</b><i>attr</i><b>, <br>
unsigned int</b> <i>size</i><b>, unsigned int</b>
<i>flags</i><b>);</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>sched_setattr()</b>
<br>
The <b>sched_setattr</b>() system call sets the scheduling
policy and associated attributes for the thread whose ID is
specified in <i>pid</i>. If <i>pid</i> equals zero, the
scheduling policy and attributes of the calling thread will
be set.</p>
<p style="margin-left:11%; margin-top: 1em">Currently,
Linux supports the following "normal" (i.e.,
non-real-time) scheduling policies as values that may be
specified in <i>policy</i>:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="17%">
<p><b>SCHED_OTHER</b></p></td>
<td width="4%"></td>
<td width="68%">
<p>the standard round-robin time-sharing policy;</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="17%">
<p><b>SCHED_BATCH</b></p></td>
<td width="4%"></td>
<td width="68%">
<p>for "batch" style execution of processes;
and</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="17%">
<p><b>SCHED_IDLE</b></p></td>
<td width="4%"></td>
<td width="68%">
<p>for running <i>very</i> low priority background
jobs.</p> </td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">Various
"real-time" policies are also supported, for
special time-critical applications that need precise control
over the way in which runnable threads are selected for
execution. For the rules governing when a process may use
these policies, see <b>sched</b>(7). The real-time policies
that may be specified in <i>policy</i> are:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="15%">
<p style="margin-top: 1em"><b>SCHED_FIFO</b></p></td>
<td width="6%"></td>
<td width="51%">
<p style="margin-top: 1em">a first-in, first-out policy;
and</p> </td>
<td width="17%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="15%">
<p><b>SCHED_RR</b></p></td>
<td width="6%"></td>
<td width="51%">
<p>a round-robin policy.</p></td>
<td width="17%">
</td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">Linux also
provides the following policy: <b><br>
SCHED_DEADLINE</b></p>
<p style="margin-left:32%;">a deadline scheduling policy;
see <b>sched</b>(7) for details.</p>
<p style="margin-left:11%; margin-top: 1em">The <i>attr</i>
argument is a pointer to a structure that defines the new
scheduling policy and attributes for the specified thread.
This structure has the following form:</p>
<p style="margin-left:17%; margin-top: 1em">struct
sched_attr { <br>
u32 size; /* Size of this structure */ <br>
u32 sched_policy; /* Policy (SCHED_*) */ <br>
u64 sched_flags; /* Flags */ <br>
s32 sched_nice; /* Nice value (SCHED_OTHER, <br>
SCHED_BATCH) */ <br>
u32 sched_priority; /* Static priority (SCHED_FIFO, <br>
SCHED_RR) */ <br>
/* Remaining fields are for SCHED_DEADLINE */ <br>
u64 sched_runtime; <br>
u64 sched_deadline; <br>
u64 sched_period; <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">The fields of
this structure are as follows:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="6%">
<p><b>size</b></p></td>
<td width="5%"></td>
<td width="78%">
<p>This field should be set to the size of the structure in
bytes, as in <i>sizeof(struct sched_attr)</i>. If the
provided structure is smaller than the kernel structure, any
additional fields are assumed to be ’0’. If the
provided structure is larger than the kernel structure, the
kernel verifies that all additional fields are 0; if they
are not, <b>sched_setattr</b>() fails with the error
<b>E2BIG</b> and updates <i>size</i> to contain the size of
the kernel structure.</p></td></tr>
</table>
<p style="margin-left:22%; margin-top: 1em">The above
behavior when the size of the user-space <i>sched_attr</i>
structure does not match the size of the kernel structure
allows for future extensibility of the interface. Malformed
applications that pass oversize structures won’t break
in the future if the size of the kernel <i>sched_attr</i>
structure is increased. In the future, it could also allow
applications that know about a larger user-space
<i>sched_attr</i> structure to determine whether they are
running on an older kernel that does not support the larger
structure.</p>
<p style="margin-left:11%;"><i>sched_policy</i></p>
<p style="margin-left:22%;">This field specifies the
scheduling policy, as one of the <b>SCHED_*</b> values
listed above.</p>
<p style="margin-left:11%;"><i>sched_flags</i></p>
<p style="margin-left:22%;">This field contains zero or
more of the following flags that are ORed together to
control scheduling behavior: <b><br>
SCHED_FLAG_RESET_ON_FORK</b></p>
<p style="margin-left:32%;">Children created by
<b>fork</b>(2) do not inherit privileged scheduling
policies. See <b>sched</b>(7) for details.</p>
<p style="margin-left:22%;"><b>SCHED_FLAG_RECLAIM</b>
(since Linux 4.13)</p>
<p style="margin-left:32%;">This flag allows a
<b>SCHED_DEADLINE</b> thread to reclaim bandwidth unused by
other real-time threads.</p>
<p style="margin-left:22%;"><b>SCHED_FLAG_DL_OVERRUN</b>
(since Linux 4.16)</p>
<p style="margin-left:32%;">This flag allows an application
to get informed about run-time overruns in
<b>SCHED_DEADLINE</b> threads. Such overruns may be caused
by (for example) coarse execution time accounting or
incorrect parameter assignment. Notification takes the form
of a <b>SIGXCPU</b> signal which is generated on each
overrun.</p>
<p style="margin-left:32%; margin-top: 1em">This
<b>SIGXCPU</b> signal is <i>process-directed</i> (see
<b>signal</b>(7)) rather than thread-directed. This is
probably a bug. On the one hand, <b>sched_setattr</b>() is
being used to set a per-thread attribute. On the other hand,
if the process-directed signal is delivered to a thread
inside the process other than the one that had a run-time
overrun, the application has no way of knowing which thread
overran.</p>
<p style="margin-left:11%;"><i>sched_nice</i></p>
<p style="margin-left:22%;">This field specifies the nice
value to be set when specifying <i>sched_policy</i> as
<b>SCHED_OTHER</b> or <b>SCHED_BATCH</b>. The nice value is
a number in the range -20 (high priority) to +19 (low
priority); see <b>sched</b>(7).</p>
<p style="margin-left:11%;"><i>sched_priority</i></p>
<p style="margin-left:22%;">This field specifies the static
priority to be set when specifying <i>sched_policy</i> as
<b>SCHED_FIFO</b> or <b>SCHED_RR</b>. The allowed range of
priorities for these policies can be determined using
<b>sched_get_priority_min</b>(2) and
<b>sched_get_priority_max</b>(2). For other policies, this
field must be specified as 0.</p>
<p style="margin-left:11%;"><i>sched_runtime</i></p>
<p style="margin-left:22%;">This field specifies the
"Runtime" parameter for deadline scheduling. The
value is expressed in nanoseconds. This field, and the next
two fields, are used only for <b>SCHED_DEADLINE</b>
scheduling; for further details, see <b>sched</b>(7).</p>
<p style="margin-left:11%;"><i>sched_deadline</i></p>
<p style="margin-left:22%;">This field specifies the
"Deadline" parameter for deadline scheduling. The
value is expressed in nanoseconds.</p>
<p style="margin-left:11%;"><i>sched_period</i></p>
<p style="margin-left:22%;">This field specifies the
"Period" parameter for deadline scheduling. The
value is expressed in nanoseconds.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>flags</i> argument is provided to allow for future
extensions to the interface; in the current implementation
it must be specified as 0.</p>
<p style="margin-left:11%; margin-top: 1em"><b>sched_getattr()</b>
<br>
The <b>sched_getattr</b>() system call fetches the
scheduling policy and the associated attributes for the
thread whose ID is specified in <i>pid</i>. If <i>pid</i>
equals zero, the scheduling policy and attributes of the
calling thread will be retrieved.</p>
<p style="margin-left:11%; margin-top: 1em">The <i>size</i>
argument should be set to the size of the <i>sched_attr</i>
structure as known to user space. The value must be at least
as large as the size of the initially published
<i>sched_attr</i> structure, or the call fails with the
error <b>EINVAL</b>.</p>
<p style="margin-left:11%; margin-top: 1em">The retrieved
scheduling attributes are placed in the fields of the
<i>sched_attr</i> structure pointed to by <i>attr</i>. The
kernel sets <i>attr.size</i> to the size of its
<i>sched_attr</i> structure.</p>
<p style="margin-left:11%; margin-top: 1em">If the
caller-provided <i>attr</i> buffer is larger than the
kernel’s <i>sched_attr</i> structure, the additional
bytes in the user-space structure are not touched. If the
caller-provided structure is smaller than the kernel
<i>sched_attr</i> structure and the kernel needs to return
values outside the provided space, <b>sched_getattr</b>()
fails with the error <b>E2BIG</b>. As with
<b>sched_setattr</b>(), these semantics allow for future
extensibility of the interface.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>flags</i> argument is provided to allow for future
extensions to the interface; in the current implementation
it must be specified as 0.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>sched_setattr</b>() and <b>sched_getattr</b>() return 0.
On error, -1 is returned, and <i>errno</i> is set to
indicate the cause of the error.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>sched_getattr</b>()
and <b>sched_setattr</b>() can both fail for the following
reasons:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>attr</i> is NULL; or <i>pid</i> is negative; or
<i>flags</i> is not zero.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ESRCH</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The thread whose ID is <i>pid</i> could not be
found.</p> </td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">In addition,
<b>sched_getattr</b>() can fail for the following
reasons:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>E2BIG</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">The buffer specified by
<i>size</i> and <i>attr</i> is too small.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>size</i> is invalid; that is, it is smaller than the
initial version of the <i>sched_attr</i> structure (48
bytes) or larger than the system page size.</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">In addition,
<b>sched_setattr</b>() can fail for the following
reasons:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>E2BIG</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">The buffer specified by
<i>size</i> and <i>attr</i> is larger than the kernel
structure, and one or more of the excess bytes is
nonzero.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EBUSY</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><b>SCHED_DEADLINE</b> admission control failure, see
<b>sched</b>(7).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>attr.sched_policy</i> is not one of the recognized
policies; <i>attr.sched_flags</i> contains a flag other than
<b>SCHED_FLAG_RESET_ON_FORK</b>; or
<i>attr.sched_priority</i> is invalid; or
<i>attr.sched_policy</i> is <b>SCHED_DEADLINE</b> and the
deadline scheduling parameters in <i>attr</i> are
invalid.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EPERM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The caller does not have appropriate privileges.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EPERM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The CPU affinity mask of the thread specified by
<i>pid</i> does not include all CPUs in the system (see
<b>sched_setaffinity</b>(2)).</p> </td></tr>
</table>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls first appeared in Linux 3.14.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls are nonstandard Linux extensions.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>sched_setattr</b>()
provides a superset of the functionality of
<b>sched_setscheduler</b>(2), <b>sched_setparam</b>(2),
<b>nice</b>(2), and (other than the ability to set the
priority of all processes belonging to a specified user or
all processes in a specified group) <b>setpriority</b>(2).
Analogously, <b>sched_getattr</b>() provides a superset of
the functionality of <b>sched_getscheduler</b>(2),
<b>sched_getparam</b>(2), and (partially)
<b>getpriority</b>(2).</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">In Linux
versions up to 3.15, <b>sched_settattr</b>() failed with the
error <b>EFAULT</b> instead of <b>E2BIG</b> for the case
described in ERRORS.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>chrt</b>(1),
<b>nice</b>(2), <b>sched_get_priority_max</b>(2),
<b>sched_get_priority_min</b>(2),
<b>sched_getaffinity</b>(2), <b>sched_getparam</b>(2),
<b>sched_getscheduler</b>(2),
<b>sched_rr_get_interval</b>(2),
<b>sched_setaffinity</b>(2), <b>sched_setparam</b>(2),
<b>sched_setscheduler</b>(2), <b>sched_yield</b>(2),
<b>setpriority</b>(2), <b>pthread_getschedparam</b>(3),
<b>pthread_setschedparam</b>(3),
<b>pthread_setschedprio</b>(3), <b>capabilities</b>(7),
<b>cpuset</b>(7), <b>sched</b>(7)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>