]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
[PATCH] NTP: ntp-helper functions
authorjohn stultz <johnstul@us.ibm.com>
Tue, 6 Sep 2005 22:17:46 +0000 (15:17 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 7 Sep 2005 23:57:34 +0000 (16:57 -0700)
This patch cleans up a commonly repeated set of changes to the NTP state
variables by adding two helper inline functions:

ntp_clear(): Clears the ntp state variables

ntp_synced(): Returns 1 if the system is synced with a time server.

This was compile tested for alpha, arm, i386, x86-64, ppc64, s390, sparc,
sparc64.

Signed-off-by: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
27 files changed:
arch/alpha/kernel/time.c
arch/arm/kernel/time.c
arch/arm26/kernel/time.c
arch/cris/arch-v10/kernel/time.c
arch/cris/kernel/time.c
arch/frv/kernel/time.c
arch/h8300/kernel/time.c
arch/i386/kernel/time.c
arch/m32r/kernel/time.c
arch/m68k/kernel/time.c
arch/m68knommu/kernel/time.c
arch/mips/kernel/sysirix.c
arch/mips/kernel/time.c
arch/mips/sgi-ip27/ip27-timer.c
arch/parisc/kernel/time.c
arch/ppc/kernel/time.c
arch/ppc64/kernel/time.c
arch/s390/kernel/time.c
arch/sh/kernel/time.c
arch/sh64/kernel/time.c
arch/sparc/kernel/pcic.c
arch/sparc/kernel/time.c
arch/sparc64/kernel/time.c
arch/v850/kernel/time.c
arch/x86_64/kernel/time.c
arch/xtensa/kernel/time.c
include/linux/timex.h

index 8226c5cd788ccb142c3676727fb06161cc5cc574..67be50b7d80afba730e18746ad8e8ac63acc6068 100644 (file)
@@ -149,7 +149,7 @@ irqreturn_t timer_interrupt(int irq, void *dev, struct pt_regs * regs)
         * 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.
         */
-       if ((time_status & STA_UNSYNC) == 0
+       if (ntp_synced()
            && xtime.tv_sec > state.last_rtc_update + 660
            && xtime.tv_nsec >= 500000 - ((unsigned) TICK_SIZE) / 2
            && xtime.tv_nsec <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -502,10 +502,7 @@ do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
 
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
index 8880482dcbffd4dbbfb20ea98def232de3b439d1..69449a818dccecd78ac290032124c9998e746d4a 100644 (file)
@@ -102,7 +102,7 @@ static unsigned long next_rtc_update;
  */
 static inline void do_set_rtc(void)
 {
-       if (time_status & STA_UNSYNC || set_rtc == NULL)
+       if (!ntp_synced() || set_rtc == NULL)
                return;
 
        if (next_rtc_update &&
@@ -292,10 +292,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index 549a6b2e177ef4ca666bfd4355d9b21d7b2dafe8..e66aedd02fad7c2eccf15259efb97c162e3dec5a 100644 (file)
@@ -114,7 +114,7 @@ static unsigned long next_rtc_update;
  */
 static inline void do_set_rtc(void)
 {
-       if (time_status & STA_UNSYNC || set_rtc == NULL)
+       if (!ntp_synced() || set_rtc == NULL)
                return;
 
 //FIXME - timespec.tv_sec is a time_t not unsigned long
@@ -189,10 +189,7 @@ int do_settimeofday(struct timespec *tv)
 
        xtime.tv_sec = tv->tv_sec;
        xtime.tv_nsec = tv->tv_nsec;
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index 6b7b4e0802e3ac23991abd09fcfbf9312cf274f8..dc3dfe9b4a1aa64f09a8b35a3947d8b32e1346ec 100644 (file)
@@ -240,7 +240,7 @@ timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
         * The division here is not time critical since it will run once in 
         * 11 minutes
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - (tick_nsec / 1000) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + (tick_nsec / 1000) / 2) {
index fa2d4323da2592deef3bd5652110d953e7696850..a2d99b4aedcda34f22a5c1ec10fc4f3250050b0c 100644 (file)
@@ -114,10 +114,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index 075db6644694b460b6428ce41223cc2c546dabbc..8d6558b00e44fe86128e03922e4a402ac18fee8b 100644 (file)
@@ -85,7 +85,7 @@ static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
         * 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.
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2
@@ -216,10 +216,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index 8a600218334dfcaba3501a34e9e09d0c40f6395a..af8c5d2057dd56ed6fa30257cd9ab2cd5c521bcb 100644 (file)
@@ -116,10 +116,7 @@ int do_settimeofday(struct timespec *tv)
 
        xtime.tv_sec = tv->tv_sec;
        xtime.tv_nsec = tv->tv_nsec;
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index 9b94d84a6c3bb3601a2cb8f6261dc32e50921703..eefea7c5500893bd47e9d9485f7111ae34cd76e1 100644 (file)
@@ -194,10 +194,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
@@ -347,7 +344,7 @@ static void sync_cmos_clock(unsigned long dummy)
         * 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 ((time_status & STA_UNSYNC) != 0)
+       if (!ntp_synced())
                /*
                 * Not synced, exit, do not restart a timer (if one is
                 * running, let it run out).
index 8a2b77bc5749b50b01a45ef3c81b6d2c8870fc05..539c562cd54de57b04eb45f59ea5bea9fc3f0012 100644 (file)
@@ -171,10 +171,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
 
@@ -221,7 +218,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
         * called as close as possible to 500 ms before the new second starts.
         */
        write_seqlock(&xtime_lock);
-       if ((time_status & STA_UNSYNC) == 0
+       if (ntp_synced()
                && xtime.tv_sec > last_rtc_update + 660
                && (xtime.tv_nsec / 1000) >= 500000 - ((unsigned)TICK_SIZE) / 2
                && (xtime.tv_nsec / 1000) <= 500000 + ((unsigned)TICK_SIZE) / 2)
index e47e19588525e47c1fb19edba8ae3621201e6d08..4ec95e3cb8748721ec6b37880d0a87aaf1b55f83 100644 (file)
@@ -166,10 +166,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index 5c3ca671627c19fdd82cb71e631801448be616c7..b17c1ecba966e103d36ad2f7108b4c28a16d2b1a 100644 (file)
@@ -68,7 +68,7 @@ static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
         * 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.
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec  / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -178,10 +178,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index f3bf0e43b8bb207ed0d50d4f01a14525509d2195..b4659546271789c6498967d40f81bb68e7283f83 100644 (file)
@@ -632,10 +632,7 @@ asmlinkage int irix_stime(int value)
        write_seqlock_irq(&xtime_lock);
        xtime.tv_sec = value;
        xtime.tv_nsec = 0;
-       time_adjust = 0;                        /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
 
        return 0;
index 648c82292ed6c8ab8870b09902d694de87f211a1..0dd0df7a3b04af60f095e03bd33cd6db0c3adac9 100644 (file)
@@ -223,10 +223,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                        /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
 
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
@@ -442,7 +439,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
         * called as close as possible to 500 ms before the new second starts.
         */
        write_seqlock(&xtime_lock);
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
index 8c1b96fffa764e8e3a4c9d7ea163c04d2a61620e..cddf1cedf007108daf8bfbb8f286656f7e48e196 100644 (file)
@@ -118,7 +118,7 @@ again:
         * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
         * called as close as possible to when a second starts.
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
index 6cf7407344badb9c4a7841b94d98251ec6264e27..7ff67f8e9f8c019bd2132cef0e3cabf6768859d9 100644 (file)
@@ -188,10 +188,7 @@ do_settimeofday (struct timespec *tv)
                set_normalized_timespec(&xtime, sec, nsec);
                set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-               time_adjust = 0;                /* stop active adjtime() */
-               time_status |= STA_UNSYNC;
-               time_maxerror = NTP_PHASE_LIMIT;
-               time_esterror = NTP_PHASE_LIMIT;
+               ntp_clear();
        }
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
index bf4ddca5e853b22f460a7d4f8b0a06e396ae406c..a3c5281a5d2d8c05e328a6fc5c83f10b9981193c 100644 (file)
@@ -169,7 +169,7 @@ void timer_interrupt(struct pt_regs * regs)
                 * We should have an rtc call that only sets the minutes and
                 * seconds like on Intel to avoid problems with non UTC clocks.
                 */
-               if ( ppc_md.set_rtc_time && (time_status & STA_UNSYNC) == 0 &&
+               if ( ppc_md.set_rtc_time && ntp_synced() &&
                     xtime.tv_sec - last_rtc_update >= 659 &&
                     abs((xtime.tv_nsec / 1000) - (1000000-1000000/HZ)) < 500000/HZ &&
                     jiffies - wall_jiffies == 1) {
@@ -271,10 +271,7 @@ int do_settimeofday(struct timespec *tv)
         */
        last_rtc_update = new_sec - 658;
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irqrestore(&xtime_lock, flags);
        clock_was_set();
        return 0;
index 91ef95ccda4fca400f2efe3fd6d983a2f85a40b8..9939c206afa42c776eef326e92094a29e5eaa211 100644 (file)
@@ -128,7 +128,7 @@ static __inline__ void timer_check_rtc(void)
          * We should have an rtc call that only sets the minutes and
          * seconds like on Intel to avoid problems with non UTC clocks.
          */
-        if ( (time_status & STA_UNSYNC) == 0 &&
+        if (ntp_synced() &&
              xtime.tv_sec - last_rtc_update >= 659 &&
              abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ &&
              jiffies - wall_jiffies == 1) {
@@ -435,10 +435,7 @@ int do_settimeofday(struct timespec *tv)
         */
        last_rtc_update = new_sec - 658;
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
 
        delta_xsec = mulhdu( (tb_last_stamp-do_gtod.varp->tb_orig_stamp),
                             do_gtod.varp->tb_to_xs );
index 8ca485676780de694b31134f2303b094e5053e68..2fd75da1549522b13816e9a9c50e1be8c4db2b42 100644 (file)
@@ -139,10 +139,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
        return 0;
index d5f5aedde0a378b4d79bb6fb9f845aaa7378bc1d..02ca69918d7c0992a943f7d7d856149f0145a9a3 100644 (file)
@@ -215,10 +215,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
 
@@ -252,7 +249,7 @@ static inline void do_timer_interrupt(int irq, struct pt_regs *regs)
         * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
         * called as close as possible to 500 ms before the new second starts.
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
index 926c6fc0619c580f79654a364c952b4369ab6e37..f4a62a10053c60e6921d00b280d050a90eae8735 100644 (file)
@@ -247,10 +247,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
 
@@ -328,7 +325,7 @@ static inline void do_timer_interrupt(int irq, struct pt_regs *regs)
         * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
         * called as close as possible to 500 ms before the new second starts.
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
index 597d3ff6ad68ce16d1a5426a7562cfba3d4e065d..36a40697b8d61e66a9c129a61cb009712199f663 100644 (file)
@@ -840,10 +840,7 @@ static int pci_do_settimeofday(struct timespec *tv)
 
        xtime.tv_sec = tv->tv_sec;
        xtime.tv_nsec = tv->tv_nsec;
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        return 0;
 }
 
index 3b759aefc170e39b69f76d93487da243b46c1dc4..bc015e980341060dc9eb3fa28d6bc9485cb964bd 100644 (file)
@@ -139,7 +139,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs * regs)
 
 
        /* Determine when to update the Mostek clock. */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -554,10 +554,7 @@ static int sbus_do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        return 0;
 }
 
index 362b9c26871b26af39abe9142bf7ed830ff31e66..3f08a32f51a16d2a91231ddcf15701dbdbe3d51b 100644 (file)
@@ -449,7 +449,7 @@ static inline void timer_check_rtc(void)
        static long last_rtc_update;
 
        /* Determine when to update the Mostek clock. */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
index f722a268238a69f8921f09f63c9df3003c4b6763..ea3fd8844ff06b1bc4df01188db13407def7b833 100644 (file)
@@ -66,7 +66,7 @@ static irqreturn_t timer_interrupt (int irq, void *dummy, struct pt_regs *regs)
         * 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.
         */
-       if ((time_status & STA_UNSYNC) == 0 &&
+       if (ntp_synced() &&
            xtime.tv_sec > last_rtc_update + 660 &&
            (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
            (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
@@ -169,10 +169,7 @@ int do_settimeofday(struct timespec *tv)
        xtime.tv_sec = tv->tv_sec;
        xtime.tv_nsec = tv->tv_nsec;
 
-       time_adjust = 0;                /* stop active adjtime () */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
 
        write_sequnlock_irq (&xtime_lock);
        clock_was_set();
index 2b5d9da912a26d2d7119563217d2b19dcf2c0e24..7b6abe0582536f54f5c5aea12587d22d3ab92f1d 100644 (file)
@@ -176,10 +176,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
 
        write_sequnlock_irq(&xtime_lock);
        clock_was_set();
@@ -471,7 +468,7 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  * off) isn't likely to go away much sooner anyway.
  */
 
-       if ((~time_status & STA_UNSYNC) && xtime.tv_sec > rtc_update &&
+       if (ntp_synced() && xtime.tv_sec > rtc_update &&
                abs(xtime.tv_nsec - 500000000) <= tick_nsec / 2) {
                set_rtc_mmss(xtime.tv_sec);
                rtc_update = xtime.tv_sec + 660;
index e07287db5a40da91f6ce377e14cd9b356843a9f9..1ac7d5ce7456659ecf771df51580aacdb8282454 100644 (file)
@@ -122,10 +122,7 @@ int do_settimeofday(struct timespec *tv)
        set_normalized_timespec(&xtime, sec, nsec);
        set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
 
-       time_adjust = 0;                /* stop active adjtime() */
-       time_status |= STA_UNSYNC;
-       time_maxerror = NTP_PHASE_LIMIT;
-       time_esterror = NTP_PHASE_LIMIT;
+       ntp_clear();
        write_sequnlock_irq(&xtime_lock);
        return 0;
 }
@@ -184,7 +181,7 @@ again:
                next += CCOUNT_PER_JIFFY;
                do_timer (regs); /* Linux handler in kernel/timer.c */
 
-               if ((time_status & STA_UNSYNC) == 0 &&
+               if (ntp_synced() &&
                    xtime.tv_sec - last_rtc_update >= 659 &&
                    abs((xtime.tv_nsec/1000)-(1000000-1000000/HZ))<5000000/HZ &&
                    jiffies - wall_jiffies == 1) {
index 74fdd07d3792a55cf970c9a1ad4942511976adf7..7e050a2cc35be69f2685309ff9c445adbba8ae68 100644 (file)
@@ -260,6 +260,29 @@ extern long pps_calcnt;            /* calibration intervals */
 extern long pps_errcnt;                /* calibration errors */
 extern long pps_stbcnt;                /* stability limit exceeded */
 
+/**
+ * ntp_clear - Clears the NTP state variables
+ *
+ * Must be called while holding a write on the xtime_lock
+ */
+static inline void ntp_clear(void)
+{
+       time_adjust = 0;                /* stop active adjtime() */
+       time_status |= STA_UNSYNC;
+       time_maxerror = NTP_PHASE_LIMIT;
+       time_esterror = NTP_PHASE_LIMIT;
+}
+
+/**
+ * ntp_synced - Returns 1 if the NTP status is not UNSYNC
+ *
+ */
+static inline int ntp_synced(void)
+{
+       return !(time_status & STA_UNSYNC);
+}
+
+
 #ifdef CONFIG_TIME_INTERPOLATION
 
 #define TIME_SOURCE_CPU 0