Difference between revisions of "EBC Exercise 36 PREEMPT RT"

From eLinux.org
Jump to: navigation, search
m (Installing a PREEMPT_RT Kernel)
m (Measure the latency)
 
(11 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
  bone$ '''uname -a'''
 
  bone$ '''uname -a'''
  Linux ece434 4.19.94-ti-r45 #1buster SMP PREEMPT Thu Jun 18 19:18:41 UTC 2020 armv7l GNU/Linux
+
  Linux home 5.8.18-bone24 #1buster PREEMPT Sat Dec 5 02:08:15 UTC 2020 armv7l GNU/Linux
  
 
Also do the following.
 
Also do the following.
Line 14: Line 14:
 
  #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0  
 
  #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0  
 
   
 
   
  uname_r=4.19.94-ti-r45
+
  uname_r=5.10.145-ti-r55
 
  #uuid=
 
  #uuid=
 
  #dtb=
 
  #dtb=
Line 20: Line 20:
 
Note what '''uname''' is set to.  You'll want to return to it when you are done.
 
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.
 
Now, look for a real time kernel with similar number.
  
  bone $ '''cd /opt/scripts/tools'''
+
  bone $ '''apt search linux-image-5.10.145'''
  bone$ '''ssudo ./update_kernel.sh --bone-rt-kernel'''
+
  Sorting... Done
  info: checking archive
+
Full Text Search... Done
  2020-08-06 15:12:44 URL:https://rcn-ee.com/repos/latest/buster-armhf/LATEST-bone-rt [195/195] -> "LATEST-bone-rt" [1]
+
linux-image-5.10.145-ti-r53/unknown 1bullseye armhf
-----------------------------
+
  Linux kernel, version 5.10.145-ti-r53
  Kernel Options:
+
   
  ABI:1 LTS44 4.4.145-bone-rt-r23
+
  linux-image-5.10.145-ti-r54/now 1xross armhf [installed, local]
ABI:1 LTS49 4.9.178-bone-rt-r15
+
  Linux kernel, version 5.10.145-ti-r54
  ABI:1 LTS414 4.14.185-bone-rt-r37
+
   
  '''ABI:1 LTS419 4.19.127-bone-rt-r53'''
+
  linux-image-5.10.145-ti-r55/unknown,now 1bullseye armhf [installed, automatic]
ABI:1 LTS54 5.4.52-bone-rt-r31
+
  Linux kernel, version 5.10.145-ti-r55
ABI:1 STABLE 5.6.17-bone-rt-r14
+
   
  -----------------------------
+
  linux-image-5.10.145-ti-rt-r53/unknown 1bullseye armhf
Kernel version options:
+
  Linux kernel, version 5.10.145-ti-rt-r53
  -----------------------------
+
   
LTS414: --lts-4_14
+
  linux-image-5.10.145-ti-rt-r54/unknown 1bullseye armhf
  LTS419: --lts-4_19
+
  Linux kernel, version 5.10.145-ti-rt-r54
  LTS54: --lts-5_4
+
   
STABLE: --stable
+
  '''linux-image-5.10.145-ti-rt-r55/unknown 1bullseye armhf'''
TESTING: --testing
+
  Linux kernel, version 5.10.145-ti-rt-r55
-----------------------------
 
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  
+
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 4.19 real time kernel.
+
the most current version of the 5.10 real time kernel.
 
Let's install it.
 
Let's install it.
  
  bone$ '''sudo ./update_kernel.sh --kernel 4.19.127-bone-rt-r53'''
+
  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.   
 
After a couple of minutes the new kernel is installed.   
(Mine took some 2.5 minutes.)
+
(Mine took nearly 7 minutes at home.)
 
Look in '''/boot'''
 
Look in '''/boot'''
 
  bone$ '''ls /boot'''
 
  bone$ '''ls /boot'''
  config-4.19.127-bone-rt-r53     initrd.img-4.19.94-ti-r45        uboot                         vmlinuz-4.19.94-ti-r45
+
  SOC.sh                        config-5.10.145-ti-r55        uEnv.txt
config-4.19.94-ti-r45            SOC.sh                          uEnv.txt
+
System.map-5.10.140-ti-r52    config-5.10.145-ti-rt-r55     uEnv.txt.orig
  dtbs                            System.map-4.19.127-bone-rt-r53 uEnv.txt.orig
+
System.map-5.10.145-ti-r54    dtbs/                          uboot/
  initrd.img-4.19.127-bone-rt-r53 System.map-4.19.94-ti-r45        vmlinuz-4.19.127-bone-rt-r53
+
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:
 
You see both the original kernel and the one just installed.  The file '''uEnv.txt''' tells which one to boot from:
Line 65: Line 70:
 
  #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0
 
  #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0
 
   
 
   
  uname_r=4.19.94-ti-r45
+
  # uname_r=5.10.145-ti-r55
 +
uname_r=5.10.145-ti-rt-r55
 
  #uuid=
 
  #uuid=
 
  #dtb=
 
  #dtb=
You see it's been changed to boot the new kernel. But don't reboot just net.  Let's take some measurements.
+
 
 +
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 ==
 
== Measure the latency ==
Line 103: Line 111:
 
  bone$ '''sudo reboot'''
 
  bone$ '''sudo reboot'''
  
After rebooting you will see.
+
After rebooting you will see. (See [[EBC_Exercise_06_Connecting_without_ssh]] if you have trouble ssh'ing in.)
 
  bone$ '''uname -a'''
 
  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
+
  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.
 
Now repeat the test.
Line 113: Line 121:
  
 
Once the test is done, go to your host computer to generate the plots.  (There's less to install
 
Once the test is done, go to your host computer to generate the plots.  (There's less to install
than on the bone.
+
than on the bone.)
  
 
Let's mount the bone's files on the host so they are easy to get to.
 
Let's mount the bone's files on the host so they are easy to get to.
Line 148: Line 156:
  
 
  bone$ '''sudo nano /boot/uEnv.txt'''
 
  bone$ '''sudo nano /boot/uEnv.txt'''
  uname_r=4.14.52-ti-r60
+
  uname_r=5.10.145-ti-r55
  
 
  bone$ '''sudo reboot'''
 
  bone$ '''sudo reboot'''
  
 
You should now be back to where you started.
 
You should now be back to where you started.
 
== Installing a PREEMPT_RT Kernel Alternate way ==
 
This is a set of instructions for installing the RT kernel.  They are an alternate way from what was shown above.
 
They are here for completeness.  No need to install again.
 
 
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. 
 
 
{{YoderFoot}}
 

Latest revision as of 09:00, 6 January 2023

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 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:

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.

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.