]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3541] patch to fix STA_NANO struct timex units
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 11 Nov 2018 08:56:34 +0000 (09:56 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 11 Nov 2018 08:56:34 +0000 (09:56 +0100)
bk: 5be7eec2X6cG-sMjumaa5w1nNzPakw

ChangeLog
ntpd/ntp_control.c
ntpdc/ntpdc_ops.c
util/ntptime.c

index f381a093cf948c1202162000eaf2d8abbf1a1dcf..fc90b3a50fb49e002d095af56ff2123bacdef4e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3541] patch to fix STA_NANO struct timex units <perlinger@ntp.org>
+  - applied patch by Maciej Szmigiero
+
 ---
 (4.2.8p12) 2018/08/14 Released by Harlan Stenn <stenn@ntp.org>
 
index 48cd908f9a84d6c69ced318b55a4631f2c87ce7b..63f9980ac27c0c20ffe9ad24304fd66961ec474c 100644 (file)
@@ -1910,11 +1910,13 @@ ctl_putsys(
        static struct timex ntx;
        static u_long ntp_adjtime_time;
 
-       static const double to_ms =
+       static const double to_ms_usec =
+               1.0e-3; /* usec to msec */
+       static const double to_ms_nusec =
 # ifdef STA_NANO
                1.0e-6; /* nsec to msec */
 # else
-               1.0e-3; /* usec to msec */
+               to_ms_usec;
 # endif
 
        /*
@@ -2319,7 +2321,7 @@ ctl_putsys(
        case CS_K_OFFSET:
                CTL_IF_KERNLOOP(
                        ctl_putdblf,
-                       (sys_var[varid].text, 0, -1, to_ms * ntx.offset)
+                       (sys_var[varid].text, 0, -1, to_ms_nusec * ntx.offset)
                );
                break;
 
@@ -2334,7 +2336,7 @@ ctl_putsys(
                CTL_IF_KERNLOOP(
                        ctl_putdblf,
                        (sys_var[varid].text, 0, 6,
-                        to_ms * ntx.maxerror)
+                        to_ms_usec * ntx.maxerror)
                );
                break;
 
@@ -2342,7 +2344,7 @@ ctl_putsys(
                CTL_IF_KERNLOOP(
                        ctl_putdblf,
                        (sys_var[varid].text, 0, 6,
-                        to_ms * ntx.esterror)
+                        to_ms_usec * ntx.esterror)
                );
                break;
 
@@ -2366,7 +2368,7 @@ ctl_putsys(
                CTL_IF_KERNLOOP(
                        ctl_putdblf,
                        (sys_var[varid].text, 0, 6,
-                           to_ms * ntx.precision)
+                           to_ms_usec * ntx.precision)
                );
                break;
 
@@ -2394,7 +2396,7 @@ ctl_putsys(
        case CS_K_PPS_JITTER:
                CTL_IF_KERNPPS(
                        ctl_putdbl,
-                       (sys_var[varid].text, to_ms * ntx.jitter)
+                       (sys_var[varid].text, to_ms_nusec * ntx.jitter)
                );
                break;
 
index 586ed7f058827ea68a5d2993aa93d80b88fce558..1f2396d311f94cd31643bd5a90cc44e11c34d747 100644 (file)
@@ -2920,7 +2920,7 @@ kerninfo(
        size_t itemsize;
        int res;
        unsigned status;
-       double tscale = 1e-6;
+       double tscale_usec = 1e-6, tscale_unano = 1e-6;
 
 again:
        res = doquery(impl_ver, REQ_GET_KERNEL, 0, 0, 0, (char *)NULL,
@@ -2945,16 +2945,16 @@ again:
         */
 #ifdef STA_NANO
        if (status & STA_NANO)
-               tscale = 1e-9;
+               tscale_unano = 1e-9;
 #endif
        (void)fprintf(fp, "pll offset:           %g s\n",
-           (int32)ntohl(ik->offset) * tscale);
+           (int32)ntohl(ik->offset) * tscale_unano);
        (void)fprintf(fp, "pll frequency:        %s ppm\n",
            fptoa((s_fp)ntohl(ik->freq), 3));
        (void)fprintf(fp, "maximum error:        %g s\n",
-           (u_long)ntohl(ik->maxerror) * tscale);
+           (u_long)ntohl(ik->maxerror) * tscale_usec);
        (void)fprintf(fp, "estimated error:      %g s\n",
-           (u_long)ntohl(ik->esterror) * tscale);
+           (u_long)ntohl(ik->esterror) * tscale_usec);
        (void)fprintf(fp, "status:               %04x ", status);
 #ifdef STA_PLL
        if (status & STA_PLL) (void)fprintf(fp, " pll");
@@ -3008,7 +3008,7 @@ again:
        (void)fprintf(fp, "pll time constant:    %ld\n",
            (u_long)ntohl(ik->constant));
        (void)fprintf(fp, "precision:            %g s\n",
-           (u_long)ntohl(ik->precision) * tscale);
+           (u_long)ntohl(ik->precision) * tscale_usec);
        (void)fprintf(fp, "frequency tolerance:  %s ppm\n",
            fptoa((s_fp)ntohl(ik->tolerance), 0));
 
@@ -3027,7 +3027,7 @@ again:
        (void)fprintf(fp, "pps stability:        %s ppm\n",
            fptoa((s_fp)ntohl(ik->stabil), 3));
        (void)fprintf(fp, "pps jitter:           %g s\n",
-           (u_long)ntohl(ik->jitter) * tscale);
+           (u_long)ntohl(ik->jitter) * tscale_unano);
        (void)fprintf(fp, "calibration interval: %d s\n",
                      1 << ntohs(ik->shift));
        (void)fprintf(fp, "calibration cycles:   %ld\n",
index c47e356dd79619060dacd8f8a1b423f0dee149c9..35896e90922e7f969fe1f3c056dd9104c1c9b47b 100644 (file)
@@ -349,10 +349,6 @@ main(
                printf("  status %s,\n", sprintb((u_int)ntx.status, TIMEX_STA_BITS));
                ftemp = (double)ntx.tolerance / SCALE_FREQ;
                gtemp = (double)ntx.precision;
-#ifdef STA_NANO
-               if (flash & STA_NANO)
-                       gtemp /= 1000.0;
-#endif
                printf(
                    "  time constant %lu, precision %.3f us, tolerance %.0f ppm,\n",
                    (u_long)ntx.constant, gtemp, ftemp);