EBC Exercise 36 PREEMPT RT

From eLinux.org
Revision as of 07:21, 10 October 2018 by Adairdg (talk | contribs)
Jump to: navigation, search

thumb‎ Embedded Linux Class by Mark A. Yoder


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 beaglebone 4.14.52-ti-r60 #1 SMP PREEMPT Tue Jun 26 23:02:46 UTC 2018 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=4.14.52-ti-r60
#uuid=
#dtb=

Note what uname is set to. You'll want to return to it when you are done.

Now, look for a kernel with similar number.

bone$ sudo apt update
bone$ apt-cache search linux-image-4.14 > /tmp/search

Look through /tmp/search and pick an image with -rt- in it's name.

bone$ grep 14.52 /tmp/search
linux-image-4.14.52-armv7-lpae-x3 - Linux kernel, version 4.14.52-armv7-lpae-x3
linux-image-4.14.52-armv7-rt-x4 - Linux kernel, version 4.14.52-armv7-rt-x4
linux-image-4.14.52-armv7-x4 - Linux kernel, version 4.14.52-armv7-x4
linux-image-4.14.52-bone-rt-r16 - Linux kernel, version 4.14.52-bone-rt-r16
linux-image-4.14.52-bone16 - Linux kernel, version 4.14.52-bone16
linux-image-4.14.52-ti-r59 - Linux kernel, version 4.14.52-ti-r59
linux-image-4.14.52-ti-r60 - Linux kernel, version 4.14.52-ti-r60
linux-image-4.14.52-ti-r61 - Linux kernel, version 4.14.52-ti-r61
linux-image-4.14.52-ti-rt-r59 - Linux kernel, version 4.14.52-ti-rt-r59
linux-image-4.14.52-ti-rt-r60 - Linux kernel, version 4.14.52-ti-rt-r60
linux-image-4.14.52-ti-rt-r61 - Linux kernel, version 4.14.52-ti-rt-r61
bone$ sudo apt install linux-image-4.14.52-ti-rt-r60
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  linux-firmware-image-4.14.52-ti-rt-r60
The following NEW packages will be installed:
  linux-image-4.14.52-ti-rt-r60
...
Setting up linux-image-4.14.52-ti-rt-r60 (1stretch) ...
update-initramfs: Generating /boot/initrd.img-4.14.52-ti-rt-r60
zz-uenv_txt: Updating /boot/uEnv.txt [uname_r=-4.14.52-ti-rt-r60]

Mine took some 2.5 minutes.

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 > rt.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 beaglebone 4.14.52-ti-rt-r60 #1 SMP PREEMPT Tue Jun 26 23:28:55 UTC 2018 armv7l GNU/Linux

Now repeat the test.

bone$ cd ~/exercises/linux/kernel/rt
bone$ time sudo ./hist.gen > nort.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:

Historygram from cyclictest

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.

bone$ sudo nano /boot/uEnv.txt
uname_r=4.14.52-ti-r60
bone$ sudo reboot

You should now be back to where you started.




thumb‎ Embedded Linux Class by Mark A. Yoder