]> git.baikalelectronics.ru Git - kernel.git/commitdiff
[PATCH] ntp: add time_adjust to tick length
authorRoman Zippel <zippel@linux-m68k.org>
Sun, 1 Oct 2006 06:28:25 +0000 (23:28 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 1 Oct 2006 07:39:26 +0000 (00:39 -0700)
This folds update_ntp_one_tick() into second_overflow() and adds time_adjust
to the tick length, this makes time_next_adjust unnecessary.  This slightly
changes the adjtime() behaviour, instead of applying it to the next tick, it's
applied to the next second.

Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
Cc: john stultz <johnstul@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/timex.h
kernel/time/ntp.c
kernel/timer.c

index 1cde6f6a27121a1cd363d9e26ba6aff08d14067e..b5f297e1766843c84a377dd799b3b06fe8d59995 100644 (file)
@@ -217,7 +217,6 @@ extern long time_freq;              /* frequency offset (scaled ppm) */
 extern long time_reftime;      /* time at last adjustment (s) */
 
 extern long time_adjust;       /* The amount of adjtime left */
-extern long time_next_adjust;  /* Value for time_adjust at next tick */
 
 extern void ntp_clear(void);
 extern void ntp_update_frequency(void);
index 238ce47ef09d2b326b0d857a5f37ca8a9945e9a4..65223b7ed8105cbe5182952ea28a74dc1f3ff41d 100644 (file)
@@ -22,8 +22,9 @@ unsigned long tick_usec = TICK_USEC;          /* USER_HZ period (usec) */
 unsigned long tick_nsec;                       /* ACTHZ period (nsec) */
 static u64 tick_length, tick_length_base;
 
-/* Don't completely fail for HZ > 500.  */
-int tickadj = 500/HZ ? : 1;            /* microsecs */
+#define MAX_TICKADJ            500             /* microsecs */
+#define MAX_TICKADJ_SCALED     (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \
+                                 TICK_LENGTH_SHIFT) / HZ)
 
 /*
  * phase-lock loop variables
@@ -40,7 +41,6 @@ long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us)         */
 long time_freq;                                /* frequency offset (scaled ppm)*/
 long time_reftime;                     /* time at last adjustment (s)  */
 long time_adjust;
-long time_next_adjust;
 
 /**
  * ntp_clear - Clears the NTP state variables
@@ -160,46 +160,19 @@ void second_overflow(void)
        time_adj = max(time_adj, ((MAXPHASE / HZ) << SHIFT_UPDATE) / MINSEC);
        time_offset -= time_adj;
        tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE);
-}
-
-/*
- * Returns how many microseconds we need to add to xtime this tick
- * in doing an adjustment requested with adjtime.
- */
-static long adjtime_adjustment(void)
-{
-       long time_adjust_step;
-
-       time_adjust_step = time_adjust;
-       if (time_adjust_step) {
-               /*
-                * We are doing an adjtime thing.  Prepare time_adjust_step to
-                * be within bounds.  Note that a positive time_adjust means we
-                * want the clock to run faster.
-                *
-                * Limit the amount of the step to be in the range
-                * -tickadj .. +tickadj
-                */
-               time_adjust_step = min(time_adjust_step, (long)tickadj);
-               time_adjust_step = max(time_adjust_step, (long)-tickadj);
-       }
-       return time_adjust_step;
-}
 
-/* in the NTP reference this is called "hardclock()" */
-void update_ntp_one_tick(void)
-{
-       long time_adjust_step;
-
-       time_adjust_step = adjtime_adjustment();
-       if (time_adjust_step)
-               /* Reduce by this step the amount of time left  */
-               time_adjust -= time_adjust_step;
-
-       /* Changes by adjtime() do not take effect till next tick. */
-       if (time_next_adjust != 0) {
-               time_adjust = time_next_adjust;
-               time_next_adjust = 0;
+       if (unlikely(time_adjust)) {
+               if (time_adjust > MAX_TICKADJ) {
+                       time_adjust -= MAX_TICKADJ;
+                       tick_length += MAX_TICKADJ_SCALED;
+               } else if (time_adjust < -MAX_TICKADJ) {
+                       time_adjust += MAX_TICKADJ;
+                       tick_length -= MAX_TICKADJ_SCALED;
+               } else {
+                       time_adjust = 0;
+                       tick_length += (s64)(time_adjust * NSEC_PER_USEC /
+                                            HZ) << TICK_LENGTH_SHIFT;
+               }
        }
 }
 
@@ -213,14 +186,7 @@ void update_ntp_one_tick(void)
  */
 u64 current_tick_length(void)
 {
-       u64 ret;
-
-       /* calculate the finest interval NTP will allow.
-        */
-       ret = tick_length;
-       ret += (u64)(adjtime_adjustment() * 1000) << TICK_LENGTH_SHIFT;
-
-       return ret;
+       return tick_length;
 }
 
 
@@ -263,7 +229,7 @@ int do_adjtimex(struct timex *txc)
        result = time_state;    /* mostly `TIME_OK' */
 
        /* Save for later - semantics of adjtime is to return old value */
-       save_adjust = time_next_adjust ? time_next_adjust : time_adjust;
+       save_adjust = time_adjust;
 
 #if 0  /* STA_CLOCKERR is never set yet */
        time_status &= ~STA_CLOCKERR;           /* reset STA_CLOCKERR */
@@ -310,8 +276,7 @@ int do_adjtimex(struct timex *txc)
            if (txc->modes & ADJ_OFFSET) {      /* values checked earlier */
                if (txc->modes == ADJ_OFFSET_SINGLESHOT) {
                    /* adjtime() is independent from ntp_adjtime() */
-                   if ((time_next_adjust = txc->offset) == 0)
-                        time_adjust = 0;
+                   time_adjust = txc->offset;
                }
                else if (time_status & STA_PLL) {
                    ltemp = txc->offset;
index 78d3fa10fcd6136f70540a82bcdbcb8c35bcde69..654dd5df24175d0187cab4a374d55d39c9ea0ba6 100644 (file)
@@ -937,8 +937,6 @@ static void update_wall_time(void)
                /* interpolator bits */
                time_interpolator_update(clock->xtime_interval
                                                >> clock->shift);
-               /* increment the NTP state machine */
-               update_ntp_one_tick();
 
                /* accumulate error between NTP and clock interval */
                clock->error += current_tick_length();