All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: alsa-devel@alsa-project.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: Re: ALSA calling pcm_pointer excessively?
Date: Thu, 10 May 2012 19:13:59 +0200	[thread overview]
Message-ID: <4FABF757.8080505@ladisch.de> (raw)
In-Reply-To: <4FABF574.7090804@ladisch.de>

I wrote:
> This (untested) patch tries to avoid too many busy looping.

Oops, off-by-one error (avail == avail_min should not wait).


Regards,
Clemens

--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1894,7 +1894,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	snd_pcm_uframes_t xfer = 0;
 	snd_pcm_uframes_t offset = 0;
-	int err = 0;
+	int busy_loops = 0, err = 0;

 	if (size == 0)
 		return 0;
@@ -1919,12 +1919,17 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
 	runtime->twake = runtime->control->avail_min ? : 1;
 	while (size > 0) {
 		snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
-		snd_pcm_uframes_t avail;
+		snd_pcm_uframes_t avail, avail_nowait_min;
 		snd_pcm_uframes_t cont;
+
+		if (busy_loops < 5)
+			avail_nowait_min = 1;
+		else
+			avail_nowait_min = min(runtime->control->avail_min, size);
 		if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
 			snd_pcm_update_hw_ptr(substream);
 		avail = snd_pcm_playback_avail(runtime);
-		if (!avail) {
+		if (avail < avail_nowait_min) {
 			if (nonblock) {
 				err = -EAGAIN;
 				goto _end_unlock;
@@ -1934,6 +1939,9 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
 			err = wait_for_avail(substream, &avail);
 			if (err < 0)
 				goto _end_unlock;
+			busy_loops = 0;
+		} else {
+			busy_loops++;
 		}
 		frames = size > avail ? avail : size;
 		cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;

  reply	other threads:[~2012-05-10 17:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10 16:06 ALSA calling pcm_pointer excessively? Russell King - ARM Linux
2012-05-10 16:29 ` Russell King - ARM Linux
2012-05-10 17:05   ` Clemens Ladisch
2012-05-10 17:13     ` Clemens Ladisch [this message]
2012-05-10 18:18       ` Russell King - ARM Linux
2012-05-10 18:43         ` Clemens Ladisch
2012-05-10 23:09           ` Russell King - ARM Linux
2012-05-10 17:47     ` Jassi Brar
2012-05-11 13:31     ` Takashi Iwai
2012-05-11 14:02       ` Russell King - ARM Linux
2012-05-11 14:17         ` Takashi Iwai
2012-05-11 15:04           ` Russell King - ARM Linux
2012-05-11 16:31             ` Takashi Iwai
2012-05-11 16:38               ` Russell King - ARM Linux
2012-05-11 17:07                 ` Takashi Iwai
2012-05-10 16:34 ` Trent Piepho
2012-05-10 16:42   ` Russell King - ARM Linux
2012-05-10 17:00 ` Jassi Brar
2012-05-10 17:04   ` Trent Piepho
2012-05-10 17:04   ` Russell King - ARM Linux
2012-05-10 17:18     ` Jassi Brar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FABF757.8080505@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linux@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.