The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
@ 2025-02-03 12:49 srinivas.kandagatla
  2025-02-03 14:09 ` Dmitry Baryshkov
  2025-02-03 14:17 ` Mark Brown
  0 siblings, 2 replies; 8+ messages in thread
From: srinivas.kandagatla @ 2025-02-03 12:49 UTC (permalink / raw)
  To: broonie
  Cc: lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel,
	dmitry.baryshkov, Srinivas Kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

With the existing code, we are only setting up one period at a time, in a
ping-pong buffer style. This tiggers lot of underruns in the dsp
leading to jitter noise during audio playback.

Fix this by scheduling all the periods, this will ensure that the dsp
has enough buffer feed and ultimatley fixing the underruns and audio
distortion.

Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
Reported-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 sound/soc/qcom/qdsp6/q6apm-dai.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index c9404b5934c7..148c3fb77168 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -299,15 +299,17 @@ static int q6apm_dai_trigger(struct snd_soc_component *component,
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct q6apm_dai_rtd *prtd = runtime->private_data;
-	int ret = 0;
+	int ret = 0, i;
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
 		 /* start writing buffers for playback only as we already queued capture buffers */
-		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-			ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+			for (i = 0; i < runtime->periods; i++)
+				ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
+		}
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 		/* TODO support be handled via SoftPause Module */
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 12:49 [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming srinivas.kandagatla
@ 2025-02-03 14:09 ` Dmitry Baryshkov
  2025-02-03 14:12   ` Srinivas Kandagatla
  2025-02-03 14:17 ` Mark Brown
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry Baryshkov @ 2025-02-03 14:09 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: broonie, lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel

On Mon, Feb 03, 2025 at 12:49:45PM +0000, srinivas.kandagatla@linaro.org wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> 
> With the existing code, we are only setting up one period at a time, in a
> ping-pong buffer style. This tiggers lot of underruns in the dsp
> leading to jitter noise during audio playback.
> 
> Fix this by scheduling all the periods, this will ensure that the dsp
> has enough buffer feed and ultimatley fixing the underruns and audio
> distortion.
> 
> Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
> Reported-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
>  sound/soc/qcom/qdsp6/q6apm-dai.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
> index c9404b5934c7..148c3fb77168 100644
> --- a/sound/soc/qcom/qdsp6/q6apm-dai.c
> +++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
> @@ -299,15 +299,17 @@ static int q6apm_dai_trigger(struct snd_soc_component *component,
>  {
>  	struct snd_pcm_runtime *runtime = substream->runtime;
>  	struct q6apm_dai_rtd *prtd = runtime->private_data;
> -	int ret = 0;
> +	int ret = 0, i;
>  
>  	switch (cmd) {
>  	case SNDRV_PCM_TRIGGER_START:
>  	case SNDRV_PCM_TRIGGER_RESUME:
>  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
>  		 /* start writing buffers for playback only as we already queued capture buffers */
> -		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
> -			ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
> +		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
> +			for (i = 0; i < runtime->periods; i++)
> +				ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);

So, all errors except the last one are ignored now?

> +		}
>  		break;
>  	case SNDRV_PCM_TRIGGER_STOP:
>  		/* TODO support be handled via SoftPause Module */
> -- 
> 2.39.5
> 

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 14:09 ` Dmitry Baryshkov
@ 2025-02-03 14:12   ` Srinivas Kandagatla
  0 siblings, 0 replies; 8+ messages in thread
From: Srinivas Kandagatla @ 2025-02-03 14:12 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: broonie, lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel



On 03/02/2025 14:09, Dmitry Baryshkov wrote:
> On Mon, Feb 03, 2025 at 12:49:45PM +0000, srinivas.kandagatla@linaro.org wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>>
>> With the existing code, we are only setting up one period at a time, in a
>> ping-pong buffer style. This tiggers lot of underruns in the dsp
>> leading to jitter noise during audio playback.
>>
>> Fix this by scheduling all the periods, this will ensure that the dsp
>> has enough buffer feed and ultimatley fixing the underruns and audio
>> distortion.
>>
>> Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
>> Reported-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>> ---
>>   sound/soc/qcom/qdsp6/q6apm-dai.c | 8 +++++---
>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
>> index c9404b5934c7..148c3fb77168 100644
>> --- a/sound/soc/qcom/qdsp6/q6apm-dai.c
>> +++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
>> @@ -299,15 +299,17 @@ static int q6apm_dai_trigger(struct snd_soc_component *component,
>>   {
>>   	struct snd_pcm_runtime *runtime = substream->runtime;
>>   	struct q6apm_dai_rtd *prtd = runtime->private_data;
>> -	int ret = 0;
>> +	int ret = 0, i;
>>   
>>   	switch (cmd) {
>>   	case SNDRV_PCM_TRIGGER_START:
>>   	case SNDRV_PCM_TRIGGER_RESUME:
>>   	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
>>   		 /* start writing buffers for playback only as we already queued capture buffers */
>> -		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
>> -			ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
>> +		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
>> +			for (i = 0; i < runtime->periods; i++)
>> +				ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
> 
> So, all errors except the last one are ignored now?

this needs fixing,

thanks for review
--srini
> 
>> +		}
>>   		break;
>>   	case SNDRV_PCM_TRIGGER_STOP:
>>   		/* TODO support be handled via SoftPause Module */
>> -- 
>> 2.39.5
>>
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 12:49 [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming srinivas.kandagatla
  2025-02-03 14:09 ` Dmitry Baryshkov
@ 2025-02-03 14:17 ` Mark Brown
  2025-02-03 14:30   ` Srinivas Kandagatla
  1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2025-02-03 14:17 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel,
	dmitry.baryshkov

[-- Attachment #1: Type: text/plain, Size: 656 bytes --]

On Mon, Feb 03, 2025 at 12:49:45PM +0000, srinivas.kandagatla@linaro.org wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> 
> With the existing code, we are only setting up one period at a time, in a
> ping-pong buffer style. This tiggers lot of underruns in the dsp
> leading to jitter noise during audio playback.
> 
> Fix this by scheduling all the periods, this will ensure that the dsp
> has enough buffer feed and ultimatley fixing the underruns and audio
> distortion.

Should we be writing all periods or just the minimum number of periods
that's configured?  Userspace might not have filled the whole buffer
yet.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 14:17 ` Mark Brown
@ 2025-02-03 14:30   ` Srinivas Kandagatla
  2025-02-03 15:07     ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Srinivas Kandagatla @ 2025-02-03 14:30 UTC (permalink / raw)
  To: Mark Brown
  Cc: lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel,
	dmitry.baryshkov



On 03/02/2025 14:17, Mark Brown wrote:
> On Mon, Feb 03, 2025 at 12:49:45PM +0000, srinivas.kandagatla@linaro.org wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>>
>> With the existing code, we are only setting up one period at a time, in a
>> ping-pong buffer style. This tiggers lot of underruns in the dsp
>> leading to jitter noise during audio playback.
>>
>> Fix this by scheduling all the periods, this will ensure that the dsp
>> has enough buffer feed and ultimatley fixing the underruns and audio
>> distortion.
> 
> Should we be writing all periods or just the minimum number of periods
> that's configured?  Userspace might not have filled the whole buffer
> yet.
Just minimum number of periods or 1 period. We are queuing up all the 
periods to the DSP, so that we do not have to wait for period interrupt 
to queue the next one. This significantly reduces the latency in queuing 
the periods to dsp.

--srini

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 14:30   ` Srinivas Kandagatla
@ 2025-02-03 15:07     ` Mark Brown
  2025-02-03 17:04       ` Srinivas Kandagatla
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2025-02-03 15:07 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel,
	dmitry.baryshkov

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

On Mon, Feb 03, 2025 at 02:30:26PM +0000, Srinivas Kandagatla wrote:
> On 03/02/2025 14:17, Mark Brown wrote:
> > On Mon, Feb 03, 2025 at 12:49:45PM +0000, srinivas.kandagatla@linaro.org wrote:

> > > Fix this by scheduling all the periods, this will ensure that the dsp
> > > has enough buffer feed and ultimatley fixing the underruns and audio
> > > distortion.

> > Should we be writing all periods or just the minimum number of periods
> > that's configured?  Userspace might not have filled the whole buffer
> > yet.

> Just minimum number of periods or 1 period. We are queuing up all the
> periods to the DSP, so that we do not have to wait for period interrupt to
> queue the next one. This significantly reduces the latency in queuing the
> periods to dsp.

What guarantee do you have that the data isn't garbage?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 15:07     ` Mark Brown
@ 2025-02-03 17:04       ` Srinivas Kandagatla
  2025-02-03 17:27         ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Srinivas Kandagatla @ 2025-02-03 17:04 UTC (permalink / raw)
  To: Mark Brown
  Cc: lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel,
	dmitry.baryshkov



On 03/02/2025 15:07, Mark Brown wrote:
> On Mon, Feb 03, 2025 at 02:30:26PM +0000, Srinivas Kandagatla wrote:
>> On 03/02/2025 14:17, Mark Brown wrote:
>>> On Mon, Feb 03, 2025 at 12:49:45PM +0000, srinivas.kandagatla@linaro.org wrote:
> 
>>>> Fix this by scheduling all the periods, this will ensure that the dsp
>>>> has enough buffer feed and ultimatley fixing the underruns and audio
>>>> distortion.
> 
>>> Should we be writing all periods or just the minimum number of periods
>>> that's configured?  Userspace might not have filled the whole buffer
>>> yet.
> 
>> Just minimum number of periods or 1 period. We are queuing up all the
>> periods to the DSP, so that we do not have to wait for period interrupt to
>> queue the next one. This significantly reduces the latency in queuing the
>> periods to dsp.
> 
> What guarantee do you have that the data isn't garbage?

Yes, its possible that some of the last periods might be not be written 
yet by userspace.

We can always add some checks on the available periods to queue to dsp 
something like:

----------------->cut<----------------
avail_periods = (runtime->buffer_size  - 
snd_pcm_playback_avail(runtime))/runtime->period_size;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
	for (i = 0; i < avail_periods; i++)
		ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
		if (ret)
			break;
}
----------------->cut<----------------


--srini

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming
  2025-02-03 17:04       ` Srinivas Kandagatla
@ 2025-02-03 17:27         ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2025-02-03 17:27 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: lgirdwood, perex, tiwai, krzysztof.kozlowski,
	pierre-louis.bossart, linux-sound, linux-arm-msm, linux-kernel,
	dmitry.baryshkov

[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

On Mon, Feb 03, 2025 at 05:04:54PM +0000, Srinivas Kandagatla wrote:
> On 03/02/2025 15:07, Mark Brown wrote:

> > What guarantee do you have that the data isn't garbage?

> Yes, its possible that some of the last periods might be not be written yet
> by userspace.

> We can always add some checks on the available periods to queue to dsp
> something like:

Yes, you need something like that.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-02-03 17:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-03 12:49 [PATCH] ASoC: q6apm-dai: schedule all the periods before we start streaming srinivas.kandagatla
2025-02-03 14:09 ` Dmitry Baryshkov
2025-02-03 14:12   ` Srinivas Kandagatla
2025-02-03 14:17 ` Mark Brown
2025-02-03 14:30   ` Srinivas Kandagatla
2025-02-03 15:07     ` Mark Brown
2025-02-03 17:04       ` Srinivas Kandagatla
2025-02-03 17:27         ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox