From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org, Mark Brown <broonie@linaro.org>,
Daniel Thompson <daniel.thompson@linaro.org>
Subject: Re: [PATCH] ALSA: Provide a CLOCK_MONOTONIC_RAW timestamp type
Date: Tue, 08 Jul 2014 17:00:26 +0200 [thread overview]
Message-ID: <s5hr41vopyt.wl%tiwai@suse.de> (raw)
In-Reply-To: <1404831109-8008-1-git-send-email-broonie@kernel.org>
At Tue, 8 Jul 2014 16:51:49 +0200,
Mark Brown wrote:
>
> From: Mark Brown <broonie@linaro.org>
>
> For applications which need to synchronise with external timebases such
> as broadcast TV applications the kernel monotonic time is not optimal as
> it includes adjustments from NTP and so may still include discontinuities
> due to that. A raw monotonic time which does not include any adjustments
> is available in the kernel from getrawmonotonic() so provide userspace with
> a new timestamp type SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW which provides
> timestamps based on this as an option.
>
> Reported-by: Daniel Thompson <daniel.thompson@linaro.org>
> Signed-off-by: Mark Brown <broonie@linaro.org>
> ---
>
> Mostly an RFC at this point as I don't have hardware to test this week.
This looks good to me. Or, thinking of the original use case, should
we just replace ktime_get_ts() with getrawmonotonic()? The MONOTONIC
mode is really to be monotonic.
While we're at it: there's been long-standing request from V4L guys
for improving the timestamps to sync with video streams. I suggested
to add a new mode that can be set by the driver. Worth to consider
it, too?
thanks,
Takashi
>
> include/sound/pcm.h | 11 +++++++++--
> include/uapi/sound/asound.h | 3 ++-
> sound/core/pcm_native.c | 12 +++++++++---
> 3 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/include/sound/pcm.h b/include/sound/pcm.h
> index d854fb3..6f3e10c 100644
> --- a/include/sound/pcm.h
> +++ b/include/sound/pcm.h
> @@ -931,10 +931,17 @@ void snd_pcm_timer_done(struct snd_pcm_substream *substream);
> static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
> struct timespec *tv)
> {
> - if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
> + switch (runtime->tstamp_type) {
> + case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
> ktime_get_ts(tv);
> - else
> + break;
> + case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
> + getrawmonotonic(tv);
> + break;
> + default:
> getnstimeofday(tv);
> + break;
> + }
> }
>
> /*
> diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
> index 2249483..cbf7dc85 100644
> --- a/include/uapi/sound/asound.h
> +++ b/include/uapi/sound/asound.h
> @@ -462,7 +462,8 @@ struct snd_xfern {
> enum {
> SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0, /* gettimeofday equivalent */
> SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, /* posix_clock_monotonic equivalent */
> - SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,
> + SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, /* monotonic_raw (no NTP) */
> + SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,
> };
>
> /* channel positions */
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index b653ab0..fd6d7a7 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -2540,9 +2540,15 @@ static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg)
> return -EFAULT;
> if (arg < 0 || arg > SNDRV_PCM_TSTAMP_TYPE_LAST)
> return -EINVAL;
> - runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
> - if (arg == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
> - runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
> + switch (runtime->tstamp_type) {
> + case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
> + case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
> + runtime->tstamp_type = runtime->tstamp_type;
> + break;
> + default:
> + runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
> + break;
> + }
> return 0;
> }
>
> --
> 2.0.0
>
next parent reply other threads:[~2014-07-08 15:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1404831109-8008-1-git-send-email-broonie@kernel.org>
2014-07-08 15:00 ` Takashi Iwai [this message]
2014-07-08 16:00 ` [PATCH] ALSA: Provide a CLOCK_MONOTONIC_RAW timestamp type Mark Brown
2014-07-08 19:54 ` Jaroslav Kysela
2014-07-09 11:02 ` Takashi Iwai
2014-07-08 17:01 ` Clemens Ladisch
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=s5hr41vopyt.wl%tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=broonie@linaro.org \
--cc=daniel.thompson@linaro.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.