Difference between revisions of "EBC Exercise 36 PREEMPT RT"

From eLinux.org
Jump to: navigation, search
m (Returning to the non-rt kernel)
(6 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
  bone$ '''uname -a'''
 
  bone$ '''uname -a'''
  Linux beaglebone 4.14.52-ti-r60 #1 SMP PREEMPT Tue Jun 26 23:02:46 UTC 2018 armv7l GNU/Linux
+
  Linux ece434 4.19.94-ti-r45 #1buster SMP PREEMPT Thu Jun 18 19:18:41 UTC 2020 armv7l GNU/Linux
  
 
Also do the following.
 
Also do the following.
 
  bone$ '''head /boot/uEnv.txt'''
 
  bone$ '''head /boot/uEnv.txt'''
  #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.14.52-ti-r60'''
+
  uname_r=4.19.94-ti-r45
 
  #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.
  
Now, look for a kernel with similar number.
+
Now, look for a real time kernel with similar number.
  
  bone$ '''sudo apt update'''
+
  bone $ '''cd /opt/scripts/tools'''
  bone$ '''apt-cache search linux-image-4.14 > /tmp/search
+
  bone$ '''ssudo ./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
 +
-----------------------------
  
Look through /tmp/search and pick an image with '''-rt-''' in it's name.
+
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.
bone$ '''grep 14.52 /tmp/search'''
+
Let's install it.
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'''
+
  bone$ '''sudo ./update_kernel.sh --kernel 4.19.127-bone-rt-r53'''
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) ...
+
After a couple of minutes the new kernel is installed.  
  update-initramfs: Generating /boot/initrd.img-4.14.52-ti-rt-r60
+
(Mine took some 2.5 minutes.)
  zz-uenv_txt: Updating /boot/uEnv.txt [uname_r=-4.14.52-ti-rt-r60]
+
Look in '''/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
 +
config-4.19.94-ti-r45            SOC.sh                          uEnv.txt
 +
  dtbs                            System.map-4.19.127-bone-rt-r53  uEnv.txt.orig
 +
initrd.img-4.19.127-bone-rt-r53 System.map-4.19.94-ti-r45        vmlinuz-4.19.127-bone-rt-r53
  
Mine took some 2.5 minutes.   
+
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=4.19.94-ti-r45
 +
#uuid=
 +
#dtb=
 +
You see it's been changed to boot the new kernel. But don't reboot just netLet's take some measurements.
  
 
== Measure the latency ==
 
== Measure the latency ==
Line 90: Line 105:
 
After rebooting you will see.
 
After rebooting you will see.
 
  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 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.
 
Now repeat the test.
Line 98: Line 113:
  
 
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 117: Line 132:
 
You should now see the files you just generated on the bone.
 
You should now see the files you just generated on the bone.
 
  host$ '''sudo apt install gnuplot'''
 
  host$ '''sudo apt install gnuplot'''
  host$ '''gnuplot < hist.plt'''
+
  host$ '''gnuplot hist.plt'''
 
This will generate the file '''cyclictest.png''' which contains your plot.
 
This will generate the file '''cyclictest.png''' which contains your plot.
 
  host$ '''xdg-open cyclictest.png'''
 
  host$ '''xdg-open cyclictest.png'''
Line 133: Line 148:
  
 
  bone$ '''sudo nano /boot/uEnv.txt'''
 
  bone$ '''sudo nano /boot/uEnv.txt'''
  uname_r=4.14.52-ti-r60
+
  uname_r=4.19.94-ti-r45
  
 
  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}}
 
{{YoderFoot}}

Revision as of 12:31, 6 August 2020

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 ece434 4.19.94-ti-r45 #1buster SMP PREEMPT Thu Jun 18 19:18:41 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=4.19.94-ti-r45
#uuid=
#dtb=

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

Now, look for a real time kernel with similar number.

bone $ cd /opt/scripts/tools
bone$ ssudo ./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
...

After a couple of minutes the new kernel is installed. (Mine took some 2.5 minutes.) Look in /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
config-4.19.94-ti-r45            SOC.sh                           uEnv.txt
dtbs                             System.map-4.19.127-bone-rt-r53  uEnv.txt.orig
initrd.img-4.19.127-bone-rt-r53  System.map-4.19.94-ti-r45        vmlinuz-4.19.127-bone-rt-r53

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=4.19.94-ti-r45
#uuid=
#dtb=

You see it's been changed to boot the new kernel. But don't reboot just net. 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 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 > 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=4.19.94-ti-r45
bone$ sudo reboot

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.




thumb‎ Embedded Linux Class by Mark A. Yoder