From Fedora Project Wiki

Install and Configure JACK

This has been copied from 2.3 of the Fedora Musicians guide

  1. Use PackageKit or Apper to install the jack-audio-connection-kit and qjackctl packages.
  2. Review and approve the installation, making sure that it completes correctly.
  3. Run QjackCtl from the KMenu or the Applications menu.
  4. To start the JACK server click Start. To stop the JACK server click Stop.
  5. Click Messages to see messages, which are usually errors or warnings.
  6. Click Status to see various statistics about the currently-running server.
  7. Click Connections button to see and adjust the connections between applications and audio hardware.
JACK operates with special real-time privileges. You must add all JACK users to the jackuser group. Learn how to add users to groups in Chapter 22, Users and Groups of the Fedora Deployment Guide, available at http://docs.fedoraproject.org. Do not add a user to the jackuser group if they will not use JACK.

By default, QjackCtl configures JACK to use the 'default' sound card. The 'default' sound card uses all features of the ALSA driver even though JACK provides the same features. To save memory and processor time, you should configure QjackCtl with a specific sound card.

  1. Open a terminal. In GNOME, choose Applications → System → Terminal. In KDE, click on the application launcher, then choose System → Konsole.
  2. Execute this command: cat /proc/asound/cards
  3. The cat program outputs a list of sound cards in your computer that looks similarly to the output below.

        0 [SB             ]: HDA-Intel - HDA ATI SB
                          HDA ATI SB at 0xf7ff4000 irq 16
        1 [MobilePre      ]: USB-Audio - MobilePre
                          M Audio MobilePre at usb-0000:00:13.0-2
    

    In this example output, the square brackets surround the name of the sound card. The names of the sound cards in this example output are SB and MobilePre.Identify the name of the sound card that you want to use. If you do not see your sound card in the list outputted by cat, then your computer does not detect it.

  4. Start QjackCtl.
  5. Click Setup to open the "Setup" window.
  6. In the 'Interface' text box, type the name of your preferred sound card with "hw:" in front. With the sound cards listed above, you might write hw:MobilePre.
  7. Save your settings by exiting QjackCtl. If you want to use JACK, restart QjackCtl.

Using the Jack D-Bus Interface

Control applications such as qjackctl can be configured to interact with the jack sound server using D-Bus. This has the advantage of allowing jack to request the release of the sound device from Pulseaudio (see below).

jackdbus is shipped in a separate package. To install this (as root) do:

    yum install jack-audio-connection-kit-dbus

Finally, check "Enable D-Bus interface" in Setup -> Misc within Qjackctl

Integrate JACK with PulseAudio

JACK uses D-Bus to gain control of the sound card from PulseAudio. PulseAudio should grant control, giving JACK control of it. However this does not work at the time of writing.

There are three approaches that can be taken:

1. Disable PulseAudio altogether.

Create the file ~/.pulse/client.conf conataining the line:

autospawn = no

This will prevent PulseAudio starting again. Run:

pulseaudio -k

To stop the current instance.

2. Disable PulseAudio only when starting JACK (this is not practical for JACK-DBus):

If you use QJackCtl to start JACK then just add this to the 'Execute script on startup' entry in the Setup|Options menu:

pulseaudio -k

This will kill PulseAudio for long enough for JACK to take control of the sound card, though PulseAudio will restart unless the 'autospawn=no' configuration mentioned above has been set. If starting JACK directly at the command line you can use pasuspender:

pasuspender jackd [options...]

With PulseAudio disabled you will not have sound for system sounds, browser media playback, etc (which is usually what you want). But it is possible:

3. To have PulseAudio redirected to use JACK.

In QJackCtl, set 'Execute script on startup' to:

pulseaudio -k

and 'Execute script after startup' to:

pactl load-module module-jack-source;pactl load-module module-jack-sink

Now when you start JACK, PulseAudio is killed long enough for JACK to take control of the sound card. When PulseAudio restarts it's able to communicate via JACK. If you want you can use the connection menus to disconnect or reconnect it as needed.

Running Jack in Realtime mode

NOTE: This is obsolete and kept for informational purposes. The changes suggested below are done automatically by Jack installation (/etc/security/limits.d/95-jack.conf) and no manual modification of the pam configuration should be necessary.

The JACK server jackd has the capability to run in a real-time mode which greatly decreases the chance of audio glitches. The real-time mode is enabled by passing the -R or --realtime option to jackd when starting the server. It is only possible to run jackd in real-time mode as a non-root user by modifying your PAM configuration, PAM stands for Pluggable Authentication Modules and is the primary authentification mechanism used on Fedora. The primary source of PAM documentation can be found at the following at http://www.kernel.org/pub/linux/libs/pam/

The specific PAM configuration file that needs to be modified is /etc/security/limits.conf and it controls the system resource limits. It is important to understand that modifying the resource limits configuration files can decrease the security of your system. Documentation specific to the resource limits PAM module can be found at http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/pam-6.html#ss6.12

Alternatively, one can create a new file

  /etc/security/limits.d/<priority>-<name>.conf

