mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@osdl.org>, Ingo Molnar <mingo@elte.hu>,
	Andi Kleen <ak@suse.de>, Arjan van de Ven <arjan@infradead.org>,
	Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>,
	Chris Wright <chrisw@sous-sol.org>,
	john stultz <johnstul@us.ibm.com>,
	David Miller <davem@davemloft.net>
Subject: [patch-mm 14/23] NTP: Move the cmos update code into ntp.c
Date: Sun, 10 Jun 2007 09:44:12 -0000	[thread overview]
Message-ID: <20070610092446.886512473@inhelltoy.tec.linutronix.de> (raw)
In-Reply-To: <20070610092437.118387863@inhelltoy.tec.linutronix.de>

[-- Attachment #1: ntp-make-cmos-update-generic.patch --]
[-- Type: text/plain, Size: 9147 bytes --]

i386 and sparc64 have the identical code to update the cmos clock.
Move it into kernel/time/ntp.c as there are other architectures
coming along with the same requirements.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: john stultz <johnstul@us.ibm.com>
Cc: David Miller <davem@davemloft.net>

---
 arch/i386/Kconfig          |    4 +++
 arch/i386/kernel/time.c    |   50 +-------------------------------------
 arch/sparc64/Kconfig       |    4 +++
 arch/sparc64/kernel/time.c |   53 +---------------------------------------
 include/asm-i386/timer.h   |    1 
 include/linux/time.h       |    2 +
 kernel/time/ntp.c          |   59 ++++++++++++++++++++++++++++++++++++++++++---
 7 files changed, 70 insertions(+), 103 deletions(-)

Index: linux-2.6.22-rc4-mm/arch/i386/Kconfig
===================================================================
--- linux-2.6.22-rc4-mm.orig/arch/i386/Kconfig	2007-06-10 10:44:36.000000000 +0200
+++ linux-2.6.22-rc4-mm/arch/i386/Kconfig	2007-06-10 10:44:39.000000000 +0200
@@ -18,6 +18,10 @@ config GENERIC_TIME
 	bool
 	default y
 
+config GENERIC_CMOS_UPDATE
+	bool
+	default y
+
 config CLOCKSOURCE_WATCHDOG
 	bool
 	default y
Index: linux-2.6.22-rc4-mm/arch/i386/kernel/time.c
===================================================================
--- linux-2.6.22-rc4-mm.orig/arch/i386/kernel/time.c	2007-06-10 10:44:36.000000000 +0200
+++ linux-2.6.22-rc4-mm/arch/i386/kernel/time.c	2007-06-10 10:44:39.000000000 +0200
@@ -207,55 +207,9 @@ unsigned long read_persistent_clock(void
 	return retval;
 }
 
-static void sync_cmos_clock(unsigned long dummy);
-
-static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0);
-int no_sync_cmos_clock;
-
-static void sync_cmos_clock(unsigned long dummy)
-{
-	struct timeval now, next;
-	int fail = 1;
-
-	/*
-	 * If we have an externally synchronized Linux clock, then update
-	 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-	 * called as close as possible to 500 ms before the new second starts.
-	 * This code is run on a timer.  If the clock is set, that timer
-	 * may not expire at the correct time.  Thus, we adjust...
-	 */
-	if (!ntp_synced())
-		/*
-		 * Not synced, exit, do not restart a timer (if one is
-		 * running, let it run out).
-		 */
-		return;
-
-	do_gettimeofday(&now);
-	if (now.tv_usec >= USEC_AFTER - ((unsigned) TICK_SIZE) / 2 &&
-	    now.tv_usec <= USEC_BEFORE + ((unsigned) TICK_SIZE) / 2)
-		fail = set_rtc_mmss(now.tv_sec);
-
-	next.tv_usec = USEC_AFTER - now.tv_usec;
-	if (next.tv_usec <= 0)
-		next.tv_usec += USEC_PER_SEC;
-
-	if (!fail)
-		next.tv_sec = 659;
-	else
-		next.tv_sec = 0;
-
-	if (next.tv_usec >= USEC_PER_SEC) {
-		next.tv_sec++;
-		next.tv_usec -= USEC_PER_SEC;
-	}
-	mod_timer(&sync_cmos_timer, jiffies + timeval_to_jiffies(&next));
-}
-
-void notify_arch_cmos_timer(void)
+int update_persistent_clock(struct timespec now)
 {
-	if (!no_sync_cmos_clock)
-		mod_timer(&sync_cmos_timer, jiffies + 1);
+	return set_rtc_mmss(now.tv_sec);
 }
 
 extern void (*late_time_init)(void);
