public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] ALSA: pcm_dmaengine: Use more shorter periods for SEGMENT granularity PCM DMA
@ 2026-03-27 14:29 Marek Vasut
  2026-03-30  7:41 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2026-03-27 14:29 UTC (permalink / raw)
  To: linux-sound
  Cc: Marek Vasut, Jaroslav Kysela, Lars-Peter Clausen, Mark Brown,
	Michal Simek, Takashi Iwai

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.

Signed-off-by: Marek Vasut <marex@nabladev.com>
---
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Mark Brown <broonie@kernel.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org
---
 sound/core/pcm_dmaengine.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index 1306b04be171a..092ce958e1aee 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -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;
-- 
2.53.0


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

end of thread, other threads:[~2026-03-30 21:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27 14:29 [RFC][PATCH] ALSA: pcm_dmaengine: Use more shorter periods for SEGMENT granularity PCM DMA Marek Vasut
2026-03-30  7:41 ` Takashi Iwai
2026-03-30 16:47   ` Marek Vasut

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