ASoC: soc-pcm: Use different sequence for start/stop trigger
PATCH v2 1/1 ASoC: soc-pcm: Use different sequence for start/stop trigger
On stream stop currently we stop the DMA first followed by the CPU DAI. This can cause underflow (playback) or overflow (capture) on the DAI side as the DMA is no longer feeding data while the DAI is still active. It can be observed easily if the DAI side does not have FIFO (or it is disabled) to survive the time while the DMA is stopped, but still can happen on relatively slow CPUs when relatively high sampling rate is used:
the FIFO is drained between the time the DMA is stopped and the DAI is stopped.
It can only fixed by using different sequence within trigger for 'stop' and 'start':
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Trigger order: dai_link, DMA, CPU DAI then the codec
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Trigger order: codec, CPU DAI, DMA then dai_link
---
Hi,
Changes since v1:
- Rebased on top 'ASoC: soc-component: fix a couple missing error assignments'
Changes since rfc:
- Fixed missing error assignments (copy pasted the error)
- Document the trigger order in the commit message
Regards,
Peter
sound/soc/soc-pcm.c | 64 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-)
sound/soc/soc-pcm.c +61 -3
@@ -1047,7 +1047,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)return 0 ; } -static int soc_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +static int soc_pcm_trigger_start (struct snd_pcm_substream *substream,int cmd) {struct snd_soc_pcm_runtime *rtd = substream->private_data;struct snd_soc_component *component;
@@ -1056,8 +1056,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)struct snd_soc_dai *codec_dai;int i, ret; -for_each_rtd_codec_dai (rtd, i, codec_dai) { - ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (rtd->dai_link->ops->trigger) { + ret = rtd->dai_link->ops->trigger (substream, cmd);if (ret <0 )return ret; }
@@ -1074,6 +1074,42 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)if (ret <0 )return ret; +for_each_rtd_codec_dai (rtd, i, codec_dai) { + ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (ret <0 ) +return ret; + } + +return 0 ; +} + +static int soc_pcm_trigger_stop (struct snd_pcm_substream *substream,int cmd) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component; +struct snd_soc_rtdcom_list *rtdcom; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +struct snd_soc_dai *codec_dai; +int i, ret; + +for_each_rtd_codec_dai (rtd, i, codec_dai) { + ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (ret <0 ) +return ret; + } + + ret =snd_soc_dai_trigger (cpu_dai, substream, cmd); +if (ret <0 ) +return ret; + +for_each_rtdcom (rtd, rtdcom) { + component = rtdcom->component; + + ret =snd_soc_component_trigger (component, substream, cmd); +if (ret <0 ) +return ret; + } +if (rtd->dai_link->ops->trigger) { ret = rtd->dai_link->ops->trigger (substream, cmd);if (ret <0 )
@@ -1083,6 +1119,28 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)return 0 ; } +static int soc_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +int ret; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + ret =soc_pcm_trigger_start (substream, cmd); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + ret =soc_pcm_trigger_stop (substream, cmd); +break ; +default : +return -EINVAL ; + } + +return ret; +} +static int soc_pcm_bespoke_trigger (struct snd_pcm_substream *substream,int cmd) {
Signature · 9 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 16 lines · Peter Ujfalusi
On stream stop currently we stop the DMA first followed by the CPU DAI. This can cause underflow (playback) or overflow (capture) on the DAI side as the DMA is no longer feeding data while the DAI is still active. It can be observed easily if the DAI side does not have FIFO (or it is disabled) to survive the time while the DMA is stopped, but still can happen on relatively slow CPUs when relatively high sampling rate is used:
the FIFO is drained between the time the DMA is stopped and the DAI is stopped.It can only fixed by using different sequence within trigger for 'stop' and 'start':
caseSNDRV_PCM_TRIGGER_START:
caseSNDRV_PCM_TRIGGER_RESUME:
caseSNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Trigger order:dai_link, DMA, CPU DAI then the codec
Quoted 6 lines
case
SNDRV_PCM_TRIGGER_STOP:
caseSNDRV_PCM_TRIGGER_SUSPEND:
caseSNDRV_PCM_TRIGGER_PAUSE_PUSH:
Trigger order: codec, CPU DAI, DMA thendai_linkSigned-off-by Peter Ujfalusi <[email protected]>
This patch was tested by the Intel SOF QA folks, and we don't see any errors added by this sequence change (more precisely we see the usual random IPC timeouts we are chasing but nothing new clearly caused by this patch). And the change makes sense so
Quoted 103 lines
---
Hi,Changes since v1:
- Rebased on top 'ASoC: soc-component: fix a couple missing error assignments'Changes since rfc:
- Fixed missing error assignments (copy pasted the error)
- Document the trigger order in the commit messageRegards,
Petersound/soc/soc-pcm.c | 64 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-)sound/soc/soc-pcm.c +54
-3@@ -1047,7 +1047,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)return 0 ; } -static int soc_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +static int soc_pcm_trigger_start (struct snd_pcm_substream *substream,int cmd) {struct snd_soc_pcm_runtime *rtd = substream->private_data;struct snd_soc_component *component;@@ -1056,8 +1056,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)struct snd_soc_dai *codec_dai;int i, ret; -for_each_rtd_codec_dai (rtd, i, codec_dai) { - ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (rtd->dai_link->ops->trigger) { + ret = rtd->dai_link->ops->trigger (substream, cmd);if (ret <0 )return ret; }@@ -1074,6 +1074,42 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)if (ret <0 )return ret; +for_each_rtd_codec_dai (rtd, i, codec_dai) { + ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (ret <0 ) +return ret; + } + +return 0 ; +} + +static int soc_pcm_trigger_stop (struct snd_pcm_substream *substream,int cmd) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component; +struct snd_soc_rtdcom_list *rtdcom; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +struct snd_soc_dai *codec_dai; +int i, ret; + +for_each_rtd_codec_dai (rtd, i, codec_dai) { + ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (ret <0 ) +return ret; + } + + ret =snd_soc_dai_trigger (cpu_dai, substream, cmd); +if (ret <0 ) +return ret; + +for_each_rtdcom (rtd, rtdcom) { + component = rtdcom->component; + + ret =snd_soc_component_trigger (component, substream, cmd); +if (ret <0 ) +return ret; + } +if (rtd->dai_link->ops->trigger) { ret = rtd->dai_link->ops->trigger (substream, cmd);if (ret <0 )@@ -1083,6 +1119,28 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)return 0 ; } +static int soc_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +int ret; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + ret =soc_pcm_trigger_start (substream, cmd); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + ret =soc_pcm_trigger_stop (substream, cmd); +break ;
sound/soc/soc-pcm.c static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) · line 1146
Quoted 10 lines
sound/soc/soc-pcm.c +7
-0+default : +return -EINVAL ; + } + +return ret; +} +static int soc_pcm_bespoke_trigger (struct snd_pcm_substream *substream,int cmd) {
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainer[alsa-devel] Applied "ASoC: soc-pcm: Use different sequence for start/stop trigger" to the asoc tree
In reply to Peter UjfalusiThe patch
ASoC: soc-pcm: Use different sequence for start/stop trigger
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From 4378f1fbe924054a09ff0d4e39e1a581b9245252 Mon Sep 17 00:00:00 2001
From: Peter Ujfalusi <[email protected]>
Date: Fri, 27 Sep 2019 10:16:46 +0300
Subject: [PATCH] ASoC: soc-pcm: Use different sequence for start/stop trigger
On stream stop currently we stop the DMA first followed by the CPU DAI. This can cause underflow (playback) or overflow (capture) on the DAI side as the DMA is no longer feeding data while the DAI is still active. It can be observed easily if the DAI side does not have FIFO (or it is disabled) to survive the time while the DMA is stopped, but still can happen on relatively slow CPUs when relatively high sampling rate is used:
the FIFO is drained between the time the DMA is stopped and the DAI is stopped.
It can only fixed by using different sequence within trigger for 'stop' and 'start':
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Trigger order: dai_link, DMA, CPU DAI then the codec
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Trigger order: codec, CPU DAI, DMA then dai_link
--- sound/soc/soc-pcm.c | 64 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-)
sound/soc/soc-pcm.c +61 -3
@@ -1047,7 +1047,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)return 0 ; } -static int soc_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +static int soc_pcm_trigger_start (struct snd_pcm_substream *substream,int cmd) {struct snd_soc_pcm_runtime *rtd = substream->private_data;struct snd_soc_component *component;
@@ -1056,8 +1056,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)struct snd_soc_dai *codec_dai;int i, ret; -for_each_rtd_codec_dai (rtd, i, codec_dai) { - ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (rtd->dai_link->ops->trigger) { + ret = rtd->dai_link->ops->trigger (substream, cmd);if (ret <0 )return ret; }
@@ -1074,6 +1074,42 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)if (ret <0 )return ret; +for_each_rtd_codec_dai (rtd, i, codec_dai) { + ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (ret <0 ) +return ret; + } + +return 0 ; +} + +static int soc_pcm_trigger_stop (struct snd_pcm_substream *substream,int cmd) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component; +struct snd_soc_rtdcom_list *rtdcom; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +struct snd_soc_dai *codec_dai; +int i, ret; + +for_each_rtd_codec_dai (rtd, i, codec_dai) { + ret =snd_soc_dai_trigger (codec_dai, substream, cmd); +if (ret <0 ) +return ret; + } + + ret =snd_soc_dai_trigger (cpu_dai, substream, cmd); +if (ret <0 ) +return ret; + +for_each_rtdcom (rtd, rtdcom) { + component = rtdcom->component; + + ret =snd_soc_component_trigger (component, substream, cmd); +if (ret <0 ) +return ret; + } +if (rtd->dai_link->ops->trigger) { ret = rtd->dai_link->ops->trigger (substream, cmd);if (ret <0 )
@@ -1083,6 +1119,28 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)return 0 ; } +static int soc_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +int ret; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + ret =soc_pcm_trigger_start (substream, cmd); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + ret =soc_pcm_trigger_stop (substream, cmd); +break ; +default : +return -EINVAL ; + } + +return ret; +} +static int soc_pcm_bespoke_trigger (struct snd_pcm_substream *substream,int cmd) {
Signature · 6 lines
2.20.1 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel