by Paul Winkler 9/11/2000
Maintained by Patrick Shirkey
additions by Patrick Shirkey, Eric Rzewnicki, Mark Knecht
Last update Monday 27 October 2008 08:57
For the latest kernel patches and to stay informed about the bleeding edge of realtime kernel lowlatency development visit the Realtime Low Latency Wiki.
For most users the latest 2.6 series kernels are sufficient for low latency. However there are a few things you have to configure. For example make sure you have “Generic PCI bus-master DMA support” on in the kernel, run your root filesystem on ext2 and partition your discs so that your software is not stored on the root filesystem partition. It's also a good idea to have the disc you record to running on a seperate ide bus to the root filesystem disc and you definitely want to mount /tmp to tmpfs.
none /tmp tmpfs defaults 0 0
For audio you will want to use JACK and associated applications. Another important part of latency is getting your interrupt (IRQ) settings correct.
Contributed by Mark Knecht.
This is a simple, or difficult, subject. Due to the history of the PC architecture, PC's first had 1 interrupt controller, and then with the AT architecture, added a second. This accounts for the sort of strange numbers I'm going to give you next.
Here's the order of interrupt priority on a non-APIC machine:
0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 3, 4, 5, 6, 7
0 is the highest priority
7 is the lowest priority
Potentially 9, 10, 11, 3, 4, 5, 6, 7 are made available to PCI slots on many motherboards. I won't go into why the order is this way, but it is. You MUST look at your SPECIFIC motherboard to know what's available to you. Many newer mobos allow you to change the irq settings for the pci interface in the BIOS. This is also useful for USB devices as the usb IRQ generally tags along with one of the pci slots. So you may be able to change the IRQ for your USB card by adjusting the the BIOS settings for the PCI slots. If you cannot adjust the settings in the BIOS your other option is to juggle the cards around the available slots. (NB - requires opening your case)
In my experience all audio cards want to be on IRQ's 9, 10 or 11. It isn't actually that important WHAT IRQ a card is on, but it IS IMPORTANT what devices are on higher IRQs. For instance, if Steve's audio card is on IRQ 11, and nothing is on IRQ 9 or 10, then no problem. But if Steve was to insert a PCI graphics adapter on IRQ9, his audio card could start having trouble because the graphics adapter would have higher priority.
Again, I won't go into all the reasons why, but just assume that any device with a higher priority number (from the list above) gets in the way of devices with lower priorities.
One last thing about non-APIC, interrupts may be shared. Just because your card is on IRQ9 doesn't mean that another device isn't sharing IRQ9. What matters in this case is how many interrupts the other device is going to generate, and how well it's driver is written.
There are a few ways to do this. The easiest is to
cat /proc/interrupts
But you can get more information from running
lspci -v
If you want to find the IRQs for your usb device you need to look for the usb bus controller and then compare its number with the results from.
lsusb
The kernel must be configured to assign different vector numbers to specific interrupts. The standard kernel cannot do this but Clemens Ladisch has written a patch which adds this capability.
This document is specifically aimed at those interested in using 2.4.x with Andrew Morton's low-latency patch for audio purposes.
It's not really hard when you know what to do, but there's a lot of stuff to upgrade before you can compile and install the kernel if you are moving from linux 2.2.x. So if you are, don't forget to read the section on updating your system files.
We suggest scanning through this whole document to get an overview before you start mucking with the kernel. Everything described here requires kernel configuration, and it's easier to do it all in one go rather than rebuilding the kernel again for each feature you want. You should also read through the necessary upgrades to make sure you have all your software in order before you start configuring.
$ ls -l total 4 lrwxrwxrwx 1 root src 12 Jul 22 13:46 linux -> linux-2.2.16 drwxr-xr-x 14 root root 4096 Jul 21 22:59 linux-2.2.16
If that's the case, remove the link:
rm /usr/src/linux
Otherwise, if /usr/src/linux is a directory and not a symlink, rename it so the name includes the kernel version, e.g.:
mv /usr/src/linux /usr/src/linux-2.2.16
mv linux linux-2.4.x
ln -s /usr/src/linux-2.4.x /usr/src/linux
cd /usr/src/ patch -p0 < /dir/where/you/put/2.4.x-low-latency.patch
This should patch without any problems. However some people have found that this works better:
cd /usr/src/linux patch -p1 < /dir/where/you/put/2.4.x-low-latency.patch
or
gzip -cd patchXX.gz | patch -p0
YMMV
cp /usr/src/linux-2.2.x/.config /usr/src/linux
make oldconfig
cat /proc/sys/kernel/lowlatency
should yield “1” or 'on'. if not
echo 1 > /proc/sys/kernel/lowlatency
to turn it on. Building your kernel with “Low latency scheduling” and “Control low latency with sysctl” will give you a /proc/sys/kernel/lowlatency file which you can echo 0 or 1 to to disable or enable low latency patches dynamically in the kernel. This is usually done through /etc/sysctl.conf:
# # /etc/sysctl.conf - Configuration file for setting system variables # See sysctl.conf (5) for information. # kernel/lowlatency = 1
This file is executed by /etc/init.d/procps on startup or can be run manually as root with 'sysctl -p'. If you build your kernel only with 'Low latency scheduling' then low latency will be enabled by default and there will be no way to disable the low latency patches short of recompiling your kernel. If you want to double check if your kernel is patched with the low latency patches, I'm assuming Andrew Morton's patches, either repatch or check for existence of /include/linux/lowlatency.h.
Here's a particularly useful sequence:
Alt-Sysrq-k - kills all programs on current console
Alt-Sysrq-e - Drops to a login terminal
Alt-Sysrq-s - attempts to sync all mounted filesystems
(wait a moment after this... if you have a working
console, you should see an "OK" message when it's done)
Alt-Sysrq-u - attempts to remount all filesystems read-only
Alt-Sysrq-b - force immediate reboot without sync or unmount
By doing this, you can greatly reduce the chance of filesystem damage, and even avoid needing to fsck on reboot. I find that if the freeze happens while I'm in X, I'm usually unable to get the screen back, but I can do a safe reboot. Note that some of the key combinations seem to work with one Alt key and not the other… but it's not consistent, I don't know why. Try both Alt keys.
vi Makefile ... EXTRAVERSION = -ll-box1-0
none /dev/shm tmpfs defaults 0 0
And make the directory: mkdir /dev/shm
It won't affect booting an old linux 2.2 kernel - you'll just get a complaint that the kernel does not support the shm filesystem. While you are editing /etc/fstab you can also mount your /tmp/jack directory in RAM. This solution reduces the audio buffer overruns and therefore greatly improves JACKs performance if you are using a journalling filesystem (as recommended above) but you will loose all data in this dir on shutdown. Other *nix's use this approach.
none /tmp/jack tmpfs defaults 0 0
There is more information on this in the JACK FAQ.
make dep make clean make bzImage
Next check to see that the compile succeeded. There is nothing more frustrating than removing the files below before you find out that there was a problem you didn't notice while compiling. Usually compile problems are because of missing module dependencies. Often the output will look normal but you will know for sure there was something missing from the config if you don't have a System.map. If you do then proceed below, if you don't then you need to hunt down the missing dep. Sometimes the location of the dependency changes between kernel versions. If you are using a 'pre' kernel you may even have to to patch a file by hand.
ls System.map (check to see that the compile succeeded) rm -f /boot/System.map cp System.map /boot/System.map rm -f /boot/bzImage cp arch/i386/boot/bzImage /boot/bzImage-2.4.x
image=/boot/bzImage-2.4.x
label=linux-2.4.x
read-only
root=/dev/whatever_you_use
If you also want to use your cdwriter, or rip audio from a CD, there's one more thing to add in lilo.conf before you'll be able to use the drive:
append="hdX=scsi hdX=ide-scsi"
… replacing X with the drive letter of your IDE cd drive, e.g. my CD drive is /dev/hdc. (I'm not clear on which of those options is actually needed, I think it may have changed at some point. I have both options, which seems to be safe - the invalid one is ignored.) If you already have an “append” line in lilo.conf, just add the text in quotes.
/sbin/lilo
As always, running LILO is VERY important. You won't be able to boot the new kernel until you do so. This is especially important if you ever remove your old kernel!
rm /dev/cdrom ln -s /dev/srN /dev/cdrom OR ln -s /dev/scdN /dev/cdrom
(either one should work) Once again, replace N in these commands with the appropriate number. In my case, I have no real SCSI devices, so I choose /dev/sr0. Be sure that your /etc/fstab has an entry for your CDROM device that points to the correct device. The device can either be /dev/cdrom if you've updated that symlink, or it can be /dev/srN as described above. Now that you've got everything ready, try mounting a data CD to make sure that still works. Also try playing an audio cd. Next, try ripping and/or burning. Useful tools include cdrecord and cdparanoia. More information can be found in the CD-Writing HOWTO, which may be in your installed documentation, or check here: http://www.tldp.org/HOWTO/CD-Writing-HOWTO.html
There's a few things you need to do before you can load modules with 2.4.
insmod -V
See below for the correct version number. Hopefully you won't have to, but if you do then you need to download the modutils package. Compile and install it now, or use your distribution's latest available package. Make sure your old modutils is gone!