How to Build, Patch and Benchmark a Real‑Time Linux Kernel on the OK3588 Board
This guide explains how to set up a development environment for the OK3588 board, apply the PREEMPT‑RT real‑time patch to Linux 5.10.66‑rt53, configure and compile the kernel, flash it, and then validate latency improvements using cyclictest and stress‑ng under both idle and full‑load scenarios.
Introduction
The Linux kernel real‑time patch (PREEMPT‑RT or RT) reduces latency and improves predictability, enabling time‑critical applications such as industrial control, audio processing, and robotics.
Test Environment
Hardware: Phytium 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 : faster response to external events.
High‑priority scheduling : real‑time tasks get higher priority.
Preemptive support : tasks can pre‑empt long‑running kernel code.
Lock optimizations : reduced lock contention and critical‑section time.
Improved thread handling : better scheduling for real‑time threads.
What the Patch Changes
High‑resolution timers for nanosecond‑level delays.
Interrupt threading so that real‑time tasks are not pre‑empted by interrupts.
Spinlocks ( spinlock_t) replaced by real‑time mutexes ( rt_mutex) to enable priority inheritance and avoid priority inversion.
Installation and Usage of the Real‑Time Patch
Typical steps:
Download the kernel source:
wget https://www.kernel.org/pub/linux/kernel/vX.Y/linux-X.Y.Z.tar.xzDownload 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.patchConfigure the kernel (enable Preemption Model with a real‑time option) using make menuconfig.
Compile the kernel: make Flash the kernel to the board (example command): ./upgrade_tool di -b boot.img Reboot to run the new kernel.
Verifying the Real‑Time Kernel
Check the running kernel version: uname -r A real‑time kernel includes the -rt suffix.
Use cyclictest to measure latency. Install it from the rt‑tests repository:
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 installTypical cyclictest command (1 000 000 loops, priority 99, FIFO policy, 25 ms interval):
cyclictest -l 1000000 -m -Sp99 --policy=fifo -h 25000 -q >output.txtParameters: -l 1000000: number of loops. -m: run in real‑time mode with detailed output. -Sp99: set priority 99 with SCHED_FIFO. --policy=fifo: use FIFO scheduling. -h 25000: 25 ms period. -q: quiet mode, only results.
Process the results with the provided run_cyclictest.sh script to generate a latency histogram plot ( plot.png).
Test Scenarios
Idle run without the RT patch.
Full‑load CPU stress test without the RT patch (using stress‑ng).
Idle run with the RT patch applied.
Full‑load CPU stress test with the RT patch applied.
For CPU stress, set all CPUs to performance governor:
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance > $i; doneRun stress‑ng (example 8 threads, FFT method, 24 h):
sudo apt-get install stress-ng
stress-ng -c 8 --cpu-method fft --timerfd-freq 1000000 -t 24h &After the stress test, run cyclictest again with the same parameters and generate the plot.
Application Scenarios for Real‑Time Kernels
Industrial automation – fast response for control loops.
Audio processing – low‑latency DSP.
Robotics – rapid sensor‑actuator feedback.
Network communication – timely packet handling.
Modern heterogeneous AMP chips (e.g., STM32MP157, RK3506) often run Linux on a general‑purpose core and an RTOS on a dedicated real‑time core, combining the strengths of both.
Conclusion
The article demonstrates how to achieve deterministic behavior on a Linux system by applying the PREEMPT‑RT patch, configuring and compiling the kernel, and validating latency improvements with systematic testing. The results show that the patched kernel consistently yields lower maximum latency under both idle and load conditions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
