]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/sched.7
sched.7: wfix
[thirdparty/man-pages.git] / man7 / sched.7
1 .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2014 Peter Zijlstra <peterz@infradead.org>
3 .\" and Copyright (C) 2014 Juri Lelli <juri.lelli@gmail.com>
4 .\" Various pieces from the old sched_setscheduler(2) page
5 .\" Copyright (C) Tom Bjorkholm, Markus Kuhn & David A. Wheeler 1996-1999
6 .\" and Copyright (C) 2007 Carsten Emde <Carsten.Emde@osadl.org>
7 .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
8 .\"
9 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
10 .\" This is free documentation; you can redistribute it and/or
11 .\" modify it under the terms of the GNU General Public License as
12 .\" published by the Free Software Foundation; either version 2 of
13 .\" the License, or (at your option) any later version.
14 .\"
15 .\" The GNU General Public License's references to "object code"
16 .\" and "executables" are to be interpreted as the output of any
17 .\" document formatting or typesetting system, including
18 .\" intermediate and printed output.
19 .\"
20 .\" This manual is distributed in the hope that it will be useful,
21 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
22 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 .\" GNU General Public License for more details.
24 .\"
25 .\" You should have received a copy of the GNU General Public
26 .\" License along with this manual; if not, see
27 .\" <http://www.gnu.org/licenses/>.
28 .\" %%%LICENSE_END
29 .\"
30 .\" Worth looking at: http://rt.wiki.kernel.org/index.php
31 .\"
32 .TH SCHED 7 2016-10-08 "Linux" "Linux Programmer's Manual"
33 .SH NAME
34 sched \- overview of CPU scheduling
35 .SH DESCRIPTION
36 Since Linux 2.6.23, the default scheduler is CFS,
37 the "Completely Fair Scheduler".
38 The CFS scheduler replaced the earlier "O(1)" scheduler.
39 .\"
40 .SS API summary
41 Linux provides the following system calls for controlling
42 the CPU scheduling behavior, policy, and priority of processes
43 (or, more precisely, threads).
44 .TP
45 .BR sched_setscheduler (2)
46 Set the scheduling policy and parameters of a specified thread.
47 .TP
48 .BR sched_getscheduler (2)
49 Return the scheduling policy of a specified thread.
50 .TP
51 .BR sched_setparam (2)
52 Set the scheduling parameters of a specified thread.
53 .TP
54 .BR sched_getparam (2)
55 Fetch the scheduling parameters of a specified thread.
56 .TP
57 .BR sched_get_priority_max (2)
58 Return the maximum priority available in a specified scheduling policy.
59 .TP
60 .BR sched_get_priority_min (2)
61 Return the minimum priority available in a specified scheduling policy.
62 .TP
63 .BR sched_rr_get_interval (2)
64 Fetch the quantum used for threads that are scheduled under
65 the "round-robin" scheduling policy.
66 .TP
67 .BR sched_yield (2)
68 Cause the caller to relinquish the CPU,
69 so that some other thread be executed.
70 .TP
71 .BR sched_setaffinity (2)
72 (Linux-specific)
73 Set the CPU affinity of a specified thread.
74 .TP
75 .BR sched_getaffinity (2)
76 (Linux-specific)
77 Get the CPU affinity of a specified thread.
78 .TP
79 .BR sched_setattr (2)
80 Set the scheduling policy and parameters of a specified thread.
81 This (Linux-specific) system call provides a superset of the functionality of
82 .BR sched_setscheduler (2)
83 and
84 .BR sched_setparam (2).
85 .TP
86 .BR sched_getattr (2)
87 Fetch the scheduling policy and parameters of a specified thread.
88 This (Linux-specific) system call provides a superset of the functionality of
89 .BR sched_getscheduler (2)
90 and
91 .BR sched_getparam (2).
92 .\"
93 .SS Scheduling policies
94 The scheduler is the kernel component that decides which runnable thread
95 will be executed by the CPU next.
96 Each thread has an associated scheduling policy and a \fIstatic\fP
97 scheduling priority,
98 .IR sched_priority .
99 The scheduler makes its decisions based on knowledge of the scheduling
100 policy and static priority of all threads on the system.
101
102 For threads scheduled under one of the normal scheduling policies
103 (\fBSCHED_OTHER\fP, \fBSCHED_IDLE\fP, \fBSCHED_BATCH\fP),
104 \fIsched_priority\fP is not used in scheduling
105 decisions (it must be specified as 0).
106
107 Processes scheduled under one of the real-time policies
108 (\fBSCHED_FIFO\fP, \fBSCHED_RR\fP) have a
109 \fIsched_priority\fP value in the range 1 (low) to 99 (high).
110 (As the numbers imply, real-time threads always have higher priority
111 than normal threads.)
112 Note well: POSIX.1 requires an implementation to support only a
113 minimum 32 distinct priority levels for the real-time policies,
114 and some systems supply just this minimum.
115 Portable programs should use
116 .BR sched_get_priority_min (2)
117 and
118 .BR sched_get_priority_max (2)
119 to find the range of priorities supported for a particular policy.
120
121 Conceptually, the scheduler maintains a list of runnable
122 threads for each possible \fIsched_priority\fP value.
123 In order to determine which thread runs next, the scheduler looks for
124 the nonempty list with the highest static priority and selects the
125 thread at the head of this list.
126
127 A thread's scheduling policy determines
128 where it will be inserted into the list of threads
129 with equal static priority and how it will move inside this list.
130
131 All scheduling is preemptive: if a thread with a higher static
132 priority becomes ready to run, the currently running thread
133 will be preempted and
134 returned to the wait list for its static priority level.
135 The scheduling policy determines the
136 ordering only within the list of runnable threads with equal static
137 priority.
138 .SS SCHED_FIFO: First in-first out scheduling
139 \fBSCHED_FIFO\fP can be used only with static priorities higher than
140 0, which means that when a \fBSCHED_FIFO\fP threads becomes runnable,
141 it will always immediately preempt any currently running
142 \fBSCHED_OTHER\fP, \fBSCHED_BATCH\fP, or \fBSCHED_IDLE\fP thread.
143 \fBSCHED_FIFO\fP is a simple scheduling
144 algorithm without time slicing.
145 For threads scheduled under the
146 \fBSCHED_FIFO\fP policy, the following rules apply:
147 .IP * 3
148 A \fBSCHED_FIFO\fP thread that has been preempted by another thread of
149 higher priority will stay at the head of the list for its priority and
150 will resume execution as soon as all threads of higher priority are
151 blocked again.
152 .IP *
153 When a \fBSCHED_FIFO\fP thread becomes runnable, it
154 will be inserted at the end of the list for its priority.
155 .IP *
156 A call to
157 .BR sched_setscheduler (2),
158 .BR sched_setparam (2),
159 or
160 .BR sched_setattr (2)
161 will put the
162 \fBSCHED_FIFO\fP (or \fBSCHED_RR\fP) thread identified by
163 \fIpid\fP at the start of the list if it was runnable.
164 As a consequence, it may preempt the currently running thread if
165 it has the same priority.
166 (POSIX.1 specifies that the thread should go to the end
167 of the list.)
168 .\" In 2.2.x and 2.4.x, the thread is placed at the front of the queue
169 .\" In 2.0.x, the Right Thing happened: the thread went to the back -- MTK
170 .IP *
171 A thread calling
172 .BR sched_yield (2)
173 will be put at the end of the list.
174 .PP
175 No other events will move a thread
176 scheduled under the \fBSCHED_FIFO\fP policy in the wait list of
177 runnable threads with equal static priority.
178
179 A \fBSCHED_FIFO\fP
180 thread runs until either it is blocked by an I/O request, it is
181 preempted by a higher priority thread, or it calls
182 .BR sched_yield (2).
183 .SS SCHED_RR: Round-robin scheduling
184 \fBSCHED_RR\fP is a simple enhancement of \fBSCHED_FIFO\fP.
185 Everything
186 described above for \fBSCHED_FIFO\fP also applies to \fBSCHED_RR\fP,
187 except that each thread is allowed to run only for a maximum time
188 quantum.
189 If a \fBSCHED_RR\fP thread has been running for a time
190 period equal to or longer than the time quantum, it will be put at the
191 end of the list for its priority.
192 A \fBSCHED_RR\fP thread that has
193 been preempted by a higher priority thread and subsequently resumes
194 execution as a running thread will complete the unexpired portion of
195 its round-robin time quantum.
196 The length of the time quantum can be
197 retrieved using
198 .BR sched_rr_get_interval (2).
199 .\" On Linux 2.4, the length of the RR interval is influenced
200 .\" by the process nice value -- MTK
201 .\"
202 .SS SCHED_DEADLINE: Sporadic task model deadline scheduling
203 Since version 3.14, Linux provides a deadline scheduling policy
204 .RB ( SCHED_DEADLINE ).
205 This policy is currently implemented using
206 GEDF (Global Earliest Deadline First)
207 in conjunction with CBS (Constant Bandwidth Server).
208 To set and fetch this policy and associated attributes,
209 one must use the Linux-specific
210 .BR sched_setattr (2)
211 and
212 .BR sched_getattr (2)
213 system calls.
214
215 A sporadic task is one that has a sequence of jobs, where each
216 job is activated at most once per period.
217 Each job also has a
218 .IR "relative deadline" ,
219 before which it should finish execution, and a
220 .IR "computation time" ,
221 which is the CPU time necessary for executing the job.
222 The moment when a task wakes up
223 because a new job has to be executed is called the
224 .IR "arrival time"
225 (also referred to as the request time or release time).
226 The
227 .IR "start time"
228 is the time at which a task starts its execution.
229 The
230 .I "absolute deadline"
231 is thus obtained by adding the relative deadline to the arrival time.
232
233 The following diagram clarifies these terms:
234
235 .in +4n
236 .nf
237 arrival/wakeup absolute deadline
238 | start time |
239 | | |
240 v v v
241 -----x--------xooooooooooooooooo--------x--------x---
242 |<- comp. time ->|
243 |<------- relative deadline ------>|
244 |<-------------- period ------------------->|
245 .fi
246 .in
247
248 When setting a
249 .B SCHED_DEADLINE
250 policy for a thread using
251 .BR sched_setattr (2),
252 one can specify three parameters:
253 .IR Runtime ,
254 .IR Deadline ,
255 and
256 .IR Period .
257 These parameters do not necessarily correspond to the aforementioned terms:
258 usual practice is to set Runtime to something bigger than the average
259 computation time (or worst-case execution time for hard real-time tasks),
260 Deadline to the relative deadline, and Period to the period of the task.
261 Thus, for
262 .BR SCHED_DEADLINE
263 scheduling, we have:
264
265 .in +4n
266 .nf
267 arrival/wakeup absolute deadline
268 | start time |
269 | | |
270 v v v
271 -----x--------xooooooooooooooooo--------x--------x---
272 |<-- Runtime ------->|
273 |<----------- Deadline ----------->|
274 |<-------------- Period ------------------->|
275 .fi
276 .in
277
278 The three deadline-scheduling parameters correspond to the
279 .IR sched_runtime ,
280 .IR sched_deadline ,
281 and
282 .IR sched_period
283 fields of the
284 .I sched_attr
285 structure; see
286 .BR sched_setattr (2).
287 These fields express values in nanoseconds.
288 .\" FIXME It looks as though specifying sched_period as 0 means
289 .\" "make sched_period the same as sched_deadline".
290 .\" This needs to be documented.
291 If
292 .IR sched_period
293 is specified as 0, then it is made the same as
294 .IR sched_deadline .
295
296 The kernel requires that:
297
298 sched_runtime <= sched_deadline <= sched_period
299
300 .\" See __checkparam_dl in kernel/sched/core.c
301 In addition, under the current implementation,
302 all of the parameter values must be at least 1024
303 (i.e., just over one microsecond,
304 which is the resolution of the implementation), and less than 2^63.
305 If any of these checks fails,
306 .BR sched_setattr (2)
307 fails with the error
308 .BR EINVAL .
309
310 The CBS guarantees non-interference between tasks, by throttling
311 threads that attempt to over-run their specified Runtime.
312
313 To ensure deadline scheduling guarantees,
314 the kernel must prevent situations where the set of
315 .B SCHED_DEADLINE
316 threads is not feasible (schedulable) within the given constraints.
317 The kernel thus performs an admittance test when setting or changing
318 .B SCHED_DEADLINE
319 policy and attributes.
320 This admission test calculates whether the change is feasible;
321 if it is not,
322 .BR sched_setattr (2)
323 fails with the error
324 .BR EBUSY .
325
326 For example, it is required (but not necessarily sufficient) for
327 the total utilization to be less than or equal to the total number of
328 CPUs available, where, since each thread can maximally run for
329 Runtime per Period, that thread's utilization is its
330 Runtime divided by its Period.
331
332 In order to fulfill the guarantees that are made when
333 a thread is admitted to the
334 .BR SCHED_DEADLINE
335 policy,
336 .BR SCHED_DEADLINE
337 threads are the highest priority (user controllable) threads in the
338 system; if any
339 .BR SCHED_DEADLINE
340 thread is runnable,
341 it will preempt any thread scheduled under one of the other policies.
342
343 A call to
344 .BR fork (2)
345 by a thread scheduled under the
346 .B SCHED_DEADLINE
347 policy will fail with the error
348 .BR EAGAIN ,
349 unless the thread has its reset-on-fork flag set (see below).
350
351 A
352 .B SCHED_DEADLINE
353 thread that calls
354 .BR sched_yield (2)
355 will yield the current job and wait for a new period to begin.
356 .\"
357 .\" FIXME Calling sched_getparam() on a SCHED_DEADLINE thread
358 .\" fails with EINVAL, but sched_getscheduler() succeeds.
359 .\" Is that intended? (Why?)
360 .\"
361 .SS SCHED_OTHER: Default Linux time-sharing scheduling
362 \fBSCHED_OTHER\fP can be used at only static priority 0
363 (i.e., threads under real-time policies always have priority over
364 .B SCHED_OTHER
365 processes).
366 \fBSCHED_OTHER\fP is the standard Linux time-sharing scheduler that is
367 intended for all threads that do not require the special
368 real-time mechanisms.
369
370 The thread to run is chosen from the static
371 priority 0 list based on a \fIdynamic\fP priority that is determined only
372 inside this list.
373 The dynamic priority is based on the nice value (set by
374 .BR nice (2),
375 .BR setpriority (2),
376 or
377 .BR sched_setattr (2))
378 and is increased for each time quantum the thread is ready to run,
379 but denied to run by the scheduler.
380 This ensures fair progress among all \fBSCHED_OTHER\fP threads.
381 .\"
382 .SS The nice value
383 The nice value is a per-process attribute
384 that can be used to influence the CPU scheduler to
385 favor or disfavor a process in scheduling decisions.
386 It affects the scheduling of
387 .BR SCHED_OTHER
388 and
389 .BR SCHED_BATCH
390 (see below)
391 processes.
392 According to POSIX.1, the threads in a process should share a nice value.
393 However, on Linux, the nice value is a per-thread attribute:
394 different threads in the same process may have different nice values.
395
396 The range of the nice value
397 varies across UNIX systems.
398 On modern Linux, the range is \-20 (high priority) to +19 (low priority).
399 On some other systems, the range is \-20..20.
400 Very early Linux kernels (Before Linux 2.0) had the range \-infinity..15.
401 .\" Linux before 1.3.36 had \-infinity..15.
402 .\" Since kernel 1.3.43, Linux has the range \-20..19.
403
404 The degree to which the nice value affects the relative scheduling of
405 .BR SCHED_OTHER
406 processes likewise varies across UNIX systems and
407 across Linux kernel versions.
408
409 With the advent of the CFS scheduler in kernel 2.6.23,
410 Linux adopted an algorithm that causes
411 relative differences in nice values to have a much stronger effect.
412 In the current implementation, each unit of difference in the
413 nice values of two processes results in a factor of 1.25
414 in the degree to which the scheduler favors the higher priority process.
415 This causes very low nice values (+19) to truly provide little CPU
416 to a process whenever there is any other
417 higher priority load on the system,
418 and makes high nice values (\-20) deliver most of the CPU to applications
419 that require it (e.g., some audio applications).
420
421 On Linux, the
422 .BR RLIMIT_NICE
423 resource limit can be used to define a limit to which
424 an unprivileged process's nice value can be raised; see
425 .BR setrlimit (2)
426 for details.
427 .\"
428 .SS SCHED_BATCH: Scheduling batch processes
429 (Since Linux 2.6.16.)
430 \fBSCHED_BATCH\fP can be used only at static priority 0.
431 This policy is similar to \fBSCHED_OTHER\fP in that it schedules
432 the thread according to its dynamic priority
433 (based on the nice value).
434 The difference is that this policy
435 will cause the scheduler to always assume
436 that the thread is CPU-intensive.
437 Consequently, the scheduler will apply a small scheduling
438 penalty with respect to wakeup behavior,
439 so that this thread is mildly disfavored in scheduling decisions.
440
441 .\" The following paragraph is drawn largely from the text that
442 .\" accompanied Ingo Molnar's patch for the implementation of
443 .\" SCHED_BATCH.
444 .\" commit b0a9499c3dd50d333e2aedb7e894873c58da3785
445 This policy is useful for workloads that are noninteractive,
446 but do not want to lower their nice value,
447 and for workloads that want a deterministic scheduling policy without
448 interactivity causing extra preemptions (between the workload's tasks).
449 .\"
450 .SS SCHED_IDLE: Scheduling very low priority jobs
451 (Since Linux 2.6.23.)
452 \fBSCHED_IDLE\fP can be used only at static priority 0;
453 the process nice value has no influence for this policy.
454
455 This policy is intended for running jobs at extremely low
456 priority (lower even than a +19 nice value with the
457 .B SCHED_OTHER
458 or
459 .B SCHED_BATCH
460 policies).
461 .\"
462 .SS Resetting scheduling policy for child processes
463 Each thread has a reset-on-fork scheduling flag.
464 When this flag is set, children created by
465 .BR fork (2)
466 do not inherit privileged scheduling policies.
467 The reset-on-fork flag can be set by either:
468 .IP * 3
469 ORing the
470 .B SCHED_RESET_ON_FORK
471 flag into the
472 .I policy
473 argument when calling
474 .BR sched_setscheduler (2)
475 (since Linux 2.6.32);
476 or
477 .IP *
478 specifying the
479 .B SCHED_FLAG_RESET_ON_FORK
480 flag in
481 .IR attr.sched_flags
482 when calling
483 .BR sched_setattr (2).
484 .PP
485 Note that the constants used with these two APIs have different names.
486 The state of the reset-on-fork flag can analogously be retrieved using
487 .BR sched_getscheduler (2)
488 and
489 .BR sched_getattr (2).
490
491 The reset-on-fork feature is intended for media-playback applications,
492 and can be used to prevent applications evading the
493 .BR RLIMIT_RTTIME
494 resource limit (see
495 .BR getrlimit (2))
496 by creating multiple child processes.
497
498 More precisely, if the reset-on-fork flag is set,
499 the following rules apply for subsequently created children:
500 .IP * 3
501 If the calling thread has a scheduling policy of
502 .B SCHED_FIFO
503 or
504 .BR SCHED_RR ,
505 the policy is reset to
506 .BR SCHED_OTHER
507 in child processes.
508 .IP *
509 If the calling process has a negative nice value,
510 the nice value is reset to zero in child processes.
511 .PP
512 After the reset-on-fork flag has been enabled,
513 it can be reset only if the thread has the
514 .BR CAP_SYS_NICE
515 capability.
516 This flag is disabled in child processes created by
517 .BR fork (2).
518 .\"
519 .SS Privileges and resource limits
520 In Linux kernels before 2.6.12, only privileged
521 .RB ( CAP_SYS_NICE )
522 threads can set a nonzero static priority (i.e., set a real-time
523 scheduling policy).
524 The only change that an unprivileged thread can make is to set the
525 .B SCHED_OTHER
526 policy, and this can be done only if the effective user ID of the caller
527 matches the real or effective user ID of the target thread
528 (i.e., the thread specified by
529 .IR pid )
530 whose policy is being changed.
531
532 A thread must be privileged
533 .RB ( CAP_SYS_NICE )
534 in order to set or modify a
535 .BR SCHED_DEADLINE
536 policy.
537
538 Since Linux 2.6.12, the
539 .B RLIMIT_RTPRIO
540 resource limit defines a ceiling on an unprivileged thread's
541 static priority for the
542 .B SCHED_RR
543 and
544 .B SCHED_FIFO
545 policies.
546 The rules for changing scheduling policy and priority are as follows:
547 .IP * 3
548 If an unprivileged thread has a nonzero
549 .B RLIMIT_RTPRIO
550 soft limit, then it can change its scheduling policy and priority,
551 subject to the restriction that the priority cannot be set to a
552 value higher than the maximum of its current priority and its
553 .B RLIMIT_RTPRIO
554 soft limit.
555 .IP *
556 If the
557 .B RLIMIT_RTPRIO
558 soft limit is 0, then the only permitted changes are to lower the priority,
559 or to switch to a non-real-time policy.
560 .IP *
561 Subject to the same rules,
562 another unprivileged thread can also make these changes,
563 as long as the effective user ID of the thread making the change
564 matches the real or effective user ID of the target thread.
565 .IP *
566 Special rules apply for the
567 .BR SCHED_IDLE
568 policy.
569 In Linux kernels before 2.6.39,
570 an unprivileged thread operating under this policy cannot
571 change its policy, regardless of the value of its
572 .BR RLIMIT_RTPRIO
573 resource limit.
574 In Linux kernels since 2.6.39,
575 .\" commit c02aa73b1d18e43cfd79c2f193b225e84ca497c8
576 an unprivileged thread can switch to either the
577 .BR SCHED_BATCH
578 or the
579 .BR SCHED_OTHER
580 policy so long as its nice value falls within the range permitted by its
581 .BR RLIMIT_NICE
582 resource limit (see
583 .BR getrlimit (2)).
584 .PP
585 Privileged
586 .RB ( CAP_SYS_NICE )
587 threads ignore the
588 .B RLIMIT_RTPRIO
589 limit; as with older kernels,
590 they can make arbitrary changes to scheduling policy and priority.
591 See
592 .BR getrlimit (2)
593 for further information on
594 .BR RLIMIT_RTPRIO .
595 .SS Limiting the CPU usage of real-time and deadline processes
596 A nonblocking infinite loop in a thread scheduled under the
597 .BR SCHED_FIFO ,
598 .BR SCHED_RR ,
599 or
600 .BR SCHED_DEADLINE
601 policy can potentially block all other threads from accessing
602 the CPU forever.
603 Prior to Linux 2.6.25, the only way of preventing a runaway real-time
604 process from freezing the system was to run (at the console)
605 a shell scheduled under a higher static priority than the tested application.
606 This allows an emergency kill of tested
607 real-time applications that do not block or terminate as expected.
608
609 Since Linux 2.6.25, there are other techniques for dealing with runaway
610 real-time and deadline processes.
611 One of these is to use the
612 .BR RLIMIT_RTTIME
613 resource limit to set a ceiling on the CPU time that
614 a real-time process may consume.
615 See
616 .BR getrlimit (2)
617 for details.
618
619 Since version 2.6.25, Linux also provides two
620 .I /proc
621 files that can be used to reserve a certain amount of CPU time
622 to be used by non-real-time processes.
623 Reserving CPU time in this fashion allows some CPU time to be
624 allocated to (say) a root shell that can be used to kill a runaway process.
625 Both of these files specify time values in microseconds:
626 .TP
627 .IR /proc/sys/kernel/sched_rt_period_us
628 This file specifies a scheduling period that is equivalent to
629 100% CPU bandwidth.
630 The value in this file can range from 1 to
631 .BR INT_MAX ,
632 giving an operating range of 1 microsecond to around 35 minutes.
633 The default value in this file is 1,000,000 (1 second).
634 .TP
635 .IR /proc/sys/kernel/sched_rt_runtime_us
636 The value in this file specifies how much of the "period" time
637 can be used by all real-time and deadline scheduled processes
638 on the system.
639 The value in this file can range from \-1 to
640 .BR INT_MAX \-1.
641 Specifying \-1 makes the runtime the same as the period;
642 that is, no CPU time is set aside for non-real-time processes
643 (which was the Linux behavior before kernel 2.6.25).
644 The default value in this file is 950,000 (0.95 seconds),
645 meaning that 5% of the CPU time is reserved for processes that
646 don't run under a real-time or deadline scheduling policy.
647 .PP
648 .SS Response time
649 A blocked high priority thread waiting for I/O has a certain
650 response time before it is scheduled again.
651 The device driver writer
652 can greatly reduce this response time by using a "slow interrupt"
653 interrupt handler.
654 .\" as described in
655 .\" .BR request_irq (9).
656 .SS Miscellaneous
657 Child processes inherit the scheduling policy and parameters across a
658 .BR fork (2).
659 The scheduling policy and parameters are preserved across
660 .BR execve (2).
661
662 Memory locking is usually needed for real-time processes to avoid
663 paging delays; this can be done with
664 .BR mlock (2)
665 or
666 .BR mlockall (2).
667 .SH NOTES
668 The
669 .BR cgroups (7)
670 CPU controller can be used to limit the CPU consumption of
671 groups of processes.
672 .PP
673 Originally, Standard Linux was intended as a general-purpose operating
674 system being able to handle background processes, interactive
675 applications, and less demanding real-time applications (applications that
676 need to usually meet timing deadlines).
677 Although the Linux kernel 2.6
678 allowed for kernel preemption and the newly introduced O(1) scheduler
679 ensures that the time needed to schedule is fixed and deterministic
680 irrespective of the number of active tasks, true real-time computing
681 was not possible up to kernel version 2.6.17.
682 .SS Real-time features in the mainline Linux kernel
683 .\" FIXME . Probably this text will need some minor tweaking
684 .\" ask Carsten Emde about this.
685 From kernel version 2.6.18 onward, however, Linux is gradually
686 becoming equipped with real-time capabilities,
687 most of which are derived from the former
688 .I realtime-preempt
689 patch set.
690 Until the patches have been completely merged into the
691 mainline kernel,
692 they must be installed to achieve the best real-time performance.
693 These patches are named:
694 .in +4n
695 .nf
696
697 patch-\fIkernelversion\fP-rt\fIpatchversion\fP
698 .fi
699 .in
700 .PP
701 and can be downloaded from
702 .UR http://www.kernel.org\:/pub\:/linux\:/kernel\:/projects\:/rt/
703 .UE .
704
705 Without the patches and prior to their full inclusion into the mainline
706 kernel, the kernel configuration offers only the three preemption classes
707 .BR CONFIG_PREEMPT_NONE ,
708 .BR CONFIG_PREEMPT_VOLUNTARY ,
709 and
710 .B CONFIG_PREEMPT_DESKTOP
711 which respectively provide no, some, and considerable
712 reduction of the worst-case scheduling latency.
713
714 With the patches applied or after their full inclusion into the mainline
715 kernel, the additional configuration item
716 .B CONFIG_PREEMPT_RT
717 becomes available.
718 If this is selected, Linux is transformed into a regular
719 real-time operating system.
720 The FIFO and RR scheduling policies are then used to run a thread
721 with true real-time priority and a minimum worst-case scheduling latency.
722 .SH SEE ALSO
723 .ad l
724 .nh
725 .BR chrt (1),
726 .BR taskset (1),
727 .BR getpriority (2),
728 .BR mlock (2),
729 .BR mlockall (2),
730 .BR munlock (2),
731 .BR munlockall (2),
732 .BR nice (2),
733 .BR sched_get_priority_max (2),
734 .BR sched_get_priority_min (2),
735 .BR sched_getaffinity (2),
736 .BR sched_getparam (2),
737 .BR sched_getscheduler (2),
738 .BR sched_rr_get_interval (2),
739 .BR sched_setaffinity (2),
740 .BR sched_setparam (2),
741 .BR sched_setscheduler (2),
742 .BR sched_yield (2),
743 .BR setpriority (2),
744 .BR pthread_getaffinity_np (3),
745 .BR pthread_setaffinity_np (3),
746 .BR sched_getcpu (3),
747 .BR capabilities (7),
748 .BR cpuset (7)
749 .ad
750 .PP
751 .I Programming for the real world \- POSIX.4
752 by Bill O. Gallmeister, O'Reilly & Associates, Inc., ISBN 1-56592-074-0.
753 .PP
754 The Linux kernel source files
755 .IR Documentation/scheduler/sched-deadline.txt ,
756 .IR Documentation/scheduler/sched-rt-group.txt ,
757 .IR Documentation/scheduler/sched-design-CFS.txt ,
758 and
759 .IR Documentation/scheduler/sched-nice-design.txt