Skip to contentSkip to conversation

ALSA: pcm_dmaengine: Use more shorter periods for SEGMENT granularity PCM DMA

RFC PATCH In review Marek Vasut 2 participants 3 messages Mar 27 – Mar 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ALSA: pcm_dmaengine: Use more shorter periods for SEGMENT granularity PCM DMA

The segment granularity PCM DMA updates PCM pointer at the end of every segment. In case the segments are too long, which happens with pipewire, it may happen that pcm_lib wait_for_avail() will time out while waiting for PCM pointer update and playback will fail with IO error.

In case of SEGMENT granularity, use 8 shorter segments over the default 2 long segments set in dmaengine_pcm_set_runtime_hwparams(). That gives the DMA engine some chance to update the PCM pointer every once in a while and prevent the timeout.

---
Cc: Jaroslav Kysela <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]

---
 sound/core/pcm_dmaengine.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/core/pcm_dmaengine.c +4 -0
index 1306b04be171a..092ce958e1aee 100644
@@ -424,6 +424,10 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(
 			hw->info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME;
 		if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT)
 			hw->info |= SNDRV_PCM_INFO_BATCH;
+		if (dma_caps.residue_granularity == DMA_RESIDUE_GRANULARITY_SEGMENT) {
+			hw->periods_min = 8;
+			hw->period_bytes_max /= 8;
+		}
 
 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 			addr_widths = dma_caps.dst_addr_widths;
Signature · 1 line
2.53.0
#1 lore raw
Quoted 28 lines · Marek Vasut

The segment granularity PCM DMA updates PCM pointer at the end of every segment. In case the segments are too long, which happens with pipewire, it may happen that pcm_lib wait_for_avail() will time out while waiting for PCM pointer update and playback will fail with IO error.

In case of SEGMENT granularity, use 8 shorter segments over the default 2 long segments set in dmaengine_pcm_set_runtime_hwparams(). That gives the DMA engine some chance to update the PCM pointer every once in a while and prevent the timeout.

---
Cc: Jaroslav Kysela <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]

---
 sound/core/pcm_dmaengine.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/core/pcm_dmaengine.c +0 -0
index 1306b04be171a..092ce958e1aee 100644

sound/core/pcm_dmaengine.c int snd_dmaengine_pcm_refine_runtime_hwparams( · line 430

Quoted 7 lines
sound/core/pcm_dmaengine.c +4 -0
@@ -424,6 +424,10 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(
 			hw->info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME;
 		if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT)
 			hw->info |= SNDRV_PCM_INFO_BATCH;
+		if (dma_caps.residue_granularity == DMA_RESIDUE_GRANULARITY_SEGMENT) {
+			hw->periods_min = 8;
+			hw->period_bytes_max /= 8;
+		}

Overriding with the hard-coded values at hw_params refine doesn't look like a right way. Those values are set and dealt by the drivers in general, as they are pretty hardware-specific. You can't guarantee this magic number 8 working on all available hardware.

thanks,

Takashi

#2 lore raw
Quoted 34 lines · Takashi Iwai
Quoted 32 lines · Marek Vasut

The segment granularity PCM DMA updates PCM pointer at the end of every segment. In case the segments are too long, which happens with pipewire, it may happen that pcm_lib wait_for_avail() will time out while waiting for PCM pointer update and playback will fail with IO error.

In case of SEGMENT granularity, use 8 shorter segments over the default 2 long segments set in dmaengine_pcm_set_runtime_hwparams(). That gives the DMA engine some chance to update the PCM pointer every once in a while and prevent the timeout.

---
Cc: Jaroslav Kysela <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]

---
  sound/core/pcm_dmaengine.c | 4 ++++
  1 file changed, 4 insertions(+)
sound/core/pcm_dmaengine.c +1 -0
index 1306b04be171a..092ce958e1aee 100644
@@ -424,6 +424,10 @@ int snd_dmaengine_pcm_refine_runtime_hwparams(
  			hw->info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME;
  		if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT)
  			hw->info |= SNDRV_PCM_INFO_BATCH;
+		if (dma_caps.residue_granularity == DMA_RESIDUE_GRANULARITY_SEGMENT) {
Quoted 8 lines

sound/core/pcm_dmaengine.c int snd_dmaengine_pcm_refine_runtime_hwparams( · line 430

Quoted 3 lines
sound/core/pcm_dmaengine.c +3 -0
+			hw->periods_min = 8;
+			hw->period_bytes_max /= 8;
+		}

Overriding with the hard-coded values at hw_params refine doesn't look like a right way. Those values are set and dealt by the drivers in general, as they are pretty hardware-specific. You can't guarantee this magic number 8 working on all available hardware.

This is very much why I sent this patch as an RFC .

If these limits should be set per DMA driver, do you happen to have a suggestion where to plumb it in ?