Chapter 23. 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.
23.1. Viewing thread scheduling priorities Copy linkLink copied to clipboard!
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:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
23.2. Changing the priority of services during booting Copy linkLink copied to clipboard!
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.service.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.service.d/priority.conf
# cat <<-EOF > /etc/systemd/system/mcelog.service.d/priority.confCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the scheduling policy and priority to the file in the
[Service]section.For example:
[Service] CPUSchedulingPolicy=fifo CPUSchedulingPriority=20 EOF
[Service] CPUSchedulingPolicy=fifo CPUSchedulingPriority=20 EOFCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the
systemdscripts configuration.systemctl daemon-reload
# systemctl daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Restart the service.
systemctl restart mcelog
# systemctl restart mcelogCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the service’s priority.
tuna -t mcelog -P
$ tuna -t mcelog -PCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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
thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 826 FIFO 20 0,1,2,3 13 0 mcelogCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.3. Configuring the CPU usage of a service Copy linkLink copied to clipboard!
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
# md sscdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the CPUs to use for the service to the file using the
CPUAffinityattribute in the[Service]section.For example:
[Service] CPUAffinity=0,1 EOF
[Service] CPUAffinity=0,1 EOFCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the systemd scripts configuration.
systemctl daemon-reload
# systemctl daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Restart the service.
systemctl restart service
# systemctl restart serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the CPUs to which the specified service is limited.
tuna -t mcelog -P
$ tuna -t mcelog -PCopy to Clipboard Copied! Toggle word wrap Toggle overflow where
serviceis the specified service.The following output shows that the
mcelogservice 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
thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 12954 FIFO 20 0,1 2 1 mcelogCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.4. Priority map Copy linkLink copied to clipboard!
Scheduler priorities are defined in groups, with some groups dedicated to particular kernel functions.
| 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. |