原创 RT-Linux在IMX8上的使用

2020-10-29 14:24 517 7 7 分类: MCU/ 嵌入式

By Toradex胡珊逢

 

Real-time Linux 是指在普通 Linux 内核打上 PREEMPT_RT补丁后使内核满足实时要求。下面我们将使用 Apalis iMX8QM 介绍如何开启 Linux 5.4 的实时功能。

 

首先需要下载适用于 Apalis iMX8QM 模块的最新 Linux 内核源码。


git clone -b toradex_5.4-2.1.x-imx     git://git.toradex.cn/linux-toradex.git


 

在源码根目录下打开 Makefile 文件查看内核版本,这里我们看到是5.4.47


$ head Makefile

# SPDX-License-Identifier: GPL-2.0

VERSION = 5

PATCHLEVEL = 4

SUBLEVEL = 47

EXTRAVERSION =

NAME = Kleptomaniac Octopus


 

下载对应版本的 PREEMPT_RT补丁,解压后放到源码根目录下。

https://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older/patch-5.4.47-rt28.patch.gz

 

执行下面命令为 5.4.47 内核打上补丁。


$ patch -p1     < patch-5.4.47-rt28.patch


 

根据这里的说明完成内核以及驱动模块编译。


$ make     defconfig

$ make     menuconfig


 

