User Tools

Site Tools


adjusting_audio_latency

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
adjusting_audio_latency [2019/05/01 08:26]
phatsodj Changed link to "Native Instruments Wndows Tuning tips"
adjusting_audio_latency [2019/12/19 03:02] (current)
be.ing [Disable HyperThreading/SMT]
Line 2: Line 2:
  
 The smaller the Audio Buffer you select in Mixxx'​s Sound Hardware Preferences,​ the faster you will hear changes when you manipulate controls in Mixxx, on a controller, or with timecode vinyl. However, lowering it beyond what your system can handle will cause audible glitches (pops). Here are some tips to configure your system to handle lower latency audio: The smaller the Audio Buffer you select in Mixxx'​s Sound Hardware Preferences,​ the faster you will hear changes when you manipulate controls in Mixxx, on a controller, or with timecode vinyl. However, lowering it beyond what your system can handle will cause audible glitches (pops). Here are some tips to configure your system to handle lower latency audio:
 +
 +===== All operating systems =====
 +==== Disable HyperThreading/​SMT ====
 +Simultaneous Multithreading (SMT), or HyperThreading (HT) as Intel calls it, can make some programs faster but makes realtime audio software like Mixxx much more likely to glitch. Most modern computers have SMT enabled by default. On some computers, it can be disabled in the BIOS/EFI firmware settings when booting your computer. These settings can be accessed by pressing a key as the computer is turning on. Which key you need to press is different on every computer, so watch if it says on screen or refer to the computer manufacturer'​s documentation. Unfortunately some computers do not have an option to disable SMT/​HyperThreading in the BIOS/EFI settings. On these computers, SMT can still be disabled when using Linux by setting the "​nosmt"​ kernel parameter as [[#Disable HyperThreading/​SMT1|described below]].
 +
 +SMT makes the CPU appear to the OS as if each physical CPU core was 2 cores (thus a dual core processor seems like it has 4 cores or a quad core processor seems like it has 8 cores). This allows two threads to switch off between using one CPU core, which may be beneficial for software that makes heavy use of parallel processing. However, realtime audio software like Mixxx requires reliable, uninterrupted time to use the CPU to avoid audio glitches (xruns). When two threads share the same CPU core with SMT, it is much more likely that Mixxx (or other realtime audio software) will not generate the audio it needs in time so you and your audience will hear a glitch.
  
 ===== Linux ===== ===== Linux =====
 +
 +==== Disable HyperThreading/​SMT ====
 +First, try disabling HyperThreading/​SMT by turning it off in your computer'​s BIOS/EFI settings as [[#Disable Hyperthreading/​SMT|described above]]. If that option is not available on your computer, SMT can be disabled by Linux by adding "​nosmt"​ to the kernel boot parameters. How to do this may vary depending on your distribution,​ so refer to your distribution'​s documentation for details. On Fedora, edit the text file /​etc/​default/​grub as root. There should be a line that shows something like:
 +<​code>​
 +GRUB_CMDLINE_LINUX="​rd.lvm.lv=fedora/​root rd.luks.uuid=luks-8847b15d-fd3c-4b93-a107-1e5166685508 rd.lvm.lv=fedora/​swap rhgb quiet"
 +</​code>​
 +Add the "​nosmt"​ parameter to the end of this:
 +<​code>​
 +GRUB_CMDLINE_LINUX="​rd.lvm.lv=fedora/​root rd.luks.uuid=luks-8847b15d-fd3c-4b93-a107-1e5166685508 rd.lvm.lv=fedora/​swap rhgb quiet nosmt"
 +</​code>​
 +Then, regenerate your GRUB configuration file:
 +<​code>​
 +grub2-mkconfig -o /​boot/​efi/​EFI/​fedora/​grub.cfg
 +</​code>​
 +On other distributions,​ use "​grub-mkconfig"​ instead of "​grub2-mkconfig"​ and the file path grub.cfg (after the "​-o"​) will change as well. Then reboot your computer.
 +
 +SMT can also be toggled while Linux is running with the command:
 +<​code>​
 +echo off > /​sys/​devices/​system/​cpu/​smt/​control
 +</​code>​
 +but this will be reset when you reboot unless you change the kernel boot options as described above. You can also use
 +<​code>​
 +echo on > /​sys/​devices/​system/​cpu/​smt/​control
 +</​code>​
 +to turn it back on if you want to test the impact of having it on versus off.
  
 ==== Enable realtime scheduling ==== ==== Enable realtime scheduling ====
Line 10: Line 41:
  
 === Kernel setup === === Kernel setup ===
