Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I eliminate xruns when I use jackminimix? #7

Closed
crocket opened this issue Aug 19, 2019 · 4 comments
Closed

How can I eliminate xruns when I use jackminimix? #7

crocket opened this issue Aug 19, 2019 · 4 comments

Comments

@crocket
Copy link

crocket commented Aug 19, 2019

Raspberry Pi 3 B+:

jackd -P 90 -d alsa -d speakers -p 384 -n 2 -r 48000

(384 = 48 frames/ms * 8 ms = 128 frames/period * 3 periods/buffer)

jack_netsource -n 3 -H my_desktop_computer

My Desktop Computer:

jack -P 90 -d netone -n 3
zita-a2j -j spdifin -d spdifin -p 128 -n 3 -r 48000

(spdif-in of a USB soundcard is connected to spdif-out of my onboard soundcard. Default alsa PCM device is ALSA dmix which outputs to spdif-out of my onboard soundcard.)

zita-j2a -j headphones -d headphones -p 128 -n 3 -r 48000
jackminimix -c -p port -n spk-vol
jackminimix -c -p port -n hdp-vol

Connections managed by my own jack connection manager that I wrote in python:

Speaker mode:

2019-08-19_Mon_04:08:11

Display in i3 bar
2019-08-19_Mon_04:18:57

Headphone mode:

2019-08-19_Mon_04:08:22

Display in i3 bar
2019-08-19_Mon_04:19:10

Xruns from netone while CPU load is close to 100%:

JackEngine::XRun: client = spdifin was not finished, state = Running
JackEngine::XRun: client = headphones was not finished, state = Running
JackEngine::XRun: client hdp-vol finished after current callback
JackEngine::XRun: client = spk-vol was not finished, state = Triggered
JackAudioDriver::ProcessGraphAsyncMaster: Process error

Possibilities:

  1. Either, spdifin or headphones couldn't finish in time.
  2. Either, hdp-vol or spk-vol didn't finish in time.
  3. hdp-vol finished after current callback means hdp-vol didn't finish time and caused xruns in other JACK clients.

Question:

What caused xruns?

@crocket crocket changed the title Any recommended period settings? How can I eliminate xruns when I use jackminimix? Aug 19, 2019
@crocket
Copy link
Author

crocket commented Aug 19, 2019

I guess xruns were caused because

  1. /etc/cgroup/cgrules.conf didn't assign jackminimix to audio cgroup which allocates 95% of CPU time to realtime threads of its cgroup members.
  2. jackd was started before cgrulesengd started working. Thus, cgrulesengd couldn't assign jackd to audio group.

I added jackminimix to audio cgroup in /etc/cgroup/cgrules.conf and made sure that jackd starts after cgrulesengd starts.

audio cgroup includes jackd, zita-a2j, zita-j2a, and jackminimix.

@crocket
Copy link
Author

crocket commented Aug 20, 2019

After fixing cgroup issue, I still get xruns.

Xruns seems to come from spk-vol in headphone mode and hdp-vol in speaker mode.

So, I severed connections between hdp-vol and headphones in speaker mode and spk-vol and system in headphone mode.

But, severing unused connections doesn't remove xruns.

hdp-vol finishes after a callback in speaker mode, and spk-vol finishes after a callback in headphone mode.

@crocket
Copy link
Author

crocket commented Aug 23, 2019

Executing stress-ng --iomix 8 --ionice-class idle reliably causes xruns.

@crocket
Copy link
Author

crocket commented Aug 24, 2019

My CPU is FX-8300 which has 4 cores and 8 threads.

nice -n 19 stress-ng --iomix 8 --ionice-class idle -t 5m caused multiple xruns.

nice -n 19 stress-ng --cpu 8 -t 5m didn't cause xruns.

I tried giving realtime ionice priorities to jackd and all JACK clients, but stress-ng --iomix 8 still managed to cause xruns.

I tweaked realtime ionice priorities, frames per periods, and periods per buffer. The following setup seems to withstand

nice -n 19 stress-ng --iomix 8 --ionice-class idle --cpu 8 -t 5m

without xruns.

On Raspberry Pi 3 B+:

ionice -c 1 -n 0 sudo -u pi jackd -P 90 -d alsa -d speakers -p 256 -n 2 -P -r 48000
ionice -c 1 -n 2 sudo -u pi jack_netsource -H my_desktop_computer -n 3 -m 1500

On my desktop computer:

Programs started in init scripts

ionice -c 1 -n 2 sudo -u user jackd -P 90 -d netone -n 3
ionice -c 1 -n 0 sudo -u user stdbuf -o 0 zita-a2j -j from_alsa -d spdif_in -p 128 -n 3 -r 48000
ionice -c 1 -n 0 sudo -u user stdbuf -o 0 zita-j2a -j headphones -d xfihd_hdp -p 128 -n 3 -r 48000
ionice -c 1 -n 4 sudo -u user stdbuf -o 0 jackminimix -c 2 -p 20255 -n soft-vol

~/.asoundrc

defaults.pcm.rate_converter "samplerate_best"

pcm.spdif_out {
  type hw
  card SB
  device 1
  subdevice 0
  format S16_LE
  rate 48000
  channels 2
}

pcm.smix {
  type dmix
  ipc_key 219348
  hw_ptr_alignment "rounddown"
  slave {
    pcm "spdif_out"
    period_size 512
    periods 3
    format S16_LE
    rate 48000
    channels 2
  }
  bindings {
    0 0
    1 1
  }
}

pcm.spdif_in {
  type hw
  card HD
  device 1
  subdevice 0
  format S16_LE
  rate 48000
  channels 2
}

pcm.xfihd_hdp {
  type hw
  card HD
  device 0
  subdevice 0
  format S16_LE
  rate 48000
  channels 2
}

ctl.xfihd_hdp {
  type hw
  card HD
}

pcm.!default {
  type plug
  slave.pcm {
    @func getenv
    vars [ MY_ALSA_DEVICE ]
    default "smix"
  }
  rate_converter "samplerate_best"
}

Conclusion

I guess that writing to ZFS interferes with reading from and writing to USB soundcard or ethernet adaptor. I thought ionice only affected file system operations.

Perhaps, does ionice affect xruns because I log stdout and stderr of jackd, zita-ajbridge, and jackminimix into files on ZFS without buffering? ( stdbuf -o 0 removes buffering. )

I will report this issue to jack2.

@crocket crocket closed this as completed Aug 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant