Fundamentals 16 min read

How to Build, Patch, and Benchmark a Real‑Time Linux Kernel on an OK3588 Board

This guide explains the purpose of the PREEMPT‑RT (real‑time) patch, details the hardware and toolchain used, describes the patch's key features and modifications, provides step‑by‑step instructions for downloading, applying, configuring, compiling, and flashing the kernel, and shows how to verify latency improvements with cyclictest and stress‑ng across idle and CPU‑stress scenarios.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Build, Patch, and Benchmark a Real‑Time Linux Kernel on an OK3588 Board

Introduction

The Linux kernel real‑time patch (PREEMPT‑RT or RT) reduces kernel latency, improves predictability, and enables Linux to meet the timing requirements of industrial control, audio processing, robotics, and other time‑sensitive applications.

Test Environment

Hardware platform: Feiling OK3588 development board

Kernel source: 5.10.66‑rt53

Build host: Ubuntu 20.04 LTS

Toolchain: aarch64‑linux‑gnu‑

Real‑Time Kernel Features

Low latency : the patch makes the kernel respond to external events more quickly, reducing response time and processing delay.

High‑priority scheduling : real‑time tasks receive higher priority, ensuring they finish within expected time frames.

Preemptive support : enhances kernel preemption so a real‑time task can interrupt other tasks, even long‑running kernel code.

Lock optimizations : reduces lock contention and critical‑section duration.

Improved thread handling : refines scheduling policies for real‑time threads to better support high‑priority tasks.

What the Patch Changes

High‑resolution timers provide nanosecond‑level precision.

Interrupt threading runs interrupt handlers in kernel threads, preventing real‑time tasks from being pre‑empted by interrupts.

Spinlocks ( spinlock_t) are replaced by real‑time mutexes ( rt_mutex), enabling priority inheritance and avoiding priority‑inversion problems.

Priority Inversion and Inheritance

When a low‑priority process holds a mutex and a high‑priority process blocks on it, the high‑priority process is forced to wait for the low‑priority one, degrading real‑time performance. The real‑time mutex implements priority inheritance: the holder’s priority is temporarily raised to that of the highest‑waiting task, preventing other higher‑priority tasks from further pre‑empting the holder and reducing the wait time.

Installing and Using the Real‑Time Patch

Download the kernel source:

wget https://www.kernel.org/pub/linux/kernel/vX.Y/linux-X.Y.Z.tar.xz

Download the matching RT patch from https://www.kernel.org/pub/linux/kernel/projects/rt/.

Extract and apply the patch:

tar -xf linux-X.Y.Z.tar.xz
cd linux-X.Y.Z
patch -p1 < /path/to/patch-rt-X.Y.Z.patch

Configure the kernel (enable Preemption Model → Full‑Preempt‑RT) with: make menuconfig Compile and flash the kernel:

make
./upgrade_tool di -b boot.img

Reboot the board to run the new kernel.

Verifying the Real‑Time Kernel

Check the running kernel version with uname -r; a -rt suffix indicates the real‑time kernel.

Cyclictest Benchmark

Install the rt‑tests suite and run cyclictest to measure latency:

git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
cd rt-tests
git checkout stable/v1.0
make all
make install

Typical command (idle or under load):

cyclictest -l 1000000 -m -Sp99 --policy=fifo -h 25000 -q >output.txt

Parameter explanation: -l 1000000: loop count (1 000 000 iterations) -m: run in real‑time mode with detailed output -Sp99: set priority to 99 and use

SCHED_FIFO
--policy=fifo

: explicit FIFO scheduling -h 25000: 25 ms interval between thread executions -q: quiet mode, only results are printed

Process the results with the provided run_cyclictest.sh script to generate a latency plot ( plot.png).

CPU Stress Test

Install stress‑ng and run a 24‑hour FFT load on eight CPUs:

sudo apt-get install stress-ng
stress-ng -c 8 --cpu-method fft --timerfd-freq 1000000 -t 24h &

After the stress test, repeat the cyclictest command to compare latency with and without the RT patch.

Typical Application Scenarios

Industrial automation – fast response for control and monitoring.

Audio processing and DSP – reduced audio latency.

Robotics – quick reaction to sensor and actuator events.

Time‑sensitive networking – low‑latency packet handling.

Modern heterogeneous AMP chips (e.g., STM32MP157, RK3506) often run Linux on non‑real‑time cores and an RTOS on dedicated real‑time cores, combining the strengths of both environments.

Conclusion

The article demonstrates how to obtain deterministic latency on Linux by applying the PREEMPT‑RT patch, building the kernel for an OK3588 board, and validating performance with cyclictest and stress‑ng across idle and CPU‑stress scenarios, highlighting the patch’s benefits for real‑time applications.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

EmbeddedReal-Time Kernelkernel patchcyclictestPREEMPT_RTstress-ng
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.