From: tip-bot for Xunlei Pang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, pang.xunlei@linaro.org,
linux-kernel@vger.kernel.org, john.stultz@linaro.org,
tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com
Subject: [tip:timers/core] time, drivers/rtc: Don't bother with rtc_resume () for the nonstop clocksource
Date: Fri, 3 Apr 2015 01:20:31 -0700 [thread overview]
Message-ID: <tip-0fa88cb4b82b5cf7429bc1cef9db006ca035754e@git.kernel.org> (raw)
In-Reply-To: <1427945681-29972-19-git-send-email-john.stultz@linaro.org>
Commit-ID: 0fa88cb4b82b5cf7429bc1cef9db006ca035754e
Gitweb: http://git.kernel.org/tip/0fa88cb4b82b5cf7429bc1cef9db006ca035754e
Author: Xunlei Pang <pang.xunlei@linaro.org>
AuthorDate: Wed, 1 Apr 2015 20:34:38 -0700
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 3 Apr 2015 08:18:34 +0200
time, drivers/rtc: Don't bother with rtc_resume() for the nonstop clocksource
If a system does not provide a persistent_clock(), the time
will be updated on resume by rtc_resume(). With the addition
of the non-stop clocksources for suspend timing, those systems
set the time on resume in timekeeping_resume(), but may not
provide a valid persistent_clock().
This results in the rtc_resume() logic thinking no one has set
the time and it then will over-write the suspend time again,
which is not necessary and only increases clock error.
So, fix this for rtc_resume().
This patch also improves the name of persistent_clock_exist to
make it more grammatical.
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1427945681-29972-19-git-send-email-john.stultz@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
drivers/rtc/class.c | 4 +--
include/linux/timekeeping.h | 9 +++----
kernel/time/timekeeping.c | 66 +++++++++++++++++++++++++++++++++------------
3 files changed, 54 insertions(+), 25 deletions(-)
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index d40760a..c29ba7e 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -55,7 +55,7 @@ static int rtc_suspend(struct device *dev)
struct timespec64 delta, delta_delta;
int err;
- if (has_persistent_clock())
+ if (timekeeping_rtc_skipsuspend())
return 0;
if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
@@ -102,7 +102,7 @@ static int rtc_resume(struct device *dev)
struct timespec64 sleep_time;
int err;
- if (has_persistent_clock())
+ if (timekeeping_rtc_skipresume())
return 0;
rtc_hctosys_ret = -ENODEV;
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 7a2369d..99176af 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -248,6 +248,9 @@ static inline void timekeeping_clocktai(struct timespec *ts)
/*
* RTC specific
*/
+extern bool timekeeping_rtc_skipsuspend(void);
+extern bool timekeeping_rtc_skipresume(void);
+
extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
/*
@@ -259,14 +262,8 @@ extern void getnstime_raw_and_real(struct timespec *ts_raw,
/*
* Persistent clock related interfaces
*/
-extern bool persistent_clock_exist;
extern int persistent_clock_is_local;
-static inline bool has_persistent_clock(void)
-{
- return persistent_clock_exist;
-}
-
extern void read_persistent_clock(struct timespec *ts);
extern void read_persistent_clock64(struct timespec64 *ts);
extern void read_boot_clock(struct timespec *ts);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index b7db491..79b9bc6 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -64,9 +64,6 @@ static struct tk_fast tk_fast_raw ____cacheline_aligned;
/* flag for if timekeeping is suspended */
int __read_mostly timekeeping_suspended;
-/* Flag for if there is a persistent clock on this platform */
-bool __read_mostly persistent_clock_exist = false;
-
static inline void tk_normalize_xtime(struct timekeeper *tk)
{
while (tk->tkr_mono.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_mono.shift)) {
@@ -1204,6 +1201,12 @@ void __weak read_boot_clock64(struct timespec64 *ts64)
*ts64 = timespec_to_timespec64(ts);
}
+/* Flag for if timekeeping_resume() has injected sleeptime */
+static bool sleeptime_injected;
+
+/* Flag for if there is a persistent clock on this platform */
+static bool persistent_clock_exists;
+
/*
* timekeeping_init - Initializes the clocksource and common timekeeping values
*/
@@ -1221,7 +1224,7 @@ void __init timekeeping_init(void)
now.tv_sec = 0;
now.tv_nsec = 0;
} else if (now.tv_sec || now.tv_nsec)
- persistent_clock_exist = true;
+ persistent_clock_exists = true;
read_boot_clock64(&boot);
if (!timespec64_valid_strict(&boot)) {
@@ -1282,11 +1285,47 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_RTC_HCTOSYS_DEVICE)
/**
+ * We have three kinds of time sources to use for sleep time
+ * injection, the preference order is:
+ * 1) non-stop clocksource
+ * 2) persistent clock (ie: RTC accessible when irqs are off)
+ * 3) RTC
+ *
+ * 1) and 2) are used by timekeeping, 3) by RTC subsystem.
+ * If system has neither 1) nor 2), 3) will be used finally.
+ *
+ *
+ * If timekeeping has injected sleeptime via either 1) or 2),
+ * 3) becomes needless, so in this case we don't need to call
+ * rtc_resume(), and this is what timekeeping_rtc_skipresume()
+ * means.
+ */
+bool timekeeping_rtc_skipresume(void)
+{
+ return sleeptime_injected;
+}
+
+/**
+ * 1) can be determined whether to use or not only when doing
+ * timekeeping_resume() which is invoked after rtc_suspend(),
+ * so we can't skip rtc_suspend() surely if system has 1).
+ *
+ * But if system has 2), 2) will definitely be used, so in this
+ * case we don't need to call rtc_suspend(), and this is what
+ * timekeeping_rtc_skipsuspend() means.
+ */
+bool timekeeping_rtc_skipsuspend(void)
+{
+ return persistent_clock_exists;
+}
+
+/**
* timekeeping_inject_sleeptime64 - Adds suspend interval to timeekeeping values
* @delta: pointer to a timespec64 delta value
*
* This hook is for architectures that cannot support read_persistent_clock64
* because their RTC/persistent clock is only accessible when irqs are enabled.
+ * and also don't have an effective nonstop clocksource.
*
* This function should only be called by rtc_resume(), and allows
* a suspend offset to be injected into the timekeeping values.
@@ -1296,13 +1335,6 @@ void timekeeping_inject_sleeptime64(struct timespec64 *delta)
struct timekeeper *tk = &tk_core.timekeeper;
unsigned long flags;
- /*
- * Make sure we don't set the clock twice, as timekeeping_resume()
- * already did it
- */
- if (has_persistent_clock())
- return;
-
raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&tk_core.seq);
@@ -1334,8 +1366,8 @@ void timekeeping_resume(void)
unsigned long flags;
struct timespec64 ts_new, ts_delta;
cycle_t cycle_now, cycle_delta;
- bool suspendtime_found = false;
+ sleeptime_injected = false;
read_persistent_clock64(&ts_new);
clockevents_resume();
@@ -1381,13 +1413,13 @@ void timekeeping_resume(void)
nsec += ((u64) cycle_delta * mult) >> shift;
ts_delta = ns_to_timespec64(nsec);
- suspendtime_found = true;
+ sleeptime_injected = true;
} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time);
- suspendtime_found = true;
+ sleeptime_injected = true;
}
- if (suspendtime_found)
+ if (sleeptime_injected)
__timekeeping_inject_sleeptime(tk, &ts_delta);
/* Re-base the last cycle value */
@@ -1421,14 +1453,14 @@ int timekeeping_suspend(void)
* value returned, update the persistent_clock_exists flag.
*/
if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec)
- persistent_clock_exist = true;
+ persistent_clock_exists = true;
raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&tk_core.seq);
timekeeping_forward_now(tk);
timekeeping_suspended = 1;
- if (has_persistent_clock()) {
+ if (persistent_clock_exists) {
/*
* To avoid drift caused by repeated suspend/resumes,
* which each can add ~1 second drift error,
next prev parent reply other threads:[~2015-04-03 8:32 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-02 3:34 [PATCH 00/21] 4.1 time and rtc changes for tip/timers/core John Stultz
2015-04-02 3:34 ` [PATCH 01/21] time: Add y2038 safe read_boot_clock64() John Stultz
2015-04-03 8:15 ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 02/21] time: Add y2038 safe read_persistent_clock64() John Stultz
2015-04-03 8:15 ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 03/21] time: Add y2038 safe update_persistent_clock64() John Stultz
2015-04-03 8:16 ` [tip:timers/core] time: Add y2038 safe update_persistent_clock64( ) tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 04/21] ARM: OMAP: 32k counter: Provide y2038-safe omap_read_persistent_clock() replacement John Stultz
2015-04-03 8:16 ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 05/21] ARM: tegra: clock: Provide y2038-safe tegra_read_persistent_clock() replacement John Stultz
2015-04-03 8:16 ` [tip:timers/core] clocksource/drivers/tegra: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 06/21] ARM: time: Provide read_boot_clock64() and read_persistent_clock64() John Stultz
2015-04-03 8:17 ` [tip:timers/core] ARM, clocksource/drivers: Provide read_boot_clock64() and read_persistent_clock64() and use them tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 07/21] rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacement John Stultz
2015-04-03 8:17 ` [tip:timers/core] drivers/rtc: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 08/21] rtc/test: Update driver to address y2038/y2106 issues John Stultz
2015-04-03 8:17 ` [tip:timers/core] drivers/rtc/test: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 09/21] rtc/ab3100: " John Stultz
2015-04-03 8:17 ` [tip:timers/core] drivers/rtc/ab3100: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 10/21] rtc/mc13xxx: " John Stultz
2015-04-03 8:18 ` [tip:timers/core] drivers/rtc/mc13xxx: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 11/21] rtc/mxc: Modify rtc_update_alarm() not to touch the alarm time John Stultz
2015-04-03 8:18 ` [tip:timers/core] drivers/rtc/mxc: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 12/21] rtc/mxc: Convert get_alarm_or_time()/set_alarm_or_time() to use time64_t John Stultz
2015-04-03 8:18 ` [tip:timers/core] drivers/rtc/mxc: Convert get_alarm_or_time()/ set_alarm_or_time() " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 13/21] rtc/mxc: Update driver to address y2038/y2106 issues John Stultz
2015-04-03 8:19 ` [tip:timers/core] drivers/rtc/mxc: Update driver to address y2038 /y2106 issues tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 14/21] alpha: rtc: Change to use rtc_class_ops's set_mmss64() John Stultz
2015-04-03 8:19 ` [tip:timers/core] alpha, rtc: Change to use rtc_class_ops' s set_mmss64() tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 15/21] time: Don't build timekeeping_inject_sleeptime64() if no one uses it John Stultz
2015-04-03 8:19 ` [tip:timers/core] time: Don' t " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 16/21] rtc: Remove redundant rtc_valid_tm() from rtc_resume() John Stultz
2015-04-03 8:19 ` [tip:timers/core] drivers/rtc: " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 17/21] time: Fix a bug in timekeeping_suspend() with no persistent clock John Stultz
2015-04-03 6:16 ` Ingo Molnar
2015-04-03 8:20 ` [tip:timers/core] " tip-bot for Xunlei Pang
2015-04-02 3:34 ` [PATCH 18/21] time: rtc: Don't bother into rtc_resume() for the nonstop clocksource John Stultz
2015-04-03 8:20 ` tip-bot for Xunlei Pang [this message]
2015-04-02 3:34 ` [PATCH 19/21] clocksource: Improve comment explaining clocks_calc_max_nsecs()'s 50% safety margin John Stultz
2015-04-02 8:50 ` Peter Zijlstra
2015-04-02 17:30 ` John Stultz
2015-04-02 18:34 ` Peter Zijlstra
2015-04-02 18:41 ` John Stultz
2015-04-02 18:43 ` Peter Zijlstra
2015-04-02 18:50 ` John Stultz
2015-04-02 19:04 ` Peter Zijlstra
2015-04-03 8:20 ` [tip:timers/core] " tip-bot for John Stultz
2015-04-02 3:34 ` [PATCH 20/21] timekeeping: Change timekeeping_check_update() to take a tk_read_base John Stultz
2015-04-02 3:34 ` [PATCH 21/21] time: Rework debugging variables so they aren't global John Stultz
2015-04-02 7:47 ` Peter Zijlstra
2015-04-02 7:51 ` Ingo Molnar
2015-04-02 8:36 ` Peter Zijlstra
2015-04-02 8:41 ` Peter Zijlstra
2015-04-02 17:32 ` John Stultz
2015-04-03 6:21 ` Ingo Molnar
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-0fa88cb4b82b5cf7429bc1cef9db006ca035754e@git.kernel.org \
--to=tipbot@zytor.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=pang.xunlei@linaro.org \
--cc=peterz@infradead.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 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.