Recent Changes - Search:

Research

Notes

Architecture

Faults

System

Planning

Background

OS

Misc

edit SideBar

RTPatch

Installing a Kernel with the RT Patch


April 22, 2014

(NB: appears to be missing the important bit of creating the initrd.img file. However, this may not be needed... has something to do with scsi drives and whether or not their drivers are modules or built in).

Installing new kernels has gone from Extremely Intimidating to routine over the course of TAing an OS course, working with a custom OS, and now my current research. It is, however, still a bit of a pain, especially if you need to muck with the configuration.

This post outlines how to install a kernel with the RT Patch, and was tested on Ubuntu 12.04. The > indicates your terminal prompt.

Setup: get Kernel, Patch, and Tools

The kernel source you select should have an RT Patch available for it. So, first check your current kernel:
> uname -a

My kernel was 3.2.0-60, so I had to pick a new kernel. I went with 3.2.55 from https://www.kernel.org/pub/linux/kernel/v3.x/ (you will need to download the source for the kernel regardless; picking one that is the same or close to your current will make configuration much easier). The corresponding patch I downloaded from https://www.kernel.org/pub/linux/kernel/projects/rt/3.2/

Unzip and de-tar (patch only needs de-zipping):
> gzip -d kernel_name.tar.gz
> tar xf patch_name.tar

Finally, to install needed tools:
sudo apt-get build-dep linux-image-`uname -r` ... I wonder if this is okay

Patch and Build Kernel

Go into patch source directory and patch:
> patch -p1 <../patch_directory

If you haven't done this before: > sudo apt-get install kernel-package


See Update at bottom for the VMA / Ancestor fix


If you don't do a make menuconfig, your old config should be used, and only new options will be prompted. May want to edit the EXTRAVERSION in the top level Makefile if you are rebuilding an existing kernel (with different configuration options, for example).
> make-kpkg clean
> make menuconfig
> fakeroot make-kpkg --initrd --revision=3.2.55.RTpatch kernel_image

For configuration, I selected 5 for the level of RT (fully premptable kernel). The rest I just used the defaults. There were not too many new configuration options since the kernel I selected was similar to my current. And everything seems to work just fine.

The building takes a long time, so you should probably consider using the -j option to speed up building.

Install Kernel, Config Grub

> sudo dpkg -i ../linux-image-3.2.55-rt81_3.2.55.RTpatch_amd64.deb

To make sure Grub shows the splash screen, edit /etc/default/grub with root privileges. Change GRUB_HIDDEN_TIMEOUT=whatever to GRUB_HIDDEN_TIMEOUT= (NOTHING here, just a newline). Set GRUB_TIMEOUT as desired. You can also set GRUB_DEFAULT to be the index of the kernel you want to boot by default. If your new kernel is in a sub-menu, the first index selects the sub-menu and the next index selects the kernel. For example, GRUB_DEFAULT="2>1" to select the 2nd sub-menu, first item (0-indexed). To make the changes stick:
> sudo update-grub

Test / Verify Kernel

Restart and select the RT kernel on the grub splash screen. Verify the kernel running by checking: uname -r (or -a). Next, cat /sys/kernel/realtime should print 1 (and exist for that matter). Finally, you should see some RT processes when you run top.

Configuration for Debugging

There are some useful configuration options that can help with figuring out the source of kernel latency. However, the tracing mechanisms increase latency, so should likely only be used in a debugging version of the kernel. While doing a make menuconfig, check under Kernel hacking ---> Tracers for the following options:

  • Kernel Function Tracer
  • Interrupts-off Latency Tracer
  • _ Interrupts-off Latency Histogram
  • Preemption-off Latency Tracer
  • _ Preemption-off Latency Histogram
  • Scheduling Latency Tracer
  • _ Scheduling Latency Histogram
  • Missed timer offsets Histogram

Install kernel headers

If you are doing any system level programming you probably want to have the correct headers included. This is only really a problem if your original kernel (headers) don't have a feature that your new kernel does. For example, I upgraded from 3.2 to 3.14, and sub-reapers were introduced in 3.4. The command looks something like this (source):

sudo make headers_install INSTALL_HDR_PATH=/usr/


February 20, 2016

Update: fix for Anon_VMA problem

There is a patch for the Anon_VMA problem, described and explored in Kmemleak.

Download the kernel source you want as described above and apply the rt-preempt patch. Then edit mm/mmap.c and mm/rmap.c as described here: Attach:anon_vma_length_patch.txt. Make sure to update the EXTRAVERSION variable in the top level Makefile (and remember that '_'s are not allowed in it).

Resources (may or not be useful)

Most useful:

Also helpful:

Edit - History - Print - Recent Changes - Search
Page last modified on February 20, 2016, at 12:21 PM