Skip to content

Commit b33b4cf

Browse files
author
kingdo9
committed
Real Time Kernel Documentation Update
1 parent d540b35 commit b33b4cf

11 files changed

+410
-39
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Controlling RGB LED display with Raspberry Pi GPIO
22
==================================================
33

4-
A library to control commonly available 64x64, 32x32 or 16x32 RGB LED panels
4+
A library to control commonly available 128x64, 64x64, 32x32 or 16x32 RGB LED panels
55
with the Raspberry Pi. Can support PWM up to 11Bit per channel, providing
66
true 24bpp color with CIE1931 profile.
77

@@ -264,7 +264,7 @@ choose these here:
264264
This can have values such as
265265
- `--led-gpio-mapping=regular` The standard mapping of this library, described in the [wiring](./wiring.md) page.
266266
- `--led-gpio-mapping=adafruit-hat` The Adafruit HAT/Bonnet, that uses this library or
267-
- `--led-gpio-mapping=adafruit-hat-pwm` Adafruit HAT with the anti- hardware mod [described below](#improving-).
267+
- `--led-gpio-mapping=adafruit-hat-pwm` Adafruit HAT with the anti- hardware mod [described below](#improving-flicker-hardware-patch).
268268
- `--led-gpio-mapping=compute-module` Additional 3 parallel chains can be used with the Compute Module.
269269

270270
Learn more about the mappings in the [wiring documentation](wiring.md#alternative-hardware-mappings).
@@ -884,7 +884,7 @@ the refresh rate.
884884
If you have a loaded system and one of the newer Pis with 4 cores, you can
885885
reserve one core just for the refresh of the display. Add:
886886
```
887-
isolcpus=3
887+
isolcpus=domain,managed_irq,3 nohz_full=3 rcu_nocbs=3 irqaffinity=0,1,2
888888
```
889889
890890
to the end of the line in `/boot/cmdline.txt` (pre-bookworm) or

RT-kernel/README.md

Lines changed: 316 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,332 @@
1+
# Real Time Kernel
12

2-
If you are suffering from random flickering because of other tasks run by your
3-
linux kernel, you can install this RT kernel and kernel modules in your rPI image.
3+
If you are using SPWM displays or normal displays without the PWM hardware modification; to help with flickering it is highly recommended to flash this optimized kernel.
44

5-
Note that installing a recent kernel (this kernel and module is 6.12.75-rt16-v8+)
6-
on a very old rPi distro, userspace may not be compatible enough.
5+
First perform the below **cmdline.txt** modification, this also helps with intermittent flicker especially when combined with the real time kernel as guided below. Apply this regardless of using RT kernel or not, as it helps with interrupts on Core 3 which is what the library uses to refresh the display.
6+
```
7+
nano /boot/firmware/cmdline.txt
8+
9+
# Add to the end of the line
10+
isolcpus=domain,managed_irq,2,3 nohz_full=2,3 rcu_nocbs=2,3 irqaffinity=0,1 idle=poll
11+
```
12+
---
713

8-
On my older dietpi distribution, the wifi firmware was too old to work with this
9-
kernel.
14+
[Option 1 - Download Preinstalled Image - Pi 4 / 3 / Zero 2W - Trixie 64-bit Lite](#option-1---download-preinstalled-trixie-image---64-bit-lite)
1015

11-
I was able to fix it with
12-
but you could also try to get raspberry4_kernel_rt_trixie_120425_firmware.tar.gz
13-
from https://mega.nz/file/rRcQDBqC#yhaByUa1z-TEmLc1joEF6QEZvDfirOIKrFf_yzoFOcA
16+
[Option 2 - Copy RT Kernel To Your Current Raspberry OS installation](#option-2---copy-rt-kernel-to-your-current-raspberry-os-installation)
17+
18+
[Option 3 - Compile and Apply Your Own Raspberry Real Time Kernel](#option-3---compile-and-install-your-own-raspberry-real-time-kernel)
19+
20+
[Recommended Performance Mods](#performance-mods)
21+
22+
---
23+
24+
<br>
25+
26+
## Option 1 - Download Preinstalled Trixie Image - 64-bit Lite
27+
28+
Full image with Hzeller library installed + RT Kernel.
29+
30+
<a href="https://mega.nz/file/GAMEyDzS#9MvAs_ffPo4cROvovjziP0neAxOb1h7nzIK7DXxaYHo">Raspberry Pi 4 Lite Trixie 64-Bit - RT Kernel Preinstalled image</a>
31+
32+
<a href="https://mega.nz/file/OMtgRKhS#o5Wf4Gj1_YgTWME3bG5F_eVfDQyjr_iBGwGkOgsJiUc">Raspberry Pi 3 Lite Trixie 64-Bit - RT Kernel Preinstalled image</a>
33+
34+
<a href="https://mega.nz/file/HclGUIRB#r0uKTZQDuR_AVmVPV3GOcuWbR5tM3lmVFJ4m1YO-wGg">Raspberry Pi Zero 2W Lite Trixie 64-Bit - RT Kernel Preinstalled image</a>
35+
<br><br>
36+
To access via SSH, either use Ethernet / USB Ethernet. \
37+
user / password \
38+
Then if you need to set up Wi-Fi, use the command - **nmtui**
39+
40+
Alternatively, set up a Wi-Fi hotspot on your phone using the details \
41+
Raspberry / password1 \
42+
Then SSH from your phone to the connected Raspberry device. Android will show the IP of the connected device to the Hotspot when clicking (i) \
43+
Again use **nmtui** to change or remove the Wi-Fi connection.
44+
45+
46+
<img alt="Image" src="./img/kernel_guide_1.png" />
47+
<img alt="Image" src="./img/kernel_guide_2.png" />
1448

15-
this may also be enough:
16-
apt-get update; apt-get install --reinstall firmware-brcm80211
1749

18-
Note that this RT kernel is aggressive. Once you start the RT code, on my Pi3 and Pi4,
19-
it actually prevents the boot from completing if it hasn't yet (including networking),
20-
so make sure networking is up and sshd running before you start RT code.
2150

22-
For more info and instructions, please review this bug:
23-
https://github.com/hzeller/rpi-rgb-led-matrix/issues/1754#issuecomment-4014842065
24-
including how to patch and build your own kernel:
25-
https://github.com/hzeller/rpi-rgb-led-matrix/issues/1754#issuecomment-4017608624
26-
Huge thanks to @kingdo9 for making all this happen.
51+
---
52+
## Option 2 - Copy RT Kernel To Your Current Raspberry OS installation
53+
54+
**This precompiled kernel is for Raspberry Pi 4 / 3 / Zero 2W - 64-bit. Alternatively [compile your own](#option-3---compile-and-install-your-own-raspberry-kernel)**
55+
56+
Download and copy the below kernel files to your Raspberry Pi in the /tmp directory.
57+
58+
The kernel version compiled is 6.18.18-rt
59+
So its best your OS image is already close to it.
60+
61+
[raspberry_kernel_rt_trixie_120425_v2_boot.tar.gz](./raspberry_kernel_rt_trixie_120425_v2_boot.tar.gz)
62+
63+
[raspberry_kernel_rt_trixie_120425_v2_root.tar.gz](./raspberry_kernel_rt_trixie_120425_v2_root.tar.gz)
64+
65+
66+
```
67+
tar -xzf /tmp/raspberry_kernel_rt_trixie*boot.tar.gz -C /boot/firmware
68+
tar -xzf /tmp/raspberry_kernel_rt_trixie*root.tar.gz -C /
69+
```
70+
71+
Reboot and check your kernel reads
72+
```
73+
uname -a
74+
Linux raspberry 6.18.18-rt-v8+ #1 SMP PREEMPT_RT
75+
```
76+
###########################################################
77+
78+
**Optionally if you are not already using a similar Trixie image**, if your original kernel was much older and encounter issues with Wi-Fi, you may need to perform the additional step to match your images firmware.
79+
80+
You may only need the below to fix it
81+
```
82+
apt-get update; apt-get install --reinstall firmware-brcm80211
83+
```
84+
Alternatively if using Pi 4, extract it from below. \
85+
Kernel firmware \
86+
https://mega.nz/file/rRcQDBqC#yhaByUa1z-TEmLc1joEF6QEZvDfirOIKrFf_yzoFOcA
87+
```
88+
tar -xzf /tmp/raspberry4_kernel_rt_trixie_120425_firmware.tar.gz -C /
89+
```
90+
Depending on what your original kernel/os image was, you may see some dmesg prompts like the below which should be fine.
2791

28-
Also, please note that RT does what it says, it will prevent the rest of linux
29-
form running if needed, and it is normal to see output like this:
3092
```
3193
42.834070] rcu: INFO: rcu_preempt self-detected stall on CPU
3294
42.834101] rcu: $3-....: (3 GPs behind) idle=7d5c/1/0x4000000000000000 softirq=0/0 f
3395
491 rcuc=5301 jiffies (starved)
3496
42.834124] rcu: t = 525theta jiffies g = 3129 alpha = 2711 ncpus=4) 105.845757] rcu: INFO: rcu_preempt self-detected stall on CPU
3597
105.845787] rcu: $3-....: (3 GPs behind) idle=7d5c/1/0x4000000000000000 softirq=0/0 f
3698
915 rcuc=21054 jiffies (starved)
37-
105.845810] rcu: ( t = 21003 jiffies g = 3129 alpha = 4721 ncpus=4)
38-
168.858199] rcu: INFO: rcu_preempt self-detected stall on CPU
39-
168.858227] rcu: $3-....: (3 GPs behind) idle=7d5c/1/0x4000000000000000 softirq=0/0 f
40-
7396 rcuc=36807 jiffies (starved)
41-
168.858250] rcu: t = 36756 jiffies g = 3129 alpha = 6251 ncpus=4)
42-
231.870579] rcu: INFO: rcu_preempt self-detected stall on CPU
43-
231.870609] rcu: $3-....: (3 GPs behind) idle=7d5c/1/0x4000000000000000 softirq=0/0 f
44-
4817 rcuc=52560 jiffies (starved)
45-
231.870631] rcu: ( t = 52509 jiffies g = 3129 alpha = 7973 ncpus=4)
46-
242.658727] INFO: task systemd: 1 blocked for more than 120 seconds.
47-
242.658803] Not tainted 6.12.75-rt16-v8+ #1
48-
242.658814] "echo > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
49-
242.659892] INFO: task (postboot): 513 blocked for more than 120 seconds.
50-
242.659904] Not tainted 6.12.75-rt16-v8+ #1
51-
242.659912] "echo > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
5299
```
100+
<br>
101+
102+
103+
---
104+
## Option 3 - Compile and Install Your Own Raspberry Real Time Kernel
105+
Install and start Raspberry OS, I'm using Trixie Lite 64-bit
106+
Find the kernel version of your current Raspberry Pi install.
107+
108+
```
109+
uname -a
110+
```
111+
<span style="color:darkred;font-weight:bold">
112+
Using a Desktop Ubuntu Linux system, currently using Ubuntu 24.0 - To cross compile
113+
114+
</span>
115+
116+
```
117+
apt install -y bc bison flex libssl-dev make libc6-dev libncurses-dev libelf-dev crossbuild-essential-arm64 git
118+
cd /home/user/
119+
mkdir kernel
120+
cd kernel
121+
git clone https://github.com/raspberrypi/linux.git
122+
cd linux
123+
```
124+
<br>
125+
126+
**OPTIONAL** - Below will show the current kernel version currently checked out. Run the below to change kernel version by using git checkout. To find kernel version branches available, navigate to https://github.com/raspberrypi/linux
127+
```
128+
head -n 4 Makefile
129+
git checkout rpi-6.12.y
130+
```
131+
132+
<img alt="Image" src="./img/kernel_guide_3.png" />
133+
<br><br><br>
134+
135+
**Set the Kernel variable where kernel8 as being Pi 4 / 3 / Zero 2W | Other references link
136+
https://www.raspberrypi.com/documentation/computers/linux_kernel.html**
137+
138+
```
139+
KERNEL=kernel8
140+
```
141+
142+
**Make default config, my example as Pi 4 / 3 / Zero 2W**
143+
```
144+
make KERNEL=kernel8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_rt_defconfig
145+
```
146+
147+
**Other Config examples below.**
148+
149+
**64-bit (ARCH=arm64)**
150+
151+
Pi 3 / 3+ / CM3 / CM3+ / Zero 2 W / Pi 4 / Pi 400 / CM4 / CM4S - `bcm2711_rt_defconfig`
152+
153+
Pi 5 / Pi 500 / CM5 - `bcm2712_rt_defconfig`
154+
155+
**32-bit (ARCH=arm)**
156+
157+
Pi 1 / CM1 / Zero / Zero W / Pi 2 - `bcmrpi_rt_defconfig`
158+
159+
Pi 3 / 3+ / CM3 / CM3+ / Zero 2 W - `bcm2709_rt_defconfig`
160+
161+
**Note: Raspberry Pi OS 32-bit on Pi 4 class devices normally uses a 64-bit kernel by default; building a true 32-bit kernel for those needs ARCH=arm and extra boot config.**
162+
163+
<br>
164+
165+
**Edit Kernel options**
166+
167+
```
168+
# nano - CTRL+S | CTRL+X - Save and Quit
169+
170+
# Disabling Wi-Fi power saving by default - equivalent to /sbin/iwconfig wlan0 power off
171+
nano include/net/cfg80211.h
172+
WIPHY_FLAG_PS_ON_BY_DEFAULT = 0
173+
---------------------------------------------
174+
175+
# Options to remove and unnecessary overhead
176+
# Search with CTRL+W and edit, or paste the below block at the bottom.
177+
178+
nano .config
179+
180+
CONFIG_B43LEGACY_DEBUG=n
181+
CONFIG_BSD_PROCESS_ACCT=n
182+
CONFIG_BSD_PROCESS_ACCT_V3=n
183+
CONFIG_CFG80211_DEFAULT_PS=n
184+
CONFIG_CHECKPOINT_RESTORE=n
185+
CONFIG_DEBUG_BUGVERBOSE=n
186+
CONFIG_DEBUG_FS=n
187+
CONFIG_DEBUG_MISC=n
188+
CONFIG_DETECT_HUNG_TASK=n
189+
CONFIG_FTRACE=n
190+
CONFIG_HOTPLUG_CPU=n
191+
CONFIG_KALLSYMS_ALL=n
192+
CONFIG_KGDB=n
193+
CONFIG_KGDB_KDB=n
194+
CONFIG_KPROBES=n
195+
CONFIG_LATENCYTOP=n
196+
CONFIG_MAGIC_SYSRQ=n
197+
CONFIG_NETFILTER_XT_TARGET_AUDIT=n
198+
CONFIG_OSNOISE_TRACER=n
199+
CONFIG_PERF_EVENTS=n
200+
CONFIG_PM_DEBUG=n
201+
CONFIG_PRINTK_TIME=n
202+
CONFIG_PROFILING=n
203+
CONFIG_PSI=n
204+
CONFIG_RCU_TRACE=n
205+
CONFIG_RTLWIFI_DEBUG=n
206+
CONFIG_SCHEDSTATS=n
207+
CONFIG_SCHED_AUTOGROUP=n
208+
CONFIG_SCHED_TRACER=n
209+
CONFIG_SLUB_DEBUG=n
210+
CONFIG_STACK_TRACER=n
211+
CONFIG_TASKSTATS=n
212+
CONFIG_TASK_DELAY_ACCT=n
213+
CONFIG_TASK_IO_ACCOUNTING=n
214+
CONFIG_TASK_XACCT=n
215+
CONFIG_TIMERLAT_TRACER=n
216+
CONFIG_TRACING=n
217+
```
218+
219+
220+
```
221+
make KERNEL=kernel8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
222+
```
223+
```
224+
General Setup > Timers Subsystem > Timer tick handling > Full dynticks system (tickless)
225+
Ensure General Setup > Fully Preemptible Kernel (Real-Time)
226+
Ensure General Setup > Preemption Model - Low-Latency Desktop
227+
228+
Save
229+
Exit
230+
```
231+
232+
<img alt="Image" src="./img/kernel_guide_4.png" /><br>
233+
<img alt="Image" src="./img/kernel_guide_5.png" /><br><br>
234+
235+
```
236+
make -j"$(nproc)" KERNEL=kernel8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image.gz modules dtbs
237+
```
238+
239+
**Now we copy the relevant files to the Raspberry OS sdcard.**
240+
**Use SD card reader to attach sdcard to Ubuntu system.**
241+
**In the console, find the mountpoints of the sdcard.**
242+
```
243+
mount | grep /dev/sd
244+
```
245+
**Example**
246+
```
247+
/media/user/bootfs
248+
/media/user/rootfs
249+
```
250+
251+
**Making sure you are still in the current working directory e.g**
252+
```
253+
cd /home/user/kernel/linux
254+
```
255+
256+
**Backup existing Kernel and related files**
257+
```
258+
cp /media/user/bootfs/${KERNEL}.img /media/user/bootfs/${KERNEL}.bak
259+
mkdir -p /media/user/bootfs/dtbbak
260+
mkdir -p /media/user/bootfs/overlays/dtboverlaysbak
261+
cp /media/user/bootfs/*.dtb /media/user/bootfs/dtbbak
262+
cp /media/user/bootfs/overlays/*.dtb* /media/user/bootfs/overlays/dtboverlaysbak
263+
```
264+
265+
**Copy the RT Kernel to the sdcard**
266+
```
267+
cp arch/arm64/boot/Image.gz /media/user/bootfs/${KERNEL}.img
268+
cp arch/arm64/boot/dts/broadcom/*.dtb /media/user/bootfs
269+
cp arch/arm64/boot/dts/overlays/*.dtb* /media/user/bootfs/overlays
270+
sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/media/user/rootfs modules_install
271+
```
272+
273+
**Add the Kernel parameters for RT at the end of the line - CTRL+S , CTRL+X to save in nano**
274+
```
275+
nano /media/user/bootfs/cmdline.txt
276+
277+
# Add this to the end of the line
278+
isolcpus=domain,managed_irq,2,3 nohz_full=2,3 rcu_nocbs=2,3 irqaffinity=0,1 idle=poll
279+
280+
```
281+
282+
**Put the sdcard back into the Pi and boot**
283+
**Confirm Real Time kernel is now installed**
284+
285+
```
286+
uname -a
287+
```
288+
289+
---
290+
291+
292+
## Performance Mods
293+
294+
CTRL+S , CTRL+X to Save and Exit from Nano
295+
296+
297+
```
298+
nano /etc/rc.local
299+
300+
#!/bin/sh -e
301+
echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
302+
echo 3 > /sys/devices/virtual/workqueue/cpumask
303+
exit 0
304+
305+
---- Save
306+
307+
chmod +x /etc/rc.local
308+
reboot
309+
```
310+
<br>
311+
312+
Force turbo, disabling CPU frequency changes
313+
314+
```
315+
nano /boot/firmware/config.txt
316+
317+
# Add
318+
force_turbo=1
319+
```
320+
<br>
321+
322+
When running the library, even though the display refresh thread uses Core 3 automatically, I also assign the parent process to Core 2 and set the priority using:
323+
324+
```
325+
taskset -c 2 chrt -f 99 /opt/rpi-rgb-led-matrix/examples-api-use/demo -D8 --led-rows=64 --led-cols=128 --led-limit-refresh=60 --led-no-busy-waiting ....
326+
```
327+
<br>
328+
329+
330+
Original discussion thread
331+
https://github.com/hzeller/rpi-rgb-led-matrix/issues/1754
332+

RT-kernel/img/kernel_guide_1.png

45.9 KB
Loading

RT-kernel/img/kernel_guide_2.png

26.9 KB
Loading

RT-kernel/img/kernel_guide_3.png

35.2 KB
Loading

RT-kernel/img/kernel_guide_4.png

31.4 KB
Loading

RT-kernel/img/kernel_guide_5.png

13.9 KB
Loading
-9.86 MB
Binary file not shown.
8.25 MB
Binary file not shown.

RT-kernel/raspberry4_kernel_rt_trixie_120425_root.tar.gz renamed to RT-kernel/raspberry_kernel_rt_trixie_120425_v2_root.tar.gz

21.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)