RTAI, Kernel-Threads and Drivers

June 2, 2018

Base System

As base system a debian 8 installation served for the further RTAI Patch and the development of some useful realtime Software. Though everey linux distribution should be fine for this job, a well documented and widely used one is beneficial.

For preparation of the base system a number of packages had to be installed:


apt-get install 
mc
lilo
build-essential
valgrind
gdb
ddd
ncurses
autoconf
ssh
libncurses-dev
install 
cvs 
subversion 
build-essential 
git-core 
g++-multilib 
gcc-multilib
libtool
automake

Building the kernel

Use those versions for a basically tested and running system:


su
cd /usr/src/
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.9.80.tar.bz2
tar xvjf linux-4.9.80.tar.bz2
ln -s linux-4.9.80 linux
cd linux
cp /boot/.config .
make menuconfig


-->Processor type and features
    -->Processor family
        Generic x86_64


-->Processor type and features
    -->Maximum number of CPU’s
        2


-->Processor type and features
    -->SMT (Hyperthreading) scheduler support
        disable


-->Power management and ACPI options
    Disable everything, except “ACPI”


-->Power management and ACPI options
    -->ACPI
        Disable everything, except “Power Management Timer Support” 


-->Power management and ACPI options
    -->CPU Frequency scaling
        Disable


-->Power management and ACPI options
    -->CPU idle
        Disable CPU idle PM support

Bad latency:


–>General Setup
    –>Auditing support deselected

Kernel Stack Korruption on rt_start_task():


–>General Setup
    -> Stack Protector buffer overflow detection(none)


make -j3
make modules_install
cp arch/x86/boot/bzImage /boot/vmlinuz-4.9.80
update-initramfs -k 4.9.80 -u/c

Lilo

Zum boot mit dem neuen Kernel wird die lilo.conf angepasst: Linux-Loader (/etc/lilo.conf)


large-memory
lba32
boot=/dev/sda
install=menu
map=/boot/map
#prompt
default=rtai
timeout=0
 
image=/boot/vmlinuz-4.9.80
        label="rtai"
        root=/dev/sda1
        initrd="/boot/initrd.img-4.9.80"
        append="lapic=notscdeadline i915.enable_guc_loading=1 i915.enable_guc_submission=1 consoleblank=0"
        read-only
        optional

 
image=/boot/vmlinuz-3.16.0-4-amd64
        label="normal" 
        root=/dev/sda1
        initrd="/boot/initrd.img-3.16.0-4-amd64"
        append=""
        read-only
        optional 

#video=intelfb,consoleblank=0,vt.global_cursor_default=0,console=/dev/fb0,hwcursor=false,silent=1"

RTAI Patch


wget https://www.rtai.org/userfiles/downloads/RTAICONTRIB/rtai-5.1.tar.bz2
tar xvjf lrtai-5.1.tar.bz2
ln -s rtai-5.1 rtai
cd rtai
make menuconfig


-->General
    -->Inlining mode of user-space services
        Enable “Eager inlining”


-->Machine
    -->Number of CPUs (SMP only)
        2


-->Base system
    -->other features
        set global heap to 2048Kib
        set size of Stacks 512Kib
Apply the Patch and build kernel

cd /usr/src/linux/
make clean
patch -p1 < ../rtai/base/arch/x86/patches/hal-linux-4.9.80-x86-4.patch
make -j3
make modules_install
cp arch/x86/boot/bzImage /boot/vmlinuz-4.9.80
update-initramfs -k 4.9.80 -u/c

Build RTAI Modules and Lib


cd /usr/src/rtai/
make -j3
make install

Load some RTAI Modules:


insmod /usr/realtime/modules/rtai_hal.ko
insmod /usr/realtime/modules/rtai_sched.ko
insmod /usr/realtime/modules/rtai_shm.ko
insmod /usr/realtime/modules/rtai_msg.ko
insmod /usr/realtime/modules/rtai_tasklets.ko
insmod /usr/realtime/modules/rtai_fifos.ko
insmod /usr/realtime/modules/rtai_sem.ko
insmod /usr/realtime/modules/rtai_tbx.ko
insmod /usr/realtime/modules/rtai_mbx.ko
insmod /usr/realtime/modules/rtai_mq.ko
insmod /usr/realtime/modules/rtai_bits.ko
insmod /usr/src/can/rtai_can_module.ko