From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, Jerome Anand <jerome.anand@intel.com>
Subject: Re: [PATCH 4/4] ALSA: x86: Refactor PCM process engine
Date: Mon, 6 Feb 2017 10:00:37 -0600 [thread overview]
Message-ID: <48628c32-c0bd-b443-cf51-d0224817f235@linux.intel.com> (raw)
In-Reply-To: <s5hy3xj48mt.wl-tiwai@suse.de>
On 02/06/2017 09:54 AM, Takashi Iwai wrote:
> On Mon, 06 Feb 2017 16:46:53 +0100,
> Pierre-Louis Bossart wrote:
>> Looks nice, with one comment below:
>>
>>
>>> +/* process a bd, advance to the next */
>>> +static void had_advance_ringbuf(struct snd_pcm_substream *substream,
>>> + struct snd_intelhad *intelhaddata)
>>> +{
>>> + int num_periods = substream->runtime->periods;
>>> +
>>> + /* reprogram the next buffer */
>>> + had_prog_bd(substream, intelhaddata);
>>> +
>>> + /* proceed to next */
>>> + intelhaddata->pcmbuf_head++;
>>> + intelhaddata->pcmbuf_head %= num_periods;
>>> +}
>>> +
>>> +/* process the current BD(s);
>>> + * returns the current PCM buffer byte position, or -EPIPE for underrun.
>>> + */
>>> +static int had_process_ringbuf(struct snd_pcm_substream *substream,
>>> + struct snd_intelhad *intelhaddata)
>>> +{
>>> + int len, processed;
>>> + unsigned long flags;
>>> +
>>> + processed = 0;
>>> + spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
>>> + for (;;) {
>>> + /* get the remaining bytes on the buffer */
>>> + had_read_register(intelhaddata,
>>> + AUD_BUF_LEN(intelhaddata->bd_head),
>>> + &len);
>>> + if (len < 0 || len > intelhaddata->period_bytes) {
>>> + dev_dbg(intelhaddata->dev, "Invalid buf length %d\n",
>>> + len);
>>> + len = -EPIPE;
>>> + goto out;
>>> + }
>>> +
>>> + if (len > 0) /* OK, this is the current buffer */
>>> + break;
>>> +
>>> + /* len=0 => already empty, check the next buffer */
>>> + if (++processed >= intelhaddata->num_bds) {
>>> + len = -EPIPE; /* all empty? - report underrun */
>>> + goto out;
>>> + }
>>> + had_advance_ringbuf(substream, intelhaddata);
>>> + }
>>> +
>>> + len = intelhaddata->period_bytes - len;
>>> + len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head;
>> I don't know if this code is completely correct (and I had similar
>> concerns with David's).
>> If the len==0, then the new buffer descriptor will be used in the next
>> iteration. If the register is read immediately, there is a risk that
>> the DMA position has not moved and len then becomes
>> intelhaddata->period_bytes, but the last line will increase the number
>> of bytes by a period. I think there should be a test here to handle
>> this corner case.
> That's OK. When len=0, the loop goes to the next buffer -- i.e.
> pcm_buf is also increased. Then it reads len=period_bytes and quits
> the loop. Now len is re-calculated as
> len = period_bytes - len;
> --> len = 0
> len += period_bytes * pcmbuf_head;
> --> len = new head position in bytes
>
> which is exactly the expected position.
>
>
ok, i guess I need more coffee... David's code did not include the
additional read and I wanted to check this was fine.
Thanks for the precision.
next prev parent reply other threads:[~2017-02-06 16:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-03 16:43 [PATCH 0/4] Yet another patchset for LPE audio refactoring Takashi Iwai
2017-02-03 16:43 ` [PATCH 1/4] ALSA: x86: Don't pass SNDRV_PCM_INFO_BATCH flag Takashi Iwai
2017-02-03 19:39 ` Pierre-Louis Bossart
2017-02-03 20:13 ` Takashi Iwai
2017-02-03 23:13 ` Pierre-Louis Bossart
2017-02-04 7:57 ` Takashi Iwai
2017-02-06 19:01 ` Takashi Iwai
2017-02-06 21:27 ` Pierre-Louis Bossart
2017-02-06 21:51 ` Takashi Iwai
2017-02-03 16:43 ` [PATCH 2/4] ALSA: x86: Explicit specify 32bit DMA Takashi Iwai
2017-02-03 16:43 ` [PATCH 3/4] ALSA: x86: Don't check connection in lowlevel accessors Takashi Iwai
2017-02-03 16:44 ` [PATCH 4/4] ALSA: x86: Refactor PCM process engine Takashi Iwai
2017-02-03 19:47 ` Pierre-Louis Bossart
2017-02-03 20:11 ` Takashi Iwai
2017-02-03 23:22 ` Pierre-Louis Bossart
2017-02-04 7:51 ` Takashi Iwai
2017-02-06 11:22 ` Takashi Iwai
2017-02-06 15:46 ` Pierre-Louis Bossart
2017-02-06 15:54 ` Takashi Iwai
2017-02-06 16:00 ` Pierre-Louis Bossart [this message]
2017-02-06 19:07 ` [PATCH 0/4] Yet another patchset for LPE audio refactoring Takashi Iwai
2017-02-06 21:16 ` Pierre-Louis Bossart
2017-02-06 21:45 ` Takashi Iwai
2017-02-06 23:56 ` Pierre-Louis Bossart
2017-02-07 1:22 ` Pierre-Louis Bossart
2017-02-07 6:39 ` Takashi Iwai
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=48628c32-c0bd-b443-cf51-d0224817f235@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=jerome.anand@intel.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 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).