All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexander E. Patrakov" <patrakov@gmail.com>
To: Raymond Yau <superquad.vortex2@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	ALSA Development Mailing List <alsa-devel@alsa-project.org>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: Re: [RFC PATCH 1/4] ALSA: core: let low-level driver or userspace disable rewinds
Date: Tue, 14 Jul 2015 22:39:20 +0500	[thread overview]
Message-ID: <55A54948.8060703@gmail.com> (raw)
In-Reply-To: <CAN8cciZy2b+spcMp7UkK5Jfh9ks=1z+Pzrj4YCYyMEGDPHeY3g@mail.gmail.com>

14.07.2015 08:32, Raymond Yau wrote:
>
>
>     1. What amount of power-saving are we talking about, for Intel
>     chips? (ideally, this should be in the commit message)
>
>
> Refer to HDA043-A
>
> Energy efficient audio buffering and dynamic FIFO limit change

<deleted a long quote>

I expected an answer in the form "XXX mW out of YYY, for such-and-such 
buffer and period sizes".

>     2. Shouldn't SND_PCM_APPEND (the mode used by dmix and friends) be
>     also made incompatible with this flag, because, when mixing, it
>     essentially overwrites incompletely-mixed data, i.e. rewinds without
>     saying the word "rewind"? Shouldn't all other kinds of freewheeling
>     be made incompatible with this flag, because the card, essentially,
>     is never told about the application pointer? Or is this a
>     userspace-only concern?
>
>
> if SND_PCM_APPEND use fmode = O_APPEND when snd_device_open(), this seem
> support sequential write only and no random write

dmix uses mmap and never advances application pointer on the slave 
(which is a hw device). While each instance of dmix can indeed perform 
mmap-based writes sequentially, what the device sees is not sequential. 
E.g., for two periods and two applications, started simultaneously, the 
sequence is like this:

1st app writes 1st period
1st app writes 2nd period
2nd app overwrites 1st period with the mix
2nd app overwrites 2nd periodwith the mix
hw completes playing 1st period
1st app writes 1st period
2nd app overwrites 1st period with the mix
hw completes playing 2nd period
2nd app writes 2nd period
1st app overwrites 2nd period with the mix
hw completes playing 1st period

...and so on, and we have not considered xruns here, which complicate 
the picture even further. The point is: what the hardware sees is not a 
stream of sequential writes, so the no-rewind flag is not appropriate.

And it is never notified about the application pointer, so the flag is 
definitely not appropriate again.

>
> Do it mean pulseaudio cannot rewind dmix as dmix alway append data to hw
> device ?

No, see above.

Regarding dmix rewindability status: dmix is not actually rewindable 
(but pretends to be), and, while (unlike for extplug) I don't see any 
reason why it must be unrewindable, there is no opposition to mark it as 
unrewindable and then call the problem solved.

Regarding PulseAudio: for PATCH 1/4, it is completely irrelevant. 
Pulseaudio wants to be responsive to the events that new streams appear 
and existing ones change software-based volume. Let's suppose that it 
wants to respond in no later than 10 ms (just a made-up number). Then, 
at no point there should be more than 10 ms of buffered audio that 
cannot be replaced. If PulseAudio starts using this new flag, then it 
has to wake up the CPU every 10 ms. I.e. "let the audio DMA engine wake 
up every 0.125 ms, as it does by default, and let the CPU wake up every 
1000 ms unless something important happens (in which case there is a 
rewind)" would be replaced by "let the audio DMA engine wake up once in 
10 ms, and also let the CPU wake up every 10 ms", which is much worse. 
Unfortunately, the patch does not offer a way to say "let the DMA engine 
wake up every 10 ms, and CPU wake up every 1000 ms (and occasionally 
perform rewinds, but leave 10 ms untouched)".

