EBC Exercise 36 PREEMPT RT

Here are instructions on how to install a PREEMPT_RT Kernel and run some tests on it.

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 uname_r=5.10.145-ti-r55
 * 1) Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0
 * 1) uuid=
 * 2) 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'''

This is old and may no longer work Go to "New Kernel is Installed"
Now, look for a real time kernel with similar number.

bone $ cd /opt/scripts/tools bone$ sudo ./update_kernel.sh --bone-rt-kernel info: checking archive 2020-08-06 15:12:44 URL:https://rcn-ee.com/repos/latest/buster-armhf/LATEST-bone-rt [195/195] -> "LATEST-bone-rt" [1] - Kernel Options: ABI:1 LTS44 4.4.145-bone-rt-r23 ABI:1 LTS49 4.9.178-bone-rt-r15 ABI:1 LTS414 4.14.185-bone-rt-r37 ABI:1 LTS419 4.19.127-bone-rt-r53 ABI:1 LTS54 5.4.52-bone-rt-r31 ABI:1 STABLE 5.6.17-bone-rt-r14 - Kernel version options: - LTS414: --lts-4_14 LTS419: --lts-4_19 LTS54: --lts-5_4 STABLE: --stable TESTING: --testing - Please pass one of the above kernel options to update_kernel.sh -

I'm running at 4.19 kernel. The highlighted line above (4.19.127-bone-rt-r53) is the most current version of the 4.19 real time kernel. Let's install it.

bone$ sudo ./update_kernel.sh --kernel 4.19.127-bone-rt-r53 ...

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 config-5.10.140-ti-r52     initrd.img-5.10.145-ti-rt-r55  uEnv.txt config-5.10.145-ti-r55     SOC.sh                         uEnv.txt.orig config-5.10.145-ti-rt-r55  System.map-5.10.140-ti-r52     vmlinuz-5.10.140-ti-r52 dtbs                       System.map-5.10.145-ti-r55     vmlinuz-5.10.145-ti-r55 initrd.img-5.10.140-ti-r52 System.map-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 uname_r=5.10.145-ti-rt-r55
 * 1) Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0
 * 1) uname_r=5.10.145-ti-r55
 * 1) uuid=
 * 2) 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. 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.