UbuntuHelp:HowToVanillaKernelWithRealtimePreemption
来自Ubuntu中文
To get to the goal of true real-time, low-latency audio work under Linux, you will absolutely require Realtime-Preemption. Ingo Molnar, who currently works for Red Hat, wrote a patch that will apply to the the official vanilla kernel sources. This patch gives you roughly 95% preemption, as compared to about 50% preemption without the patch. If you don't think you need the extra preemption, you can stick with Dapper's default kernel.
Take note that if you follow this tutorial, you may lose some of the Ubuntu-specific features that are not supported by the official Linux kernel (generally device driver modules). This should only affect a small group of users, but if you find that a particular piece of hardware stops working with this kernel, you may require additional manual patching.
Firstly, get the latest patch from http://people.redhat.com/mingo/realtime-preempt/. At the time of writing, the latest patch listed there is patch-2.6.16-rt26. We also will want the bd-claim.patch as well, which fixes EVMS (one of the things Ubuntu's patched kernel fixes).
sudo su cd /usr/src wget http://people.redhat.com/mingo/realtime-preempt/older/patch-2.6.16-rt26 apt-get install kernel-patch-evms gunzip kernel-patches/diffs/evms-bd-claim/2.6-bd-claim.patch.gz </code> Now download the latest matching official kernel source from [http://www.kernel.org/ http://www.kernel.org/]. At the time of writing, the latest kernel is 2.6.16 (do not use the 2.6.16.x kernels, they will cause issues when patching!). <pre> wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.tar.bz2 tar jxf linux-2.6.16.tar.bz2 mv linux-2.6.16 linux-2.6.16-rt26 mv linux linux.old ln -s linux-2.6.16-rt26/ linux </code> If you use the NVIDIA module for your video, you can prepare to make the deb package for this as well: <pre> apt-get install nvidia-kernel-source tar zxf nvidia-kernel-source.tar.gz </code> ''There are other modules that you may require as well. Please add them to the wiki here if you have the package names. If you require assistance, post on the discussion page of this wiki and one of the editors will hopefully be able to assist you.'' Now, let's patch the kernel source. <pre> cd linux/ patch -sp1 < ../patch-2.6.16-rt26 patch -sp1 < ../kernel-patches/diffs/evms-bd-claim/2.6-bd-claim.patch </code> For other patches, test them first without making changes using the --dry-run option. If the test applied cleanly, successfully, then apply your extra patch. If you like the fancy Ubuntu screen while booting, you can apply the bootsplash patch. <pre> cd .. wget ftp://ftp.bootsplash.org/pub/bootsplash/kernel/bootsplash-3.1.6-2.6.15.diff cd linux/ patch -p1 < ../bootsplash-3.1.6-2.6.15.diff </code> Now, copy the config from Ubuntu's default kernel, install libncurses-dev dependency and run menuconfig. <pre> cp /boot/config-`uname -r` .config apt-get install libncurses-dev build-essential make menuconfig </code> If you have never used menuconfig before, you should learn. Look around, change the settings that you are certain you want to change. In this step, you must change the following settings: * Enable '''Processor type and features > High Resolution Timer Support''' * Set '''Processor type and features > High Resolution Timer resolution (nanoseconds)''' to ''1000''. * Set '''Processor type and features > Processor family''' to the type of CPU in your system. * Set '''Processor type and features > Preemption Mode''' to ''Complete Preemption (Real-Time)''. * Set '''Processor type and features > Timer frequency''' to ''1000 Hz''. * Disable '''Kernel Hacking > Kernel debugging''' Once you have done that, Exit from menuconfig and select Yes to save your kernel configuration. Now build the kernel and module debs. This step will take a very long time (possibly in the hours range, depending on your hardware). You will need kernel-package installed for this: <pre> apt-get install kernel-package make-kpkg clean make-kpkg modules_clean make-kpkg --revision 1 --initrd kernel_image kernel_headers modules_image </code> Once that is complete with no errors, you can then install the new deb packages: <pre> cd .. dpkg -i *2.6.16-rt26*.deb exit </code> Now you probably want to tell GRUB to remember your default kernel choice. This is optional though, if you don't want to set this, you'll just have to always select your kernel from the GRUB menu at every boot. <pre> nano /boot/grub/menu.lst </code> Change the line that says ''default 0'' to say ''default saved'' located near the top of the file. Next, find the line that says something similar to ''kernel /vmlinuz-2.6.16-rt26 root=/dev/hda2 ro quiet splash'' located nearer the bottom of the file, and remove the word ''splash'' from the end of the line. This will prevent your screen from being blank as your system boots the realtime kernel. Exit nano, saving the changes, and then restart your computer. At the GRUB prompt, hit Esc and choose the kernel from the menu. You will boot into the new kernel with realtime-preemption, allowing you to be as close as currently possible to true, low-latency real-time audio. If something goes wrong, just choose the original kernel from the GRUB menu during bootup, and then remove the kernel packages: <pre> sudo apt-get remove kernel-image-2.6.16-rt26 kernel-headers-2.6.16-rt26 </code> If you installed modules, you can remove them as well: <pre> sudo apt-get remove nvidia-kernel-2.6.16-rt26 </code> [[category:UbuntuHelp]]