]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
ALSA: pcm - Optimize the call of snd_pcm_update_hw_ptr() in read/write loop
authorTakashi Iwai <tiwai@suse.de>
Fri, 11 May 2012 15:50:49 +0000 (17:50 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 11 May 2012 17:05:12 +0000 (19:05 +0200)
commit0910c216f78d1097a4ac6dcc83b38809dea94160
tree906b3beea4baea0c31062ff2ebc1714fedc48a62
parentb2522f9262539fc328b4b9344f8a2f7ef2cb18d5
ALSA: pcm - Optimize the call of snd_pcm_update_hw_ptr() in read/write loop

In the PCM read/write loop, the driver calls snd_pcm_update_hw_ptr()
at each time at the beginning of the loop.  Russell King reported that
this hogs CPU significantly.

The current code assumes that the pointer callback is very fast and
cheap, also not too much fine grained.  It's not true in all cases.
When the pointer advances short samples while the read/write copy has
been performed, the driver updates the hw_ptr and gets avail > 0
again.  Then it tries to read/write these small chunks.  This repeats
until the avail really gets to zero.

For avoiding this situation, a simple workaround is to call
snd_pcm_update_hw_ptr() only once at starting the loop, assuming that
the read/write copy is performed fast enough.  If the available count
becomes short, it goes to snd_pcm_wait_avail() anyway, and this
processes right.

Tested-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_lib.c