I've been struggling for a while trying to build the RT-PREEMPT kernel for hard realtime audio recording, and I think that I've finally been successful. I am by no means an expert, so if anyone has suggestions or improvement, please reply! But here is my method and outcome. I mainly followed this guide: https://hegdesuhas.wordpress.com/201...reempt-ubuntu/ though I made some slight adjustments. In general, I'm doing everything through the terminal, but many of these steps can be done through GUI programs. (Archive manager, text editor, etc.)

Step 0 - Make a working directory

I did everything from ~/kernel, so I started by making and moving to that directory.

Code:
#Make working directory
mkdir ~/kernel && cd ~/kernel
Step 1 - Download kernel and patch

Look through https://www.kernel.org/pub/linux/kernel/projects/rt/ and download the most recent RT patch. I used the patch-*.*.*-rt6.patch.gz. I don't know much about the patches.*.*.*-rt6.tar.gz, so I can't guarantee that these steps will work using them. So use the single patch file.

At the time of writing, the most current RT patch is for kernel 3.18.11, so that's what I used.

Code:
#Download the RT patch
wget https://www.kernel.org/pub/linux/kernel/projects/rt/3.18/patch-3.18.11-rt6.patch.gz
Then, look through https://www.kernel.org/pub/linux/kernel/ and find the kernel that matches the version of the patch you downloaded.

Code:
#Download kernel
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.11.tar.gz &&
Step 2 - Unzip the kernel

Code:
#x - extract
#z - pipe through gunzip
#v - verbose (text output)
#f - from file
tar -xzvf linux-3.18.11.tar.gz
Step 3 - Patch the kernel

This part took me the longest to figure out, but this worked for me:

Code:
#Move to kernel source directory
cd linux-3.18.11

#c - pipe file contents to stdout
#d - decompress
gzip -cd ../patch-3.18.11-rt6.patch.gz | patch -p1 --verbose
Step 4 - Enable realtime processing

This step requires libncurses-dev

Code:
sudo apt-get install libncurses-dev
The next step should create a graphical menu in the terminal that you can scroll through. I included button presses enclosed in []s, except for menu scrolling with the up and down arrows, which I excluded. Comments are preceeded by #. They are only for clarification.

Code:
make menuconfig

##Graphical Menu##

Processor type and features ---> [Enter]
Preemption Model (Voluntary Kernel Preemption (Desktop)) [Enter]
Fully Preemptible Kernel (RT) [Enter] #Select

[Esc][Esc]

Kernel hacking --> [Enter]
Memory Debugging [Enter]
Check for stack overflows #Already deselected - do not select


[Esc][Esc]


[Right Arrow][Right Arrow]

<Save> [Enter]

.config

<Okay> [Enter]

<Exit> [Enter]


[Esc][Esc]


[Right Arrow]
<Exit> [Enter]
Step 5 - Compile the kernel

This step takes a long time. Unless you have a really fast computer, I would recommend doing something else for a while or letting it run overnight.

Code:
make -j3
The -j3 has to do with parallel processing. If you only have a single core processor, you can omit this option. I read somewhere that in general, you should use (# of cores)+1 after -j. I have no proof that this is the best option. It's worked well for me. If you don't know much about your processors, you can use:

Code:
sudo apt-get install cpufrequtils
cpufreq-info
or

Code:
sudo apt-get install hardinfo
hardinfo
to determine how many cores you have.

Step 6 - Make modules & install

This step will take some time, but not nearly as long as the previous step.

Code:
sudo make modules_install -j3
sudo make install -j3
Step 7 - Verify and update

Verify that initrd.img-3.18.11-rt6, vmlinuz-3.18.11-rt6, and config-3.18.11-rt6 exist. They should have been created in the previous step.

Code:
cd /boot
ls
Update grub - this will allow you to select the new kernel on bootup.

Code:
sudo update-grub
Verify that there is a menuentry containing the text "menuentry 'Ubuntu, with Linux 3.18.11-rt6'". Feel free to replace "vim" with "kate", "gedit", or whatever text editor you prefer. Do not edit this file.

Code:
vim /boot/grub/grub.cfg
If you would like to make this kernel your new default (optional), this can be done by editing the /etc/default/grub file. More info here: https://help.ubuntu.com/community/Gr...iguring_GRUB_2

Step 8 - Reboot and enjoy!

Good job! Reboot the computer, and when the grub menu appears during boot, select the newly created RT kernel.

Code:
sudo reboot
Once rebooted, you can verify that everything was successful by doing:

Code:
uname -a
My output looks like:

Code:
Linux oliver-home 3.18.11-rt6 #1 SMP PREEMPT RT Sun Apr 12 03:32:57 EDT 2015 i686 i686 i686 GNU/Linux
Note the "SMP PREEMPT RT".

---

Since doing this, xruns in jack occur much more predictably. If I use bad settings, I'll get a ton of xruns immediately, but otherwise, for the most part, I get none.

I hope that this is helpful! Please post any questions, comments, or suggestions. I'm interested to know if this method is successful for others. Thanks for reading!

Best of luck,
Oliver Evans