]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
ntp: improve adjtimex frequency rounding
authorRoman Zippel <zippel@linux-m68k.org>
Mon, 22 Sep 2008 21:42:44 +0000 (14:42 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 24 Sep 2008 15:33:13 +0000 (17:33 +0200)
Change PPM_SCALE_INV_SHIFT so that it doesn't throw away any input bits
(19 is the amount of the factor 2 in PPM_SCALE), the output frequency
can then be calculated back to its input value, as the inverse divide
produce a slightly larger value, which is then correctly rounded by the
final shift.

Reported-by: Martin Ziegler <ziegler@uni-freiburg.de>
Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
Cc: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
include/linux/timex.h
kernel/time/ntp.c

index c00bcdd3ae424da4a864b55ac05b139316aadefb..9007313b5b7168ae03ed85e63d80ce6afe0ce438 100644 (file)
@@ -82,7 +82,7 @@
  */
 #define SHIFT_USEC 16          /* frequency offset scale (shift) */
 #define PPM_SCALE (NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
-#define PPM_SCALE_INV_SHIFT 20
+#define PPM_SCALE_INV_SHIFT 19
 #define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
                       PPM_SCALE + 1)
 
index 450a45cb01c1ceb57d260a798911bbe1c3135723..ddb0465a6baab4d81d79ed7799f463e5f5d9cf55 100644 (file)
@@ -406,9 +406,8 @@ adj_done:
        if (time_status & (STA_UNSYNC|STA_CLOCKERR))
                result = TIME_ERROR;
 
-       txc->freq          = shift_right((s32)(time_freq >> PPM_SCALE_INV_SHIFT) *
-                                        (s64)PPM_SCALE_INV,
-                                        NTP_SCALE_SHIFT);
+       txc->freq          = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) *
+                                        (s64)PPM_SCALE_INV, NTP_SCALE_SHIFT);
        txc->maxerror      = time_maxerror;
        txc->esterror      = time_esterror;
        txc->status        = time_status;