Skip to content

Commit 615bcab

Browse files
committed
ASoC: SOF: Intel: hda-pcm: Place the constraint on period time instead of buffer time
Instead of constraining the buffer time to be double of the host buffer size it is better to set it for the priod time. This will implicitly constrain the buffer time to a safe value (num_periods is at least 2) and prohibits applications to set smaller period size than what will be covered by the initial DMA burst. Fixes: 02ea2a0 ("ASoC: SOF: Intel: hda-pcm: Use dsp_max_burst_size_in_ms to place constraint") Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent b347fc4 commit 615bcab

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,25 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
291291
* On playback start the DMA will transfer dsp_max_burst_size_in_ms
292292
* amount of data in one initial burst to fill up the host DMA buffer.
293293
* Consequent DMA burst sizes are shorter and their length can vary.
294-
* To make sure that userspace allocate large enough ALSA buffer we need
295-
* to place a constraint on the buffer time.
294+
* To avoid immediate xrun by the initial burst we need to place
295+
* constraint on the period size (via PERIOD_TIME) to cover the size of
296+
* the host buffer.
297+
* We need to add headroom of max 10ms as the firmware needs time to
298+
* settle to the 1ms pacing and initially it can run faster for few
299+
* internal periods.
296300
*
297301
* On capture the DMA will transfer 1ms chunks.
298-
*
299-
* Exact dsp_max_burst_size_in_ms constraint is racy, so set the
300-
* constraint to a minimum of 2x dsp_max_burst_size_in_ms.
301302
*/
302-
if (spcm->stream[direction].dsp_max_burst_size_in_ms)
303+
if (spcm->stream[direction].dsp_max_burst_size_in_ms) {
304+
unsigned int period_time = spcm->stream[direction].dsp_max_burst_size_in_ms;
305+
306+
period_time += min(period_time, 10);
307+
303308
snd_pcm_hw_constraint_minmax(substream->runtime,
304-
SNDRV_PCM_HW_PARAM_BUFFER_TIME,
305-
spcm->stream[direction].dsp_max_burst_size_in_ms * USEC_PER_MSEC * 2,
309+
SNDRV_PCM_HW_PARAM_PERIOD_TIME,
310+
period_time * USEC_PER_MSEC,
306311
UINT_MAX);
312+
}
307313

308314
/* binding pcm substream to hda stream */
309315
substream->runtime->private_data = &dsp_stream->hstream;

0 commit comments

Comments
 (0)