Skip to contentSkip to conversation

busy loop in snd_pcm_plugin_status()

PATCH Thierry Reding 1 participant 1 message Oct 14, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

I'm seeing a strange issue when using linphone (3.4.3) with alsa-lib (1.0.24.1) on an Atom-based platform. I was able to trace the problem down to the snd_pcm_plugin_status() function. The problem is that the call to the snd_atomic_read_ok() function fails because snd_pcm_plugin_avail_update() has already called snd_atomic_write_{begin,end}() in the meantime. The result is that I'm seeing calls to snd_pcm_plugin_status() where the code jumps back to the _again between 200 and 1800 times before succeeding. This in turn leads to delays in the linphone of 20 to 180 milliseconds, which results in rather absurdly high CPU usage (usually 100%) and correspondingly bad audio playback and side-effects (choppiness, linphone no longer terminates calls properly, ...).

I'm using the attached patch as a workaround, but I'm pretty sure it's not a proper fix. The strange thing is that I see that behaviour only on the Atom platform (Intel HDA, Sigmatel 92HD83 codec). Another ARM-based platform does not exhibit the same issue.

Can anybody shed some light on the situation?

Cheers,
Thierry

src/pcm/pcm_plugin.c +1 -1
index d88e117..8a865a2 100644
@@ -523,9 +523,9 @@ static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
 	snd_atomic_read_t ratom;
 	snd_atomic_read_init(&ratom, &plugin->watom);
  _again:
-	snd_atomic_read_begin(&ratom);
 	/* sync with the latest hw and appl ptrs */
 	snd_pcm_plugin_avail_update(pcm);
+	snd_atomic_read_begin(&ratom);
 
 	err = snd_pcm_status(plugin->gen.slave, status);
 	if (err < 0) {