From: Clemens Ladisch <clemens@ladisch.de>
To: Jaroslav Kysela <perex@perex.cz>
Cc: pl bossart <bossart.nospam@gmail.com>, alsa-devel@alsa-project.org
Subject: Re: [PATCH] disable period wakeups
Date: Tue, 16 Nov 2010 10:19:40 +0100 [thread overview]
Message-ID: <4CE24CAC.2070909@ladisch.de> (raw)
In-Reply-To: <alpine.LNX.2.00.1011151123380.29422@eeebox2.perex-int.cz>
Jaroslav Kysela wrote:
>> pl bossart wrote:
>>> Here's the second set of patches based on feedback from Takashi,
>>> Jaroslav and Clemens. Hope this is fine now.
>
> The problem in the kernel side is that there is no ring buffer boundary
> check using system jiffies. Without this check, the actual implementation
> does not guarantee the consistency of hw_ptr.
How about this?
--8<---------------------------------------------------------------->8--
ALSA: pcm: detect xruns in no-period-wakeup mode
When period wakeups are disabled, successive calls to the pointer update
function do not have a maximum allowed distance, so xruns cannot be
detected with the pointer value only.
To detect xruns, compare the actually elapsed time with the time that
should have theoretically elapsed since the last update. When the
hardware pointer has wrapped around due to an xrun, the actually elapsed
time will be too big by about hw_ptr_buffer_jiffies.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
---
sound/core/pcm_lib.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
--- alsa-kernel/sound/core/pcm_lib.c
+++ alsa-kernel/sound/core/pcm_lib.c
@@ -374,9 +374,23 @@ static int snd_pcm_update_hw_ptr0(struct
(unsigned long)runtime->hw_ptr_base);
}
- /* without period interrupts, there are no regular pointer updates */
- if (runtime->no_period_wakeup)
+ if (runtime->no_period_wakeup) {
+ /*
+ * Without regular period interrupts, we have to check
+ * the elapsed time to detect xruns.
+ */
+ jdelta = jiffies - runtime->hw_ptr_jiffies;
+ hdelta = jdelta - delta * HZ / runtime->rate;
+ while (hdelta > runtime->hw_ptr_buffer_jiffies / 2 + 1) {
+ delta += runtime->buffer_size;
+ hw_base += runtime->buffer_size;
+ if (hw_base >= runtime->boundary)
+ hw_base = 0;
+ new_hw_ptr = hw_base + pos;
+ hdelta -= runtime->hw_ptr_buffer_jiffies;
+ }
goto no_delta_check;
+ }
/* something must be really wrong */
if (delta >= runtime->buffer_size + runtime->period_size) {
next prev parent reply other threads:[~2010-11-16 9:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 21:42 [PATCH] disable period wakeups pl bossart
2010-11-15 9:58 ` Clemens Ladisch
2010-11-15 10:26 ` Jaroslav Kysela
2010-11-16 9:19 ` Clemens Ladisch [this message]
2010-11-18 8:35 ` Jaroslav Kysela
2010-11-18 8:57 ` Clemens Ladisch
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=4CE24CAC.2070909@ladisch.de \
--to=clemens@ladisch.de \
--cc=alsa-devel@alsa-project.org \
--cc=bossart.nospam@gmail.com \
--cc=perex@perex.cz \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).