-To use real time scheduling, you will either need to boot Linux with the "​threadirqs"​ parameter or use a kernel with the [[https://rt.wiki.kernel.org/index.php/Main_Page|realtime patch set]]. To always boot with the "​threadirqs"​ kernel argument, add it to your grub.cfg by editing /​etc/​default/​grub as root, adding "​threadirqs"​ to the line for GRUB_CMDLINE_LINUX,​ then generate a new grub.cfg file. On most distributions,​ do this by running ''​grub-mkconfig -o /​boot/​grub/​grub.cfg''​. On Fedora, run ''​grub2-mkconfig -o /​boot/​grub2/​grub.cfg''​ if you boot with BIOS (legacy) or ''​grub2-mkconfig -o /​boot/​efi/​EFI/​fedora/​grub.cfg''​ if you boot with EFI (if /boot/efi does not exist, you boot with BIOS). Reboot. Check that you have booted with the "​threadirqs"​ kernel parameter by running ''​grep threadirqs /​proc/​cmdline''​. If you booted with the "​threadirqs"​ kernel parameter, all the parameters you booted with will be printed. If there is no output, you did not boot with the "​threadirqs"​ kernel parameter.+To use real time scheduling, you will either need to boot Linux with the "​threadirqs"​ parameter or use a kernel with the [[https://​wiki.linuxfoundation.org/realtime/start|realtime patch set]]. To always boot with the "​threadirqs"​ kernel argument, add it to your grub.cfg by editing /​etc/​default/​grub as root, adding "​threadirqs"​ to the line for GRUB_CMDLINE_LINUX,​ then generate a new grub.cfg file. On most distributions,​ do this by running ''​grub-mkconfig -o /​boot/​grub/​grub.cfg''​. On Fedora, run ''​grub2-mkconfig -o /​boot/​grub2/​grub.cfg''​ if you boot with BIOS (legacy) or ''​grub2-mkconfig -o /​boot/​efi/​EFI/​fedora/​grub.cfg''​ if you boot with EFI (if /boot/efi does not exist, you boot with BIOS). Reboot. Check that you have booted with the "​threadirqs"​ kernel parameter by running ''​grep threadirqs /​proc/​cmdline''​. If you booted with the "​threadirqs"​ kernel parameter, all the parameters you booted with will be printed. If there is no output, you did not boot with the "​threadirqs"​ kernel parameter.
  
 To use a kernel with the realtime patch set, Fedora users can install the kernel-rt package from the [[http://​ccrma.stanford.edu/​planetccrma/​software/​|Planet CCRMA]] repository. Ubuntu users can install the [[https://​help.ubuntu.com/​community/​UbuntuStudio/​RealTimeKernel|kernel-rt or kernel-lowlatency]] packages. [[http://​nongnu.org/​crossfade|Crossfade]] and [[http://​ubuntustudio.org/​|Ubuntu Studio]] are distributions that come with a realtime patched kernel. Arch Linux users can install the [[https://​aur.archlinux.org/​packages/​linux-rt/​|linux-rt]] or [[https://​aur.archlinux.org/​packages/​linux-rt-lts/​|linux-rt-lts]] packages. Note that kernels with the realtime patch set may have some stability issues. To use a kernel with the realtime patch set, Fedora users can install the kernel-rt package from the [[http://​ccrma.stanford.edu/​planetccrma/​software/​|Planet CCRMA]] repository. Ubuntu users can install the [[https://​help.ubuntu.com/​community/​UbuntuStudio/​RealTimeKernel|kernel-rt or kernel-lowlatency]] packages. [[http://​nongnu.org/​crossfade|Crossfade]] and [[http://​ubuntustudio.org/​|Ubuntu Studio]] are distributions that come with a realtime patched kernel. Arch Linux users can install the [[https://​aur.archlinux.org/​packages/​linux-rt/​|linux-rt]] or [[https://​aur.archlinux.org/​packages/​linux-rt-lts/​|linux-rt-lts]] packages. Note that kernels with the realtime patch set may have some stability issues.
Line 44: Line 75:
 The number to watch is the "​Max",​ which tells you the maximum observed latency in microseconds between the desired wake-up time and the actual wake-up time. For a ''​SCHED_FIFO''​ thread on a realtime kernel, a max latency of under 10 microseconds is easily achievable. For a generic kernel, this will be harder. The number to watch is the "​Max",​ which tells you the maximum observed latency in microseconds between the desired wake-up time and the actual wake-up time. For a ''​SCHED_FIFO''​ thread on a realtime kernel, a max latency of under 10 microseconds is easily achievable. For a generic kernel, this will be harder.
  
-To see how a non-realtime thread behaves, try ''​--policy other'',​ which uses the ''​SCHED_OTHER''​ scheduling policy (the default).+To see how a non-realtime thread behaves, try ''​%%--%%policy other'',​ which uses the ''​SCHED_OTHER''​ scheduling policy (the default).
  
 ==== Raise the IRQ priority of your sound card ==== ==== Raise the IRQ priority of your sound card ====
Line 62: Line 93:
 </​code>​ </​code>​
  
-Alternately,​ you can use the ''​cpupower''​ utility: ''​sudo cpupower frequency-set -g performance''​.+Alternately,​ you can use the ''​cpupower''​ utility: ''​sudo cpupower frequency-set -g performance''​
  
 The CPU governor will be reset when rebooting your computer. To run this every time your computer boots, save the above shell script to /​etc/​rc.d/​rc.local and set that file to be executable ''​chmod +x /​etc/​rc.d/​rc.local''​ (this should work even on distributions using systemd). Note that this will run through your battery'​s charge much faster. The CPU governor will be reset when rebooting your computer. To run this every time your computer boots, save the above shell script to /​etc/​rc.d/​rc.local and set that file to be executable ''​chmod +x /​etc/​rc.d/​rc.local''​ (this should work even on distributions using systemd). Note that this will run through your battery'​s charge much faster.
adjusting_audio_latency.1556713568.txt.gz ยท Last modified: 2019/05/01 08:26 by phatsodj