[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1358750325-21217-6-git-send-email-feng.tang@intel.com>
Date: Mon, 21 Jan 2013 14:38:45 +0800
From: Feng Tang <feng.tang@...el.com>
To: Thomas Gleixner <tglx@...utronix.de>,
John Stultz <john.stultz@...aro.org>,
Ingo Molnar <mingo@...e.hu>,
"H. Peter Anvin" <hpa@...ux.intel.com>, x86@...nel.org,
Len Brown <lenb@...nel.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
linux-kernel@...r.kernel.org
Cc: Feng Tang <feng.tang@...el.com>
Subject: [RFC PATCH 5/5] timekeeping: Add support for clocksource which doesn't stop during suspend
There are some new processors whose TSC clocksource won't stop during
suspend. Currently, after system resumes from sleep state, kernel will
use persistent clock or RTC to compensate the sleep time, but for those
new types of clocksources, we could skip the special compensation from
external sources, and just use current clocksource for recounting.
This can solve some time drift bugs caused by the not-so-accurate RTC
devices.
Signed-off-by: Feng Tang <feng.tang@...el.com>
---
kernel/time/timekeeping.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index cbc6acb..628c9ba 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -749,22 +749,36 @@ void timekeeping_inject_sleeptime(struct timespec *delta)
static void timekeeping_resume(void)
{
struct timekeeper *tk = &timekeeper;
+ struct clocksource *clock = tk->clock;
unsigned long flags;
struct timespec ts;
+ cycle_t cycle_now, cycle_delta;
+ s64 nsec;
read_persistent_clock(&ts);
-
clockevents_resume();
clocksource_resume();
write_seqlock_irqsave(&tk->lock, flags);
- if (timespec_compare(&ts, &timekeeping_suspend_time) > 0) {
+ if (clock->flags & CLOCK_SOURCE_SUSPEND_NOTSTOP) {
+ cycle_now = clock->read(clock);
+ cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
+ clock->cycle_last = cycle_now;
+
+ nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
+ ts = ns_to_timespec(nsec);
+ } else if (timespec_compare(&ts, &timekeeping_suspend_time) > 0)
ts = timespec_sub(ts, timekeeping_suspend_time);
- __timekeeping_inject_sleeptime(tk, &ts);
+ else {
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
}
+
+ __timekeeping_inject_sleeptime(tk, &ts);
+
/* re-base the last cycle value */
- tk->clock->cycle_last = tk->clock->read(tk->clock);
+ clock->cycle_last = clock->read(clock);
tk->ntp_error = 0;
timekeeping_suspended = 0;
timekeeping_update(tk, false);
@@ -1134,7 +1148,6 @@ static inline void old_vsyscall_fixup(struct timekeeper *tk)
#endif
-
/**
* update_wall_time - Uses the current clocksource to increment the wall time
*
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists