Introduction
This document describes how to apply the option "PREEMPT_RT", which has been a standard feature of the Linux kernel since version 6.12.
Note: PREEMPT_RT existed prior to version 6.12, but was released as a patch to the standard Linux kernel. To use it, you had to patch the kernel.
In environments where the PREEMPT_RT option is applied, the kernel preemption feature is enhanced and task response times are significantly reduced. It is mainly used in fields that require strict timing control, such as industrial equipment, robotics, and communication equipment, and achieves real-time performance that is difficult to achieve with the standard Linux kernel.
Although PREEMPT_RT is a powerful means to add real-time performance to the Linux kernel, real-time does not always mean immediate response. Real-time means that processing is guaranteed to be completed within a set amount of time, and does not necessarily mean high-speed processing.
Note: Real-time performance is also highly dependent on hardware configuration, device drivers, and user space design. Please understand that PREEMPT_RT is an environment where the fluctuations in process scheduling by the Linux kernel are reduced.
1. How to set up PREEMPT_RT
If you have Linux kernel 6.12 or later, all you need to do is to specify the option in the kernel configuration settings using defconfig or menuconfig.
The following is a screen shot of the menuconfig screen searching for a description of PREEMPT_RT.
[Figure 1] PREEMPT_RT description
Point: Since EXPERT is listed as "Depends on", it means that CONFIG_EXPERT must be enabled as well. Note that arm (32-bit) is not supported by default.
Note: As of version 6.12, PREEMPT_RT is only available for ARM64, RISCV, and X86 (32/64-bit) target architectures without patches. ARM (32-bit) users are still recommended to apply the patch.
See realtime:start [Wiki] for an overview of the PREEMPT_RT patch and repository location information.
1-1. Configuration in defconfig
If you are using a defconfig file, add the following statement to the end of the defconfig file you are using.
CONFIG_EXPERT=y
CONFIG_PREEMPT_RT=y Note: defconfig files are stored under architecture-specific configs directories, such as arch/arm/configs and arch/arm64/configs.
Tip: The addition does not have to be at the end, but be aware of conflicts with other preemption mode settings (CONFIG_PREEMPT_NONE, CONFIG_PREEMPT_VOLUNTARY, and CONFIG_PREMPT). The mode specified on a later line will be applied.
1-2. Configuration in menuconfig
When configuring with menuconfig, set the options on the screen displayed by "make menuconfig".
Select "General setup -> Preemption Model -> Fully Preemptible Kernel (Real-Time)" from the "Location" menu in Figure 1. If you do not enable EXPERT beforehand, the options will not be displayed.
[Figure 2] General setup -> Preemption Model (before activating EXPERT)
The EXPERT option is enabled by entering "y" when "General setup -> Configure standard kernel features (expert users)" is selected. To disable it, enter "n".
[Figure 3] Enabling the EXPERT option
After enabling EXPERT, open General setup -> Preemption Model again, and you will see the option "Fully Preemptible Kernel (Real-Time)" corresponding to PREEMPT_RT. Select this option and press the Enter key.
[Figure 4] General setup -> Preemption Model (after enabling EXPERT)
After that, < Save >, move to the top menu, and < Exit > to complete the process.
[Figure 5] Top menu screen
Tip: Refer to the explanatory comments at the top of the screen for menuconfig operation. You can use the up, down, left and right arrow keys to move through the menus and enter shortcuts in the explanatory comments.
2. Options related to scheduling cycle (HZ)
In addition to PREEMPT_RT, there is another option called CONFIG_HZ that you should check if you are concerned about real-time performance.
To configure CONFIG_HZ using defconfig, add one of the following settings to the defconfig file.
CONFIG_HZ_100=y
CONFIG_HZ_250=y
CONFIG_HZ_300=y
CONFIG_HZ_1000=yWhen configuring menuconfig, select the option in "Kernel features -> Timer frequency".
[Figure 6] Kernel features -> Timer frequency
2-1. What is CONFIG_HZ?
CONFIG_HZ is an option that sets the frequency (Hz) of timer interrupts in the Linux kernel. It defines how many times per second the kernel generates timer interrupts, which affects the accuracy of time-dependent functions such as process scheduling and timeout handling.
The setting values include the following.
[Table 1] CONFIG_HZ Setting Values
Set value (period) |
Main application |
| 100 (10 msec) | For environments requiring low power consumption and low overhead, such as server applications. Can be set with CONFIG_HZ_100=y. |
| 250 (4 msec) | Provides balanced responsiveness for desktop applications. Can be set with CONFIG_HZ_250=y. |
| 300 (3.3 msec) | For some embedded applications and special real-time requirements. Can be set with CONFIG_HZ_300=y. |
| 1000 (1 msec) | For environments that require real-time performance or systems with a lot of user interaction. Can be set with CONFIG_HZ_1000=y. |
Note: Higher HZ values may increase the frequency of timer interrupts and increase the CPU load. Conversely, a lower value will reduce timing accuracy, so it is important to set the appropriate value for your application.
Note: 100Hz is standard on arm architecture Linux environments such as Cyclone® V SoC and Arria® 10 SoC, and 250Hz is standard on arm64 architecture environments such as Agilex™ 7/5/3.
3. Preemption model (supplement)
The following is a summary of the effects of selecting each option item of the preemption model, including PREEMPT_RT. The following is a summary of the effects and overview of each option item of the preemption model, including PREEMPT_RT.
[Table 2] Summary of Preemption Model
PREEMPT_NONE |
PREEMPT_VOLUNTARY |
PREEMPT_VOLUNTARY |
PREEMPT_RT |
|
| Summary | No preemption occurs in kernel space. Interrupts wait until kernel processing is complete. | Provides spontaneous preemption. The kernel performs preemption only at specific points (e.g., when the kernel spontaneously reaches a scheduling point). | Provide full preemption. Preemption (task switching through interrupts) is also possible within the kernel. | Provides the most aggressive real-time preemption. |
| Use case | Systems that require high throughput but do not require real-time performance. | Used in desktop and server environments, but with a lower preemption level than PREEMPT. | Desktop environments and embedded systems that require a certain degree of real-time performance. | Used in certain embedded systems where real-time user space tasks need to be prioritized over interrupt handlers. |
| Benefits | Throughput can be higher because kernel processing is not interrupted. Simpler implementation and easier debugging. | Improved system stability and low overhead. | When interrupts occur not only in user space but also in kernel space, the system can switch to higher priority tasks. Low latency and high responsiveness. | Provides excellent real-time performance. |
| Disadvantages | High latency and low responsiveness. | System is not as responsive as PREEMPT. | Does not provide the same real-time performance as PREEMPT_RT. | May increase overhead and degrade overall performance. |
Tip: In addition to the above, there is also an option called PREEMPT_DYNAMIC. If this option is selected, the kernel argument allows mode selection for preemption at boot time:
- preempt=none (PREEMPT_NONE)
- preempt=voluntary (PREEMPT_VOLUNTARY)
- preempt=full (PREEMPT)
As of Kernel 6.12, it is not possible to select PREEMPT_RT as a kernel argument for PREEMPT_DYNAMIC.
Conclusion
This article has introduced the PREEMPT_RT option in the Linux kernel.
As mentioned early in the article, as of version 6.12, standard support for PREEMPT_RT is limited to ARM64, RISCV, and x86 (32/64-bit) architectures; if you wish to use PREEMPT_RT in an ARM 32-bit environment, as before If you want to use PREEMPT_RT in an ARM 32-bit environment, you will need to download and apply the real-time patch for the same version of the target kernel as before.
Since the real-time patch targets the mainline Linux kernel published by kernel.org, please be careful when applying the patch to the SoC FPGA kernel repository environment. Please check the differences before and after the patch is applied, and take care to avoid unintended changes.
Finally, the following is a link to the commit history of changes that are standard for PREEMPT_RT. You will notice that the architecture of the changes is limited.