13. RT-Linux

Video introduction to this chapter:

../../_images/video.png

“23-Use real-time RT-Linux on LubanCat”

https://www.bilibili.com/video/BV1Js4y1B7jd/

RT-Linux is a real-time operating system based on the Linux kernel. It combines the versatility and real-time performance of the Linux operating system to provide developers with a unified platform to develop real-time applications.

The core of RT-Linux is a real-time extension of the Linux kernel, which provides the necessary scheduling mechanism and time management for real-time tasks. By adopting the preemptive scheduling strategy, high-priority real-time tasks can interrupt low-priority tasks to ensure timely response of real-time tasks. RT-Linux improves task scheduling and interrupt handling, so that tasks can be executed according to the scheduled time.

RT-Linux is suitable for applications that are sensitive to time requirements, such as industrial automation, robot control, aerospace systems, etc. It can provide precise task scheduling and fast response time to ensure that the system can operate normally under the requirements of real-time tasks.

Compared with the traditional Linux kernel, RT-Linux has improved real-time performance, but it is not a hard real-time system, and cannot guarantee the absolute accuracy of task execution time. For extremely time-critical applications, a more specialized real-time operating system may be required.

RT-Linux is compatible with the versatility of the Linux operating system and can be developed using various tools and libraries in the Linux ecosystem. Developers can use a wide range of development tools and resources to build real-time applications, thereby improving development efficiency.

注解

LubanCat’s kernel also supports RT-Linux, and the kernel is modified using the PREEMPT_RT patch.

13.1. LubanCat RT-Linux installation method

13.1.1. Install the kernel package

Uninstall the old kernel: Because the old kernel is not compatible with RT-Linux, it must be uninstalled

1
2
#Uninstall the old kernel
sudo apt remove -y -f linux-headers-4.19.232 linux-image-4.19.232

Get the RT-Linux kernel

Click to download the update package

kernel package 1: Store the header files of the kernel. kernel package 2: store the kernel, driver and /boot partition content. kernel package 3: store debug related, used for kernel hang or debug kernel function. kernel package 4: store some header files.

Install the RT-Linux kernel

  • Put the four kernel packages on the board and move them to the storage folder.

1
2
#One-click install all
sudo dpkg -i *.deb

Restart the effective kernel

1
reboot

13.1.2. Update the kernel online

Uninstall the old kernel: Because the old kernel is not compatible with RT-Linux, it must be uninstalled.

1
2
#Uninstall the old kernel
sudo apt remove -y -f linux-headers-4.19.232 linux-image-4.19.232

Get the RT-Linux kernel

1
2
#Install new kernel online
sudo apt install linux-headers-4.19.232-rt104 linux-image-4.19.232-rt104 linux-image-4.19.232-rt104-dbg

Restart the effective kernel

1
reboot

13.2. LubanCat RT-Linux test

13.2.1. cyclictest

Cyclictest is a tool for testing the real-time performance of Linux systems, which can measure the response time and clock accuracy of the system. Cyclictest evaluates the system’s ability to process real-time tasks by creating periodic loads.

注意

This test is a load test, and the load is very heavy. If you log in with ssh, you may not be able to enter the console and display information, so it is recommended to use the serial port root login. The following commands are written according to the serial port root login.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#apt update package
apt update

#installation tool
apt install -y python git

#Download the source code of cyclictest
git clone https://github.com/jlelli/rt-tests.git

#Enter the source code directory
cd rt-tests

#Compile the source code (if there is an error, it should be that the dependency is not done properly, just install it according to the missing dependency).
make -j4

#Load test (this method needs to be executed under the rt-tests directory)
./cyclictest -t 4  -p 99 -n -m -d 0 & ./hackbench -l -1 -g 15 -f 25 -P &

#No-load test (this method needs to be executed under the rt-tests directory)
./cyclictest -t 4  -p 99 -n -m -d 0

#Install to /usr/bin (this option is optional)
make install

#Load test (this option is optional and can be executed in other directories)
cyclictest -t 4  -p 99 -n -m -d 0 & hackbench -l -1 -g 15 -f 25 -P &

#No-load test (this option is optional and can be executed in other directories)
cyclictest -t 4  -p 99 -n -m -d 0

hackbench -l -1 -g 15 -f 25 -P is used to make load

  • -l -1: Indicates that hackbench will run in an infinite loop and will not exit automatically.

  • -g 15: Set the number of processes in each process group to 15. Each process group will spawn a set of processes for communication.

  • -f 25: Set the number of parent-child relationships between each process group to 25. This determines how the process groups communicate with each other.

  • -P: Use multiple CPU cores to run the test to simulate the situation of a multi-core system.

cyclictest -t 4 -p 99 -n -m -d 0

  • -t 4: Specifies to use 4 threads for testing. Each thread will create a periodic load.

  • -p 99: Set the priority of the thread to 99, which is the highest real-time priority. Use the highest priority to better test the real-time performance of the system.

  • -n: Disable sleep during testing. This will prevent the system from going to sleep to keep the system active.

  • -m: Lock memory before running tests. This will prevent memory paging faults during testing and provide more consistent test results.

  • -d 0: Disable delayed output. This will prevent the output of detailed latency data per thread and only show overall statistics for the test

13.2.2. cyclictest test results (no desktop image)

  • When RT-Linux is fully loaded, it ran for 174447434us (174447 seconds, about two days), and the stability is relatively good. The maximum delay is 58us, and the average delay is 21us.

未找到图片
  • In the current test of RT-Linux, the maximum delay time is 71us, as shown in the figure below.

未找到图片

When RT-Linux is empty:

未找到图片
  • It can be seen that under no load, the average delay is less than 10us, and the maximum delay does not exceed 71.

Under normal linux full load

未找到图片

Normal linux under no load

未找到图片

13.2.3. cyclictest test results (with desktop image)

The test of mirror cyclictest with desktop is relatively poor, and the system has not been fully adapted.

未找到图片