[LAD] revisiting system timer sound application wake up
Ricardo Biehl Pasquali
pasqualirb at gmail.com
Mon Aug 20 00:01:52 CEST 2018
08/08/2018 (ignore this date)
Around December 2007 to February 2009 Lennart Poettering
has asked some questions in alsa-devel mailing list in
order to implement the timer based audio scheduling for
In 2008 he wrote an article named "What's Cooking in
PulseAudio's glitch-free Branch".
I have not found detailed documentation about PulseAudio
timer wake up and I'm not sure about some implementation
details. By using the emails from Lennart and his article
a Documentation can start to grow.
Do PulseAudio synchronize to sound device by adjusting the
timer or the amount committed (application pointer)?
The nice thing about the second case is that the period
time (in application's view) is bonded to system clock
instead of sound device's.
What timer interface does PulseAudio use? timerfd?
How the deviation of system and sound device clock is
today? Perhaps someone that works with sound cards or SoCs
can answer this. Do the most of today's hardware has the
same clock for sound device and system?
How sound devices deal with random accesses to their ring
buffer. Do most of them allow writing/reading anywhere and
How is the acurracy and precision of the hardware pointer
returned by sound devices?
Does SNDRV_PCM_INFO_BATCH flag reveals something about the
As PulseAudio runs in many Linux distributions today, it
seems an interesting idea to implement an utility to
collect some information regarding the above issues. Then
make it available to the public. E.g. it would be possible
to know the pointer acurracy for specific devices.
SCHED_DEADLINE and timerfd
There are a few works over there about SCHED_DEADLINE and
- This paper presented in Linux Audio Conference 2011:
BAGNOLI, Giacomo; CUCINOTTA, Tommaso; FAGGIOLI, Dario.
2011. Low-Latency Audio on Linux by Means of Real-Time
Dario Faggioli is one of the authors of SCHED_DEADLINE.
- This presentation of Alessio Balsini: "Experimenting
with the Android Audio Pipeline and SCHED_DEADLINE".
OSPM 2018. Here is an overview:
In SCHED_DEADLINE I assume there is no way to accurately
adjust the timer. As well as there is no way to adjust
when the first expiration will be. I think this is because
of Constant Bandwidth Server algorithm. Must ask to some
developer of this.
Having this in mind, the only way to synchronize to sound
device is by adjusting the amount read/written
Timerfd on the other hand is fully adjustable. However, it
can be preempted by a high priority task. Anyway I don't
see that as a problem as it should ralely happen.
Perhaps SCHED_DEADLINE is suitable for professional
environment (aiming almost-zero glitches).
Thoughts on this? Is there someone planning to implement
SCHED_DEADLINE in PulseAudio?
I'm currently working on both implementations (not for
Take a look at 'Documentation/timer_wakeup.rst',
'tools/timer_wakeup.c' and 'tools/deadline_wakeup.c'.
'tools/waveplay.c' play .wav files using the application
wakeup method specified in 'tools/Makefile'.
Many of the points I've mentioned should get well covered
by some documentation (e.g. ALSA, PulseAudio). Also, I
think ALSA's internal (kernel-level) documentation needs
I'm actually working on that, documenting some stuff as I'm
developing a small sound library that interacts directly
to ALSA in kernel, and the application wakeup using
timerfd and SCHED_DEADLINE.
More information about the Linux-audio-dev