[alsa-devel] busy loop in snd_pcm_plugin_status()

Thierry Reding thierry.reding at avionic-design.de
Fri Oct 14 13:17:20 CEST 2011


I'm seeing a strange issue when using linphone (3.4.3) with alsa-lib
( 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?

-------------- next part --------------
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
index d88e117..8a865a2 100644
--- a/src/pcm/pcm_plugin.c
+++ b/src/pcm/pcm_plugin.c
@@ -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);
-	snd_atomic_read_begin(&ratom);
 	/* sync with the latest hw and appl ptrs */
+	snd_atomic_read_begin(&ratom);
 	err = snd_pcm_status(plugin->gen.slave, status);
 	if (err < 0) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20111014/bd3ddf03/attachment.sig 

More information about the Alsa-devel mailing list