[alsa-devel] Master Plan on rewinding

Alexander E. Patrakov patrakov at gmail.com
Wed Sep 10 07:38:06 CEST 2014


10.09.2014 01:56, Pierre-Louis Bossart wrote:
>
>>> 2. PulseAudio blindly assumes that it can rewind up to hwbuf_frames -
>>> (snd_pcm_avail() + rewind_safeguard) frames. The rewind safeguard is
>>> needed due to reasons that I don't completely understand, but one of
>>> them is imprecise reporting of the hardware pointer, and another one is
>>> that the hardware transfers several bytes at a time, and the bytes we
>>> need to overwrite may be already cached by the hardware.
>>
>> Pierre added the rewind safeguard due to DMA controller problems. IIRC,
>> some DMA controllers go nuts (such as breaking the stream, causing
>> interrupt storms, or something else seriously buggy) when trying to
>> write to data that the DMA controller is just about to transfer. Pierre
>> (now cc:ed) would know more about this than I do, though.
>>
>> In my world, since this is a very hardware near problem, ALSA rather
>> than PulseAudio should take these kinds of problems into account when
>> reporting back snd_pcm_rewindable() so PulseAudio does not have to.
>
>
> Sorry to chime-in late on this, my real job keeps me busy.

Better late than never.

> I would like to highlight that there is a fundamental conflict between
> requirements here.
> - for power consumption optimization, you want to let the hardware
> prefetch audio samples opportunistically and buffer as much as possible
> as close as possible to the serial link. Given the pressure on power
> optimizations these days, no one should expect the hardware buffering to
> reduce - and this buffering could vary depending on the platform power
> modes with the position of the DMA read pointer becoming less predictable.
> - for low-latency and user interaction, you want to rewind the write
> pointer as much as possible.

Spot-on.

> The question is 'how much'. The reason why i introduced this
> 'rewind_safeguard' was to factor in a good-enough latency that no one
> would ever complain about and yet large enough to avoid using stale data.
> We could ask drivers to provide a conservative estimate of this
> safeguard, but asking for a dynamic query of a safe position or an
> empirical determination based on the min period size is really asking
> for trouble. At a given point, if you really need very low-latency, i.e.
> sub ms, you will need a dedicated configuration that probably doesn't
> rely on rewinds and you probably don't use PulseAudio in the first place.

Well, now there are two people criticizing the heuristic. I would like 
to retract it, but I currently can't, because there are no other 
constructive proposals.

The best solution would indeed be if a driver provides a conservative 
estimate of the rewind safeguard, but the problem is that nobody will 
add this to old drivers for no-longer-manufactured hardware. So we 
either need some other heuristic here, or we have to allow rewinding 
further than the nearest period only on cards where drivers explicitly 
say OK by providing a safeguard value. But the later proposal kills 
power-efficient PulseAudio on old kernels that simply don't know how to 
provide this information. Surely you won't like it.

-- 
Alexander E. Patrakov


More information about the Alsa-devel mailing list