Chapter 19. Setting scheduler priorities
Red Hat Enterprise Linux for Real Time kernel allows fine-grained control of scheduler priorities. It also allows application-level programs to be scheduled at a higher priority than kernel threads.
Setting scheduler priorities can carry consequences and may cause the system to become unresponsive or behave unpredictably if crucial kernel processes are prevented from running as needed. Ultimately, the correct settings are workload-dependent.
19.1. Viewing thread scheduling priorities
Thread priorities are set using a series of levels, ranging from 0
(lowest priority) to 99
(highest priority). The systemd
service manager can be used to change the default priorities of threads after the kernel boots.
Procedure
To view scheduling priorities of running threads, use the tuna utility:
# tuna --show_threads thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 2 OTHER 0 0xfff 451 3 kthreadd 3 FIFO 1 0 46395 2 ksoftirqd/0 5 OTHER 0 0 11 1 kworker/0:0H 7 FIFO 99 0 9 1 posixcputmr/0 ...[output truncated]...
19.2. Changing the priority of services during booting
Using systemd
, you can set up real-time priority for services launched during the boot process.
Unit configuration directives are used to change the priority of a service during boot process. The boot process priority change is done by using the following directives in the service section of /etc/systemd/system/service.system.d/priority.conf
:
CPUSchedulingPolicy=
Sets the CPU scheduling policy for executed processes. Takes one of the scheduling classes available on Linux:
-
other
-
batch
-
idle
-
fifo
-
rr
CPUSchedulingPriority=
Sets the CPU scheduling priority for an executed processes. The available priority range depends on the selected CPU scheduling policy. For real-time scheduling policies, an integer between 1
(lowest priority) and 99
(highest priority) can be used.
Prerequisites
- You have administrator privileges.
- A service that runs on boot.
Procedure
For an existing service:
Create a supplementary service configuration directory file for the service.
# cat <<-EOF > /etc/systemd/system/mcelog.system.d/priority.conf
Add the scheduling policy and priority to the file in the
[SERVICE]
section.For example:
[SERVICE] CPUSchedulingPolicy=fifo CPUSchedulingPriority=20 EOF
Reload the
systemd
scripts configuration.# systemctl daemon-reload
Restart the service.
# systemctl restart mcelog
Verification
Display the service’s priority.
$ tuna -t mcelog -P
The output shows the configured priority of the service.
For example:
thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 826 FIFO 20 0,1,2,3 13 0 mcelog
Additional resources
19.3. Configuring the CPU usage of a service
Using systemd
, you can specify the CPUs on which services can run.
Prerequisites
- You have administrator privileges.
Procedure
Create a supplementary service configuration directory file for the service.
# md sscd
Add the CPUs to use for the service to the file using the
CPUAffinity
attribute in the[SERVICE]
section.For example:
[SERVICE] CPUAffinity=0,1 EOF
Reload the systemd scripts configuration.
# systemctl daemon-reload
Restart the service.
# systemctl restart service
Verification
Display the CPUs to which the specified service is limited.
$ tuna -t mcelog -P
where
service
is the specified service.The following output shows that the
mcelog
service is limited to CPUs 0 and 1.thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 12954 FIFO 20 0,1 2 1 mcelog
:_content-type: REFERENCE
19.4. Priority map
Scheduler priorities are defined in groups, with some groups dedicated to particular kernel functions.
Table 19.1. Thread priority table
Priority | Threads | Description |
---|---|---|
1 | Low priority kernel threads |
This priority is usually reserved for the tasks that need to be just above |
2 - 49 | Available for use | The range used for typical application priorities. |
50 | Default hard-IRQ value | This priority is the default value for hardware-based interrupts. |
51 - 98 | High priority threads |
Use this range for threads that execute periodically and must have quick response times. Do |
99 | Watchdogs and migration | System threads that must run at the highest priority. |