Skip to content

Introduce userspace-driven ALSA timers

Ivan Orlov linux-doc linux-kselftest linux-sound lkml 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest4 patches 1 replyIn review
  2. v44 patches 2 repliesSuperseded
  3. v34 patches 4 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v24 patches2 repliesSuperseded
v14 patches8 repliesSuperseded

Changes in v5 from the cover letter

- Add missing error processing noticed by Takashi Iwai <[email protected]>
- Return timer file descriptor as part of the snd_timer_uinfo structure. This is a more standard way of using ioctl interface, where the return value of the ioctl is either 0 or an error code.

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4ALSA: aloop: Allow using global timerssound/drivers/aloop.c+2 -00 replies
2/4Docs/sound: Add documentation for userspace-driven ALSA timersDocumentation/sound/index.rst Documentation/sound/utimers.rst+127 -00 replies
3/4ALSA: timer: Introduce virtual userspace-driven timersinclude/uapi/sound/asound.h sound/core/Kconfig sound/core/timer.c+251 -10 replies
4/4selftests: ALSA: Cover userspace-driven timers with testtools/testing/selftests/alsa/Makefile tools/testing/selftests/alsa/global-timer.c tools/testing/selftests/alsa/utimer-test.c+253 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/4] Introduce userspace-driven ALSA timers

There are multiple possible timer sources which could be useful for the sound stream synchronization: hrtimers, hardware clocks (e.g. PTP), timer wheels (jiffies). Currently, using one of them to synchronize the audio stream of snd-aloop module would require writing a kernel-space driver which exports an ALSA timer through the snd_timer interface.

However, it is not really convenient for application developers, who may want to define their custom timer sources for audio synchronization.

For instance, we could have a network application which receives frames and sends them to snd-aloop pcm device, and another application listening on the other end of snd-aloop. It makes sense to transfer a new period of data only when certain amount of frames is received through the network, but definitely not when a certain amount of jiffies on a local system elapses. Since all of the devices are purely virtual it won't introduce any glitches and will help the application developers to avoid using sample-rate conversion.

This patch series introduces userspace-driven ALSA timers: virtual timers which are created and controlled from userspace. The timer can be created from the userspace using the new ioctl SNDRV_TIMER_IOCTL_CREATE. After creating a timer, it becomes available for use system-wide, so it can be passed to snd-aloop as a timer source (timer_source parameter would be "-1.SNDRV_TIMER_GLOBAL_UDRIVEN.{timer_id}"). When the userspace app decides to trigger a timer, it calls another ioctl SNDRV_TIMER_IOCTL_TRIGGER on the file descriptor of a timer. It initiates a transfer of a new period of data.

Userspace-driven timers are associated with file descriptors. If the application wishes to destroy the timer, it can simply release the file descriptor of a virtual timer.

I believe introducing new ioctl calls is quite inconvenient (as we have a limited amount of them), but other possible ways of app <-> kernel communication (like virtual FS) seem completely inappropriate for this task (but I'd love to discuss alternative solutions).

This patch series also updates the snd-aloop module so the global timers can be used as a timer_source for it (it allows using userspace-driven timers as timer source).

V1 -> V2:
- Fix some problems found by Christophe Jaillet <[email protected]>
V2 -> V3:
- Add improvements suggested by Takashi Iwai <[email protected]> V3 -> V4:
- Address comments from Jaroslav Kysela <[email protected]> and Mark Brown <[email protected]>
V4 -> V5:
- Add missing error processing noticed by Takashi Iwai <[email protected]>
- Return timer file descriptor as part of the snd_timer_uinfo structure. This is a more standard way of using ioctl interface, where the return value of the ioctl is either 0 or an error code.

Please, find the patch-specific changelog in the following patches.

Ivan Orlov (4):
ALSA: aloop: Allow using global timers
Docs/sound: Add documentation for userspace-driven ALSA timers
ALSA: timer: Introduce virtual userspace-driven timers
selftests: ALSA: Cover userspace-driven timers with test

 Documentation/sound/index.rst               |   1 +
 Documentation/sound/utimers.rst             | 126 +++++++++++
 include/uapi/sound/asound.h                 |  17 +-
 sound/core/Kconfig                          |  10 +
 sound/core/timer.c                          | 225 ++++++++++++++++++++
 sound/drivers/aloop.c                       |   2 +
 tools/testing/selftests/alsa/Makefile       |   4 +-
 tools/testing/selftests/alsa/global-timer.c |  87 ++++++++
 tools/testing/selftests/alsa/utimer-test.c  | 164 ++++++++++++++
 9 files changed, 633 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/sound/utimers.rst
 create mode 100644 tools/testing/selftests/alsa/global-timer.c
 create mode 100644 tools/testing/selftests/alsa/utimer-test.c
Signature · 1 line
2.34.1