Building your own real-time kernel

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

User avatar
autostatic
Established Member
Posts: 1994
Joined: Wed Dec 09, 2009 5:26 pm
Location: Beverwijk, The Netherlands
Has thanked: 32 times
Been thanked: 104 times
Contact:

Re: Building your own real-time kernel

Post by autostatic »

DJ Barney wrote:Apologies if that sounds over critical in any way. Some may prefer the more technical path. But I'm concerned that I see some confusion out there about what is the major strength of Linux when it comes to music production ... real time capability, customisation, and on the most part up to date hardware support if one is prepared to wait a little for patches (or can write their own).
No need to apologize! I really wasn't aware of the method you're describing and to me it looks like a very simple way to build a real-time kernel for Debian. Maybe I'll add it to the Wiki, but first I'll give it a testdrive myself :).
And if the method described in the Wiki is too technical than I should work on making it easier to understand what each step does. The method in the Wiki does allow you to make some changes in the kernel config that could improve the Linux audio experience. That's why I started this thread actually, I really want to know what people tweak in their kernel configs regarding Linux audio. But new methods to actually build a real-time kernel are always welcome.
User avatar
Michael Z Freeman
Established Member
Posts: 43
Joined: Thu Dec 17, 2009 1:49 pm
Location: England
Contact:

Re: Building your own real-time kernel

Post by Michael Z Freeman »

AutoStatic wrote:
DJ Barney wrote:Apologies if that sounds over critical in any way. Some may prefer the more technical path. But I'm concerned that I see some confusion out there about what is the major strength of Linux when it comes to music production ... real time capability, customisation, and on the most part up to date hardware support if one is prepared to wait a little for patches (or can write their own).
No need to apologize! I really wasn't aware of the method you're describing and to me it looks like a very simple way to build a real-time kernel for Debian. Maybe I'll add it to the Wiki, but first I'll give it a testdrive myself :).
I'd be very interested to see if you get the same results :mrgreen:
And if the method described in the Wiki is too technical than I should work on making it easier to understand what each step does. The method in the Wiki does allow you to make some changes in the kernel config that could improve the Linux audio experience. That's why I started this thread actually, I really want to know what people tweak in their kernel configs regarding Linux audio. But new methods to actually build a real-time kernel are always welcome.
The method on the wiki looks to be one of the most succinct and accurate descriptions I've seen. One of the wider problems is that Linux kernel development has become mature (as of quite a few years ago some would say). The Linux kernel is now a big busy fast moving place, but possibly at the expense of accurate documentation when it comes to kernel development. There are a lot of outdated and just plain inaccurate or misleading guides out there. the best one of found is here - http://users.wowway.com/~zlinuxman/Kernel.htm

That identifies one method that I've never found described anywhere ...
It used to be a real pain to create a "lean and mean" custom kernel: one which only contains the function necessary to execute on your specific machine. It can easily take all day to customize the kernel configuration to get everything you need but nothing that you don't need, and it is easy to leave something out that you need but don't realize that you need. However, starting with kernel version 2.6.32, a new kernel configuration option is available called "make localmodconfig". Initialize the .config file, either by copying it from the stock kernel config file in /boot or by running "make menuconfig" with no previous .config file, then run the preceding command. It runs "lsmod" to find all the modules loaded on the currently running system. It will then read all the Makefiles to map which CONFIG enables which module. It will then read the Kconfig files to find the dependencies and selects that may be needed to support a CONFIG. Finally, it reads the .config file and removes any module ("=m") that is not needed to enable the currently loaded modules. With this tool, you can strip the .config file of all drivers which are not useful in your machine, and it will take much less time to build the kernel. 80% compile time reduction seems to be typical.
I have not tried it but it sure sounds like it beats going through config options manually :P

