之前的项目一直使用linux+ qt+实时内核(ucos或freertos)的方式开进行开发。最新的方法考虑使用linux(打实时补丁)+fpga来进行项目开发。
我们当前使用的linux内核是3.0.101。所以是时候写一篇博客了。
主要分为RT-Preempt 和rt-tests两部分的移植,前者是内核补丁,后者是测试demo。
rt补丁地址是 https://www.kernel.org/pub/linux/kernel/projects/rt/
rt-tests的维基百科地址是
https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/rt-tests#compile-and-install
必须保证内核版本和rt补丁版本的一致。当前内核版本如下:
rt补丁版本如下
执行命令
patch -p1 < ../patch-3.0.101-rt130.patch > ../log.txt。打补丁信息就输出到log.txt文件。因为我的内核不是原始内核,所以patch过程中会有好多错误。下一步查看log.txt文件。大部分的错行问题不大,但是一定确保所有的错误都手动解决。如果有的补丁和rt补丁冲突,要进行卸载。
问题:
gc_hal_kernl_os.c 会报错,
参考网址:https://www.baidu.com/link?url=9EnkYMKaUQTUioJD4Pi1TSaV73S6JvbtjP63-2MIyDauW9UdWBQLK3_oX4UBg3MbbdkxqH0w6bj2j4rnkfBHd_&wd=&eqid=9b50217e00200be5000000035e82f597
我修改了红色字体的代码。
git/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c +@@ -3043,7 +3043,7 @@ gckOS_CreateMutex( + gcmkONERROR(gckOS_Allocate(Os, gcmSIZEOF(struct mutex), Mutex)); + + /* Initialize the mutex. */ +- mutex_init(*Mutex); ++ mutex_init((struct mutex*)*Mutex); + + /* Return status. */ + gcmkFOOTER_ARG("*Mutex=0x%X", *Mutex); +@@ -3088,7 +3088,7 @@ gckOS_DeleteMutex( + gcmkVERIFY_ARGUMENT(Mutex != gcvNULL); + + /* Destroy the mutex. */ +- mutex_destroy(Mutex); ++ mutex_destroy((struct mutex*)Mutex);
配置内核:
make menuconfig
linux3.0 的在 kernel features 。更高版本的可能不在这个目录
编译内核 make uImage
下载到开发板,运行。
rt-tests
下载rt_tests源码 git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
切换分支: git checkout origin/stable/v1.0
b) 交叉编译 修改Makefile中的编译器
下面两句一定要改为自己的编译器名。
CC = arm-none-linux-gnueabi-gcc
AR = arm-none-linux-gnueabi-ar
执行make指令,生成cyclictest文件,下载到开发板。
./cyclictest -t 5 -p 80 -n 注释: 运行五个线程,线程优先级为80,无限循环
实测在a9处理器上开50个任务延时1ms,误差小于0.2ms。基本满足要求。
cyclictest运行结果详解
T: 0 序号为0的线程 P: 0 线程优先级为0 C: 9397 计数器。线程的时间间隔每达到一次,计数器加1 I: 1000 时间间隔为1000微秒(us) Min: 最小延时(us) Act: 最近一次的延时(us) Avg:平均延时(us) Max: 最大延时(us)
另外补充一句维基百科的信息
rt-tests suite can be installed from source. Therefore the libnuma and build-essentials are required. The given example is for a Debian based system:
sudo apt-get install build-essential libnuma-dev
libnuma-dev is required for build. Usually, it's safe to have libnuma-dev installed also in non-NUMA systems, but if you don't want to install the NUMA libs (e.g. in embedded environment) then compile with make NUMA=0.
Clone source code (check out the latest stable branch, because the master branch is not used for stable release any more), compile it and install it to the local filesystem
git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git cd rt-tests git checkout stable/v1.0
git checkout -b stable/v1.0 origin/stable/v1.0
make all make install
The last step is optional. All compiled programs can be executed from the build directory directly. If only a single program should be compiled only the single make target for the specific program could be executed (example for cyclictest):
make cyclictest
realtime/documentation/howto/tools/rt-tests.txt · Last modified: 2019/03/15 14:35 by Clark Williams