that contains the resource limits for individual users and/or groups. The jack-audio-connection-kit package that comes with Fedora contains the file

  /etc/security/limits.d/99-jack.conf

that does this job for you.

The resource limits that need to be changed to allow jackd to run in realtime mode are named rtprio and memlock. To increase the limits for a specific user named fred you would add the following to /etc/security/limits.conf

fred - rtprio 70 fred - memlock 50000

The value of rtprio can be set in the range 0 - 99 where any value greater that 0 will allow the user to change the scheduling policy to "real-time". By default the JACK server requires a minimum rtprio setting of 20 but jackd will accept a command line parameter -P or --realtime-priority which will change the minimum required value of rtprio that is needed, but the default of 20 is nearly always sufficient.

The appropriate value for memlock is dependent on the amount of memory present in the system but a minimum value of 50000(50MB) and a maximum value of half the available memory can be used as a rough guideline.

To verify that the resource limits have been modified you can use the bash built-in ulimit command, for example:

$ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
max nice                        (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 8191
max locked memory       (kbytes, -l) 50000
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
max rt priority                 (-r) 70
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 8191
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
file locks                      (-x) unlimited

Keep in mind that you may have to re-login before changes to limits.conf, or additions to the limits.d/ directory to take effect.

rtirq

rtirq is a startup script which allows you to tune the realtime priority of software IRQ threads handling audio devices.

As root:

    yum install rtirq

For rtirq to function you will need to append the threadirqs parameter to the kernel command line.

To set this as default for newly installed kernels add it to the GRUB_CMDLINE_LINUX variable in /etc/default/grub (grub2).

The default realtime priorities chosen in the rtirq package are those that work best with Jack defaults. You can tailor rtirq to your specific hardware needs by editing /etc/sysconfig/rtirq

To list available IRQ's:

cat /proc/interrupts

         CPU0       CPU1       CPU2       CPU3       
  0:        137          0          0          0   IO-APIC-edge      timer
  1:         88          0          0          0   IO-APIC-edge      i8042
  8:          1          0          0          0   IO-APIC-edge      rtc0
  9:       1064          0          0          0   IO-APIC-fasteoi   acpi
 12:        195          0          0          0   IO-APIC-edge      i8042
 16:        269         63          0          0   IO-APIC-fasteoi   ehci_hcd:usb1
 17:          0          0          0          0   IO-APIC-fasteoi   ath9k
 19:          0          0          0          0   IO-APIC-fasteoi   xhci_hcd:usb3
 23:         39          0          0          0   IO-APIC-fasteoi   ehci_hcd:usb2
 41:       8357      18983       9722      12125   PCI-MSI-edge      ahci
 42:      42399          0          0          0   PCI-MSI-edge      i915
 43:      26616          0          0          0   PCI-MSI-edge      p5p1
 44:         12          0          0          0   PCI-MSI-edge      mei
 45:        672          0          0          0   PCI-MSI-edge      snd_hda_intel
NMI:         15         25         22         14   Non-maskable interrupts

rtirq prioritizes the following IRQ's by default using a simple pattern matching method. This will result in elevating the realtime priority of any interrupt containing the string "snd" (in the above example it will match snd_hda_intel)

/etc/sysconfig/rtirq

.
.
# IRQ thread service names
# (space separated list, from higher to lower priority).
RTIRQ_NAME_LIST="rtc snd i8042"
.
.

You can check the priorities by issuing the following command. This output is based on a machine with an onboard HDA intel sound device using the default rtirq settings:


sudo service rtirq status

  PID CLS RTPRIO  NI PRI %CPU STAT COMMAND	
  511 FF      70   - 110  0.0 S    irq/45-snd_hda_	
   44 FF      50   -  90  0.0 S    irq/9-acpi	
   67 FF      50   -  90  0.8 S    irq/41-ahci	
   79 FF      50   -  90  0.0 S    irq/16-ehci_hcd	
   81 FF      50   -  90  0.0 S    irq/23-ehci_hcd	
   82 FF      50   -  90  0.0 S    irq/19-xhci_hcd	
   83 FF      50   -  90  0.0 S    irq/12-i8042	
   84 FF      50   -  90  0.0 S    irq/1-i8042	
   88 FF      50   -  90  0.0 S    irq/8-rtc0	
  184 FF      50   -  90  0.1 S    irq/42-i915	
  498 FF      50   -  90  0.0 S    irq/44-mei	
  570 FF      50   -  90  0.0 S    irq/17-ath9k	
  877 FF      50   -  90  0.0 S    irq/43-p5p1	
    3 TS       -   0  19  0.3 S    ksoftirqd/0	
   10 TS       -   0  19  0.2 S    ksoftirqd/1	
   14 TS       -   0  19  0.2 S    ksoftirqd/2	
   18 TS       -   0  19  0.1 S    ksoftirqd/3	
   22 TS       -   0  19  0.0 S    ksoftirqd/4	
   26 TS       -   0  19  0.0 S    ksoftirqd/5	
   30 TS       -   0  19  0.0 S    ksoftirqd/6	
   34 TS       -   0  19  0.1 S    ksoftirqd/7	

If you use other devices you prioritize them by inserting a matching string in RTIRQ_NAME_LIST after rtc. For example, RTIRQ_NAME_LIST="rtc usb2 snd i8042" could be used to match a USB class complaint device on USB bus 2, or RTIRQ_NAME_LIST="rtc firewire_ohci snd i8042" to match a firewire_ohci or firewire_core device interrupt

realTimeConfigQuickScan

realTimeConfigQuickScan is a utility which inspects the realtime capabilities of your system. If any errors are found it suggests methods to rectify the problem.

As root:

    yum install realTimeConfigQuickScan

realTimeConfigQuickScan has both text and grpahical user interfaces. Either select QuickScan from your desktop menu or run realTimeConfigQuickScan from the terminal.

An example using an untuned system. This machine has an onboard intel sound device on IRQ 45

$ SOUND_CARD_IRQ=45 realTimeConfigQuickScan
== GUI-enabled checks ==
Checking if you are root... no - good
Checking filesystem 'noatime' parameter... found - warning
/ does not have the 'noatime' parameter set
/mnt/rawhide does not have the 'noatime' parameter set
/home does not have the 'noatime' parameter set
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#filesystems
Checking CPU Governors... CPU 0: 'ondemand' CPU 1: 'ondemand' CPU 2: 'ondemand' CPU 3: 'ondemand' CPU 4: 'ondemand' CPU 5: 'ondemand' CPU 6: 'ondemand' CPU 7: 'ondemand'  - not good
Set CPU Governors to 'performance' with 'cpufreq-set -c <cpunr> -g performance'
See also: http://linuxmusicians.com/viewtopic.php?f=27&t=844
Checking swappiness... 60 - not good
** vm.swappiness is larger than 10
set it with '/sbin/sysctl -w vm.swappiness=10'
See also: http://linuxmusicians.com/viewtopic.php?f=27&t=452&start=30#p8916
Checking for resource-intensive background processes... none found - good
Checking checking sysctl inotify max_user_watches... < 524288 - not good
increase max_user_watches by adding 'fs.inotify.max_user_watches = 524288' to /etc/sysctl.conf and rebooting
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#sysctl.conf
Checking access to the high precision event timer... not readable - not good
/dev/hpet found, but not readable.
make /dev/hpet readable by the 'audio' group
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#hpet
Checking access to the real-time clock... not readable - not good
/dev/rtc found, but not readable.
make /dev/rtc readable by the 'audio' group
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#real-time_clock
Checking whether you're in the 'audio' group... yes - good
Checking for multiple 'audio' groups... no - good
chrt: failed to set pid 0's policy: Operation not permitted
Checking the ability to prioritize processes with chrt... no - not good
Could not assign a 80 rtprio value. Set up limits.conf.
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#limits.conf
Checking kernel support for high resolution timers... found - good
Kernel with Real-Time Preemption... not found - not good
Kernel without real-time capabilities found
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#installing_a_real-time_kernel
Checking if kernel system timer is set to 1000 hz... found - good
Checking kernel support for tickless timer... found - good
== Other checks ==
Checking filesystem types... ok.
not found.
** Warning: no tmpfs partition mounted on /tmp
   For more information, see:
   - http://wiki.linuxmusicians.com/doku.php?id=system_configuration#tmpfs
   - http://lowlatency.linuxaudio.org

An example of a fully tuned system. This system uses threadirqs rather than PREEMPT_RT kernel and has a USB class compliant device on USB bus 2 (thus the shared IRQ warning)

== GUI-enabled checks ==
Checking if you are root... no - good
Checking filesystem 'noatime' parameter...  - good

Checking CPU Governors... CPU 0: 'performance' CPU 1: 'performance' CPU 2: 'performance' CPU 3: 'performance'  - good
Checking swappiness... 10 - good
Checking for resource-intensive background processes... none found - good
Checking checking sysctl inotify max_user_watches... >= 524288 - good
Checking access to the high precision event timer... readable - good
Checking access to the real-time clock... readable - good
Checking whether you're in the 'audio' group... yes - good
Checking for multiple 'audio' groups... no - good
yes - good.
Checking the ability to prioritize processes with chrt... yes - good
Checking kernel support for high resolution timers... found - good
Kernel with Real-Time Preemption... not found - not good
Kernel without real-time capabilities found
For more information, see http://wiki.linuxmusicians.com/doku.php?id=system_configuration#installing_a_real-time_kernel
Checking if kernel system timer is set to 1000 hz... found - good
Checking kernel support for tickless timer... found - good
== Other checks ==
Checking filesystem types... ok.
ok.
** multiple devices found at the sound cards' IRQ

CPU Performance Governing

Fedora uses cpupower rather than cpufreq-set as quoted in the realTimeConfigQuickScan output. As of Fedora 17, cpupower is part of the kernel-tools package.

To set your CPU Governors to performance, edit /etc/sysconfig/cpupower to read:

# See 'cpupower help' and cpupower(1) for more info
CPUPOWER_START_OPTS="frequency-set -g performance"
CPUPOWER_STOP_OPTS="frequency-set -g ondemand"