HOWTO: Install Real-Time Linux Kernel

2 minute read

I work with robots everyday.

By working, I mean to write computer programs that listen to signals from sensors, cameras; compute stuffs; and then send motion commands to the robot controller. Everything happen very quickly, especially the commanding part which should occur exactly every 8 milliseconds.

This needs for exactness requires the program/process sending motion commands to be very punctual. Unfortunately, in a common Operating System (OS) like generic Ubuntu/Linux, a program/process is often disrupt by other processes. These processes can be from the user or the OS itself. This situation causes undesirable delays in the critical real-time process.

To avoid this issue, one needs a Real-Time Operating System (RTOS). While there are many RTOS available, they have a few issues:

  • not free (QNX, vxwork);
  • does not support the software ecosystem for robotics (ROS, OpenRAVE).

Achieving Real-Time capability with Linux

Fortunately, there are free alternatives. Real-Time Linux is one such alternative. In this post I will briefly capture steps I have taken to achieve Real-Time capability with Linux.

There is one thing that needs to be clear: there is no such thing as a Real-Time Linux distribution. Rather, one can achieve Real-Time capability by running a Fully Preemptible Linux Kernel instead of the generic Kernel. Fortunately, it is quite simple to do so.

Compiling a Fully Preemptible Linux Kernel (Real-Time patched)

First, choose a RT patch from this mirror. I chose version 4.14.78-rt47. The lastest patch as of the time of this writing is 4.19-rt3, unfornately does not work on my machine running Ubuntu 16.04. In any case, the worst that can happen is you have to do the whole compiling/install process again.

Note the Kernel version you have choosen, download the corresponding kernel from this mirror. Both steps can be done via the terminal as below.

cd ~/Downloads
# download patch
# download kernel

Unzipped the archives and patch the kernel with the RT patch.

tar xvf linux-4.14.78.tar.xz
cd linux-4.14.78
xzcat ../patch-4.14.78-rt47.patch.xz | patch -p1 --verbose

We now enable the option Fully Preemptible Kernel (RT). First, install two necessary dependencies.

sudo apt-get install libncurses-dev libssl-dev

Configure the compilation by doing

make menuconfig

You will see a graphical user interface (GUI) show up in the terminal. This GUI contains configurations for compiling the Kernel. The bit that we need is called Preemption Model:

  • Navigate using arrow keys to Processor type and feature, then press Enter;
  • look for Preemption Model, press Enter;
  • choose Fully Preemptible Kernel (RT) option;
  • return to the first screen by pressing Esc multiple times;
  • save .config file, then exit.

Compile the Kernel and install.

make -j20
sudo make modules_install -j20
sudo make install -j20

And that’s it. Reboot, remember to choose the patched Kernel in Advanced Boot Setting, and enjoy!


Some useful reads I came across while working on this: