From: Alexander Gordeev <lasaine@lvk.cs.msu.su>
To: john stultz <johnstul@us.ibm.com>
Cc: linux-kernel@vger.kernel.org,
"Nikita V. Youshchenko" <yoush@cs.msu.su>,
linuxpps@ml.enneenne.com,
Rodolfo Giometti <giometti@enneenne.com>,
Thomas Gleixner <tglx@linutronix.de>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jon Hunter <jon-hunter@ti.com>, Ingo Molnar <mingo@elte.hu>,
John Kacur <jkacur@redhat.com>
Subject: Re: [PATCHv3 13/16] pps: capture MONOTONIC_RAW timestamps as well
Date: Thu, 5 Aug 2010 16:16:37 +0400 [thread overview]
Message-ID: <20100805161637.373cf63b@desktopvm.lvknet> (raw)
In-Reply-To: <1280963037.2678.28.camel@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 4542 bytes --]
В Wed, 04 Aug 2010 16:03:57 -0700
john stultz <johnstul@us.ibm.com> пишет:
> On Thu, 2010-08-05 at 01:06 +0400, Alexander Gordeev wrote:
> > MONOTONIC_RAW clock timestamps are ideally suited for frequency
> > calculation and also fit well into the original NTP hardpps design. Now
> > phase and frequency can be adjusted separately: the former based on
> > REALTIME clock and the latter based on MONOTONIC_RAW clock.
> > A new function getnstime_raw_and_real is added to timekeeping subsystem
> > to capture both timestamps at the same time and atomically.
> >
> > Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su>
> > ---
> > include/linux/pps_kernel.h | 3 ++-
> > include/linux/time.h | 2 ++
> > kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++
> > 3 files changed, 38 insertions(+), 1 deletions(-)
> >
> > diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h
> > index 5af0498..39fc712 100644
> > --- a/include/linux/pps_kernel.h
> > +++ b/include/linux/pps_kernel.h
> > @@ -48,6 +48,7 @@ struct pps_source_info {
> > };
> >
> > struct pps_event_time {
> > + struct timespec ts_raw;
> > struct timespec ts_real;
> > };
> >
> > @@ -111,7 +112,7 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
> >
> > static inline void pps_get_ts(struct pps_event_time *ts)
> > {
> > - getnstimeofday(&ts->ts_real);
> > + getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
> > }
> >
> > #endif /* LINUX_PPS_KERNEL_H */
> > diff --git a/include/linux/time.h b/include/linux/time.h
> > index ea3559f..1da8a7b 100644
> > --- a/include/linux/time.h
> > +++ b/include/linux/time.h
> > @@ -143,6 +143,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);
> > extern int do_getitimer(int which, struct itimerval *value);
> > extern void getnstimeofday(struct timespec *tv);
> > extern void getrawmonotonic(struct timespec *ts);
> > +extern void getnstime_raw_and_real(struct timespec *ts_raw,
> > + struct timespec *ts_real);
> > extern void getboottime(struct timespec *ts);
> > extern void monotonic_to_bootbased(struct timespec *ts);
> >
> > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> > index caf8d4d..ef37b14 100644
> > --- a/kernel/time/timekeeping.c
> > +++ b/kernel/time/timekeeping.c
> > @@ -286,6 +286,40 @@ void ktime_get_ts(struct timespec *ts)
> > EXPORT_SYMBOL_GPL(ktime_get_ts);
> >
> > /**
> > + * getnstime_raw_and_real - Returns both the time of day an raw
> > + * monotonic time in a timespec format
> > + * @ts_mono_raw: pointer to the timespec to be set to raw
> > + * monotonic time
> > + * @ts_real: pointer to the timespec to be set to the time
> > + * of day
> > + */
> > +void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
> > +{
> > + unsigned long seq;
> > + s64 nsecs_raw, nsecs_real;
> > +
> > + WARN_ON(timekeeping_suspended);
> > +
> > + do {
> > + seq = read_seqbegin(&xtime_lock);
> > +
> > + *ts_raw = raw_time;
> > + *ts_real = xtime;
> > +
> > + nsecs_raw = timekeeping_get_ns_raw();
> > + nsecs_real = timekeeping_get_ns();
> > +
> > + /* If arch requires, add in gettimeoffset() */
> > + nsecs_real += arch_gettimeoffset();
>
> Hmm. So this brings up an interesting point. If the system is an one
> which uses arch_gettimeoffset() (which means it doesn't have
> clocksources), I'm not sure if this function would return what you'd
> expect.
>
> The issue is that jiffies is the basic clocksource that is in use on
> these systems, but the arch_gettimeoffset() function returns an
> inter-tick time value (usually by reading the interrupt generating
> decrementer or whatnot). So in this case, you'd get a
> CLOCK_MONOTONIC_RAW time that is based off the raw jiffies value at the
> last tick, and CLOCK_REALTIME time value at the exact time of the call.
>
> That offset between the two would then vary depending on when in the
> inter-tick period the call was made.
>
>
> The two solutions would be:
> 1) Add the arch_gettimeoffset() value to nsecs_raw as well. Should be
> safe, as any freq variance from the raw freq will be limited to 1 tick
> length and won't accumulate.
>
> 2) Don't add arch_gettimeoffset to either value, providing the raw and
> real time values at the last tick.
>
> I'd probably go with #1.
>
> Otherwise, the code looks good.
Ok, thanks for the point! I'll use #1 then.
--
Alexander
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 489 bytes --]
next prev parent reply other threads:[~2010-08-05 12:16 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-04 21:06 [PATCHv3 00/16] pps: several fixes and improvements Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 01/16] pps: trivial fixes Alexander Gordeev
2010-08-05 8:57 ` Rodolfo Giometti
2010-08-04 21:06 ` [PATCHv3 02/16] pps: declare variables where they are used in switch Alexander Gordeev
2010-08-05 9:05 ` Rodolfo Giometti
2010-08-04 21:06 ` [PATCHv3 03/16] pps: fix race in PPS_FETCH handler Alexander Gordeev
2010-08-05 5:19 ` Vitezslav Samel
2010-08-05 10:19 ` Alexander Gordeev
2010-08-05 11:07 ` Vitezslav Samel
2010-08-05 14:31 ` Alexander Gordeev
2010-08-05 9:15 ` Rodolfo Giometti
2010-08-04 21:06 ` [PATCHv3 04/16] pps: unify timestamp gathering Alexander Gordeev
2010-08-05 9:17 ` Rodolfo Giometti
2010-08-04 21:06 ` [PATCHv3 05/16] pps: access pps device by direct pointer Alexander Gordeev
2010-08-05 9:32 ` Rodolfo Giometti
2010-08-05 11:42 ` Alexander Gordeev
2010-08-05 12:31 ` Rodolfo Giometti
2010-08-09 7:53 ` Alexander Gordeev
2010-08-09 12:47 ` Rodolfo Giometti
2010-08-04 21:06 ` [PATCHv3 06/16] pps: convert printk/pr_* to dev_* Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 07/16] pps: move idr stuff to pps.c Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 08/16] pps: add async PPS event handler Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 09/16] pps: don't disable interrupts when using spin locks Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 10/16] pps: use BUG_ON for kernel API safety checks Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 11/16] pps: simplify conditions a bit Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 12/16] ntp: add hardpps implementation Alexander Gordeev
2010-08-04 22:49 ` john stultz
2010-08-05 12:00 ` Alexander Gordeev
2010-08-04 23:26 ` Andrew Morton
2010-08-04 23:39 ` David Daney
2010-08-04 23:49 ` Andrew Morton
2010-08-04 21:06 ` [PATCHv3 13/16] pps: capture MONOTONIC_RAW timestamps as well Alexander Gordeev
2010-08-04 23:03 ` john stultz
2010-08-05 12:16 ` Alexander Gordeev [this message]
2010-08-04 23:29 ` Andrew Morton
2010-08-05 12:29 ` Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 14/16] pps: add kernel consumer support Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 15/16] pps: add parallel port PPS client Alexander Gordeev
2010-08-04 23:34 ` Andrew Morton
2010-08-05 12:48 ` Alexander Gordeev
2010-08-04 21:06 ` [PATCHv3 16/16] pps: add parallel port PPS signal generator Alexander Gordeev
2010-08-04 23:38 ` Andrew Morton
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=20100805161637.373cf63b@desktopvm.lvknet \
--to=lasaine@lvk.cs.msu.su \
--cc=akpm@linux-foundation.org \
--cc=giometti@enneenne.com \
--cc=jkacur@redhat.com \
--cc=johnstul@us.ibm.com \
--cc=jon-hunter@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxpps@ml.enneenne.com \
--cc=mingo@elte.hu \
--cc=schwidefsky@de.ibm.com \
--cc=tglx@linutronix.de \
--cc=yoush@cs.msu.su \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox