Note: if this is the first time ALSA has been installed on this system, install the libraries and utilities from the ALSA website as well. After extracting the drivers package navigate into the new directory (alsa-driver-1.0.14 at the time of writing) and issue the following command:

Note: if this is the first time ALSA has been installed on this system, install the libraries and utilities from the ALSA website as well. After extracting the drivers package navigate into the new directory (alsa-driver-1.0.14 at the time of writing) and issue the following command:

replace <drivers> in the above command to include a comma separated list of the drivers for the sound card(s) on the system. ./configure –-help will give a full list of drivers and options, or find out which driver is needed through the sound card matrix [[Matrix:Main]].

replace <drivers> in the above command to include a comma separated list of the drivers for the sound card(s) on the system. ./configure –-help will give a full list of drivers and options, or find out which driver is needed through the sound card matrix [[Matrix:Main]].

Line 90:

Line 90:

The priorities of these processes will need to be reset after each reboot, so a simple init script would suffice for doing this as the pids shouldn't change. Or use the ''pgrep'' command to locate the threads:

The priorities of these processes will need to be reset after each reboot, so a simple init script would suffice for doing this as the pids shouldn't change. Or use the ''pgrep'' command to locate the threads:

# chrt -f -p 99 `pgrep softirq-timer`

# chrt -f -p 99 `pgrep softirq-timer`

+

+

A more detailed explanation of thread priorities can be found over at the ffado project's wiki: [http://subversion.ffado.org/wiki/IrqPriorities IRQ priorities How-To]

Real-time audio work is a relative idea, latency is inherent when processing audio in the digital domain, however it is possible to get latencies far below perceptible levels. The steps needed to get such results is what this article will address.

To build a new kernel, get the source to it. This can be had from Kernel.org (at the time of writing the latest stable version is 2.6.22). Next get the corresponding real-time kernel patch by Ingo Molnar, which is available from his website. Download the latest version for the choice of kernel version. For example, patch-2.6.22-rt9 for kernel version 2.6.22. Next un-gzip the patch in the directory of the kernel source and apply it. This is usually done with patch -p1 -i patch-2.6.xx.x-rtx.

Configure the newly patched kernel. Use the make menuconfig command on a text console, or make xconfig for a GUI.

Make sure that the drivers needed to boot the system are built in. Usually this is an IDE driver and ext3 file system support. Configure other drivers such as network and video as well as USB/firewire/parallel drivers.

Some prefer leaving the ALSA drivers for their sound card out of the initial kernel configuration, as they like to download the latest version from the ALSA website and build them later. Enable sound card support within “Device Drivers”. Building and installing the ALSA drivers will be covered later.

Navigate to the “Processor type and features” category. There will be an option “Preemption mode”. Set this to “Complete Preemption (Real Time)”.

There are also some additional tweaks which are commonly recommended by the Linux Audio Users community:

Note: if this is the first time ALSA has been installed on this system, install the libraries and utilities from the ALSA website as well. After extracting the drivers package navigate into the new directory (alsa-driver-1.0.14 at the time of writing) and issue the following command:

replace <drivers> in the above command to include a comma separated list of the drivers for the sound card(s) on the system. ./configure –-help will give a full list of drivers and options, or find out which driver is needed through the sound card matrix Matrix:Main.

Once the ALSA system is configured type the make command to build it.

Then, as root type make install to install the ALSA modules into the /lib/modules/<kernel version> directory.

After ALSA is installed modify the PAM security system to allow regular users to operate software at a high priority (real time) level. Edit /etc/security/limits.conf as root (in Debian based systems). Add the following lines to limits.conf:

@audio - rtprio 95
@audio - memlock 512000
@audio - nice -19

This is from Florian Schmidt's website and is a starting point only, though it should work nicely for any system. The rtprio setting is the maximum priority a user of the audio group can run a task. The memlock setting is the maximum amount of memory that a member of the audio group can lock with a realtime task. This should be less than the maximum physical amount of memory, some recommend it to be half. nice is the minimum “nice level” a task can be run as (the willingness of a task to give up it's cpu time). These settings will get jackd, ardour and other RT capable programs runing at higher priorities, but there is still a bit more to do.

The next and final step is to set a few thread priorities. The real time patch should have created several IRQ threads as well as added a “hrtimer” thread. These can be viewed with ps -e. Use the chrt command to set thread priorities (in Debian this is part of the schedutils package). It doesn't matter which order the priorities are set. Scan the output of the ps -e command looking for threads like “softirq-timer” and “softirq-hrtimer”, taking note of the pid of each one (on a dual core system there are two of each, one for each CPU). Find the pid of the IRQ thread that the sound card resides on. Looking at the output of cat /proc/interrupts should reveal this. Set new priorities for each thread:

chrt -f -p 99 6
chrt -f -p 99 12
chrt -f -p 99 818

These will set the threads identified (6, 12, and 818) to a real-time priority level (99). That high of a priority may not be necessary and a bit insecure, feel free to tweak as you see fit. These commands are the last settings that need to be changed and allow the kernel timers to operate on a much higher priority, thus insuring more satisfactory scheduling latencies.

The priorities of these processes will need to be reset after each reboot, so a simple init script would suffice for doing this as the pids shouldn't change. Or use the pgrep command to locate the threads:

# chrt -f -p 99 `pgrep softirq-timer`

A more detailed explanation of thread priorities can be found over at the ffado project's wiki: IRQ priorities How-To

It is a common problem to experience problems of many types when dealing with APIC enabled kernels and motherboards. These can range from dificulties in setting IRQs to full system lockups when using certain IRQs. If you experience any new problems after booting a real-time patched kernel try adding the noapic boot option to grub and see if that solves the problem, also, if the processor is single core, or there is no need for a kernel optimized for dual core processors then you can try disabling IO-APIC in the kernel config.