X-LINUX-RT is an STM32 MPU OpenSTLinux Expansion Package that targets real-time (RT) feature in the Linux kernel.
A RT system is a system which responds to a request in a time laps and not as fast as possible:
- determinism
- LATENCY but not SPEED
To have a better understanding about RT Linux, you can refer to the Linux RT foundation website[1].
1. X-LINUX-RT[edit source]
1.1. Main software modification[edit source]
Moving on a Linux-RT impacts kernel configuration:
- Power management is not "compliant" with a real time context as it changes system behavior. There is no more frequency scaling ; it's a fixed frequency.
- High Resolution timers and periodic ticks should be used in order to have a precise tick.
2. Distribution package: re-generate X-LINUX-RT OpenSTLinux distribution[edit source]
With the following procedure, the complete distribution can be re-generated by enabling the X-LINUX-RT expansion package.
2.1. Download the STM32MP1 Distribution Package[edit source]
For ecosystem release v4.1.0 :
Install the STM32MP1 Distribution Package v4.1.0.
2.2. Install X-LINUX-RT environment[edit source]
- Clone the meta-st-x-linux-rt git repositories
cd <Distribution Package installation directory>/layers/meta-st git clone https://github.com/STMicroelectronics/meta-st-x-linux-rt.git cd ../..
- Source the build environment with the correct board and layer.
DISTRO=openstlinux-weston MACHINE=stm32mp13-rt source layers/meta-st/scripts/envsetup.sh
DISTRO=openstlinux-weston MACHINE=stm32mp15-rt source layers/meta-st/scripts/envsetup.sh
2.3. Build the image[edit source]
bitbake st-image-weston
2.4. Program the built image into the Flash memory[edit source]
Follow this link to see how to program the built image.
3. Developer package: build RT BSP with the SDK[edit source]
Linux RT can be built with sources provided in the OpenSTLinux BSP packages in addition with patches and device tree files provided in X-LINUX-RT meta layer.
3.1. Install the OpenSTLinux SDK[edit source]
The OpenSTLinux SDK contains all the basis needed for the X-LINUX-RT Expansion package, so it needs to be downloaded and installed: see OpenSTLinux SDK installation guide. Once done, a directory is present on your machine containing the OpenSTLinux SDK.
3.2. Download the Developer package[edit source]
The STM32MP1 Developer Package, containing all the BSP source code, must be downloaded and extracted. To do this, follow only the STM32MP1_Developer_Package#Installing_the_OpenSTLinux_BSP_packages (and not the sub-chapters ).
Two BSP components (OP-TEE OS and Linux kernel) must be modified for RT feature. The procedure to modify them is explained in next chapters.
3.3. Download X-LINUX-RT meta layer[edit source]
- Clone the meta-st-x-linux-rt git repository
cd <Developer Package installation directory>/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabi git clone https://github.com/STMicroelectronics/meta-st-x-linux-rt.git
3.4. Modify the BSP[edit source]
As written above, to enable the RT feature, two BSP components must be modified.
3.4.1. Modify the Linux kernel[edit source]
Follow now the sub-chapter STM32MP1_Developer_Package#Building_and_deploying_the_Linux_kernel_for_the_first_time to prepare the Linux kernel.
Patches found in <Developer Package installation directory>/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabimeta-st-x-linux-rt/recipes-kernel/linux/5.15/5.15.67 must also be applied.
Enter in the directory containing Linux kernel sources, then apply patches:
for p in `ls -1 <Developer Package installation directory>/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabimeta-st-x-linux-rt/recipes-kernel/linux/5.15/5.15.67/*.patch`; do patch -p1 < $p; done
Once patches are applied, new fragments are present inside the Linux kernel source. Apply fragments as it is explain in the README.HOW_TO.txt helper file.
Then add also the following fragments:
* arch/arm/configs/fragment-07-rt.config * arch/arm/configs/fragment-07-rt-sysvinit.config * arch/arm/configs/fragment-08-rt-mp13.config
* arch/arm/configs/fragment-07-rt.config * arch/arm/configs/fragment-07-rt-sysvinit.config
The Linux kernel can now be built and deployed.
3.4.2. Modify the OP-TEE OS[edit source]
Follow now the sub-chapter STM32MP1_Developer_Package#Building_and_deploying_the_OP-TEE_for_the_first_time to prepare the OP-TEE OS.
Patches found in <Developer Package installation directory>/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabimeta-st-x-linux-rt/recipes-security/optee/optee-os must also be applied.
Enter in the directory containing OP-TEE OS sources, then apply patches
for p in `ls -1 <Developer Package installation directory>/stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26/sources/arm-ostl-linux-gnueabimeta-st-x-linux-rt/recipes-security/optee/optee-os/*.patch`; do patch -p1 < $p; done
OP-TEE OS can now be built and deployed, as explained in STM32MP1_Developer_Package#Building_and_deploying_the_OP-TEE_for_the_first_time.
4. To go further[edit source]
To check that RT feature is enabled and functional, following commands can be executed.
4.1. Check Linux kernel version[edit source]
uname -s -r -v
Without RT feature | With RT feature |
---|---|
Linux 5.15.67 #1 SMP PREEMPT Thu Sep 8 10:32:54 UTC 2022 |
Linux 5.15.67-rt49 #1 SMP PREEMPT_RT Thu Sep 8 10:32:54 UTC 2022 |
4.2. Cyclictest[edit source]
Cyclictest accurately and repeatedly measures the difference between a thread's intended wake-up time and the time at which it actually wakes up.
For a better understanding on cyclictest, refer to the cyclictest webpage in Linux RT foundation website[2].
For example, following command can be used:
cyclictest --mlockall -t -a --priority=99 --interval=200 --distance=0 -l 1000
Without RT feature | With RT feature |
---|---|
policy: fifo: loadavg: 0.03 0.08 0.08 1/173 8476 T: 0 ( 8475) P:99 I:200 C: 1000 Min: 15 Act: 71 Avg: 32 Max: 100 T: 1 ( 8476) P:99 I:200 C: 853 Min: 15 Act: 48 Avg: 31 Max: 65 |
policy: fifo: loadavg: 0.29 0.32 0.24 1/211 3815 T: 0 ( 3814) P:99 I:200 C: 1000 Min: 15 Act: 21 Avg: 23 Max: 60 T: 1 ( 3815) P:99 I:200 C: 795 Min: 16 Act: 32 Avg: 20 Max: 59 |