Description
SOF sound devices can support large audio buffers, allowing audio playback/capture to continue without waking up the host CPU and memory as often and thus save power.
For ALSA applications, this shows up as bursty updates to the ALSA hw_ptr. Many/most applications can cope with this without issues, but some applications that assume hw_ptr advances linearly, this creates problems. [1, 2]. Probably most mainstream case is Pipewire when it decides how much data it needs to fill before starting a stream (or after an xrun). If the amount of data is smaller or close to the size of the max DMA burst, xruns or even xrun loops (repeated error to start with too little data) can be hit as audio device consumes all audio data before Pipewire has a chance to provide more data.
The amount of buffering depends on the hardware and the DSP topology/configuration. For a typical SOF PCM, maximum burst size is a few milliseconds, but there are DSP topologies where the maximum burst size can be in tens of milliseconds.
There is currently no established interface in ALSA for drivers to communicate the maximum burst size. Existing interfaces are surveyed in [2]. snd_pcm_hw_params_is_block_transfer() is probably the closest match, but it does not provide enough information about size of the burst.
Proposal is to extend ALSA driver and alsa-lib interface to make this information available to applications like Pipewire.
Alternatives to consider:
- SOF could declare SNDRV_PCM_INFO_BATCH. SOF has not set this a) would disable features in applications like Pipewire, and b) SOF can deliver accurate hw_ptr location (even during bursts).
- add a new info flag SNDRV_PCM_INFO_BURSTY_DMA. this would be overlapping with existing BLOCK_TRANSFER/BATCH flags and still not provide enough information to applications to fully understand driver behaviour.
- add an attribute to UCM -- easier to add, but the burst size can vary based on topology and hw, so maintaining correct information in UCM will be a challenge
References:
- [1] Pipewire bug hit when this information is not available https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4489
- [2] Metabug on alsa-conformance-test issues that triggered creation of this ticket [BUG][META] alsa_conformance_test fails due to too high rate sof#8717