Index: linux-2.6.22-rc4-mm/arch/sparc64/kernel/time.c
===================================================================
--- linux-2.6.22-rc4-mm.orig/arch/sparc64/kernel/time.c	2007-06-10 10:44:38.000000000 +0200
+++ linux-2.6.22-rc4-mm/arch/sparc64/kernel/time.c	2007-06-10 10:44:39.000000000 +0200
@@ -403,58 +403,9 @@ static struct sparc64_tick_ops hbtick_op
 
 static unsigned long timer_ticks_per_nsec_quotient __read_mostly;
 
-#define TICK_SIZE (tick_nsec / 1000)
-
-#define USEC_AFTER	500000
-#define USEC_BEFORE	500000
-
-static void sync_cmos_clock(unsigned long dummy);
-
-static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0);
-
-static void sync_cmos_clock(unsigned long dummy)
-{
-	struct timeval now, next;
-	int fail = 1;
-
-	/*
-	 * If we have an externally synchronized Linux clock, then update
-	 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-	 * called as close as possible to 500 ms before the new second starts.
-	 * This code is run on a timer.  If the clock is set, that timer
-	 * may not expire at the correct time.  Thus, we adjust...
-	 */
-	if (!ntp_synced())
-		/*
-		 * Not synced, exit, do not restart a timer (if one is
-		 * running, let it run out).
-		 */
-		return;
-
-	do_gettimeofday(&now);
-	if (now.tv_usec >= USEC_AFTER - ((unsigned) TICK_SIZE) / 2 &&
-	    now.tv_usec <= USEC_BEFORE + ((unsigned) TICK_SIZE) / 2)
-		fail = set_rtc_mmss(now.tv_sec);
-
-	next.tv_usec = USEC_AFTER - now.tv_usec;
-	if (next.tv_usec <= 0)
-		next.tv_usec += USEC_PER_SEC;
-
-	if (!fail)
-		next.tv_sec = 659;
-	else
-		next.tv_sec = 0;
-
-	if (next.tv_usec >= USEC_PER_SEC) {
-		next.tv_sec++;
-		next.tv_usec -= USEC_PER_SEC;
-	}
-	mod_timer(&sync_cmos_timer, jiffies + timeval_to_jiffies(&next));
-}
-
-void notify_arch_cmos_timer(void)
+int update_persistent_clock(struct timespec now)
 {
-	mod_timer(&sync_cmos_timer, jiffies + 1);
+	return set_rtc_mmss(now.tv_sec);
 }
 
 /* Kick start a stopped clock (procedure from the Sun NVRAM/hostid FAQ). */
Index: linux-2.6.22-rc4-mm/include/linux/time.h
===================================================================
--- linux-2.6.22-rc4-mm.orig/include/linux/time.h	2007-06-10 10:44:36.000000000 +0200
+++ linux-2.6.22-rc4-mm/include/linux/time.h	2007-06-10 10:44:39.000000000 +0200
@@ -93,6 +93,8 @@ extern struct timespec wall_to_monotonic
 extern seqlock_t xtime_lock __attribute__((weak));
 
 extern unsigned long read_persistent_clock(void);
+extern int update_persistent_clock(struct timespec now);
+extern int no_sync_cmos_clock __read_mostly;
 void timekeeping_init(void);
 
 static inline unsigned long get_seconds(void)
