Skip to content

Commit fe76d2e

Browse files
ujfalusibroonie
authored andcommitted
ASoC: SOF: Intel: hda-pcm: Use dsp_max_burst_size_in_ms to place constraint
If the PCM have the dsp_max_burst_size_in_ms set then place a constraint to limit the minimum buffer time to avoid xruns caused by DMA bursts spinning on the ALSA buffer. Cc: stable@vger.kernel.org # 6.8 Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://msgid.link/r/20240321130814.4412-4-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 842bb8b commit fe76d2e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sound/soc/sof/intel/hda-pcm.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
259259
snd_pcm_hw_constraint_mask64(substream->runtime, SNDRV_PCM_HW_PARAM_FORMAT,
260260
SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_S32);
261261

262+
/*
263+
* The dsp_max_burst_size_in_ms is the length of the maximum burst size
264+
* of the host DMA in the ALSA buffer.
265+
*
266+
* On playback start the DMA will transfer dsp_max_burst_size_in_ms
267+
* amount of data in one initial burst to fill up the host DMA buffer.
268+
* Consequent DMA burst sizes are shorter and their length can vary.
269+
* To make sure that userspace allocate large enough ALSA buffer we need
270+
* to place a constraint on the buffer time.
271+
*
272+
* On capture the DMA will transfer 1ms chunks.
273+
*
274+
* Exact dsp_max_burst_size_in_ms constraint is racy, so set the
275+
* constraint to a minimum of 2x dsp_max_burst_size_in_ms.
276+
*/
277+
if (spcm->stream[direction].dsp_max_burst_size_in_ms)
278+
snd_pcm_hw_constraint_minmax(substream->runtime,
279+
SNDRV_PCM_HW_PARAM_BUFFER_TIME,
280+
spcm->stream[direction].dsp_max_burst_size_in_ms * USEC_PER_MSEC * 2,
281+
UINT_MAX);
282+
262283
/* binding pcm substream to hda stream */
263284
substream->runtime->private_data = &dsp_stream->hstream;
264285
return 0;

0 commit comments

Comments
 (0)