All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Raymond Yau <superquad.vortex2@gmail.com>
Cc: ALSA Development Mailing List <alsa-devel@alsa-project.org>
Subject: Re: [PATCH] ALSA - HDA - Add period time constraint to hda-intel
Date: Thu, 26 May 2011 08:15:56 +0200	[thread overview]
Message-ID: <s5hboyq2dib.wl%tiwai@suse.de> (raw)
In-Reply-To: <BANLkTim2oO6JnFQre97U6PdaFe6C91AeXg@mail.gmail.com>

At Thu, 26 May 2011 10:01:14 +0800,
Raymond Yau wrote:
> 
> 2011/5/24 Takashi Iwai <tiwai@suse.de>:
> 
> >> ALSA hda_intel.c:1680: azx_pcm_prepare: bufsize=0x1aeb00, format=0x4111
> >> ...
> >> ALSA pcm_native.c:1531: playback drain error (DMA or IRQ trouble?)
> >
> > Wouldn't it be better to fix the PCM timeout itself?
> > Does the patch below work?
> >
> >
> > thanks,
> >
> > Takashi
> >
> > ---
> > diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
> > index abfeff16..a754722 100644
> > --- a/sound/core/pcm_lib.c
> > +++ b/sound/core/pcm_lib.c
> > @@ -1756,8 +1756,16 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
> >        wait_queue_t wait;
> >        int err = 0;
> >        snd_pcm_uframes_t avail = 0;
> > +       long wait_time = 10; /* 10 seconds timeout as default */
> >        long tout;
> >
> > +       if (runtime->rate) {
> > +               long t = (runtime->period_size * 2 + runtime->rate - 1) /
> > +                       runtime->rate;
> > +               wait_time = max(t, wait_time);
> > +       }
> > +       wait_time = msecs_to_jiffies(wait_time * 1000);
> > +
> >        init_waitqueue_entry(&wait, current);
> >        add_wait_queue(&runtime->tsleep, &wait);
> >        for (;;) {
> > @@ -1767,7 +1775,7 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
> >                }
> >                set_current_state(TASK_INTERRUPTIBLE);
> >                snd_pcm_stream_unlock_irq(substream);
> > -               tout = schedule_timeout(msecs_to_jiffies(10000));
> > +               tout = schedule_timeout(wait_time);
> >                snd_pcm_stream_lock_irq(substream);
> >                switch (runtime->status->state) {
> >                case SNDRV_PCM_STATE_SUSPENDED:
> >
> 
> you patch only fix the playback write/capture read error .
> 
> does it mean that even when the application (e.g. PA server) set
> stop_threshold to boundary can only freerun for 10 seconds only ?

Yeah, this was overlooked.  The patch below fixes both issues.
Also it checks no_period_wakeup flag just to be sure (although setting
this for normal read/write/drain operations doesn't make sense).


thanks,

Takashi

---
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index abfeff16..f134130 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1756,8 +1756,18 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 	wait_queue_t wait;
 	int err = 0;
 	snd_pcm_uframes_t avail = 0;
-	long tout;
-
+	long wait_time, tout;
+
+	if (runtime->no_period_wakeup)
+		wait_time = MAX_SCHEDULE_TIMEOUT;
+	else {
+		wait_time = 10;
+		if (runtime->rate) {
+			long t = runtime->period_size * 2 / runtime->rate;
+			wait_time = max(t, wait_time);
+		}
+		wait_time = msecs_to_jiffies(wait_time * 1000);
+	}
 	init_waitqueue_entry(&wait, current);
 	add_wait_queue(&runtime->tsleep, &wait);
 	for (;;) {
@@ -1765,9 +1775,8 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 			err = -ERESTARTSYS;
 			break;
 		}
-		set_current_state(TASK_INTERRUPTIBLE);
 		snd_pcm_stream_unlock_irq(substream);
-		tout = schedule_timeout(msecs_to_jiffies(10000));
+		tout = schedule_timeout_interruptible(wait_time);
 		snd_pcm_stream_lock_irq(substream);
 		switch (runtime->status->state) {
 		case SNDRV_PCM_STATE_SUSPENDED:
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 1a07750..b597408 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1481,11 +1481,20 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
 			break; /* all drained */
 		init_waitqueue_entry(&wait, current);
 		add_wait_queue(&to_check->sleep, &wait);
-		set_current_state(TASK_INTERRUPTIBLE);
 		snd_pcm_stream_unlock_irq(substream);
 		up_read(&snd_pcm_link_rwsem);
 		snd_power_unlock(card);
-		tout = schedule_timeout(10 * HZ);
+		if (runtime->no_period_wakeup)
+			tout = MAX_SCHEDULE_TIMEOUT;
+		else {
+			tout = 10;
+			if (runtime->rate) {
+				long t = runtime->period_size * 2 / runtime->rate;
+				tout = max(t, tout);
+			}
+			tout = msecs_to_jiffies(tout * 1000);
+		}
+		tout = schedule_timeout_interruptible(tout);
 		snd_power_lock(card);
 		down_read(&snd_pcm_link_rwsem);
 		snd_pcm_stream_lock_irq(substream);
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2011-05-26  6:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24  4:15 [PATCH] ALSA - HDA - Add period time constraint to hda-intel Raymond Yau
2011-05-24  6:09 ` Takashi Iwai
2011-05-26  2:01   ` Raymond Yau
2011-05-26  6:15     ` Takashi Iwai [this message]
2011-06-23  1:14       ` Raymond Yau

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=s5hboyq2dib.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=superquad.vortex2@gmail.com \
    /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.