ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occurs
Subsystems (3)
PATCH 1/1 ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occurs
From: "Fang, Yang A" <[email protected]>
We should not read sst hw_ptr and pcm_delay in sst_platform_pcm_pointer Since it will be ricky if sst_platform_pcm_pointer is called while dsp is updating the timestamp.Now read sst hw_ptr after period elapse interrupt occurs.
--- sound/soc/intel/atom/sst-mfld-platform-pcm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
sound/soc/intel/atom/sst-mfld-platform-pcm.c +11 -7
@@ -263,17 +263,27 @@ static int sst_platform_alloc_stream(struct snd_pcm_substream *substream,static void sst_period_elapsed (void *arg) {struct snd_pcm_substream *substream = arg; +struct snd_soc_pcm_runtime *rtd;struct sst_runtime_stream *stream; +struct pcm_stream_info *str_info;int status; +int ret_val;if (!substream || !substream->runtime)return ; + rtd = substream->private_data; stream = substream->runtime->private_data;if (!stream)return ; status =sst_get_stream_status (stream);if (status !=SST_PLATFORM_RUNNING )return ; + str_info = &stream->stream_info; + ret_val = stream->ops->stream_read_tstamp (sst->dev, str_info); +if (ret_val) { +dev_err (rtd->dev,"sst: err code = %d\n" , ret_val); +return ; + }snd_pcm_period_elapsed (substream); }
@@ -660,20 +670,14 @@ static snd_pcm_uframes_t sst_platform_pcm_pointer (struct snd_pcm_substream *substream) { struct sst_runtime_stream *stream; -int ret_val, status; +int status;struct pcm_stream_info *str_info; -struct snd_soc_pcm_runtime *rtd = substream->private_data; stream = substream->runtime->private_data; status =sst_get_stream_status (stream);if (status ==SST_PLATFORM_INIT )return 0 ; str_info = &stream->stream_info; - ret_val = stream->ops->stream_read_tstamp (sst->dev, str_info); -if (ret_val) { -dev_err (rtd->dev,"sst: error code = %d\n" , ret_val); -return ret_val; - } substream->runtime->delay = str_info->pcm_delay;return str_info->buffer_ptr; }
Signature · 1 line
1.7.9.5
Mark Brown
maintainerQuoted 4 lines · On Sun, Aug 16, 2015 at 11:12:25PM -0700, [email protected] wrote:
We should not read sst
hw_ptrandpcm_delayinsst_platform_pcm_pointerSince it will be ricky ifsst_platform_pcm_pointeris called while dsp is updating the timestamp.Now read ssthw_ptrafter period elapse interrupt occurs.
So I guess there's still some risk that we could run into problems here if we take too long to service the interrupt and/or the period is very short? Is there anything we can do to improve that?
Quoted 15 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Monday, August 17, 2015 12:56 PM
To: Fang, Yang A
Cc: [email protected]; [email protected]; [email protected]; Nujella, Sathyanarayana; [email protected]; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: Re: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursOn Sun, Aug 16, 2015 at 11:12:25PM -0700, [email protected] wrote:
Quoted 8 lines
Quoted 4 lines
We should not read sst
hw_ptrandpcm_delayinsst_platform_pcm_pointerSince it will be ricky ifsst_platform_pcm_pointeris called while dsp is updating the timestamp.Now read ssthw_ptrafter period elapse interrupt occurs.So I guess there's still some risk that we could run into problems here if we take too long to service the interrupt and/or the period is very short? Is there anything we can do to improve that?
Hi Mark,
I think before and after the patch. There is no difference in term of handling the period elapse interrupt . because before the patch sst_period_elapsed calls the snd_pcm_period_elapsed which in turn calling the sst_platform_pcm_pointer which calls the stream_read_tstamp.
Mark Brown
maintainerQuoted 5 lines · Yang A
Quoted 4 lines
Quoted 4 lines
We should not read sst
hw_ptrandpcm_delayinsst_platform_pcm_pointerSince it will be ricky ifsst_platform_pcm_pointeris called while dsp is updating the timestamp.Now read ssthw_ptrafter period elapse interrupt occurs.
Quoted 8 lines
Quoted 3 lines
So I guess there's still some risk that we could run into problems here if we take too long to service the interrupt and/or the period is very short? Is there anything we can do to improve that?
I think before and after the patch. There is no difference in term of handling the period elapse interrupt . because before the patch
sst_period_elapsedcalls thesnd_pcm_period_elapsedwhich in turn calling thesst_platform_pcm_pointerwhich calls thestream_read_tstamp.
I'm not sure I understand what the patch fixes then? My concern is that we're just moving the timing around which changes but doesn't address the race condition.
Quoted 24 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, August 18, 2015 5:35 PM
To: Fang, Yang A
Cc: [email protected]; [email protected]; [email protected]; Nujella, Sathyanarayana; [email protected]; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: Re: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursQuoted 8 lines · Yang A
Quoted 8 lines
Quoted 4 lines
We should not read sst
hw_ptrandpcm_delayinsst_platform_pcm_pointerSince it will be ricky ifsst_platform_pcm_pointeris called while dsp is updating the timestamp.Now read ssthw_ptrafter period elapse interrupt occurs.So I guess there's still some risk that we could run into problems here if we take too long to service the interrupt and/or the period is very short? Is there anything we can do to improve that?
Quoted 8 lines
Quoted 4 lines
I think before and after the patch. There is no difference in term of
handling the period elapse interrupt . because before the patchsst_period_elapsedcalls thesnd_pcm_period_elapsedwhich in turn calling thesst_platform_pcm_pointerwhich calls thestream_read_tstamp.I'm not sure I understand what the patch fixes then? My concern is that we're just moving the timing around which changes but doesn't address the race condition.
We are seeing the issue during the long time playback.
The ring_buffer_counter (part of snd_sst_tstamp struct )supposes only increasing by the firmware once firmware fetches one period size of data.
It will update the ring_buffer_counter in the mailbox and trigger a period elapse interrupt. We have found the ring_buffer_counter got decreased
during long time playback if we call stream_read_tstamp to read mailbox in sst_platform_pcm_pointer function.
There are two cases sst_platform_pcm_pointer will be getting called. One is called by sst_period_elapsed function.
The second case is triggered by the userspace ioctl . The second case supposes reading the same case ring_buffer_counter value as last read
when period elapse interrupt occurs . However we saw it somehow decreases.This causes audio stutter.
Quoted 55 lines
-----Original Message-----
From: Fang, Yang A
Sent: Wednesday, August 19, 2015 6:25 PM
To: 'Mark Brown'
Cc: [email protected]; [email protected]; [email protected]; Nujella, Sathyanarayana; [email protected]; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: RE: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursQuoted 11 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, August 18, 2015 5:35 PM
To: Fang, Yang A
Cc: [email protected]; [email protected]; [email protected]; Nujella, Sathyanarayana; [email protected]; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: Re: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursQuoted 15 lines
Quoted 13 lines · Yang A
Quoted 8 lines
Quoted 4 lines
We should not read sst
hw_ptrandpcm_delayinsst_platform_pcm_pointerSince it will be ricky ifsst_platform_pcm_pointeris called while dsp is updating the timestamp.Now read ssthw_ptrafter period elapse interrupt occurs.So I guess there's still some risk that we could run into problems here if we take too long to service the interrupt and/or the period is very short? Is there anything we can do to improve that?
I think before and after the patch. There is no difference in term
of handling the period elapse interrupt . because before the patchsst_period_elapsedcalls thesnd_pcm_period_elapsedwhich in turn calling thesst_platform_pcm_pointerwhich calls the
stream_read_tstamp.Quoted 4 lines
I'm not sure I understand what the patch fixes then? My concern is that we're just moving the timing around which changes but doesn't address the race condition.
We are seeing the issue during the long time playback.
Thering_buffer_counter(part ofsnd_sst_tstampstruct )supposes only increasing by the firmware once firmware fetches one period size of data.
It will update thering_buffer_counterin the mailbox and trigger a period
elapse interrupt. We have found thering_buffer_countergot decreased during long time playback if we callstream_read_tstampto read mailbox insst_platform_pcm_pointerfunction.
Quoted 6 lines
There are two cases
sst_platform_pcm_pointerwill be getting called. One is called bysst_period_elapsedfunction.
The second case is triggered by the userspace ioctl . The second case
supposes reading the same casering_buffer_countervalue as last read when period elapse interrupt occurs . However we saw it somehow decreases.This causes audio stutter.
So I moved stream_read_tstamp to read the mailbox sst_period_elapsed to make sure read after receving the interrupt and return a cached value if other place tried to read. you are right this is indeed a workaround patch for the time being
Quoted 76 lines
-----Original Message-----
From: Fang, Yang A
Sent: Wednesday, August 19, 2015 6:30 PM
To: 'Mark Brown'
Cc: '[email protected]'; '[email protected]'; '[email protected]'; Nujella, Sathyanarayana; '[email protected]'; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: RE: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursQuoted 30 lines
-----Original Message-----
From: Fang, Yang A
Sent: Wednesday, August 19, 2015 6:25 PM
To: 'Mark Brown'
Cc: [email protected]; [email protected]; [email protected]; Nujella, Sathyanarayana; [email protected]; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: RE: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursQuoted 17 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, August 18, 2015 5:35 PM
To: Fang, Yang A
Cc: [email protected]; [email protected]; [email protected]; Nujella, Sathyanarayana; [email protected]; Sripathi, Srinivas; Iriawan, Denny; Jain, Praveen K; Koul, Vinod; Mirche, Dinesh
Subject: Re: [PATCH] ASoC: Intel: Bsw: Read sst DSP DMA pointer after period elapse occursQuoted 4 lines · Yang A
Quoted 4 lines
Quoted 4 lines
We should not read sst
hw_ptrandpcm_delayinsst_platform_pcm_pointerSince it will be ricky ifsst_platform_pcm_pointeris called while dsp is updating the timestamp.Now read ssthw_ptrafter period elapse interruptoccurs.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
So I guess there's still some risk that we could run into problems here if we take too long to service the interrupt and/or the period is very short? Is there anything we can do to
improve that?
Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
I think before and after the patch. There is no difference in
term of handling the period elapse interrupt . because before the patchsst_period_elapsedcalls thesnd_pcm_period_elapsedwhich in turn calling thesst_platform_pcm_pointerwhich calls the
stream_read_tstamp.Quoted 4 lines
I'm not sure I understand what the patch fixes then? My concern is that we're just moving the timing around which changes but doesn't address the race condition.
We are seeing the issue during the long time playback.
Thering_buffer_counter(part ofsnd_sst_tstampstruct )supposes only increasing by the firmware once firmware fetches one period size of data.
It will update thering_buffer_counterin the mailbox and trigger a
period elapse interrupt. We have found thering_buffer_countergot decreased during long time playback if we callstream_read_tstampto read mailbox insst_platform_pcm_pointerfunction.Quoted 6 lines
There are two cases
sst_platform_pcm_pointerwill be getting called. One is called bysst_period_elapsedfunction.
The second case is triggered by the userspace ioctl . The second case
supposes reading the same casering_buffer_countervalue as last read when period elapse interrupt occurs . However we saw it somehow decreases.This causes audio stutter.
Quoted 4 lines
So I moved
stream_read_tstampto read the mailboxsst_period_elapsedto make sure read after receving the interrupt and return a cached value if other place tried to read. you are right this is indeed a workaround patch for the time being
Hi Mark,
Could you please let me know your further comment? Thanks,
Yang
Mark Brown
maintainerQuoted 1 line · Yang A
Could you please let me know your further comment?
At the very least this needs a better, more comprehensible patch which makes it clear that this is just a workaround rather than actually fixing anything. Of course I'd be much happier with a patch which was a clear fix.