mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Heena Sirwani <heenasirwani@gmail.com>
Cc: linux-kernel@vger.kernel.org, john.stultz@linaro.org, arnd@arndb.de
Subject: Re: [PATCH v2] timekeeping: Added a function to return tv_sec portion of ktime_get_real_ts64()
Date: Tue, 28 Oct 2014 16:43:42 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.11.1410281641350.5308@nanos> (raw)
In-Reply-To: <20141027050804.GA8550@heena-HP-Compaq-8200-Elite-MT-PC>

On Mon, 27 Oct 2014, Heena Sirwani wrote:
> The following patch adds a function to return tv_sec portion of
> ktime_get_real_ts64() function in order to have a function that returns
> seconds as 64-bit integers instead of 32-bit integers to address the
> y2038 problem.
> 
> The function is similar to get_seconds() function except that it
> includes read_seqcount_retry loop which is required for 32-bit
> architectures. This is because 32-bit machines cannot access 64-bit
> tk->xtime_sec variable atomically, requiring two 32-bit register loads.
>  
> Signed-off-by: Heena Sirwani <heenasirwani@gmail.com>
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
> ---
> Changes in v2:
>         - Removed the local variable nsecs as it was not required.
> 
>  include/linux/timekeeping.h |  1 +
>  kernel/time/timekeeping.c   | 19 +++++++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
> index 115d55e..91454de 100644
> --- a/include/linux/timekeeping.h
> +++ b/include/linux/timekeeping.h
> @@ -29,6 +29,7 @@ struct timespec get_monotonic_coarse(void);
>  extern void getrawmonotonic(struct timespec *ts);
>  extern void ktime_get_ts64(struct timespec64 *ts);
>  extern time64_t ktime_get_seconds(void);
> +extern time64_t ktime_get_real_seconds(void);
>  
>  extern int __getnstimeofday64(struct timespec64 *tv);
>  extern void getnstimeofday64(struct timespec64 *tv);
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index 93fc596..c17c620 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -673,6 +673,25 @@ time64_t ktime_get_seconds(void)
>  }
>  EXPORT_SYMBOL_GPL(ktime_get_seconds);
>  
> +time64_t ktime_get_real_seconds(void)
> +{
> +	time64_t seconds;
> +	struct timekeeper *tk = &tk_core.timekeeper;
> +	unsigned int seq;
> +
> +	if (IS_ENABLED(CONFIG_64BIT))
> +		return tk->xtime_sec;
> +
> +	do {
> +		seq = read_seqcount_begin(&tk_core.seq);
> +		seconds = tk->xtime_sec;
> +
> +	} while (read_seqcount_retry(&tk_core.seq, seq));
> +
> +	return seconds;
> +}
> +EXPORT_SYMBOL_GPL(ktime_get_real_seconds);

Nice and clean implementation! Though I wonder whether we should just
name it get_seconds64().

Thanks,

	tglx

  reply	other threads:[~2014-10-28 15:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-27  5:08 Heena Sirwani
2014-10-28 15:43 ` Thomas Gleixner [this message]
2014-10-28 15:50   ` Arnd Bergmann
2014-10-28 17:13     ` Thomas Gleixner
2014-10-28 19:54       ` Arnd Bergmann
2014-10-28 20:31         ` Thomas Gleixner
2014-10-28 20:35           ` Arnd Bergmann
2014-10-28 20:52             ` Thomas Gleixner

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.1410281641350.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®