Realtime (RT) Kernel
Note: this a "backport" or better a "Gentoo'ification" of the RT Kernel howto originally written by gimpel, contributed to the openSUSE jacklab community.
- the original version can be found here (German): http://www.linux-club.de/ftopic31817.html
- the translated and edited version can be found here: http://en.opensuse.org/RT_Kernel_Instructions
RT Kernel - why?
This is an update of the HowTo from gimpel (gimpel.funpic.de), translated by oc2pus. Updated by metasymbol and gentoo'ified by gimpel again :P
The main goal in audio-processing is the latency. The latency is the delay beetween signal-creating and reaching the processing in the system (e.g time between pressing a key on the keyboard and hearing the tone). The standard kernels have the disadvantage that the processing is slower (~11ms) as in Windows or using a MAC . The faster the system, means the lower the latency, the more things can happen simular on a the system (e.g. more synths ..) Ingo Molnar, a RedHat developer and some others have started a project to minimize the latency in Linux: Realtime Preemption. By using excellent audio-hardware the JACK demon (Jack Audio Connection Kit) reach latency < 1ms, similar to the MacOS X „coreaudio“ system. For interested people follows a little step-by-step HowTo to patch a vanilla kernel with Realtime Preemption stuff and how to compile and install this new kernel.
This is an experimental kernel.
the -rt patch is under heavy development all the time. So if you hit a bad day, you'll get a unstable/unusable kernel. See http://lkml.org for support, and check for a new version some days later if you happen to run into problems.
Sample kernel is the stable linux-2.6.16.
Obtain the kernel-source and necessary patches
The simple approach
Evermind's overlay provides an ebuild for rt-sources. So to get the latest kernel source including the -rt patch, just type
emerge -av rt-sources
After that continue with the configuration part.
Download the sources
- download current vanilla kernel
- download Realtime Preemption patch
Note: this is an example, the version of the -rt patch changes almost daily. So just take a look at http://people.redhat.com/mingo/realtime-preempt, choose the latest version and replace -rt22 with the current version throughout the whole guide.
unpack and patch kernel
cd /usr/src/linux su <password> tar xvjf /path/to/linux-2.6.16.tar.bz2 linux-2.6.16 linux-2.6.16-rt22 cd linux-2.6.16-rt22 patch -p1 < /path/to/patch-2.6.16-rt22
Clone the config
It's a good thing to clone your current (working) kernel configuration
- if you have support for access to the config via /proc/config.gz enabled:
zcat /proc/config.gz > .config
- if you don't, the copy then config from the current kernel's source tree
cp /usr/src/linux-`uname -r`/.config .config
Note: this step will cause a ton of questions. You can basically say No to everthing you don't need or you have no idea of what it is. In the next step we will adjust all important settings.
Adjust important settings
Enter the configuration menu
and make the following settings:
- activate rt full preempt
Processor type and features ---> Preemption Mode (Complete Preemption (Real-Time)) ---> ( ) No Forced Preemption (Server) ( ) Voluntary Kernel Preemption (Desktop) ( ) Preemptible Kernel (Low-Latency Desktop) (X) Complete Preemption (Real-Time)
- set the internal timer frequency
Processor type and features ---> Timer frequency (1000 HZ) ---> (X) 1000 HZ
- enable realtime clock support
Device drivers ---> Character devices ---> <*> Enhanced Real Time Clock Support
- ALSA should have RTC support too
Device drivers ---> Sound ---> Advanced Linux Sound Architecture ---> <*> RTC Timer support [*] Use RTC as default sequencer timer
- make sure you get no overhead by debug features
(note: need to look at a -rt kernel config for a full list)
Kernel hacking ---> [*] Magic SysRq key #that one is always good to have ;) [ ] Kernel debugging
- activate realtime-lsm (deprecated)
Note that the kernel config option is only available when the kernel is patched with rt-lsm patch. If it isn't, you can emerge realtime-lsm to get the module after the kernel is compiled an installed. Only activate "Default Linux Capabilities" in that case.
Security options ---> [*] Enable different security models <M> Default Linux Capabilities <M> Realtime Capabilities
Leave the menu with "Exit" and save configuration.
Compile and install new kernel
- compile the kernel:
make && make modules_install
Now get a coffee or something...
- install the kernel:
cp arch/i386/boo/bzImage /boot/kernel-2.6.16-rt22 cp System.map /boot/System.map-2.6.16-rt22
- if you don't have support for your chipset and / filesystem built into the kernel, you will most likely need an intrd:
cd /boot mkinitrd -k kernel-2.6.16-rt22 -i initrd-2.6.16-rt22
- Configure the bootloader
nano -w /boot/grub/grub.conf
Copy the existing entry for your old kernel and edit the names. The name should match your new kernel.
- pray and reboot... :)
Activate and test RT
after reboot it's time to activate the user real-time module:
- determine the gid of the audio group
that spits out something, the important one is the gid of the audio group
if your user is not in the audio group yet, as root do
gpasswd -a <username> audio
and re-login the user afterwards.
- Then load realtime-lsm
modprobe commoncap modprobe realtime gid=18
- To ensure this gets loaded automagically after reboot:
echo "realtime" /etc/modules.autoload.d/kernel-2.6 echo "options realtime gid=18" >> /etc/modules.d/realtime modules-update
Now the normal user is able to run audio with realtime capabilities.
lsmod|grep realtime realtime 5512 0 commoncap 7040 1 realtime
make sure you have the latest version of PAM installed from the overlay
equery which pam
the path to the ebuild should point to where you've put the proaudio overlay. If you don't have equery installed:
emerge -av gentoolkit
Then edit /etc/security/limits.conf
# rtprio @audio - rt_priority 90 @audio - nice -5 @audio - memlock 500000
This sets the RT priority to 90, nices RT tasks to -5, and grants a memlock of ~500MB. TODO: explain those values more in depth
If you do not use PAM, there is a tool to set RLIMITS priorities:
- Untar it and see the included README and manpage what to do with it ;)
- A sample set_rlimits.conf entry could look like this:
@audio /usr/bin/jackd nice=-1 rtprio=85 @audio /usr/bin/qjackctl nice=-1 rtprio=84 @audio /usr/bin/ardour nice=-1 rtprio=83 @audio /usr/bin/hydrogen nice=-1 rtprio=82 @audio /usr/bin/jackeq nice=-1 rtprio=81 @audio /usr/bin/jack-rack nice=-1 rtprio=80 @audio /usr/bin/jamin nice=-1 rtprio=79 @audio /usr/bin/qsynth nice=-1 rtprio=78 @audio /usr/bin/rosegarden nice=-1 rtprio=77 @audio /usr/bin/seq24 nice=-1 rtprio=76 @audio /usr/bin/specimen nice=-1 rtprio=75 @audio /usr/bin/vkeybd nice=-1 rtprio=74 @audio /usr/bin/zynaddsubfx nice=-1 rtprio=73 @audio /usr/bin/ams nice=-1 rtprio=72 @audio /usr/bin/amsynth nice=-1 rtprio=71
Note: this sample is respectfully taken from: http://ubuntustudio.com/wiki/index.php/Breezy:Using_set_rlimits
- TODO: ebuild ^^
testing audio RT
with qjackctl and zynaddsubfx
- Start qjackctl and make your config
- press Start -> if JACK starts successfully,
- start zynaddsubfx
- in qjackctl open Connect
- and connect zynadd to the alsa playback devices
- then play around with zynadd
Hopefully you will hear the beautifull sound of ZynAddSubFX in all its glory ;)
- So far read the excellent document written by Daniel Robbins, Chief architect of Gentoo GNU/Linux and CEO of Gentoo Technologies, Inc.:
- and take a look at the rtirq tool
emerge -av rtirq
no Gentoo specific listed atm, but i'm sure there are issues.
- reiser4 users: forget it!
- PAM RLIMITS - explain the values more in depth
- IRQ tweakage with rtirq - why and how, etc..
- fix typos and grammar :P