]> git.alsa-project.org Git - alsa-lib.git/commit
PCM: Avoid busy loop in snd_pcm_write_areas() with rate plugin
authorTakashi Iwai <tiwai@suse.de>
Tue, 13 Nov 2012 15:16:26 +0000 (16:16 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 13 Nov 2012 15:16:26 +0000 (16:16 +0100)
commit3fd4ab9be0db7c7430ebd258f2717a976381715d
treeb159671766371decf9609572dbf49b4e249b8796
parent49dde08641f8c6b480c0d410d4fdb2160752dd9a
PCM: Avoid busy loop in snd_pcm_write_areas() with rate plugin

snd_pcm_write_areas() tries to wait until avail >= avail_min condition
is satisfied.  This doesn't work always well when a rate plugin is in
the play.

When a partial data with a smaller size than a period is written, the
rate plugin doesn't transfer the data immediately to the slave PCM,
but kept in an internal buffer and it changes only the hwptr of the
plugin.  Thus, the condition "avail < avail_min" is triggered for a
wait check although the underlying slave PCM has enough room.  This
results in a call of snd_pcm_wait() which returns immediately after
poll() call, and the snd_pcm_write_areas() loop continues.  As a
consequence, it falls into a CPU hog.

This patch fixes that busy loop by introducing a new fast_ops to check
the availability for wait of avail_min.  Then a plugin can ask the
slave PCM whether the wait is required (or possible).

A few plugins like multi plugin need a special handling.  Otherwise a
generic plugin function can be used.

Reported-by: Trent Piepho <tpiepho@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm.c
src/pcm/pcm_generic.c
src/pcm/pcm_generic.h
src/pcm/pcm_hooks.c
src/pcm/pcm_local.h
src/pcm/pcm_meter.c
src/pcm/pcm_mmap_emul.c
src/pcm/pcm_multi.c
src/pcm/pcm_plugin.c
src/pcm/pcm_rate.c