Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 0910c216 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

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: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent b2522f92
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment