...ArchBang Linux is very good for audio after proper configuration...
O Hay Cool People! So, I went for a try of ArchBang Linux (yeah, I'm a noob of ArchBang and Arch...) and I fell in love for it's exquisite lightweight Arch-based performances. So, I installed it and tweaked a little in order to get lowlatency. The results I found are very promising! In the following I'll briefly speak about the tweaking I made on the system while linking the pages I used as base. All the tweaking were performed on a fresh install, after a full system update and are based on info I collected online, mostly from Pro-Audio Gentoo Overlay, Linuxaudio and the Arch Pro Audio guide. This tutorial is mostly intended to sum up all the useful info and act as a quick reference memorandum and links bookmark (Is why I think that it could be useful). So don't expect deep explanations of Arch and ArchBang (I said: I'm a noob), everything will be explained at the linked pages. Let's go!
When talking about package installation please refer to Arch and ArchBang resources for explanations and howtos (the packages are from both repos and AUR). Most of this tweaking are not OS specific, however carefully extend them to your OS (some command, path, package name etc... etc... could be different or need to be treated in another way). Keep in mind that you are experimenting with your system. Be careful and don't make actions you think could be dangerous for system and data. Reading the linked pages is strongly recommended: if done it will minimize the risk of ruining the system. Also, understanding what you are doing will be easier (and maybe you can understand how optimize this tweaking for your particular situation... or maybe you could suggest some further tweaking for my system ).
After a fresh install I found my user in the audio group, with jack installed... cool! First of all we need a comfortable tool to manage CPU governors. I recommend to install cpupower (WARNING: if you are using a laptop that could be a bad idea... See the UPDATE 4). Here what to know. We will set the governors to "performance" when making music. Then we install systemd-rtirq (check the "UPDATE 2:" at the bottom of the post) and we enable it with
Code: Select all
systemctl enable rtirq
We will also have to boot the kernel with threadirqs option enabled. To do it edit the file /etc/default/grub by changing the argument of GRUB_CMDLINE_LINUX="" to this:
Code: Select all
GRUB_CMDLINE_LINUX="threadirqs"
Code: Select all
grub-mkconfig -o /boot/grub/grub.cfg
As always we are going to add noatime to the filesystem mount options. To do it we just have to open /etc/fstab with our favorite text editor and put noatime in the options field, making the line of our disk to look like:
Code: Select all
/dev/sda1 / ext4 defaults,noatime 0 1
Code: Select all
vm.swappiness=10
vm.vfs_cache_pressure=50
fs.inotify.max_user_watches = 524288
you can find good explanation of what those lines do at here and here. Is worth enabling real-time prioritizing. For that use the pam package. Follow the instructions to install. The default limits.conf file you find on ArchBang should be enough good, just run:
Code: Select all
pacman -Q --owns /etc/security/limits.conf
Of course, you can edit limits.conf to taste, remember to set up the jack priority at least 10 lower the one you set in rtprio. Also remeber that your user is probably in the audio group since its creation during installation. Now I decided to have a try with cgroups. So install libcgroup from AUR and then edit /etc/cgconfig.conf adding this at bottom:
Code: Select all
namespace {
cpu = /;
}
group rtaudio {
perm {
task {
uid = root;
gid = audio;
}
admin {
uid = root;
gid = root;
}
}
cpu {
cpu.rt_runtime_us = 950000;
}
}
Code: Select all
# One of the following line is needed for jack
#@audio:jackd cpu rtaudio/
@audio:jackdbus cpu rtaudio/
# Comment the 2 following lines if not using snd-aloop
@audio:alsa_in cpu rtaudio/
@audio:alsa_out cpu rtaudio/
@audio:ardour cpu rtaudio/
# Add one line for each RT software
@audio:mplayer cpu rtaudio/
@audio:jamin cpu rtaudio/
Code: Select all
#!/bin/sh
########################################################################
# Prepare the system for low latency audio operation. Steps: #
# Set CPU governors for performances - Unload not needed kernel #
# modules - Kill not needed processes - Stop unwanted services - #
# Load the high res timer and set tasklet daemon priority - #
# Check the timers frequencies. #
########################################################################
# Governors:
echo Setting CPU governors:
# Set CPU governors to performance:
cpupower frequency-set -g performance
echo DONE
# Kernel Modules
echo Unloading unwanted Kernel Modules
# Parallel Port
modprobe -r ppdev
# Printer
modprobe -r lp
# Webcam
modprobe -r uvcvideo
modprobe -r videodev
# Wireless
modprobe -r ath9k
# NIC
modprobe -r r8169
# Bluetooth USB
modprobe -r btusb
echo DONE
# Unwanted Processes
echo Killing unwanted processes:
# Compositing
killall -w compton
# Wbar
killall -w wbar
# Conky
sudo -u crocoduck killall -w conky
# Panel tint2
sudo -u crocoduck killall -w tint2
echo DONE
# Unwanted Services
echo Stop unwanted services
# Teamviewer
systemctl stop teamviewerd
# Entropy collection
systemctl stop haveged
# Networking
systemctl stop NetworkManager
systemctl stop wpa_supplicant
echo DONE
# High Res Timer and Tasklet
echo Loading ALSA high res timer and TASKLETPR
# Load the ALSA high res timer
modprobe snd-hrtimer
# Define a variable TASKLETPR and set it to 76
TASKLETPR=76
# Set the priority of the tasklet daemon
ps -eLo pid,cmd \
| grep [t]asklet | awk '{ system("chrt -f -p '$TASKLETPR' " $1)}'
echo DONE
# Checking the Timers frequencyes
echo Probing Timers frequencies for hpet and rtc0:
echo HPET:
cat /proc/sys/dev/hpet/max-user-freq
echo RTC0:
cat /sys/class/rtc/rtc0/max_user_freq
echo Finished
Code: Select all
#!/bin/sh
########################################################################
# Restore default system operation after lowlatency preparation with #
# ArchPerformances.sh #
########################################################################
# Governors:
echo Setting CPU governors:
# Set CPU governors to ondemand:
cpupower frequency-set -g ondemand
echo DONE
# Kernel Modules
echo Reloading unwanted Kernel Modules
# Parallel Port
modprobe ppdev
# Printer
modprobe lp
# Webcam
modprobe uvcvideo
modprobe videodev
# Wireless
modprobe ath9k
# NIC
modprobe r8169
# Bluetooth USB
modprobe btusb
echo DONE
# Unwanted Processes
echo Restarting unwanted processes:
sudo -u crocoduck compton -b &
sudo -u crocoduck wbar &
sudo -u crocoduck conky &
sudo -u crocoduck tint2 &
echo DONE
# Unwanted Services
echo Start unwanted services
# Teamviewer
systemctl start teamviewerd
# Entropy collection
systemctl start haveged
# Networking
systemctl start NetworkManager
systemctl start wpa_supplicant
echo DONE
Code: Select all
dev.hpet.max-user-freq=3072
Code: Select all
echo 3072 >/sys/class/rtc/rtc0/max_user_freq
Code: Select all
#!/bin/bash
echo 3072 >/sys/class/rtc/rtc0/max_user_freq
The kernel that comes with a standard ArchBang installation is not so bad for audio tasks. As a matter of fact into his Kernel Configuration we can see:
Code: Select all
CONFIG_PREEMPT_RCU=y
CONFIG_PREEMPT_NOTIFIERS=y
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
CONFIG_PREEMPT=y
CONFIG_PREEMPT_COUNT=y
# CONFIG_PREEMPT_TRACER is not set
CONFIG_IRQ_FORCED_THREADING=y
Code: Select all
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
CONFIG_HZ_300=y
# CONFIG_HZ_1000 is not set
CONFIG_HZ=300
Code: Select all
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000
I experienced an issue with any USB soundcard I used, probably because some weirdness in my laptop's USB hardware. When I tried to lower the latency below 8ms a lot of xrun appeared. With the help of cool people from ArchBang forums (they helped me with timer's frequencies too) I found that the issue is related to a driver in use with newer kernels as supplied by arch repos and AUR: ehci-pci . A kernel that still use ehci-hcd doesn't have this problem (check the "UPDATE 3:" at the bottom of the post). The best experience I had is with linux-rt-lts. You can install a lot of interesting kernels from AUR, but if you don't want to compile every single kernel cool rt kernels are supplied by archaudio repos. Just add the following to your pacman.conf:
Code: Select all
[archaudio-production]
SigLevel = Never
Server = http://repos.archaudio.org/$repo/$arch
Finally, my jack configurations:
When using the internal sound card (standard core repo kernel is enough for good performances with her):
Code: Select all
/usr/bin/jackd -P89 -t5000 -dalsa -r96000 -p64 -n3 -D -Chw:Intel,0 -Phw:Intel,0
When using USB audio (need to use linux-rt-lts):
Code: Select all
/usr/bin/jackd -v -P89 -p128 -t5000 -dalsa -r48000 -p64 -n3 -D -Chw:CODEC,0 -Phw:CODEC,0
UPDATE:
As always, stay tuned with Arch and Archbang news: you need that news for taking all the manual interventions that could be required after an update. On 2013-09-17 on the arch's site appeared a message regarding systcl.conf. So:
If you installed Archbang and followed this guide before 2013-09-17 and your system is up to date then you need an adjustment, as we edited sysctl.conf adding
Code: Select all
vm.swappiness=10
vm.vfs_cache_pressure=50
fs.inotify.max_user_watches = 524288
Code: Select all
systemctl --version
Code: Select all
pacman -Qs procps-ng
Code: Select all
cat /proc/sys/vm/swappiness
Finally, I see that the fs.inotify.max_user_watches value is not so effective for audio performances... you can comment it.
If you installed ArchBang after 2013-09-17 and are following this guide now, just create directly /etc/sysctl.d/99-sysctl.conf with this content:
Code: Select all
vm.swappiness=10
vm.vfs_cache_pressure=50
At the time I wrote the guide there were 2 packages in AUR : systemd-rtirq and rtirq. Some time ago the two packages has been merged. As a consequence there is just one now: rtirq. So, if you followed this guide when systemd-rtirq was still alive and you are manually maintaining updated the AUR packages then you can proceed like this:
Remove systemd-rtirq (and its dependencies which are not required by any other installed package):
Code: Select all
pacman -Rs systemd-rtirq
Then install rtirq and enable the service as before:
Code: Select all
systemctl enable rtirq
If you are following this guide now:
Just install the package rtirq. Then enable the service with:
Code: Select all
systemctl enable rtirq
Some tip to understand if rtirq is working for real:
give this 2 guys:
Code: Select all
systemctl status rtirq
/usr/bin/rtirq status
Code: Select all
rtirq.service - Realtime IRQ thread system tuning
Loaded: loaded (/etc/systemd/system/rtirq.service; enabled)
Active: active (exited) since Wed 2013-12-25 21:13:36 CET; 2min 7s ago
Process: 869 ExecStart=/usr/bin/rtirq start (code=exited, status=0/SUCCESS)
Main PID: 869 (code=exited, status=0/SUCCESS)
Code: Select all
PID CLS RTPRIO NI PRI %CPU STAT COMMAND
42 FF 90 - 130 0.0 S irq/8-rtc0
266 FF 85 - 125 0.0 S irq/45-snd_hda_
70 FF 80 - 120 0.0 S irq/16-uhci_hcd
77 FF 79 - 119 0.0 S irq/16-uhci_hcd
78 FF 79 - 119 0.0 S irq/18-uhci_hcd
73 FF 78 - 118 0.0 S irq/19-uhci_hcd
72 FF 77 - 117 0.0 S irq/20-uhci_hcd
71 FF 76 - 116 0.0 S irq/21-uhci_hcd
40 FF 75 - 115 0.0 S irq/1-i8042
39 FF 74 - 114 0.3 S irq/12-i8042
23 FF 50 - 90 0.0 S irq/9-acpi
37 FF 50 - 90 0.0 S irq/40-PCIe PME
38 FF 50 - 90 0.0 S irq/41-PCIe PME
75 FF 50 - 90 0.0 S irq/19-ehci_hcd
76 FF 50 - 90 0.0 S irq/20-ehci_hcd
79 FF 50 - 90 0.1 S irq/42-ahci
193 FF 50 - 90 0.0 S irq/43-i915
245 FF 50 - 90 0.0 S irq/16-ath9k
611 FF 50 - 90 0.0 S irq/18-i801_smb
825 FF 50 - 90 0.0 S irq/44-enp3s0
3 TS - 0 19 0.0 S ksoftirqd/0
14 TS - 0 19 0.0 S ksoftirqd/1
Actually, the latest kernel images of linux-rt-lts are supplied with ehci-pci, but I'm having no issues with them. Probably there was some kind of bug in the previous versions of the driver and/or in its implementation.
UPDATE 4:
A note for laptop users: beware laptop-mode-tools and cpupower. They used to be nice tools, but they have started behave strangely on my machine with latest kernels (the kernel version at the time of this UPDATE is 3.17.3-1). I suggest to not install laptop-mode-tools and cpupower. Install tlp instead. It is assuring to me a nice 0 xruns experience!
The symptoms of my machine were: unbalanced CPU frequency between the cores, overheating with not so huge load, USB hardware being shut down without apparent or easily reproducible reason. Have a look at here and here to find out.