开启 > General setup >

  • Configure standard kernel features

     > General setup > reemption Model 中选择 Fully Preemptible Kernel (Real-Time)

    image001.png

    为了获得更好的实时性能,我们将关闭显示功能以及部分音频功能。在 > Device Drivers > Graphics support 中取消相关显示接口。

    image002.png

     

     > Device Drivers > Sound card support > Advanced Linux Sound Architecture > ALSA for SoC audio support > SoC Audio for Freescale CPUs 中取消 AUDIO TO HDMI TX module support  XCVR 支持。

    image003.png

     

    保存配置后退出,开始编译内核。


    $ make     Image.gz 2>&1 | tee build.log

    $ make -j3     modules

    $ mkdir     modules

    $ export     INSTALL_MOD_PATH=modules

    $ make     modules_install


     

     arch/arm64/boot  modules/lib/modules 目录分别是内核文件 Image.gz 和驱动模块。将其复制到 Apalis iMX8QM 模块的 /media/mmcblk0p1  /lib/modules/。然后执行重启命令。


    root@apalis-imx8:~# sync

    root@apalis-imx8:~# reboot


     

    启动后可以查看目前运行的内核配置情况。


    root@apalis-imx8:~#     zcat /proc/config.gz |grep PREEMPT                                                                                                                        CONFIG_HAVE_PREEMPT_LAZY=y                                                                                                                                                    CONFIG_PREEMPT_LAZY=y                                                                                                                                                         #     CONFIG_PREEMPT_NONE is not set                                                                                                                                              # CONFIG_PREEMPT_VOLUNTARY is not set                                                                                                                                         # CONFIG_PREEMPT is not set                                                                                                                                                   CONFIG_PREEMPT_RT=y                                                                                                                                                           CONFIG_PREEMPT_COUNT=y                                                                                                                                                    CONFIG_PREEMPTION=y                                                                                                                                                           CONFIG_PREEMPT_RCU=y                                                                                                                                                          CONFIG_PREEMPT_NOTIFIERS=y


     

     Apalis iMX8QM 上的两个 A72  四个 A53 核心的时钟都设置到最高。


    root@apalis-imx8:~# echo performance >     /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor

    root@apalis-imx8:~# echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

    root@apalis-imx8:~# cpufreq-info |grep current

          current policy: frequency should be within 600 MHz and 1.20 GHz.

          current CPU frequency is 1.20 GHz (asserted by call to hardware).

          current policy: frequency should be within 600 MHz and 1.20 GHz.

          current CPU frequency is 1.20 GHz (asserted by call to hardware).

          current policy: frequency should be within 600 MHz and 1.20 GHz.

          current CPU frequency is 1.20 GHz (asserted by call to hardware).

      current     policy: frequency should be within 600 MHz and 1.20 GHz.

          current CPU frequency is 1.20 GHz (asserted by call to hardware).

          current policy: frequency should be within 600 MHz and 1.60 GHz.

          current CPU frequency is 1.60 GHz (asserted by call to hardware).

          current policy: frequency should be within 600 MHz and 1.60 GHz.

          current CPU frequency is 1.60 GHz (asserted by call to hardware).


     

    执行 cyclictest 工具查看内核实时性能。


    root@apalis-imx8:~# cyclictest -n m -S -p 99     --policy=fifo -i 431 -H 300

    # /dev/cpu_dma_latency set to 0us

    policy: fifo: loadavg: 0.42 0.31 0.13 2/399     834         

     

    T: 0 (      829) P:99 I:431 C:  59963     Min:      6 Act:    8 Avg:    9 Max:      24

    T: 1 (      830) P:99 I:431 C:  59962     Min:      5 Act:    5 Avg:    6 Max:      26

    T: 2 (      831) P:99 I:431 C:  59962     Min:      5 Act:    7 Avg:    6 Max:      20

    T: 3 (      832) P:99 I:431 C:  59962     Min:      5 Act:    6 Avg:    6 Max:      21

    T: 4 (      833) P:99 I:431 C:  59962     Min:      4 Act:    5 Avg:    6 Max:      20

    T: 3 (      832) P:99 I:431 C:  60517     Min:      5 Act:    7 Avg:    6 Max:      21

    T: 4 (      833) P:99 I:431 C:  60517     Min:      4 Act:    7 Avg:    6 Max:      17

    T: 5 (      834) P:99 I:431 C:  60517     Min:      3 Act:    5 Avg:    4 Max:      12


    下面链接是我们提供的包含实时内核的 BSP,可用于评估和测试。

    ftp://ftp.toradex.cn/Documents/ApplicationNote/resources/RT-Linux/Apalis-iMX8_Reference-Minimal-Image-rt-Tezi_5.0.0-devel-20201028085956+build.0.zip

     

     

    总结

    使用 Toradex Linux BSP 可以很方便集成 PREEMPT-RT 补丁,实现 real-time Linux。为了获得更好的实时性能,除了调整 Linux 内核配置,还需要关注文件系统,通常一个精简的文件系统,由于加载的应用软件或者驱动较少,可以避免占用 CPU 资源。在类似 Apalis iMX8 这种异构多核架构的处理器上会有额外的 Cortex-M4 核心,其可以运行 FreeRTOS提供硬实时能力。具体使用方法可以参考文末链接。

     

     

     

     

     

     

     

     

    参考:

    https://developer.toradex.cn/knowledge-base/real-time-linux

    https://blog.savoirfairelinux.com/en-ca/2020/linux-for-real-time-systems-evaluation-and-security-considerations/

    https://www.toradex.cn/blog/nxp-imx8-m4he-xinfreertos-rpmsg-ying-yong-shi-li

  • 作者: hai.qin_651820742, 来源:面包板社区

    链接: https://mbb.eet-china.com/blog/uid-me-1864768.html

    版权声明:本文为博主原创,未经本人允许,禁止转载!

    文章评论0条评论)

    登录后参与讨论
    相关推荐阅读
    hai.qin_651820742 2020-11-20 09:39
    NXP iMX8基于Qtwayland配置双屏显示
    By Toradex秦海1). 简介嵌入式平台多屏显示是比较常见的功能,在NXP iMX6上面,由于使用了基于fbdev/X11的显示接口驱动和显示服务,可以比较方便的通过framebuff...
    hai.qin_651820742 2020-11-17 10:46
    使用Squashfs和Overlayfs提高嵌入式Linux文件系统可靠性
    By Toradex胡珊逢 在使用嵌入式 Linux 系统的时,会出现由于设备意外断电引起文件系统损坏而最终使该设备无法启动的现象。为了应对这种情况,通常会从硬件设计如采...
    hai.qin_651820742 2020-10-23 17:51
    嵌入式平台WIFI AP模式测试
    By Toradex秦海1). 简介本文介绍基于ARM嵌入式平台使用开源Hostapd软件配置测试WiFi Access Point模式,也就是AP模式。 本文所使用的ARM嵌入式...
    hai.qin_651820742 2020-10-15 10:43
    DeviceTreeOverlay使用
    By Toradex 胡珊逢1). 简介目前较新的 Linux 内核都支持  Device Tree 来管理外设,这对嵌入式设备来说显得尤为...
    hai.qin_651820742 2020-09-30 15:13
    在 Windows 中使用 WSL 编译 Linux 和 U-Boot
    By Toradex 胡珊逢1). 简介通常当编译 Linux、U-Boot 相关源代码时,由于编译工具或者文件系统限制,这些任务需要在 Linux&...
    广告
    EE直播间
    更多
    我要评论
    0
    7
    1
    2
    3
    4
    5
    6
    7
    8
    9
    0
    广告
    关闭 热点推荐上一条 /6 下一条