xenomai是linux實時改造的重要方案之一,下面給出其具體的安裝以及Ubuntu核心編譯過程。
具體原理圖如下
原理
1 下載下傳ubuntu核心以及xenomai3.1軟體包
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.9.38.tar.gz
複制
wget https://xenomai.org/downloads/xenomai/stable/xenomai-3.1.tar.bz2
複制
2 壓縮包解壓縮,并且複制到/usr/src
sudo tar xf linux-4.9.38.tar.gz
sudo tar xf xenomai-3.1.tar.bz2
複制
sudo cp -r linux-4.9.38 /usr/src
sudo cp -r xf xenomai-3.1 /usr/src
複制
3 給ubuntu核心打上xenomai更新檔,建立一個x86_64位核心
cd linux-4.9.38
複制
sudo wget https://xenomai.org/downloads/ipipe/v4.x/x86/older/ipipe-core-4.9.38-x86-3.patch
複制
../xenomai-3.1/scripts/prepare-kernel.sh --arch=x86_64 --ipipe=ipipe-core-4.9.38-x86-3.patch
複制
4 配置核心
yes "" | make oldconfig
sudo apt install libncurses5-dev
make menuconfig
複制
具體配置如下所示:
* General setup
--> Local version - append to kernel release: -xenomai-3.1
--> Timers subsystem
--> High Resolution Timer Support (Enable)
* Xenomai/cobalt
--> Sizes and static limits
--> Number of registry slots (512 --> 4096)
--> Size of system heap (Kb) (512 --> 4096)
--> Size of private heap (Kb) (64 --> 256)
--> Size of shared heap (Kb) (64 --> 256)
--> Maximum number of POSIX timers per process (128 --> 512)
--> Drivers
--> RTnet
--> RTnet, TCP/IP socket interface (Enable)
--> Drivers
--> New intel(R) PRO/1000 PCIe (Enable)
--> Realtek 8169 (Enable)
--> Loopback (Enable)
--> Add-Ons
--> Real-Time Capturing Support (Enable)
* Power management and ACPI options
--> CPU Frequency scaling
--> CPU Frequency scaling (Disable)
--> ACPI (Advanced Configuration and Power Interface) Support
--> Processor (Disable)
--> CPU Idle
--> CPU idle PM support (Disable)
* Pocessor type and features
--> Enable maximum number of SMP processors and NUMA nodes (Disable)
// Ref : http://xenomai.org/pipermail/xenomai/2017-September/037718.html
--> Processor family
--> Core 2/newer Xeon (if "cat /proc/cpuinfo | grep family" returns 6, set as Generic otherwise)
// Xenomai will issue a warning about CONFIG_MIGRATION, disable those in this orde
--> Transparent Hugepage Support (Disable)
--> Allow for memory compaction (Disable)
--> Contiguous Memory Allocation (Disable)
--> Allow for memory compaction
--> Page Migration (Disable)
* Device Drivers
--> Staging drivers
--> Unisys SPAR driver support
--> Unisys visorbus driver (Disable)
5 進一步建構實時核心
sudo apt install kernel-package
複制
sudo apt-get install libssl-dev
複制
6 編譯核心
CONCURRENCY_LEVEL=$(nproc) make-kpkg --rootcmd fakeroot --initrd kernel_image kernel_headers
複制
7 安裝生成的系統檔案
cd ..
sudo dpkg -i linux-headers-4.9.38-xenomai-3.1_4.9.38-xenomai-3.1-10.00.Custom_amd64.deb linux-image-4.9.38-xenomai-3.1_4.9.38-xenomai-3.1-10.00.Custom_amd64.deb
複制
8 允許非root使用者
sudo addgroup xenomai --gid 1234
sudo addgroup root xenomai
sudo usermod -a -G xenomai $USER
複制
9 配置GRUB
sudo gedit /etc/default/grub
複制
具體修改如下
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.9.38-xenomai-3.1"
#GRUB_DEFAULT=saved
#GRUB_SAVEDEFAULT=true
# Comment the following lines
#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash xenomai.allowed_group=1234"
GRUB_CMDLINE_LINUX=""
更新GRUB并重新啟動
sudo update-grub
複制
重新開機電腦
sudo reboot
複制
重新開機後選擇Ubuntu進階核心
10 安裝xenomai使用者空間庫
uname -r
複制
# 4.9.38-xenomai-3.1
dmesg | grep Xenomai
複制
# [1.417024] [Xenomai] scheduling class idle registered.
# [1.417025] [Xenomai] scheduling class rt registered.
# [1.417045] [Xenomai] disabling automatic C1E state promotion on Intel processo
# [1.417055] [Xenomai] SMI-enabled chipset found, but SMI workaround disabled
# [1.417088] I-pipe: head domain Xenomai registered.
# [1.417704] [Xenomai] allowing access to group 1234
# [1.417726] [Xenomai] Cobalt v3.1 (Sisyphus's Boulder) [DEBUG]
cd xenomai-3.1
./configure --with-pic --with-core=cobalt --enable-smp --disable-tls --enable-dlopen-libs --disable-clock-monotonic-raw
make -j`nproc`
sudo make install
複制
11 Update bashrc
echo '
### Xenomai
export XENOMAI_ROOT_DIR=/usr/xenomai
export XENOMAI_PATH=/usr/xenomai
export PATH=$PATH:$XENOMAI_PATH/bin:$XENOMAI_PATH/sbin
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$XENOMAI_PATH/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$XENOMAI_PATH/lib
export OROCOS_TARGET=xenomai
' >> ~/.xenomai_rc
複制
echo 'source ~/.xenomai_rc' >> ~/.bashrc
source ~/.bashrc
複制
12 測試
增權重限
sudo chmod -R 777 /dev/rtdm/memdev-private
sudo chmod -R 777 /dev/rtdm/memdev-shared
複制
xeno latency
複制
== Sampling period: 100 us
== Test mode: periodic user-mode task
== All results in microseconds
warming up...
RTT| 00:00:01 (periodic user-mode task, 100 us period, priority 99)
RTH|----lat min|----lat avg|----lat max|-overrun|---msw|---lat best|--lat worst
RTD| 0.174| 0.464| 1.780| 0| 0| 0.174| 1.780
RTD| 0.088| 0.464| 1.357| 0| 0| 0.088| 1.780
RTD| 0.336| 0.464| 1.822| 0| 0| 0.088| 1.822
RTD| 0.342| 0.464| 1.360| 0| 0| 0.088| 1.822
RTD| 0.327| 0.462| 2.297| 0| 0| 0.088| 2.297
RTD| 0.347| 0.463| 1.313| 0| 0| 0.088| 2.297
RTD| 0.314| 0.464| 1.465| 0| 0| 0.088| 2.297
RTD| 0.190| 0.464| 1.311| 0| 0| 0.088| 2.297
如果安裝中遇到問題歡迎留言交流。