天天看点

Xenomai3.1+ubuntu 18.04/16.04

xenomai是linux实时改造的重要方案之一,下面给出其具体的安装以及Ubuntu内核编译过程。

具体原理图如下

Xenomai3.1+ubuntu 18.04/16.04

原理

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

如果安装中遇到问题欢迎留言交流。