In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to turn linux into a real-time operating system". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to turn linux into a real-time operating system.
1. What is a real-time operating system?
Real-time refers to the task response time when scheduling. Windows is usually 15ms, but the biggest problem is that it cannot be guaranteed. For example, the average value is 1ms, but as the system load changes, sometimes even reaching 100ms, it is not available in this industry. Some industrial applications require higher time accuracy. For example, an electric power monitoring system must run a task in 10ms to monitor the power operation status. Once the time is not accurate and the program cannot be run, the timely response to power failure can not be guaranteed.
two。 How to realize the real-time system? 3.PREEMPT_RT
PREEMPT_RT is a real-time patch to the Linux kernel. Highly rated by Linus:
Controlling a laser with Linux is crazy, but everyone in this room is crazy in his own way. So if you want to use Linux to control an industrial welding laser, I have no problem with your using PREEMPT_RT. "- Linus Torvalds
4. Download the linux kernel source code using method 4. 1
You can take a look at these two domestic ones, and they are relatively fast.
4.2 download RT patch
Patch is downloaded from https://rt.wiki.kernel.org/index.php/Main_Page, and the version number of the linux kernel must be the same.
4.3 method of use
1. Decompress kernel source code
two。 Play patch
3. Compile the linux kernel and install
Tar xzvf linux-4.4.138.tar.gz
Cd linux-4.4.138
Patch-p1
< ../patch-4.4.138-rt65.patch make menuconfig需要安装这个libncurses-dev模块 编译内核需要libssl-dev模块 sudo apt-get install libncurses-dev sudo apt-get install libssl-dev 配置linux内核 make menuconfig 选择Processor type and feature ->Fully Preemptible Kernel (RT) this option, the specific path is shown below. Save.
Compile the kernel, install, and update grub.
Adding INSTALL_MOD_STRIP=1 at compile time can generate modules without debugging information, greatly reducing the size of the kernel.
Make-J2
# sudo make modules_install-j2
# the kernel generated by this command contains a lot of debugging information, so use the INSTALL_MOD_STRIP option
Sudo make INSTALL_MOD_STRIP=1 modules_install
Sudo make install-J2
Sudo update-grub2
After reboot, there will be one more startup option for linux-4.4.138-rt.
5. Test sudo apt-get install rt-tests
Install this tool and run the cyclictest program for real-time testing:
Sudo cyclictest-t 5-p 80-n
Note: run five threads with thread priority of 80, infinite loop
Details of the running results of cyclictest:
T: 0 thread with sequence number 0
P: 0 thread priority is 0
C: 9397 counter. Every time the time interval of a thread reaches, the counter increases by 1.
I: 1000 interval is 1000 microseconds (us)
Min: minimum delay (us)
Act: last delay (us)
Avg: average delay (us)
Max: maximum delay (us)
Example of test results:
1. Physical machine test results
# / dev/cpu_dma_latency set to 0us
Policy: fifo: loadavg: 0.13 0.06 0.02 1/244 19255
T: 0 (18989) Min 80 IRAV 1000 C: 155947 Act: 1 Avg: 1 Max: 17
T: 1 (18990) Min 80 iRO 1500 C: 103964 Min: 1 Act: 1 Avg: 1 Max: 15
T: 2 (18991) Min 80 IRAV 2000 C: 77973 Min: 1 Act: 1 Avg: 1 Max: 7
T: 3 (18992) Min 80 IRO 2500 C: 62378 Min: 1 Act: 1 Avg: 1 Max: 10
T: 4 (18993) Min 80 iren 3000 C: 51982 Act: 1 Avg: 1 Max: 7
two。 Virtual machine test results
The effect in the virtual machine is general, but it is too limited by the host.
My@ubuntu:~/rt/linux-4.4.138$ sudo cyclictest-p 80-T5-n
# / dev/cpu_dma_latency set to 0us
Policy: fifo: loadavg: 0.69 0.19 0.07 1/726 5825
T: 0 (5821) Min 80 IRAV 1000 C: 8168 Act: 7 Avg: 327 Max: 7005
T: 1 (5822) Min 80 IRV 1500 C: 5455 Avg: 7 Act: 411 Max: 7516
T: 2 (5823) Min 80 IRAV 2000 C: 4098 Min: 14 Act: 174 Avg: 320 Max: 2362
T: 3 (5824) Min 80 IRO 2500 C: 3275 Act: 52 Avg: 319 Max: 6940
T: 4 (5825) Min 80 iren 3000 C: 2732 Min: 8 Act: 214 Avg: 299 Max: 5198
3. You can also run it multiple times and count the results.
Sudo cyclictest-l10000000-m-n-T1-P99-i2-h200
-l10000000: specify 10 million cycles
-m: lock current and future memory allocations
-n: specifies the use of clock_nanosleep
-T1: specify a thread to test
-P99: specify the highest priority
-i2: specifies the basic thread interval in us, in this case 2us
-H200: specifies the distribution of statistical results.
The execution of the program ends in 20 seconds, and the output shows an average delay of 1 us and a maximum delay of 15 us. Seen through the histogram, most of them are concentrated within 1-7 us.
# / dev/cpu_dma_latency set to 0us
Policy: fifo: loadavg: 0.36 0.33 0.28 1/246 32690
T: 0 (32688) Avg 99 Irius 2 Centro 10000000 Min: 0 Act: 2 Avg: 1 Max: 15
# Histogram
000000 000051
000001 6635143
000002 3352561
000003 008966
000004 002414
000005 000648
000006 000180
000007 000025
000008 000002
000009 000001
000010 000000
000011 000000
000012 000001
000013 000001
000014 000006
000015 000001
. (all 0 in the middle, omitted)
000097 000000
000098 000000
000099 000000
# Total: 010000000
# Min Latencies: 00000
# Avg Latencies: 00001
# Max Latencies: 00009
# Histogram Overflows: 00000
# Histogram Overflow at cycle number:
# Thread 0:
6. Summary
The real-time patch can better meet our needs (1ms) and achieve strong real-time performance.
At this point, I believe you have a deeper understanding of "how to turn linux into a real-time operating system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.