Latency & RT Kernels

If your building your kernel and you have older hardware sometimes the latest kernel and rt patch are not the best for latency.

My J1900 running Lubuntu 19.04 seems to do real well with 4.4.179-rt181. It had ~250us with 5.1 and all kinds of errors with 4.1.

First go to Kernels.org and pick out a linux-n.n.n.tar.xz kernel that has a patch-n.n.n-rtn.patch.gz patch in projects/rt download them both into a clean directory.

Building Preempt RT Kernels

I made a bash script to unzip and patch the kernel. Copy the following into a file, I called mine rt.sh to just save time typing. Make sure the file is executable.

#!/bin/bash

PATCHGZ=$(find *.patch.gz -maxdepth 1 -type f)
echo $PATCHGZ
KERNEL=$(find *.xz -maxdepth 1 -type f)
echo $KERNEL

tar -xpf $KERNEL
gunzip $PATCHGZ

PATCHDIR=$(ls -d */)
echo $PATCHDIR

PATCH=$(find *.patch -maxdepth 1 -type f)
echo $PATCH

cp $PATCH $PATCHDIR

cd $PATCHDIR

cat $PATCH | patch -p1

Place the file in with your kernel.xz and patch.gz and run it as a source by using a dot space.

. ./rt.sh

Next run make xconfig and make sure you pick fully preemptable kernel save and close.

Next depending on how many cores you have add one to that and run make. For 4 cores run make -j5.

make xconfig

If you get an error about not finding Qt4 you may need to install it with

sudo apt-get install libqt4-dev pkg-config

Build the kernel

make -j5
sudo make modules_install
sudo make install

Reboot and select your new Preempt Rt kernel usually from the Advanced option at bootup.

In a terminal check that you have the Preempt Rt kernel running with

uname -a

For real time operation the govener “feature” should be turned off for the best latency.

systemctl list-units --all --type=service | grep ondemand
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

sudo systemctl disable ondemand
re-boot, then check again (being sure to wait a minute after the re-boot):

systemctl list-units --all --type=service | grep ondemand
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor