kernel build & preempt-rt patch & xenomai

6 篇文章 2 订阅
4 篇文章 0 订阅

提前准备好 linux 内核源码,如果是 x86 系统,可以去下载原生内核(Vanilla kernel):
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.17.tar.gz

如果是arm系统,或者其他系统,则下载厂商定制过的内核源码。

如果有需要,patch内核,如 preempt-rt 补丁:(注意补丁版本必须与内核版本对应,此处均为 3.18.17 版本。如果是定制过的内核,则必须找到对应定制过的补丁.)

wget https://www.kernel.org/pub/linux/kernel/projects/rt/3.18/patch-3.18.17-rt14.patch.gz   // 注意 patch 和 patchs

cd linux-3.18.17    //内核源码根目录
zcat ../patch-3.18.17-rt14.patch.gz | patch -p1     // 打补丁,如果.bz2压缩格式则使用 bzcat;
// 如果在源码根目录的上层目录,则 patch -p0 < xxx.patch

在现有系统上修改配置:

make mrproper   //清理一下
scp pi@raspberrypi:/proc/config.gz .    //复制现有系统的配置文件,x86系统则可以找到 /boot/config-3.18.17-32-generic 文件

gunzip -c config.gz > .config

// 因为你的交叉编译器可能不叫gcc,而是 arm-linux-gnueabihf-gcc,所以:
export CCPREFIX=/home/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
// 这样子运行你的交叉编译器:
${CCPREFIX}gcc -v

//根据需要修改.config文件,或者 make menuconfig 图形化修改内核配置
ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig

ARCH=arm CROSS_COMPILE=${CCPREFIX} make -jx        // build kernel, 多核系统

mkdir module_build_directory
INSTALL_MOD_PATH=module_build_directory make modules_install  // build modules
// 这里是交叉编译,所以不能直接安装,如果是x86系统,直接 make && sudo make modules_install && sudo make install && sudo update-grub 即可

复制新的内核到sd卡(树莓派2)

Copy arch/arm/boot/Image to /boot/kernel7.img on SD card.
Copy arch/arm/boot/dts/bcm2709-rpi-2-b.dtb to /boot/bcm2709-rpi-2-b.dtb on SD card
Copy (merge if necessary) kernel-rt/lib to / on SD card.


cd linux/arch/arm/boot
scp Image pi@raspberrypi:/tmp
scp dtb/bcm2709-rpi-2-b.dtb pi@raspberrypi:/tmp

cd module_build_directory
tar czf modules.tgz *
scp modules.tgz pi@raspberrypi:/tmp

// ssh to raspberry
ssh pi@your_ip_address_to_rasp
cd /
sudo mv /tmp/Image /boot/kernel7.img        // 忽略属性不同的信息
scp mv /tmp/bcm2709-rpi-2-b.dtb /boot/bcm2709-rpi-2-b.dtb   
sudo tar xzf /tmp/modules.tgz           // 解压后可以通过ls /lib/modules查看

关于内核配置

Symbol(s) Description:
[ ], [*]    Options in square brackets can be activated or deactivated. The asterisk marks the menu entry as activated. The value can be changed with the space key. It is also possible to press Y key (Yes) to activate or N key (No) to deactivate the selected entry.

If the option is activated, the selected feature/driver will be built into the kernel and will always be available at boot time.

< >, <M>, <*>   Options in angle brackets can be activated or deactivated, but also activated as module (indicated by a M). The values can be modified by pressing Y/N keys as before or by pressing the M key to activate the feature/driver as a module.

See the Kernel Modules article for differentiation.

{M}, {*}    Options in curly brackets can be activated or activated as module but not be deactivated. This happens because another feature/driver is dependent on this feature.
-M-, -*-    Options between hyphens are activated in the shown way by another feature/driver. There is no choice.
Tag Description:
(NEW)   This driver is new in the kernel and is maybe not stable enough.
(EXPERIMENTAL)  This driver is experimental and most likely not stable enough.
(DEPRECATED)    This driver is deprecated and not needed for most systems.
(OBSOLETE)  This driver is obsolete and should not be activated.

