All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: pl bossart <bossart.nospam@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	General PulseAudio Discussion
	<pulseaudio-discuss@mail.0pointer.de>,
	alsa-devel@alsa-project.org
Subject: Re: [RFC] disabling ALSA period interrupts
Date: Mon, 17 May 2010 11:12:15 +0200	[thread overview]
Message-ID: <4BF1086F.9070900@ladisch.de> (raw)
In-Reply-To: <AANLkTil6ftaJ_wC--Tsq4pxPDAg9zmISstHuTvCWc_pk@mail.gmail.com>

pl bossart wrote:
> Takashi Iwai wrote:
> > The biggest problem I can foresee is the handling of PCM position.
> > In the current implementation, the PCM position continues to go over
> > the buffer size until the certain boundary that is close to long int
> > max.  Without interrupts (i.e. snd_pcm_period_elapsed()), this
> > position update won't work reliably.

Pointer updates (snd_pcm_avail or implicitly when writing samples) are
still necessary, and the interval between them can never be more than
the buffer time if you want to avoid xruns.

It seems to work fine with a simple test program.

> Good catch. I thought the processing was the same whether you called
> snd_pcm_period_elapsed or snd_pcm_avail when the timer fires, since in
> both cases you call the .pointer routine, but there's some code in
> snd_pcm_update_hw_ptr0 that is only executed in an interrupt context.

When an interrupt happens, we know that the current position must be at
least at the end of the period that was started at the last interrupt.
This code does the following: If it looks as if the current position is
less than that, we know that the period interrupt was delayed and that
an entire buffer was played before the position wrapped around to the
current position, so we have to add one buffer size to get the correct
position.

In practice, this implies an underrun.  Without interrupts, this
underrun could not be detected (except by the fact your own timer
has arrived too late).

> Likewise there are a bunch of fixes for hw_ptr position that make use
> of this boundary field (which I have to admit I don't understand too
> much).

The boundary is a multiple of the buffer size, so you can use
ptr%buffer_size to get the position in the actual hardware buffer.
The boundary is larger than the buffer size to allow computations on
pointer values even when long xruns happen.

> Here is my latest set of patches before I forget about them.

Instead of a new field in snd_pcm_hardware, you should better use a new
flag so that userspace also knows about this capability.

Following are my own patches that I wrote before I saw yours; they look
essentially the same.

> Still some work to be done on the alsa-lib one, for some reason the
> hw_param->flags field I used gets overwritten if I don't use the
> hw_device. I suspect this is due to some black magic with the
> pcm->hw_flags when slave devices are used.

Until now this field has been used only for flags used internally in
alsa-lib, so this might be a bug in alsa-lib.


Regards,
Clemens

  reply	other threads:[~2010-05-17  9:12 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-29 22:38 [RFC] disabling ALSA period interrupts pl bossart
2010-04-29 23:18 ` Raymond Yau
     [not found]   ` <k2j6160a5131004291644rd8645dc7oecee28ee290b683f@mail.gmail.com>
2010-04-30  0:59     ` Raymond Yau
2010-04-30  1:09 ` Raymond Yau
2010-04-30 13:46   ` pl bossart
2010-04-30 22:51     ` Raymond Yau
2010-04-30  3:47 ` Raymond Yau
2010-04-30 11:24 ` Clemens Ladisch
2010-04-30 13:44   ` pl bossart
2010-05-06  1:24     ` Raymond Yau
2010-05-14  8:12     ` Takashi Iwai
2010-05-14 13:36       ` pl bossart
2010-05-14 21:03         ` pl bossart
2010-05-17  9:12           ` Clemens Ladisch [this message]
2010-05-17  9:14             ` [PATCH 1/3] add API to allow disabling " Clemens Ladisch
2010-05-17  9:23               ` Jassi Brar
2010-05-17 11:16                 ` Clemens Ladisch
2010-05-17 11:27                   ` Jassi Brar
2010-05-17 14:42                     ` Jaroslav Kysela
2010-05-17 16:05                       ` pl bossart
2010-05-17 16:22                         ` Jaroslav Kysela
2010-05-17 16:37                           ` pl bossart
2010-05-17 16:54                             ` Jaroslav Kysela
2010-05-18  9:11                       ` Jassi Brar
2010-05-17 13:59               ` pl bossart
2010-05-17  9:14             ` [PATCH 2/3] ALSA: hda-intel: add support for disabling period irq Clemens Ladisch
2010-05-17 14:05               ` pl bossart
2010-05-17  9:15             ` [PATCH 3/3] ALSA: oxygen: " Clemens Ladisch
2010-05-17 14:17             ` [RFC] disabling ALSA period interrupts pl bossart
2010-05-20 14:50           ` Clemens Ladisch
2010-04-30 16:44 ` Liam Girdwood
2010-04-30 17:39   ` pl bossart
2010-05-04  3:18     ` Raymond Yau
2010-05-07 23:25 ` [alsa-devel] " Lennart Poettering
2010-05-08  3:12   ` pl bossart
2010-05-12  4:00     ` pl bossart
2010-05-12 13:00       ` Jaroslav Kysela
2010-05-12 17:10         ` [alsa-devel] " pl bossart
2010-05-12 18:15           ` Jaroslav Kysela
2010-05-13  3:56             ` pl bossart
2010-05-12  7:22   ` James Courtier-Dutton
2010-05-12 12:42     ` pl bossart
2010-05-13  0:37       ` Raymond Yau
2010-05-14  0:43       ` Raymond Yau
2010-05-14  1:51         ` pl bossart
2010-05-14  2:45           ` Raymond Yau
2010-05-14  3:09           ` Raymond Yau
2010-05-14  4:03           ` Raymond Yau
2010-05-12 13:08 ` Jassi Brar
2010-05-12 13:50   ` [alsa-devel] " pl bossart
2010-05-12 14:15     ` Jassi Brar
2010-05-12 14:16     ` Mark Brown
2010-05-13  0:04       ` Raymond Yau
2010-05-14  4:07       ` Jassi Brar
2010-05-14  4:39         ` pl bossart
2010-05-14  5:27           ` Jassi Brar
2010-05-12 14:41     ` Raymond Yau
2010-05-13  7:27     ` 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=4BF1086F.9070900@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=bossart.nospam@gmail.com \
    --cc=pulseaudio-discuss@mail.0pointer.de \
    --cc=tiwai@suse.de \
    /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.