There must be many other methods and tweaks that can get latency right down below 10ms. For example the Mixxx site says this ...
For best scratch performance with vinyl control, your system must be able to handle setting the latency to 10ms or less ...
( Source: http://mixxx.org/wiki/doku.php/vinyl_control )

So although I can use vinyl control I'm only just on the threshold of being able to use my Serrato record at full performance..

Another thing. If you ask me technical configuration advice or methods should all have references to Kernel.org sources. Selecting any of the Gitweb links on that page will allow searching of up to date Kernel sources and documentation. This is especially important when setting up a professional production system, such as those used in recording studios or in live performances. It's just as important as, for example, being a factory manager who has to insure real-time performance of robots on his production line ... otherwise his car does not get built properly. Same with a music track.
User avatar
autostatic
Established Member
Posts: 1994
Joined: Wed Dec 09, 2009 5:26 pm
Location: Beverwijk, The Netherlands
Has thanked: 32 times
Been thanked: 104 times
Contact:

Re: Building your own real-time kernel

Post by autostatic »

DJ Barney wrote:I'd be very interested to see if you get the same results :mrgreen:
I'll report back!
DJ Barney wrote:The method on the wiki looks to be one of the most succinct and accurate descriptions I've seen. One of the wider problems is that Linux kernel development has become mature (as of quite a few years ago some would say). The Linux kernel is now a big busy fast moving place, but possibly at the expense of accurate documentation when it comes to kernel development. There are a lot of outdated and just plain inaccurate or misleading guides out there. the best one of found is here - http://users.wowway.com/~zlinuxman/Kernel.htm
Nice one, good catch! Very informative stuff, thanks.
DJ Barney wrote:I have not tried it but it sure sounds like it beats going through config options manually :P
I'm definitely going to try this out. I'm already using a quite fast machine to compile my kernels but if I could do it in a few minutes, that'd be awesome.
DJ Barney wrote:There must be many other methods and tweaks that can get latency right down below 10ms.
It's not just the kernel that helps to achieve this. Fwiw, I easily achieve 8ms of software latency (128/48000*3), it's my default setting. When working with softsynths or Guitarix I take it a notch down to 4ms (64/48000*3). I could go lower but then I have little headroom regarding DSP load. A real-time kernel definitely plays a big part in this but it's also all the other stuff mentioned in the System Configuration Wiki page.
User avatar
autostatic
Established Member
Posts: 1994
Joined: Wed Dec 09, 2009 5:26 pm
Location: Beverwijk, The Netherlands
Has thanked: 32 times
Been thanked: 104 times
Contact:

Re: Building your own real-time kernel

Post by autostatic »

Tried make localmodconfig and it reduced the outcoming linux-image package with about two thirds. Definitely a keeper!
brummer

Re: Building your own real-time kernel

Post by brummer »

AutoStatic wrote:Tried make localmodconfig and it reduced the outcoming linux-image package with about two thirds. Definitely a keeper!
Indeed a really nice one, reduce my image size from 34MB to 6,4MB, with a somewhat shorter build-time :D
brummer

Re: Building your own real-time kernel

Post by brummer »

. . . but it still need a bit more attention to get all needed modules build, special microcode loader and usb drivers must manually enabled, same is true for vfat/msdos file system support, if you would like to mount your mobile device.
User avatar
autostatic
Established Member
Posts: 1994
Joined: Wed Dec 09, 2009 5:26 pm
Location: Beverwijk, The Netherlands
Has thanked: 32 times
Been thanked: 104 times
Contact:

Re: Building your own real-time kernel

Post by autostatic »

On my notebook I've had some lockups with a real-time kernel build after using make localmodconfig. So when using this make routine be aware that you might end up with a kernel that lacks necessary features.
User avatar
bluebell
Established Member
Posts: 1924
Joined: Sat Sep 15, 2012 11:44 am
Location: Saarland, Germany
Has thanked: 112 times
Been thanked: 119 times

Re: Building your own real-time kernel

Post by bluebell »

I once patched a kernel to make it realtime (threads for interrupt handling) but that patch was incompatible with the VirtualBox modules. I got crashs. Since I don't have a dedicated system/OS for musical purposes I want to use my "all day"-PC for Rosegarden, too.

The most important result regarding less xruns is HZ1000. Because it sounds good I chose a Low-Latency Desktop model as well.

So I use a stock kernel from my distribution and change 2 things:

make menuconfig
-> Processor type and features
---> Preemption Model: Low-Latency Desktop
---> Timer Frequency: 1000 HZ

That makes a big difference avoiding xruns so I can use 3 buffers with 64 frames/period with my Focusrite Scarlett 2i2 (USB) without having xruns in normal operation.

Ending Rosegarden or starting Audacity from within Rosegarden causes some xruns, maybe because of internal reconfigurations in JACK. But that's all.

Recipe:
- Getting the Kernel source (in my case linux-source-3.2.0, Ubuntu 12.04 LTS)
- make menuconfig
Processor type and features
Preemption Model: Low-Latency Desktop
Timer Frequency: 1000 HZ
- make-kpkg clean
- fakeroot make-kpkg -j 4 --initrd --revision=1.0.hm kernel_image kernel_headers
(My PC has 4 cores so I can use "-j 4" to fully load my CPU)

Then I get linux-headers-3.2.31_1.0.hm_amd64.deb and linux-image-3.2.31_1.0.hm_amd64.deb and can "dpkg -i" them.

Linux – MOTU UltraLite AVB – Qtractor – http://suedwestlicht.saar.de/

User avatar
raboof
Established Member
Posts: 1855
Joined: Tue Apr 08, 2008 11:58 am
Location: Deventer, NL
Has thanked: 50 times
Been thanked: 74 times
Contact:

Re: Building your own real-time kernel

Post by raboof »

bluebell wrote:Because it sounds good I chose a Low-Latency Desktop model as well.
That's the "preemption model" - choices are 'No Forced Preemption (Server)', 'Voluntary Kernel Preemption (Desktop)' and 'Preemptible Kernel (Low-Latency Desktop)'. Indeed I think you want the latter for real-time audio.
That makes a big difference avoiding xruns so I can use 3 buffers with 64 frames/period with my Focusrite Scarlett 2i2 (USB) without having xruns in normal operation.
Cool good to hear
User avatar
Michael Z Freeman
Established Member
Posts: 43
Joined: Thu Dec 17, 2009 1:49 pm
Location: England
Contact:

Re: Building your own real-time kernel

Post by Michael Z Freeman »

Need some help. I had some trouble building the latest Debian Kernel for RT with high resolution timers. This, ironically, because I'm not having to apply patches this time. So I can't use "test_patches". The standard Debian build method is not working, for me or I'm not understanding the method correctly.

However I wonder if I even have to build my own kernel ? I have seen suggestions that Hydrogen, Ardour and so forth don't even use the hardware based (HPTC, etc) Kernel timers and make their timing using another method. How true is this ? The only reason I'm building is to put in the kernel config settings for the hardware (MB based) high resolution timer. If I don't have to then I can use a stock RT kernel.
User avatar
Michael Z Freeman
Established Member
Posts: 43
Joined: Thu Dec 17, 2009 1:49 pm
Location: England
Contact:

Re: Building your own real-time kernel

Post by Michael Z Freeman »

Thought I'd update this again for the confused out there. The standard advice out there is to enable high resolution timers (the actual hardware timers on the motherboard) in the Kernel. However this is now obsolete except for applications that specifically require those timers (Rosegarden I think). If you are using Jack and anything that uses Jack alsa for the MIDI timing then you DO NOT need these timers !

I installed the stock debian RT kernel (which does not have the HR timers in its config) and am getting better performance as reported by QJackCtl ... zero XRuns where before I would get them when switching applications, loading the browser, etc. I have not exhaustively checked the midi timing but Hydrogen and so forth are functioning OK.

From #ardour (Freenode) ...

Code: Select all

grobda24 | Does Ardour require HPTC/RTC (whatever it is) kernel hardware based high resolution timers to be available for MIDI
rgareus  | grobda24: no                  
grobda24 | rgareus: ha HA ! (hello!)
rgareus  | grobda24: ahoy.                                                                                                   
grobda24 | that gets me excited because I was having to build the kernel just for those timers
rgareus  | grobda24: older ALSA_seqeuencer only apps e.g rosegarden, qtractor use the high-precision or realtime clock
rgareus  | grobda24: but JACK (and a2jmidid) don't
rgareus  | grobda24: but a2jmidi uses the ALSA-built-in high-resolution timer (kernel-module snd_hrtimer)                  
grobda24 | rgareus: interesting. any idea about Hydrogen ?
rgareus  | grobda24: I don't know. but I hazard a guess that it's using RTC, too. (unless it also has suport for jack-midi these days ?!)  
User avatar
autostatic
Established Member
Posts: 1994
Joined: Wed Dec 09, 2009 5:26 pm
Location: Beverwijk, The Netherlands
Has thanked: 32 times
Been thanked: 104 times
Contact:

Re: Building your own real-time kernel

Post by autostatic »

Thanks for the info! I'll add it to the wiki.
User avatar
khz
Established Member
Posts: 1648
Joined: Thu Apr 17, 2008 6:29 am
Location: German
Has thanked: 42 times
Been thanked: 92 times

Re: Building your own real-time kernel

Post by khz »

.. needed information to configure your kernel ...

http://kernel-seeds.gentoostudio.org/working.html
http://kmuto.jp/debian/hcl/
. . . FZ - Does humor belongs in Music?
. . GNU/LINUX@AUDIO ~ /Wiki $ Howto.Info && GNU/Linux Debian installing >> Linux Audio Workstation LAW
  • I don't care about the freedom of speech because I have nothing to say.
Shadow_7
Established Member
Posts: 175
Joined: Tue Jun 08, 2010 3:35 pm

Re: Building your own real-time kernel

Post by Shadow_7 »

AutoStatic wrote:Tried make localmodconfig and it reduced the outcoming linux-image package with about two thirds. Definitely a keeper!
Be cautious when using that. It removes a lot of modules. Like every filesystem or device that is not currently in use on the local machine. For example iso9660 support, or loopback to mount an iso image locally without burning a disc.
emarsk
Established Member
Posts: 96
Joined: Wed Jul 27, 2011 3:50 pm

Re: Building your own real-time kernel

Post by emarsk »

khz wrote:.. needed information to configure your kernel ...

http://kernel-seeds.gentoostudio.org/working.html
http://kmuto.jp/debian/hcl/
I'd just add a couple more rt specific:
http://gentoostudio.org/?p=maninstall&s=kernel
http://proaudio.tuxfamily.org/wiki/inde ... orkstation

And just a note of about this site:
http://kernel-seeds.org/
You'll find precious infos about kernel settings, and barebone .config files to use as a minimal starting point.
Don't miss it! It's real gold.
Please, avoid some common spelling errors:
http://theoatmeal.com/comics/misspelling
Post Reply