mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Heena Sirwani <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, john.stultz@linaro.org,
	hpa@zytor.com, mingo@kernel.org, heenasirwani@gmail.com,
	tglx@linutronix.de, arnd@arndb.de
Subject: [tip:timers/2038] timekeeping: Provide y2038 safe accessor to the seconds portion of CLOCK_REALTIME
Date: Wed, 29 Oct 2014 07:18:46 -0700	[thread overview]
Message-ID: <tip-dbe7aa622db96b5cd601f59d09c4f00b98b76079@git.kernel.org> (raw)
In-Reply-To: <7adcfaa8962b8ad58785d9a2456c3f77d93c0ffb.1414578445.git.heenasirwani@gmail.com>

Commit-ID:  dbe7aa622db96b5cd601f59d09c4f00b98b76079
Gitweb:     http://git.kernel.org/tip/dbe7aa622db96b5cd601f59d09c4f00b98b76079
Author:     Heena Sirwani <heenasirwani@gmail.com>
AuthorDate: Wed, 29 Oct 2014 16:01:50 +0530
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 29 Oct 2014 15:15:40 +0100

timekeeping: Provide y2038 safe accessor to the seconds portion of CLOCK_REALTIME

ktime_get_real_seconds() is the replacement function for get_seconds()
returning the seconds portion of CLOCK_REALTIME in a time64_t. For
64bit the function is equivivalent to get_seconds(), but for 32bit it
protects the readout with the timekeeper sequence count. This is
required because 32-bit machines cannot access 64-bit tk->xtime_sec
variable atomically.

[tglx: Massaged changelog and added docbook comment ]

Signed-off-by: Heena Sirwani <heenasirwani@gmail.com>
Reviewed-by: Arnd Bergman <arnd@arndb.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: opw-kernel@googlegroups.com
Link: http://lkml.kernel.org/r/7adcfaa8962b8ad58785d9a2456c3f77d93c0ffb.1414578445.git.heenasirwani@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/timekeeping.h |  1 +
 kernel/time/timekeeping.c   | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 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 a693270..0aef92a 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -676,6 +676,36 @@ time64_t ktime_get_seconds(void)
 }
 EXPORT_SYMBOL_GPL(ktime_get_seconds);
 
+/**
+ * ktime_get_real_seconds - Get the seconds portion of CLOCK_REALTIME
+ *
+ * Returns the wall clock seconds since 1970. This replaces the
+ * get_seconds() interface which is not y2038 safe on 32bit systems.
+ *
+ * For 64bit systems the fast access to tk->xtime_sec is preserved. On
+ * 32bit systems the access must be protected with the sequence
+ * counter to provide "atomic" access to the 64bit tk->xtime_sec
+ * value.
+ */
+time64_t ktime_get_real_seconds(void)
+{
+	struct timekeeper *tk = &tk_core.timekeeper;
+	time64_t seconds;
+	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);
+
 #ifdef CONFIG_NTP_PPS
 
 /**

  reply	other threads:[~2014-10-29 14:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-29 10:30 [PATCH v8 0/2] Added ktime_get_seconds() and ktime_get_real_seconds() Heena Sirwani
2014-10-29 10:31 ` [PATCH v8 1/2] timekeeping: Added a function to return tv_sec portion of ktime_get_ts64() Heena Sirwani
2014-10-29 10:47   ` Arnd Bergmann
2014-10-29 14:18   ` [tip:timers/2038] timekeeping: Provide fast accessor to the seconds part of CLOCK_MONOTONIC tip-bot for Heena Sirwani
2014-10-29 10:31 ` [PATCH v8 2/2] timekeeping: Added a function to return tv_sec portion of ktime_get_real_ts64() Heena Sirwani
2014-10-29 14:18   ` tip-bot for Heena Sirwani [this message]
2014-10-29 14:21 ` [PATCH v8 0/2] Added ktime_get_seconds() and ktime_get_real_seconds() Thomas Gleixner
2014-10-29 15:11   ` [OPW kernel] " Arnd Bergmann

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=tip-dbe7aa622db96b5cd601f59d09c4f00b98b76079@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=arnd@arndb.de \
    --cc=heenasirwani@gmail.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome