ubuntu安装实时内核

ubuntu安装实时内核

注意:安装过程中可能会遇到各种问题,百度搜索,基本上可以解决。

1.准备工作

系统:Ubuntu 20.04.2 LTS

内核版本:Linux star-A 5.4.28-50-generic

目标内核:linux-5.4.28-rt19

内核下载地址:Index of /pub/linux/kernel/v5.x/

Index of /kernel/v5.x/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

rt_preempt补丁下载地址:Index of /pub/linux/kernel/projects/rt/

建议使用测试过的内核版本,不要随意换内核版本,否则可能会出问题。

安装依赖 :sudo apt-get install -y build-essential kernel-package libncurses5-dev

2.打补丁

#创建rt_linux_build
star@star-A:mkdir rt_linux_build
#改变目录到rt_linux_build
star@star-A:cd ~/rt_linux_build
#复制linux-5.4.28.tar.gz到lrt_linux_build
star@star-A:~/rt_linux_build$ cp ~/Downloads/linux-5.4.28.tar.gz ./
#复制patch-5.4.28-rt19.patch.gz到rt_linux_build
star@star-A:~/rt_linux_build$ cp ~/Downloads/patch-5.4.28-rt19.patch.gz ./
#解压linux-5.4.28.tar.gz到rt_linux_build
star@star-A:~/rt_linux_build$ tar zxvf linux-5.4.28.tar.gz 
#解压patch-5.4.28-rt19.patch.gz到rt_linux_build
star@star-A:~/rt_linux_build$ gzip -d patch-5.4.28-rt19.patch.gz
#复制patch-5.4.28-rt19.patch到linux-5.4.28
star@star-A:~/rt_linux_build$ cp patch-5.4.28-rt19.patch ./linux-5.4.28
#打补丁
star@star-A:~/rt_linux_build/linux-5.4.28$ patch -p1 < patch-5.4.28-rt19.patch


3. 配置内核

star@star-A:~/rt_linux_build/linux-5.6.19$ make menuconfig

进入内核配置界面,按照General setup —> Preemption Model —> Fully Preemptible Kernel(Real-Time)
Kernel hacking —> Memory Debugging —> Check for stack overflows not selected,这一操作一般都会有,但是在这个版本的内核配置里面没有发现,没做配置。

4. 编译内核

star@star-A:~/rt_linux_build/linux-5.4.26$ CONCURRENCY_LEVEL=$(nproc) make-kpkg --rootcmd fakeroot --initrd kernel_image kernel_headers

编译时间可能很长,试个人电脑性能而定。执行这条指令可能会遇到一些错误,百度搜索均可以解决,抽时间在补充这里的参考链接。make[1]: *** 没有规则可制作目标“debian/canonical-certs.pem”,由“certs/x509_certificate_list” 需求。 停止。_热巴小迷妹的博客-CSDN博客

5.安装内核

star@star-A:~/rt_linux_build$ sudo dpkg -i linux-headers-5.4.28-rt19_5.4.28-rt19-10.00.Custom_amd64.deb linux-image-5.4.28-rt19_5.4.28-rt19-10.00.Custom_amd64.deb
star@star-A:~/rt_linux_build$ sudo update-grub
star@star-A:~/rt_linux_build$ sudo reboot

开机之后查看内核版本:

star@star-A:~$ uname -a
Linux star-A 5.4.28-rt19 #1 SMP PREEMPT_RT Sun Apr 25 08:24:05 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

修改默认启动的内核参考:Ubuntu20.04 如何降低内核版本_JSYRD的博客-CSDN博客_ubuntu 内核降级

6.实时性测试

安装 cyclictest 实时测试软件:

star@star-A:~$ sudo apt-get install rt-tests
#查看cyclictest的版本
star@star-A:~$ cyclictest -version
cyclictest: invalid option -- 'e'
cyclictest V 1.50
………………………………………………………………

输入测试指令:

star@star-A:~$ sudo cyclictest -t 5 -p 80 -s
[sudo] star 的密码: 
# /dev/cpu_dma_latency set to 0us
policy: fifo: loadavg: 8.14 3.60 2.20 3/1443 4279           

T: 0 ( 4272) P:80 I:1000 C:  39585 Min:      1 Act:    2 Avg:    1 Max:      43
T: 1 ( 4273) P:80 I:1500 C:  26411 Min:      1 Act:    2 Avg:    2 Max:      37
T: 2 ( 4274) P:80 I:2000 C:  19813 Min:      1 Act:    3 Avg:    2 Max:      47
T: 3 ( 4275) P:80 I:2500 C:  15854 Min:      1 Act:    1 Avg:    2 Max:      44
T: 4 ( 4276) P:80 I:3000 C:  13215 Min:      1 Act:    2 Avg:    2 Max:      34

对参数进行说明:

T: 0 序号为0的线程
P: 0 线程优先级为0
C: 9397 计数器。线程的时间间隔每达到一次,计数器加1
I: 1000 时间间隔为1000微秒(us)
Min: 最小延时(us)
Act: 最近一次的延时(us)
Avg:平均延时(us)
Max: 最大延时(us)

cyclictest的一篇参考文章:cyclictest 测试以及原理浅谈_i龙家小少的博客-CSDN博客_cyclictest

7.非root用户使用 RT_PREEMPT

#修改cpu_dma_latency的权限
star@star-A:~$ chmod 606 /dev/cpu_dma_latency

  • 0
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值