关于 x86 的 preemt-rt patch & kernel build,见 连接:

  1. https://ubuntuforums.org/showthread.php?t=2273355
  2. http://askubuntu.com/questions/72964/how-can-i-install-a-realtime-kernel
  3. https://sourceforge.net/p/emc/mailman/message/33665819/ 这个注意是使用 64 位系统还是 32位,可能需要修改 .config 文件。

如果有哪个 kernel config 不懂的话,可以在这个里头搜:

  1. https://cateee.net/lkddb/

preempt-rt kernel config:

CONFIG_PREEMPT_RT_FULL: Kernel Features > Preemption Model > Fully Preemptible Kernel (RT)
Enable HIGH_RES_TIMERS: General Setup > Timers subsystem > High Resolution Timer Support (already enabled)

去掉某些 ACPI 和 PowerManage 相关选项,不能全部去掉,因为高精度时钟可能会依赖其中某些配置
去掉 CPU 频率调整选项等
去掉 Device Driver 中的 Staging Drivers 选项
去掉 Kernel Hacking 中的某些 debug 选项(如果不需要debug内核的话)

推荐配置如下(xenomai-2.6.5):

 * General setup
  --> Local version - append to kernel release: -xenomai-2.6.5
  --> Timers subsystem
      --> High Resolution Timer Support (Enable)
 * Real-time sub-system
  --> Xenomai (Enable)
  --> Nucleus (Enable)
 * Power management and ACPI options
  --> Run-time PM core functionality (Disable)
  --> ACPI (Advanced Configuration and Power Interface) Support
      --> Processor (Disable)
  --> CPU Frequency scaling
      --> CPU Frequency scaling (Disable)
  --> CPU idle
      --> CPU idle PM support (Disable)
 * Pocessor type and features
  --> Processor family
      --> Core 2/newer Xeon (if \"cat /proc/cpuinfo | grep family\" returns 6, set as Generic otherwise)
 * Power management and ACPI options
  --> Memory power savings
      --> Intel chipset idle memory power saving driver

如果遇到问题,查看 linux log ( dmesg | grep -i xenomai ),查找对应问题 see link: http://www.xenomai.org/documentation/xenomai-head/TROUBLESHOOTING.txt
如果是 xeno latency 测试,发现 周期性高延时,那么很可能是遇到了 SMI 的问题。

About how to fix it:

other ref link:

  1. http://stackoverflow.com/questions/17812548/cyclictest-for-rt-patched-linux-kernel
  2. https://rt.wiki.kernel.org/index.php/RT_PREEMPT_HOWTO
  3. http://swift.siphos.be/linux_sea/kernelbuilding.html
  4. http://rtt-lwr.readthedocs.io/en/latest/rtpc/xenomai.html
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
preempt-rt是一个在Linux操作系统内核中实施实时(real-time)功能的一个软件补丁(patch),用于提高Linux操作系统的实时性能。在普通的Linux内核中,时间分片是通过时间片轮转法来实现的,这意味着任务可能会在中断的时候被打断,从而导致实时任务无法按时完成。而preempt-rt补丁则引入了抢占式调度(preemptive scheduling),可以在高优先级实时任务到来时,立即中断低优先级任务,从而确保实时任务按时完成。 preempt-rt补丁还引入了一些改进,比如提高了中断处理的实时性,减少了中断的延迟。此外,它还改进了内核对多核处理器的支持,能够更好地利用多核处理器的性能,提高系统的响应能力。这使得Linux操作系统可以用于处理实时应用,比如工业控制、自动驾驶和机器人等领域。 preempt-rt补丁不仅仅是一个补丁,它还需要与其他实时工具和库一起使用,比如实时定时器和实时优先级调度策略等,来共同实现实时功能。有了preempt-rt补丁,Linux操作系统就可以满足实时性要求更高的应用需求,使得开发者可以更自由地选择Linux平台来开发实时应用。 但是需要注意的是,preempt-rt补丁并不适用于所有场景。由于引入了更严格的实时约束,它可能导致系统的稳定性下降,对内存和处理器资源的需求也相应增加。因此,在使用preempt-rt补丁时,需要对系统进行全面评估,并根据实际需求进行权衡。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值