CSE Roadmap

Core tier · about 5 hours · 7 parts

Part 4 of 7 · 2 min read

Effects

In plain words: A mild rule can be enough, or the rule can overrule everything. Three tests on the 2-processor machine compare policies, each pinning a normal spinner and a second spinner to one processor for 5 or 6 seconds (100 ticks of CPU time is 1 second):

Second spinner Normal spinner's CPU time Second spinner's CPU time
SCHED_OTHER (nice 0) 247 ticks 247 ticks
SCHED_BATCH 248 ticks 248 ticks
SCHED_IDLE 495 ticks 1 tick
SCHED_RR at priority 10 29 ticks 564 ticks
  • SCHED_BATCH shares equally with a normal task. Its difference is the wake-up behaviour, not the share.
  • SCHED_IDLE got 1 tick out of 496, about 0.2 per cent. The normal task took almost everything.
  • SCHED_RR took nearly everything: the normal task got 29 ticks out of 593, 4.9 per cent, not zero.

The last line is not an accident. A runaway real-time task would freeze the machine, since a normal task could never run to stop it. To prevent it, Linux applies real-time throttling: in each period, real-time tasks may use only a limited part of the processor. The settings printed on this machine:

$ cat /proc/sys/kernel/sched_rt_runtime_us /proc/sys/kernel/sched_rt_period_us
950000
1000000

In every 1,000,000 microseconds (1 second), real-time tasks may run for 950,000 microseconds, 95 per cent. The remaining 5 per cent is left for normal tasks, which matches the measured 4.9 per cent. A real-time task that loops for ever cannot freeze the machine completely.

This is also a lesson on priorities against shares (page 5): a real-time priority orders tasks, so a higher one takes everything it wants, while a nice value only sets a weight, so a nice 19 task still gets its fraction.

Real-time throttling

Real-time throttling is a Linux limit on the share of processor time that real-time tasks may use in each period, by default 950,000 of every 1,000,000 microseconds, so that normal tasks always keep a minimum share and a runaway real-time task cannot freeze the machine.

Example: a SCHED_RR task in an endless loop left the competing normal task 29 of 593 ticks, about 5 per cent.

Check yourself: 1. What share of the processor did the SCHED_IDLE task get? 2. Which setting in /proc/sys/kernel limits real-time tasks, and what is its default? 3. Why is real-time throttling a safety feature?