>
>
>     3. I have not seen any justification for the drastic measure of
>     making a DMA-based device completely unrewindable. Maybe a more
>     polite "please make this a batch/blocktransfer card" request, thus
>     disallowing only sub-period rewinds, would still be useful for
>     powersaving, without killing dmix.
>
>
> Can those non-interleaved access pcm device with two periods support
> rewind ?

Yes, but very carefully. E.g., suppose that the period size is 10 ms. 
Then, this sequence of events is valid, does not produce xruns and does 
not cause the card to play stale data:

0 ms: Application fills 2 periods via mmap, notices the timestamp and 
starts the PCM.
10 ms: Hardware plays out the 1st period and wakes up the application. 
Application writes the 1st period via mmap and notices the timestamp.
20 ms: Hardware plays out the 2nd period and wakes up the application. 
Application writes the 2nd period via mmap and notices the timestamp.
23 ms: Application wakes up for an unrelated reason and notices the 
timestamp. It knows that the sound card still has 17 ms to play, and 10 
ms (one period, as usual for batch/blocktransfer cards) are 
unrewindable. So it rewinds 6 ms and writes new data.
30 ms: Hardware plays out the 1st period and wakes up the application. 
Application writes the 1st period via mmap and notices the timestamp.

... and so on.

-- 
Alexander E. Patrakov

  reply	other threads:[~2015-07-14 17:39 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 10:10 [RFC PATCH 0/4] better support for bursty DMA usages Pierre-Louis Bossart
2015-07-08 10:10 ` [RFC PATCH 1/4] ALSA: core: let low-level driver or userspace disable rewinds Pierre-Louis Bossart
2015-07-08 14:21   ` Takashi Iwai
2015-07-08 16:58     ` Pierre-Louis Bossart
2015-07-11 17:06   ` Alexander E. Patrakov
2015-07-14  3:32     ` Raymond Yau
2015-07-14 17:39       ` Alexander E. Patrakov [this message]
2015-07-15  1:23         ` Raymond Yau
2015-07-15  4:51           ` Alexander E. Patrakov
2015-07-28 14:19     ` Pierre-Louis Bossart
2015-07-28 15:43       ` Alexander E. Patrakov
2015-07-29 17:46         ` Pierre-Louis Bossart
2015-07-30  6:11           ` Alexander E. Patrakov
2015-07-30 13:46             ` Pierre-Louis Bossart
2015-07-08 10:10 ` [RFC PATCH 2/4] ALSA: core: add .notify callback for pcm ops Pierre-Louis Bossart
2015-07-08 14:27   ` Takashi Iwai
2015-07-08 17:10     ` Pierre-Louis Bossart
2015-07-09 14:44       ` Takashi Iwai
2015-07-09  7:25     ` Raymond Yau
2015-07-09  7:35       ` Pierre-Louis Bossart
2015-07-08 10:10 ` [RFC PATCH 3/4] ALSA: core: add report of max dma burst Pierre-Louis Bossart
2015-07-08 14:37   ` Takashi Iwai
2015-07-08 17:46     ` Pierre-Louis Bossart
2015-07-10  2:35       ` Raymond Yau
2015-07-10 17:13         ` Lars-Peter Clausen
2015-07-11 17:46     ` Alexander E. Patrakov
2015-07-11 18:28       ` Jaroslav Kysela
2015-07-16  2:11         ` Raymond Yau
2015-07-08 10:10 ` [RFC PATCH 4/4] ALSA: hda: add default value for max_dma_burst Pierre-Louis Bossart
2015-07-08 14:31 ` [RFC PATCH 0/4] better support for bursty DMA usages Takashi Iwai
2015-07-08 17:50   ` Pierre-Louis Bossart
2015-07-15 10:14 ` Raymond Yau
2015-07-15 10:38   ` Alexander E. Patrakov
2015-07-22 14:44     ` 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=55A54948.8060703@gmail.com \
    --to=patrakov@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=superquad.vortex2@gmail.com \
    --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.