实时Linux内核(PREEMPT |
您所在的位置:网站首页 › debian查看内核版本 › 实时Linux内核(PREEMPT |
1.什么是实时性操作系统?
https://blog.csdn.net/ywx123_/article/details/53861274 实时性是指调度的时候,任务响应时间。windows一般是15ms,最大的问题是不能保证。比如平均值是1ms,但是随着系统负载的变化,有时甚至达到100ms,在这工业上是无法使用的。工业上一些应用要求必须有更高的时间精度,比如,一个电力监测系统必须在10ms内运行一次任务对电力运行状况进行监测,一旦时间不准,调度不到该程序运行,则无法保证对电力故障的及时响应。 实时操作系统相关论文: http://www.cs.columbia.edu/~sedwards/classes/2001/w4995-02/reports/shamil-kalpen.pdf https://www.researchgate.net/publication/3151063_Performance_Comparison_of_VxWorks_Linux_RTAI_and_Xenomai_in_a_Hard_Real-time_Application https://www.researchgate.net/publication/273759417_Performance_Comparison_of_Real-Time_and_General-Purpose_Operating_Systems_in_Parallel_Physical_Simulation_with_High_Computational_Cost https://elinux.org/images/d/de/Real_Time_Linux_Scheduling_Performance_Comparison.pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.21.9705&rep=rep1&type=pdf 2.怎么实现实时性系统?https://blog.csdn.net/lu_embedded/article/details/52485527 3.PREEMPT_RTPREEMPT_RT是Linux内核的一个实时补丁。得到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 项目主页见:https://rt.wiki.kernel.org/index.php/Main_Page 具体怎么用可以参考:https://wiki.linuxfoundation.org/realtime/documentation/howto/applications/preemptrt_setup ,这是官方的说明。 4.编译内核方法 4.1下载linux内核源码网址:https://mirrors.edge.kernel.org/pub/linux/kernel/ 国内镜像网址:http://mirror.bjtu.edu.cn/kernel/linux/kernel/ ,http://mirror.tuna.tsinghua.edu.cn/kernel/ 这两个国内的可以看一下,速度比较快。 4.2下载RT patchpatch在https://rt.wiki.kernel.org/index.php/Main_Page 下载,点击某个版本,可能有点旧,进到链接里面后,选版本号新的就可以了,与linux内核的版本号一定要一样。 更多下载地址: https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/ 1.解压内核源码 2.打patch 3.编译linux内核并安装 tar xzvf linux-4.4.138.tar.gz cd linux-4.4.138 patch -p1 < ../patch-4.4.138-rt65.patchmake menuconfig需要安装这个libncurses-dev模块 编译内核需要libssl-dev模块 sudo apt-get install libncurses-dev bison flex bc libelf-dev sudo apt-get install libssl-dev配置linux内核 #据说下载包里自带的.config文件可能导致打补丁失败,另一种办法是将原linux系统中的.config文件拷贝到内核文件夹,这样编译出来的内核与本机兼容性更好 cp /boot/config-4.15.18 ./ make menuconfig选择Processor type and feature —> Fully Preemptible Kernel (RT)这个选项,具体路径如下图。保存。(2021.3.10更新,内核5.0以上的不是这样的路径?) 编译内核,再安装,更新grub. 编译时加上 INSTALL_MOD_STRIP=1 可以生成没有调试信息的模块,大大减小内核的大小。 // 编译 make -j2 // 如果直接安装到本机上,直接make install 即可 // make install 会自动执行 update-grub2 sudo make install -j 几个可选的命令和参数: // make modules_install 用于安装/lib/modules目录下的驱动, 安装的模块可能含有调试信息,文件非常大,可以使用INSTALL_MOD_STRIP选项去除调试信息 sudo make INSTALL_MOD_STRIP=1 modules_install 如果不希望将内核安装到本机,比如将内核放到某个目录,然后复制到另一台机器上,用 INSTALL_MOD_PATH指定modules安装目录, INSTALL_PATH 指定内核安装路径: make INSTALL_MOD_PATH=~/work/linux/bin modules_install make INSTALL_PATH=~/work/linux/bin/boot install // 对于嵌入式板子还需要安装dtbs,用INSTALL_DTBS_PATH指定安装的路径。x86上不需要dtbs make INSTALL_DTBS_PATH=~/work/linux/bin dtbs_install重启后会多一个 linux-4.4.138-rt 的启动选项。 如果要在grub界面停一下,选择内核,需要修改/etc/default/grub文件 # 注释掉下面这行将会显示引导菜单 #GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=5 5.cyclictest测试实时性可参考以下网页: https://blog.csdn.net/kl1125290220/article/details/78560220 https://blog.csdn.net/longerzone/article/details/16897655 cyclictest 讲的非常详细 https://zhuanlan.zhihu.com/p/336381111 sudo apt-get install rt-tests 安装这个工具,运行cyclictest程序进行实时性测试: sudo cyclictest -t 5 -p 80 -n 注释: 运行五个线程,线程优先级为80,无限循环cyclictest运行结果详解 T: 0 序号为0的线程 P: 0 线程优先级为0 C: 9397 计数器。线程的时间间隔每达到一次,计数器加1 I: 1000 时间间隔为1000微秒(us) Min: 最小延时(us) Act: 最近一次的延时(us) Avg: 平均延时(us) Max: 最大延时(us)测试结果示例: 1.实体机测试结果 # /dev/cpu_dma_latency set to 0us policy: fifo: loadavg: 0.13 0.06 0.02 1/244 19255 T: 0 (18989) P:80 I:1000 C: 155947 Min: 1 Act: 1 Avg: 1 Max: 17 T: 1 (18990) P:80 I:1500 C: 103964 Min: 1 Act: 1 Avg: 1 Max: 15 T: 2 (18991) P:80 I:2000 C: 77973 Min: 1 Act: 1 Avg: 1 Max: 7 T: 3 (18992) P:80 I:2500 C: 62378 Min: 1 Act: 1 Avg: 1 Max: 10 T: 4 (18993) P:80 I:3000 C: 51982 Min: 1 Act: 1 Avg: 1 Max: 72.虚拟机测试结果 在虚拟机中效果一般,受主机的限制太大。 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) P:80 I:1000 C: 8168 Min: 7 Act: 445 Avg: 327 Max: 7005 T: 1 ( 5822) P:80 I:1500 C: 5455 Min: 7 Act: 411 Avg: 319 Max: 7516 T: 2 ( 5823) P:80 I:2000 C: 4098 Min: 14 Act: 174 Avg: 320 Max: 2362 T: 3 ( 5824) P:80 I:2500 C: 3275 Min: 5 Act: 52 Avg: 319 Max: 6940 T: 4 ( 5825) P:80 I:3000 C: 2732 Min: 8 Act: 214 Avg: 299 Max: 51983.也可以进行多次运行并统计结果 sudo cyclictest -l10000000 -m -n -t1 -p99 -i2000 -h100-l10000000 :指定1千万循环, -m :锁定当前和将来的内存分配, -n :指定使用 clock_nanosleep, -t1 :指定开一个线程进行测试, -p99 :指定最高优先级, -i2000 :指定基本线程间隔,单位是us, -h100 :指定统计结果的分布情况。 程序执行结束后,输出显示平均延时1 us,最大延时15 us,通过直方分布图察看,大多集中在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) P:99 I:2000 C: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 …………(中间都是0,省略) 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.总结实时性补丁能够较好地满足我们的需求(1ms),实现较强的实时性。 7.无需动手编译,直接安装预编译内核的方法ubuntu 和centos 都提供了预编译的prempt 内核, 只是ubuntu的是lowlatency 低延时内核,centos的是rt kernel最高级实时 7.1 ubuntu 安装低延时内核参考https://linuxmusicians.com/viewtopic.php?t=18536 apt-get install linux-lowlatency 7.2 centos 安装预编译的实时内核官方 redhat 8 安装rt内核文档 https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_for_real_time/8/html-single/installation_guide/index 参考https://unix.stackexchange.com/questions/341933/install-a-real-time-kernel-on-centos sudo tee /etc/yum.repos.d/CentOS-rt.repo >/dev/null |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |