EBC Exercise 36 PREEMPT RT
Embedded Linux Class by Mark A. Yoder
Here are instructions on how to install a PREEMPT_RT Kernel and run some tests on it.
Contents
Installing a PREEMPT_RT Kernel
To install a real time kernel, first see what you are currently running.
bone$ uname -a Linux home 5.8.18-bone24 #1buster PREEMPT Sat Dec 5 02:08:15 UTC 2020 armv7l GNU/Linux
Also do the following.
bone$ head /boot/uEnv.txt #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0 uname_r=5.10.145-ti-r55 #uuid= #dtb=
Note what uname is set to. You'll want to return to it when you are done.
This has changed. See: https://forum.beagleboard.org/t/debian-10-x-11-x-kernel-updates/30928
Downloading RT kernel
Now, look for a real time kernel with similar number.
bone $ apt search linux-image-5.10.145 Sorting... Done Full Text Search... Done linux-image-5.10.145-ti-r53/unknown 1bullseye armhf Linux kernel, version 5.10.145-ti-r53 linux-image-5.10.145-ti-r54/now 1xross armhf [installed, local] Linux kernel, version 5.10.145-ti-r54 linux-image-5.10.145-ti-r55/unknown,now 1bullseye armhf [installed, automatic] Linux kernel, version 5.10.145-ti-r55 linux-image-5.10.145-ti-rt-r53/unknown 1bullseye armhf Linux kernel, version 5.10.145-ti-rt-r53 linux-image-5.10.145-ti-rt-r54/unknown 1bullseye armhf Linux kernel, version 5.10.145-ti-rt-r54 linux-image-5.10.145-ti-rt-r55/unknown 1bullseye armhf Linux kernel, version 5.10.145-ti-rt-r55
I'm running at 5.10.145 kernel. The highlighted line above (5.10.145-ti-rt-r55) is the most current version of the 5.10 real time kernel. Let's install it.
bone$ sudo apt install linux-image-5.10.145-ti-rt-r55 ...
New Kernel is Installed
After a couple of minutes the new kernel is installed. (Mine took nearly 7 minutes at home.) Look in /boot
bone$ ls /boot SOC.sh config-5.10.145-ti-r55 uEnv.txt System.map-5.10.140-ti-r52 config-5.10.145-ti-rt-r55 uEnv.txt.orig System.map-5.10.145-ti-r54 dtbs/ uboot/ System.map-5.10.145-ti-r55 initrd.img-5.10.140-ti-r52 vmlinuz-5.10.140-ti-r52* System.map-5.10.145-ti-rt-r55 initrd.img-5.10.145-ti-r54 vmlinuz-5.10.145-ti-r54* config-5.10.140-ti-r52 initrd.img-5.10.145-ti-r55 vmlinuz-5.10.145-ti-r55* config-5.10.145-ti-r54 initrd.img-5.10.145-ti-rt-r55 vmlinuz-5.10.145-ti-rt-r55*
You see both the original kernel and the one just installed. The file uEnv.txt tells which one to boot from:
bone head /boot/uEnv.txt #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0 # uname_r=5.10.145-ti-r55 uname_r=5.10.145-ti-rt-r55 #uuid= #dtb=
You see it's been changed to boot the new kernel. (Notice I added the comment pointing to the old kernel.) But don't reboot just yet. Let's take some measurements.
Measure the latency
Before rebooting let's measure the non-rt latency.
bone$ cd ~/exercises/linux/kernel/rt bone$ sudo apt install rt-tests
(Check install.sh for latest instructions of what to install.) Now run the test:
bone$ time sudo ./hist.gen > nort.hist
If you get an error:
Unable to change scheduling policy! Probably missing capabilities, either run as root or increase RLIMIT_RTPRIO limits
try running ./setup.sh. If that doesn't work try:
bone$ sudo bash bone# ulimit -r unlimited bone# ./hist.gen > nort.hist bone# exit
This sets the maximum real-time scheduling priority to unlimited.
While hist.gen is running, open another window on the bone and run some time intensive tasks. Here's what I did.
bone$ cd ~/exercises/linux/modules bone$ make bone$ make clean
Repeat the two make commands until hist.gen finishes. This will take a while. Here are the times I got for hist.gen.
real 1m40.222s user 0m0.938s sys 0m7.767s
This creates a histogram data file 'nort.hist. Now you can reboot into the rt kernel.
bone$ sudo reboot
After rebooting you will see. (See EBC_Exercise_06_Connecting_without_ssh if you have trouble ssh'ing in.)
bone$ uname -a Linux green 5.10.145-ti-rt-r55 #1bullseye SMP PREEMPT_RT Wed Dec 7 00:02:33 UTC 2022 armv7l GNU/Linux
Now repeat the test.
bone$ cd ~/exercises/linux/kernel/rt bone$ time sudo ./hist.gen > rt.hist
Again, do the same time intensive things in another window.
Once the test is done, go to your host computer to generate the plots. (There's less to install than on the bone.)
Let's mount the bone's files on the host so they are easy to get to.
host$ cd host$ mkdir bone host$ sudo apt update host$ sudo apt install sshfs host$ sshfs bone:. bone
This says to mount the home directory on the bone (bone:.) on the local directory, called bone, on the host. Now change to that directory.
host$ cd bone/exercises/linux/kernel/rt host$ ls hist.gen hist.plt install.sh nort.hist rt.hist setup.sh
You should now see the files you just generated on the bone.
host$ sudo apt install gnuplot host$ gnuplot hist.plt
This will generate the file cyclictest.png which contains your plot.
host$ xdg-open cyclictest.png
This will display your cyclictest.png file. Mine looks something like:
Returning to the non-rt kernel
You can return to the non-rt kernel that you running before by editing /boot/uEnv.txt and returning uname_r to what it originally was and then rebooting.
To view the old kernel version you can look into the /boot directory.
bone$ ls /boot
bone$ sudo nano /boot/uEnv.txt uname_r=5.10.145-ti-r55
bone$ sudo reboot
You should now be back to where you started.