Solved audio/jack: artifact noises and message "Write buffer balancing"

Hi,

I noticed irregular knacking noises in my headphones. Machine did some computing, but later when the machine was idle, the noises did still appear.
Tracking it down, I found jackd being the culprit. Routing directly to OSS - no more noises. And I found messages along with the noises:
Code:
JackOSSDriver::Write buffer balancing 257 frames
JackOSSDriver::Write buffer balancing -429 frames
JackOSSDriver::Write buffer balancing 285 frames
JackOSSDriver::Write buffer balancing 265 frames
JackOSSDriver::Write buffer balancing -316 frames

Then I found something strange. There is a nice hack in /usr/local/etc/rc.d/jackd: jackd whould run rtprio, but cannot activate this as an unpriviledged user. So rc.d/jackd invokes rtprio as prefix command for daemon, and then lets daemon change from root to the jack-user. And jackd gets the commandline option to NOT engage rtprio by itself.
But the outcome then looks like this:

Code:
ps -o tid -axlHww  | grep jackd
   LWP  UID   PID  PPID  C PRI NI      VSZ     RSS MWCHAN   STAT TT         TIME COMMAND
101791    0  8754     1  0 -51  0    12856    2580 piperd   S<s   -      0:00.00 daemon: /usr/local/bin/jackd[8755] (daemon)
122472 1100  8755  8754  0 -51  0   153496   72692 sigwait  S<s   -      0:00.07 /usr/local/bin/jackd -r -d oss -r48000 -p1024 -n2 -w16 -i4 -o8 -C /dev/dsp0 -P /dev/dsp0
216324 1100  8755  8754  0  52  0   153496   72692 uwait    Is    -      0:00.00 /usr/local/bin/jackd -r -d oss -r48000 -p1024 -n2 -w16 -i4 -o8 -C /dev/dsp0 -P /dev/dsp0
216325 1100  8755  8754  0  20  0   153496   72692 select   Ss    -      0:00.05 /usr/local/bin/jackd -r -d oss -r48000 -p1024 -n2 -w16 -i4 -o8 -C /dev/dsp0 -P /dev/dsp0
216326 1100  8755  8754  0  20  0   153496   72692 select   Ss    -      0:00.00 /usr/local/bin/jackd -r -d oss -r48000 -p1024 -n2 -w16 -i4 -o8 -C /dev/dsp0 -P /dev/dsp0

Only the leading thread has rtprio (-51). The further threads are started without rtprio - just as requested per commandline.
That construct does not work as intended.

Solution: start jackd without rtprio, wait a second until it has spawned all threads. then put rtprio onto it.

The artifacts themselves are not always reproducible. They may well be attributed to other strange things I'm doing with the system - but then, it is certainly not sane to run a process with only part of the threads in rtprio...

Code:
diff --git a/audio/jack/files/jackd.in b/audio/jack/files/jackd.in
index 9f135a6c8f1b..23d0da65de76 100644
--- a/audio/jack/files/jackd.in
+++ b/audio/jack/files/jackd.in
@@ -21,14 +21,16 @@ procname=%%PREFIX%%/bin/jackd
 start_cmd="start_jackd"
 
 start_jackd() {
+  local pidf=/var/run/${name}.pid
   echo "Starting ${name}."
-  if [ $jackd_rtprio = "YES" ]; then
-    local rt="rtprio 1"
-  fi
   # log the date and parameters
   echo -e "\n[`date`] Starting the daemon, user=$jackd_user rtprio=$jackd_rtprio args=\"$jackd_args\"" >> /var/log/${name}.log
   # daemon(8) should be able to set the realtime priority, but it isn't
-  $rt daemon -p /var/run/${name}.pid -u "${jackd_user}" %%PREFIX%%/bin/jackd ${jackd_args}
+  daemon -p $pidf -u "${jackd_user}" %%PREFIX%%/bin/jackd ${jackd_args}
+  if [ $jackd_rtprio = "YES" -a -r $pidf ]; then
+    sleep 1
+    rtprio 1 -`cat $pidf`
+  fi
 }
 
 load_rc_config ${name}

P.S: I've notified the maintainer.
 
Back
Top