DEV Community

ronnie R
ronnie R

Posted on

How to Enhance Real-Time Performance of Linux 6.1 Kernel on OK-MX9352-C by Applying Real-Time Patches

As we all know, the Linux system is a non-real-time system based on time-slice scheduling, and its real-time performance is difficult to meet the timing requirements of industrial applications. Therefore, in many scenarios, the Linux operating system cannot be used. Of course, this limitation has been improved. Currently, the Linux community has added many versions of real-time patches. By applying these real-time patches to the Linux kernel, its real-time performance can be significantly enhanced.

  1. Download the patch Download the real-time patch corresponding to the Linux version. We need to download the real-time patch for Linux 4.1.15.

Index of /pub/linux/kernel/projects/rt/6.1/

The kernel version we are using is Linux 6.1.36. Find a similar patch in the “older” section: patches-6.1.33-rt11.tar.gz.

  1. Type into the kernel unpack patches-6.1.33-rt11.tar.gz to the sdk path, which is the upper layer of the kernel source code.

$ ls
OKMX93-linux-fs
OKMX93-linux-kernel appsrc build.sh
environment-setup-aarch64-toolchain extra images patches patches-6.1.33-rt11.tar.gz tools
Since more than 200 patches are in the extracted patch, use a script in the kernel directory to merge the patches.

$ cd OKMX93-linux-kernel
The script reads as follows:

!/bin/sh

cat ../patches/series | while read line
do
patch -p1 < ../patches/$line done
After executing this script, compile the kernel

make Image -j16

  1. Test real-time 3.1 cross-compiling cyctest

git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
cd rt-tests/
git checkout -b v1.0 origin/stable/v1.0
Modify Makefile

CC?=$(CROSS_COMPILE)gcc

AR?=$(CROSS_COMPILE)ar

Compile

make
3.2 cyclictest test method

Load the compiled cyclictest onto the board and increase its executable permissions, you can use the cyclictest command to carry out real-time performance testing of the Linux kernel, the test command is:

root@fl-imx6ull:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000
Specific parameters can be used as a reference:

-p

--prio = thread with PRIO ordinal 0

The priority usage method for the highest priority thread is: -p 90 / --prio=90

-m

--mlockall thread priority is 0

Lock current and future memory allocation

-c

--clock=CLOCK Counter. Every time interval of the thread is reached, the counter is increased by 1.

Select clock cyclictest -C 1 0 = CLOCK _ MONOTONIC (default) 1 = CLOCK _ REALTIME

-i

--interval=INTV

Basic thread interval, default is 1000 (unit is us)

-l

--loops=LOOPS

The number of cycles, which is 0 (infinite) by default, can be combined with the number of -I intervals to roughly calculate the time of the entire test, for example, -I 1000-l 1000000, the total cycle time is 1000 * 1000000 = 1000000000 us = 1000s, so it is roughly more than 16 minutes

-n

--nanosleep

Use clock_nanosleep

-h

--histogram=US

Draw a histogram of the delay on a standard output device after execution (many threads have the same permissions) US is the maximum trace time limit.

-q

--quiet

The -q parameter prints no information at runtime, only a summary on exit, which in combination with the -h HISTNUM parameter prints HISTNUM line statistics and a general summary on exit.

-f

--ftrace

The ftrace function traces (usually used with -b, in fact -b is usually used without -f)

-b

--breaktrace=USEC

Sends a stop trace when the delay exceeds the value specified by the USEC. USEC, in milliseconds (us)

Run Result Meaning:

T:0

Serial number is 0

P:0

Thread priority is 0

C:1000

Counter. Every time interval of the thread is reached, the counter is increased by 1.

I: 1000

Time interval is 1000 microseconds (us)

Min:

Minimum Delay (us)

Act:

Last Delay (us)

Avg:

Everyrage Delay (us)

Max:

Maximum Delay (us)

3.3 Testing unpatched kernels

First Test

root@ok-mx93:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000

/dev/cpu_dma_latency set to 0us

policy: fifo: loadavg: 0.04 0.04 0.04 1/127 996

T: 0 ( 917) P:80 I:10000 C: 10000 Min: 5 Act: 7 Avg: 7 Max: 65
T: 1 ( 918) P:80 I:10500 C: 9533 Min: 5 Act: 8 Avg: 7 Max: 126
T: 2 ( 919) P:80 I:11000 C: 9100 Min: 5 Act: 7 Avg: 7 Max: 78
T: 3 ( 920) P:80 I:11500 C: 8704 Min: 5 Act: 9 Avg: 7 Max: 80
T: 4 ( 921) P:80 I:12000 C: 8341 Min: 5 Act: 8 Avg: 6 Max: 72
T: 5 ( 922) P:80 I:12500 C: 8008 Min: 5 Act: 6 Avg: 7 Max: 75
T: 6 ( 923) P:80 I:13000 C: 7700 Min: 5 Act: 7 Avg: 7 Max: 73
T: 7 ( 924) P:80 I:13500 C: 7414 Min: 5 Act: 7 Avg: 7 Max: 71
Second test

root@ok-mx93:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000

/dev/cpu_dma_latency set to 0us

policy: fifo: loadavg: 0.00 0.00 0.00 1/128 1410

T: 0 ( 1329) P:80 I:10000 C: 10000 Min: 5 Act: 8 Avg: 7 Max: 102
T: 1 ( 1330) P:80 I:10500 C: 9531 Min: 5 Act: 6 Avg: 7 Max: 113
T: 2 ( 1331) P:80 I:11000 C: 9097 Min: 5 Act: 8 Avg: 7 Max: 79
T: 3 ( 1332) P:80 I:11500 C: 8702 Min: 5 Act: 8 Avg: 7 Max: 61
T: 4 ( 1333) P:80 I:12000 C: 8339 Min: 5 Act: 7 Avg: 6 Max: 78
T: 5 ( 1334) P:80 I:12500 C: 8006 Min: 5 Act: 7 Avg: 7 Max: 89
T: 6 ( 1335) P:80 I:13000 C: 7698 Min: 5 Act: 7 Avg: 7 Max: 55
T: 7 ( 1336) P:80 I:13500 C: 7413 Min: 5 Act: 9 Avg: 7 Max: 54
Third test

root@ok-mx93:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000

/dev/cpu_dma_latency set to 0us

policy: fifo: loadavg: 0.00 0.00 0.00 1/127 1488

T: 0 ( 1414) P:80 I:10000 C: 10000 Min: 5 Act: 7 Avg: 6 Max: 60
T: 1 ( 1415) P:80 I:10500 C: 9531 Min: 5 Act: 6 Avg: 6 Max: 65
T: 2 ( 1416) P:80 I:11000 C: 9097 Min: 5 Act: 7 Avg: 6 Max: 64
T: 3 ( 1417) P:80 I:11500 C: 8702 Min: 5 Act: 7 Avg: 7 Max: 60
T: 4 ( 1418) P:80 I:12000 C: 8339 Min: 5 Act: 7 Avg: 6 Max: 63
T: 5 ( 1419) P:80 I:12500 C: 8006 Min: 5 Act: 6 Avg: 7 Max: 51
T: 6 ( 1420) P:80 I:13000 C: 7698 Min: 5 Act: 6 Avg: 6 Max: 50
T: 7 ( 1421) P:80 I:13500 C: 7413 Min: 5 Act: 7 Avg: 7 Max: 60
3.4 Testing the kernel With Real-time Patching

First test

root@ok-mx93:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000

/dev/cpu_dma_latency set to 0us

policy: fifo: loadavg: 0.06 0.08 0.03 1/126 654

T: 0 ( 579) P:80 I:10000 C: 10000 Min: 5 Act: 8 Avg: 6 Max: 47
T: 1 ( 580) P:80 I:10500 C: 9532 Min: 5 Act: 6 Avg: 6 Max: 48
T: 2 ( 581) P:80 I:11000 C: 9099 Min: 5 Act: 6 Avg: 6 Max: 56
T: 3 ( 582) P:80 I:11500 C: 8703 Min: 5 Act: 7 Avg: 6 Max: 67
T: 4 ( 583) P:80 I:12000 C: 8341 Min: 5 Act: 7 Avg: 6 Max: 48
T: 5 ( 584) P:80 I:12500 C: 8007 Min: 5 Act: 7 Avg: 6 Max: 48
T: 6 ( 585) P:80 I:13000 C: 7699 Min: 5 Act: 7 Avg: 6 Max: 50
T: 7 ( 586) P:80 I:13500 C: 7414 Min: 5 Act: 6 Avg: 6 Max: 59
Second test

root@ok-mx93:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000

/dev/cpu_dma_latency set to 0us

policy: fifo: loadavg: 0.00 0.02 0.00 1/127 753

T: 0 ( 678) P:80 I:10000 C: 10000 Min: 5 Act: 7 Avg: 6 Max: 54
T: 1 ( 679) P:80 I:10500 C: 9532 Min: 5 Act: 9 Avg: 8 Max: 56
T: 2 ( 680) P:80 I:11000 C: 9099 Min: 5 Act: 6 Avg: 6 Max: 50
T: 3 ( 681) P:80 I:11500 C: 8703 Min: 5 Act: 7 Avg: 6 Max: 48
T: 4 ( 682) P:80 I:12000 C: 8341 Min: 5 Act: 7 Avg: 6 Max: 55
T: 5 ( 683) P:80 I:12500 C: 8007 Min: 5 Act: 6 Avg: 7 Max: 71
T: 6 ( 684) P:80 I:13000 C: 7699 Min: 5 Act: 7 Avg: 7 Max: 51
T: 7 ( 685) P:80 I:13500 C: 7414 Min: 5 Act: 6 Avg: 6 Max: 54
Third test

root@ok-mx93:~# ./cyclictest -t8 -p 80 -n -i 10000 -l 10000

/dev/cpu_dma_latency set to 0us

policy: fifo: loadavg: 0.00 0.01 0.00 1/117 835

T: 0 ( 759) P:80 I:10000 C: 10000 Min: 5 Act: 9 Avg: 6 Max: 63
T: 1 ( 760) P:80 I:10500 C: 9532 Min: 5 Act: 8 Avg: 8 Max: 77
T: 2 ( 761) P:80 I:11000 C: 9099 Min: 5 Act: 6 Avg: 7 Max: 79
T: 3 ( 762) P:80 I:11500 C: 8703 Min: 5 Act: 7 Avg: 6 Max: 61
T: 4 ( 763) P:80 I:12000 C: 8341 Min: 5 Act: 7 Avg: 6 Max: 67
T: 5 ( 764) P:80 I:12500 C: 8007 Min: 5 Act: 16 Avg: 6 Max: 65
T: 6 ( 765) P:80 I:13000 C: 7699 Min: 5 Act: 8 Avg: 6 Max: 89
T: 7 ( 766) P:80 I:13500 C: 7414 Min: 5 Act: 7 Avg: 7 Max: 76

Top comments (0)