Index: linux-2.6.22-rc4-mm/kernel/time/ntp.c
===================================================================
--- linux-2.6.22-rc4-mm.orig/kernel/time/ntp.c	2007-06-10 10:44:36.000000000 +0200
+++ linux-2.6.22-rc4-mm/kernel/time/ntp.c	2007-06-10 10:44:39.000000000 +0200
@@ -10,6 +10,7 @@
 
 #include <linux/mm.h>
 #include <linux/time.h>
+#include <linux/timer.h>
 #include <linux/timex.h>
 #include <linux/jiffies.h>
 #include <linux/hrtimer.h>
@@ -187,12 +188,64 @@ u64 current_tick_length(void)
 	return tick_length;
 }
 
+#ifdef CONFIG_GENERIC_CMOS_UPDATE
 
-void __attribute__ ((weak)) notify_arch_cmos_timer(void)
+/* Disable the cmos update - used by virtualization and embedded */
+int no_sync_cmos_clock  __read_mostly;
+
+static void sync_cmos_clock(unsigned long dummy);
+
+static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0);
+
+static void sync_cmos_clock(unsigned long dummy)
 {
-	return;
+	struct timespec now, next;
+	int fail = 1;
+
+	/*
+	 * If we have an externally synchronized Linux clock, then update
+	 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
+	 * called as close as possible to 500 ms before the new second starts.
+	 * This code is run on a timer.  If the clock is set, that timer
+	 * may not expire at the correct time.  Thus, we adjust...
+	 */
+	if (!ntp_synced())
+		/*
+		 * Not synced, exit, do not restart a timer (if one is
+		 * running, let it run out).
+		 */
+		return;
+
+	getnstimeofday(&now);
+	if (abs(xtime.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2)
+		fail = update_persistent_clock(now);
+
+	next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec;
+	if (next.tv_nsec <= 0)
+		next.tv_nsec += NSEC_PER_SEC;
+
+	if (!fail)
+		next.tv_sec = 659;
+	else
+		next.tv_sec = 0;
+
+	if (next.tv_nsec >= NSEC_PER_SEC) {
+		next.tv_sec++;
+		next.tv_nsec -= NSEC_PER_SEC;
+	}
+	mod_timer(&sync_cmos_timer, jiffies + timespec_to_jiffies(&next));
 }
 
+static void notify_cmos_timer(void)
+{
+	if (no_sync_cmos_clock)
+		mod_timer(&sync_cmos_timer, jiffies + 1);
+}
+
+#else
+static inline void notify_cmos_timer(void) { }
+#endif
+
 /* adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
  */
@@ -357,6 +410,6 @@ leave:	if ((time_status & (STA_UNSYNC|ST
 	txc->stbcnt	   = 0;
 	write_sequnlock_irq(&xtime_lock);
 	do_gettimeofday(&txc->time);
-	notify_arch_cmos_timer();
+	notify_cmos_timer();
 	return(result);
 }
Index: linux-2.6.22-rc4-mm/arch/sparc64/Kconfig
===================================================================
--- linux-2.6.22-rc4-mm.orig/arch/sparc64/Kconfig	2007-06-10 10:44:36.000000000 +0200
+++ linux-2.6.22-rc4-mm/arch/sparc64/Kconfig	2007-06-10 10:44:39.000000000 +0200
@@ -23,6 +23,10 @@ config GENERIC_TIME
 	bool
 	default y
 
+config GENERIC_CMOS_UPDATE
+	bool
+	default y
+
 config GENERIC_CLOCKEVENTS
 	bool
 	default y
Index: linux-2.6.22-rc4-mm/include/asm-i386/timer.h
===================================================================
--- linux-2.6.22-rc4-mm.orig/include/asm-i386/timer.h	2007-06-10 10:44:36.000000000 +0200
+++ linux-2.6.22-rc4-mm/include/asm-i386/timer.h	2007-06-10 10:44:39.000000000 +0200
@@ -12,7 +12,6 @@ unsigned long native_calculate_cpu_khz(v
 
 extern int timer_ack;
 extern int no_timer_check;
-extern int no_sync_cmos_clock;
 extern int recalibrate_cpu_khz(void);
 
 #ifndef CONFIG_PARAVIRT

-- 


  parent reply	other threads:[~2007-06-10  9:36 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-10  9:43 [patch-mm 00/23] High resolution timer updates and x86_64 support Thomas Gleixner
2007-06-10  9:43 ` [patch-mm 01/23] NOHZ: Fix ARM,SH,SPARC64 idle nohz handling Thomas Gleixner
2007-06-11  0:26   ` Paul Mundt
2007-06-11  5:20     ` Thomas Gleixner
2007-06-11  5:32       ` Paul Mundt
2007-06-10  9:44 ` [patch-mm 02/23] ACPI: Move timer broadcast and pmtimer access before C3 arbiter shutdown Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 03/23] Clockevents remove prototypes of removed functions Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 04/23] Timekeeping: Fixup shadow variable argument Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 05/23] timer.c cleanup recently introduced whitespace damage Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 06/23] clockevents: Fix resume logic Thomas Gleixner
2007-06-10  9:43   ` Nigel Cunningham
2007-06-10  9:51     ` Thomas Gleixner
2007-06-10 10:19   ` Rafael J. Wysocki
2007-06-10 10:30     ` Thomas Gleixner
2007-06-10 10:58       ` Rafael J. Wysocki
2007-06-10 13:17         ` Thomas Gleixner
2007-06-10 16:34           ` Rafael J. Wysocki
2007-06-10 18:45             ` Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 07/23] Tick management: spread timer interrupt Thomas Gleixner
2007-06-10 14:16   ` Andreas Mohr
2007-06-10 14:31     ` Thomas Gleixner
2007-06-10 14:35       ` Andreas Mohr
2007-06-10  9:44 ` [patch-mm 08/23] i386: PIT stop only, when in periodic or oneshot mode Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 09/23] clockevents: Fix device replacement Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 10/23] highres: Improve debug output Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 11/23] hrtimer: speedup hrtimer_enqueue Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 12/23] pcspkr: use the global PIT lock Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 13/23] i386: hpet assumes boot cpu is 0 Thomas Gleixner
2007-06-10  9:44 ` Thomas Gleixner [this message]
2007-06-10  9:44 ` [patch-mm 15/23] x86_64: untangle asm/hpet.h from asm/timex.h Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 16/23] x86_64: Use generic cmos update Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 17/23] i386: move setup_pit_timer to the correct header file Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 18/23] x86-64: remove dead code and other janitor work in tsc.c Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 19/23] x86_64: Convert to cleckevents Thomas Gleixner
2007-06-11  8:47   ` Sébastien Dugué
2007-06-11  8:57     ` Thomas Gleixner
2007-06-11 19:12     ` [patch-mm 19a/23] x86_64: hpet restore vread Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 20/23] x86_64: restore restore nohpet cmdline Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 21/23] x86-64 block irq balancing for timer Thomas Gleixner
2007-06-10 16:29   ` Arjan van de Ven
2007-06-11 19:24     ` Pallipadi, Venkatesh
2007-06-10  9:44 ` [patch-mm 22/23] x86_64: prep idle loop for dynticks Thomas Gleixner
2007-06-10  9:44 ` [patch-mm 23/23] x86_64: enable high resolution timers and dynticks Thomas Gleixner
2007-06-10 22:46 ` [patch-mm 00/23] High resolution timer updates and x86_64 support Mark Lord
2007-06-11  5:19   ` Thomas Gleixner
2007-06-11 22:43     ` Mark Lord

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=20070610092446.886512473@inhelltoy.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=chrisw@sous-sol.org \
    --cc=davem@davemloft.net \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=venkatesh.pallipadi@intel.com \
    /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®