All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lennart Poettering <mznyfn@0pointer.de>
To: ALSA Development Mailing List <alsa-devel@alsa-project.org>
Subject: Monotonic timestamps
Date: Wed, 9 Apr 2008 23:36:02 +0200	[thread overview]
Message-ID: <20080409213602.GA2589@tango.0pointer.de> (raw)

Hey!

I saw that ALSA 1.0.16 claims to support monotonic timestamps. I
couldn't figure out however, how they are supposed to work. From the
sources I only could figure out that they are enabled if a) the libc
knows CLOCK_MONOTONIC a) the kernel supports CLOCK_MONOTONIC, b) the
ALSA kernel code support timestamps this way. That's at least how I
read this code from pcm_hw.c:

<snip>
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
        if (SNDRV_PROTOCOL_VERSION(2, 0, 9) <= ver) {
                struct timespec timespec;
                if (clock_gettime(CLOCK_MONOTONIC, &timespec) == 0) {
                        int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
                        if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) <
                        0) {
                                ret = -errno;
                                SNDMSG("TTSTAMP failed\n");
                                return ret;
                        }
                        monotonic = 1;
                }
        }
#endif
          else if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver) {
                int on = 1;
                if (ioctl(fd, SNDRV_PCM_IOCTL_TSTAMP, &on) < 0) {
                        ret = -errno;
                        SNDMSG("TSTAMP failed\n");
                        return ret;
                }
        }
</snip>

The problem with this is that there seems to be no way to determine
from an application if monotonic timestamps are enabled in an
snd_pcm_t or not, ALSA just switches over to them, making the
timestamps relatively useless, because we cannot reliable relate them
to timestamps we query from the kernel ourselves -- because we just
don't know if we need to use CLOCK_MONOTONIC or CLOCK_REALTIME.

I find it very strange that ALSA just switches to monotonic timestamps
just like that, anyway. Programs written for wallclack timestamps will
break if they run on a system where ALSA uses monotonic timestamps!

There's a function missing that enables monotonic timestamps
explicitly, or at least one that can be used to query if they are
monotonic or not.

Could anybody please explain the difference between status->tstamp and
status->trigger_tstamp for me, please? The doxygen docs are bit too
terse on this, I fear.

Oh, and the code I pasted above will not compile if the #ifdef check
fails, because of the "else". The "else" should be moved inside of
#ifddef block.

Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4

             reply	other threads:[~2008-04-09 21:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-09 21:36 Lennart Poettering [this message]
2008-04-10  7:03 ` Monotonic timestamps Pieter Palmers
2008-04-10 14:15   ` Lennart Poettering
2008-04-10 17:20     ` Pieter Palmers
2008-04-10  7:48 ` Jaroslav Kysela
2008-04-10 14:26   ` Lennart Poettering
2008-04-11 12:16     ` Jaroslav Kysela
2008-04-11 12:56       ` Lennart Poettering
2008-04-21 10:47         ` Jaroslav Kysela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080409213602.GA2589@tango.0pointer.de \
    --to=mznyfn@0pointer.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.