1、确认系统使用Linux内核版本号,并下载与其接近的kernel版本
uname -a
2、kernel下载地址:国内镜像
http://mirror.tuna.tsinghua.edu.cn/kernel/
3、下载preempt-rt补丁包,与kernel版本一致
https://mirror.tuna.tsinghua.edu.cn/kernel/projects/rt/
4、使用(注debian系统最好切换root用户 su root)
4.1 打补丁
tar xzvf linux-4.9.1.tar.gz
cd linux-4.9.1
xzcat …/patch-4.9-rt1.patch.xz | patch -p1
4.2 删除所有编译的生成文件
make mrproper
4.3 拷贝config文件
cp /boot/config-4.9.0-8-amd64 .config
4.4 make menuconfig
需要安装libncurses-dev
配置Full Rt
Processor type and featuress ------>
Preemption Mode (Fully Preemptible Kernel(RT))
-> Processor type and features
Timer frequency (1000 HZ)
时钟频率调整成1000Hz
4.5 编译
make -jN /N cpu个数乘2/
make INSTALL_MOD_STRIP=1 modules_install -jN /* 不带调试信息 */
make install -jN
update-grub2
reboot
编译错误: openssl/opensslv.h : No such file or directory
apt-get install libssl-dev
4.6 查看是否安装成功
uname -a
5、测试工具安装
apt-get install rt-tests
测试结果:
6、优化
有时会发现,当安装上面进行修改后,最大延时达不到预期效果,希望在10us左右,还要进行一些优化设置.
(1) 关闭内核中调试信息
CONFIG_DEBUG_INFO = n
(2) C状态\P状态修改设置,设置到grub里,在/etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT追加
intel_idle.max_cstate=1 intel_pstate=disable processor.max_cstate=1
(3) 实时任务内核绑定,CPU隔离
参考Linux下进程与cpu绑定,缓解响应延迟问题
经过这些优化实时任务抖动会低于20us,接近10us左右.
如果超过了20us,就要从其他方面入手调查了,比如CPU频率,设置成定频.网络\USB设备资源问题等方面着手调查了.