From: Thomas Gleixner <tglx@linutronix.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Heena Sirwani <heenasirwani@gmail.com>,
linux-kernel@vger.kernel.org, john.stultz@linaro.org
Subject: Re: [PATCH v5] timekeeping: Added a function to return tv_sec portion of ktime_get_ts64()
Date: Mon, 27 Oct 2014 22:21:12 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.11.1410272219560.5308@nanos> (raw)
In-Reply-To: <6577930.2pEqZJjtqW@wuerfel>
On Sun, 26 Oct 2014, Arnd Bergmann wrote:
> On Saturday 25 October 2014 17:12:48 Thomas Gleixner wrote:
> > I'd rather have an extra field in the timekeeper
> >
> > u64 xtime_sec;
> > + u64 ktime_sec;
> >
> > and update this in tk_update_ktime_data() so the readout function
> > boils down to
> >
> > time64_t ktime_get_seconds(void)
> > {
> > #if BITS_PER_LONG < 64
> > u64 sec;
> > int seq;
> >
> > do {
> > seq = read_seqcount_begin(&tk_core.seq);
> > sec = tk->ktime_sec;
> > } while (read_seqcount_retry(&tk_core.seq, seq));
> >
> > return sec;
> > #else
> > return tk->ktime_sec;
> > #endif
> > }
> >
> > So 64bit can do w/o the seqcount and 32bit avoids all extra math, right?
> >
>
> But where would you set ktime_sec? My first thought was tk_update_ktime_data(),
> but would then either be slightly wrong because it doesn't take the current
> xtime_nsec + tk->wall_to_monotonic.tv_nsec into account, if we do
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index ec1791fae965..d72a456c6bd3 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -426,8 +426,8 @@ static inline void tk_update_ktime_data(struct timekeeper *tk)
> * nsec = base_mono + now();
> * ==> base_mono = (xtime_sec + wtm_sec) * 1e9 + wtm_nsec
> */
> - nsec = (s64)(tk->xtime_sec + tk->wall_to_monotonic.tv_sec);
> - nsec *= NSEC_PER_SEC;
> + tk->ktime_sec = (s64)(tk->xtime_sec + tk->wall_to_monotonic.tv_sec);
> + nsec = tk->ktime_sec * NSEC_PER_SEC;
> nsec += tk->wall_to_monotonic.tv_nsec;
> tk->tkr.base_mono = ns_to_ktime(nsec);
>
>
> or we'd have to add an expensive timekeeping_get_ns() call:
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index ec1791fae965..d4c95b815de6 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -426,9 +426,11 @@ static inline void tk_update_ktime_data(struct timekeeper *tk)
> * nsec = base_mono + now();
> * ==> base_mono = (xtime_sec + wtm_sec) * 1e9 + wtm_nsec
> */
> - nsec = (s64)(tk->xtime_sec + tk->wall_to_monotonic.tv_sec);
> - nsec *= NSEC_PER_SEC;
> - nsec += tk->wall_to_monotonic.tv_nsec;
> + tk->ktime_sec = (s64)(tk->xtime_sec + tk->wall_to_monotonic.tv_sec);
> + nsec = tk->wall_to_monotonic.tv_nsec;
> + if ((nsec + timekeeping_get_ns()) > NSEC_PER_SEC)
> + tk->ktime_sec += 1;
> + nsec += tk->ktime_sec * NSEC_PER_SEC;
> tk->tkr.base_mono = ns_to_ktime(nsec);
No. Why would you do that? Look at the math you implemented and just
do the same thing in the update function.
Thanks,
tglx
prev parent reply other threads:[~2014-10-27 21:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-25 12:34 Heena Sirwani
2014-10-25 15:12 ` Thomas Gleixner
2014-10-25 15:22 ` Thomas Gleixner
2014-10-25 15:39 ` Arnd Bergmann
2014-10-25 17:32 ` Thomas Gleixner
2014-10-26 20:34 ` Arnd Bergmann
2014-10-28 11:26 ` Thomas Gleixner
2014-10-28 13:21 ` Arnd Bergmann
2014-10-26 21:01 ` Arnd Bergmann
2014-10-27 21:21 ` Thomas Gleixner [this message]
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=alpine.DEB.2.11.1410272219560.5308@nanos \
--to=tglx@linutronix.de \
--cc=arnd@arndb.de \
--cc=heenasirwani@gmail.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®