From: Thomas Gleixner <tglx@linutronix.de>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
John Stultz <johnstul@us.ibm.com>,
Valdis Kletnieks <valdis.kletnieks@vt.edu>,
Arjan van de Ven <arjan@infradead.org>,
Dave Jones <davej@redhat.com>,
David Woodhouse <dwmw2@infradead.org>, Jim Gettys <jg@laptop.org>,
Roman Zippel <zippel@linux-m68k.org>
Subject: [patch 02/22] GTOD: persistent clock support, core
Date: Wed, 04 Oct 2006 17:31:32 -0000 [thread overview]
Message-ID: <20061004172222.085685000@cruncher.tec.linutronix.de> (raw)
In-Reply-To: 20061004172217.092570000@cruncher.tec.linutronix.de
[-- Attachment #1: gtod-persistent-clock-support-core.patch --]
[-- Type: text/plain, Size: 4945 bytes --]
From: John Stultz <johnstul@us.ibm.com>
Persistent clock support: do proper timekeeping across suspend/resume.
Signed-off-by: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/hrtimer.h | 3 +++
include/linux/time.h | 1 +
kernel/hrtimer.c | 8 ++++++++
kernel/timer.c | 40 +++++++++++++++++++++++++++++++++++++++-
4 files changed, 51 insertions(+), 1 deletion(-)
Index: linux-2.6.18-mm3/include/linux/hrtimer.h
===================================================================
--- linux-2.6.18-mm3.orig/include/linux/hrtimer.h 2006-10-04 18:13:53.000000000 +0200
+++ linux-2.6.18-mm3/include/linux/hrtimer.h 2006-10-04 18:13:54.000000000 +0200
@@ -146,6 +146,9 @@ extern void hrtimer_init_sleeper(struct
/* Soft interrupt function to run the hrtimer queues: */
extern void hrtimer_run_queues(void);
+/* Resume notification */
+void hrtimer_notify_resume(void);
+
/* Bootup initialization: */
extern void __init hrtimers_init(void);
Index: linux-2.6.18-mm3/include/linux/time.h
===================================================================
--- linux-2.6.18-mm3.orig/include/linux/time.h 2006-10-04 18:13:53.000000000 +0200
+++ linux-2.6.18-mm3/include/linux/time.h 2006-10-04 18:13:54.000000000 +0200
@@ -92,6 +92,7 @@ extern struct timespec xtime;
extern struct timespec wall_to_monotonic;
extern seqlock_t xtime_lock;
+extern unsigned long read_persistent_clock(void);
void timekeeping_init(void);
static inline unsigned long get_seconds(void)
Index: linux-2.6.18-mm3/kernel/hrtimer.c
===================================================================
--- linux-2.6.18-mm3.orig/kernel/hrtimer.c 2006-10-04 18:13:53.000000000 +0200
+++ linux-2.6.18-mm3/kernel/hrtimer.c 2006-10-04 18:13:54.000000000 +0200
@@ -287,6 +287,14 @@ static unsigned long ktime_divns(const k
#endif /* BITS_PER_LONG >= 64 */
/*
+ * Timekeeping resumed notification
+ */
+void hrtimer_notify_resume(void)
+{
+ clock_was_set();
+}
+
+/*
* Counterpart to lock_timer_base above:
*/
static inline
Index: linux-2.6.18-mm3/kernel/timer.c
===================================================================
--- linux-2.6.18-mm3.orig/kernel/timer.c 2006-10-04 18:13:53.000000000 +0200
+++ linux-2.6.18-mm3/kernel/timer.c 2006-10-04 18:13:54.000000000 +0200
@@ -41,6 +41,9 @@
#include <asm/timex.h>
#include <asm/io.h>
+/* jiffies at the most recent update of wall time */
+unsigned long wall_jiffies = INITIAL_JIFFIES;
+
u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES;
EXPORT_SYMBOL(jiffies_64);
@@ -743,12 +746,27 @@ int timekeeping_is_continuous(void)
return ret;
}
+/**
+ * read_persistent_clock - Return time in seconds from the persistent clock.
+ *
+ * Weak dummy function for arches that do not yet support it.
+ * Returns seconds from epoch using the battery backed persistent clock.
+ * Returns zero if unsupported.
+ *
+ * XXX - Do be sure to remove it once all arches implement it.
+ */
+unsigned long __attribute__((weak)) read_persistent_clock(void)
+{
+ return 0;
+}
+
/*
* timekeeping_init - Initializes the clocksource and common timekeeping values
*/
void __init timekeeping_init(void)
{
unsigned long flags;
+ unsigned long sec = read_persistent_clock();
write_seqlock_irqsave(&xtime_lock, flags);
@@ -758,11 +776,20 @@ void __init timekeeping_init(void)
clocksource_calculate_interval(clock, tick_nsec);
clock->cycle_last = clocksource_read(clock);
+ xtime.tv_sec = sec;
+ xtime.tv_nsec = 0;
+ set_normalized_timespec(&wall_to_monotonic,
+ -xtime.tv_sec, -xtime.tv_nsec);
+
write_sequnlock_irqrestore(&xtime_lock, flags);
}
+/* flag for if timekeeping is suspended */
static int timekeeping_suspended;
+/* time in seconds when suspend began */
+static unsigned long timekeeping_suspend_time;
+
/**
* timekeeping_resume - Resumes the generic timekeeping subsystem.
* @dev: unused
@@ -774,13 +801,23 @@ static int timekeeping_suspended;
static int timekeeping_resume(struct sys_device *dev)
{
unsigned long flags;
+ unsigned long now = read_persistent_clock();
write_seqlock_irqsave(&xtime_lock, flags);
- /* restart the last cycle value */
+
+ if (now && (now > timekeeping_suspend_time)) {
+ unsigned long sleep_length = now - timekeeping_suspend_time;
+ xtime.tv_sec += sleep_length;
+ jiffies_64 += (u64)sleep_length * HZ;
+ }
+ /* re-base the last cycle value */
clock->cycle_last = clocksource_read(clock);
clock->error = 0;
timekeeping_suspended = 0;
write_sequnlock_irqrestore(&xtime_lock, flags);
+
+ hrtimer_notify_resume();
+
return 0;
}
@@ -790,6 +827,7 @@ static int timekeeping_suspend(struct sy
write_seqlock_irqsave(&xtime_lock, flags);
timekeeping_suspended = 1;
+ timekeeping_suspend_time = read_persistent_clock();
write_sequnlock_irqrestore(&xtime_lock, flags);
return 0;
}
--
next prev parent reply other threads:[~2006-10-04 17:41 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-04 17:31 [patch 00/22] high resolution timers / dynamic ticks - V3 Thomas Gleixner
2006-10-04 17:31 ` [patch 01/22] GTOD: exponential update_wall_time Thomas Gleixner
2006-10-04 17:31 ` Thomas Gleixner [this message]
2006-10-04 17:31 ` [patch 03/22] GTOD: persistent clock support, i386 Thomas Gleixner
2006-10-04 17:31 ` [patch 04/22] time: uninline jiffies.h Thomas Gleixner
2006-10-04 17:31 ` [patch 05/22] time: fix msecs_to_jiffies() bug Thomas Gleixner
2006-10-04 17:31 ` [patch 06/22] time: fix timeout overflow Thomas Gleixner
2006-10-04 17:31 ` [patch 07/22] cleanup: uninline irq_enter() and move it into a function Thomas Gleixner
2006-10-04 17:31 ` [patch 08/22] dynticks: extend next_timer_interrupt() to use a reference jiffie Thomas Gleixner
2006-10-04 17:31 ` [patch 09/22] hrtimers: namespace and enum cleanup Thomas Gleixner
2006-10-04 17:31 ` [patch 10/22] hrtimers: clean up locking Thomas Gleixner
2006-10-04 17:31 ` [patch 11/22] hrtimers: state tracking Thomas Gleixner
2006-10-04 17:31 ` [patch 12/22] hrtimers: clean up callback tracking Thomas Gleixner
2006-10-04 17:31 ` [patch 13/22] hrtimers: Move and add documentation Thomas Gleixner
2006-10-04 17:31 ` [patch 14/22] clockevents: core Thomas Gleixner
2006-10-04 17:31 ` [patch 15/22] clockevents: drivers for i386 Thomas Gleixner
2006-10-04 17:31 ` [patch 16/22] high-res timers: core Thomas Gleixner
2006-10-04 17:31 ` [patch 17/22] GTOD: Mark TSC unusable for highres timers Thomas Gleixner
2006-10-04 17:31 ` [patch 18/22] dynticks: core Thomas Gleixner
2006-10-04 17:31 ` [patch 19/22] dyntick: add nohz stats to /proc/stat Thomas Gleixner
2006-10-04 17:31 ` [patch 20/22] dynticks: i386 arch code Thomas Gleixner
2006-10-04 17:31 ` [patch 21/22] high-res timers, dynticks: enable i386 support Thomas Gleixner
2006-10-04 17:31 ` [patch 22/22] debugging feature: timer stats Thomas Gleixner
2006-10-05 8:16 ` [patch 00/22] high resolution timers / dynamic ticks - V3 Andrew Morton
2006-10-05 8:11 ` Ingo Molnar
2006-10-05 8:17 ` Ingo Molnar
2006-10-05 20:57 ` Andi Kleen
2006-10-05 21:11 ` Thomas Gleixner
2006-10-06 7:28 ` Arjan van de Ven
2006-10-16 10:53 ` Andi Kleen
2006-10-05 8:19 ` Andrew Morton
2006-10-05 8:23 ` Ingo Molnar
2006-10-05 8:50 ` Andrew Morton
2006-10-05 9:48 ` 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=20061004172222.085685000@cruncher.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=akpm@osdl.org \
--cc=arjan@infradead.org \
--cc=davej@redhat.com \
--cc=dwmw2@infradead.org \
--cc=jg@laptop.org \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=valdis.kletnieks@vt.edu \
--cc=zippel@linux-m68k.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