Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/ntp pull in a set of patches from ntp bk to fix the



details:   https://anonhg.NetBSD.org/src/rev/7c20e4e981f6
branches:  trunk
changeset: 555933:7c20e4e981f6
user:      drochner <drochner%NetBSD.org@localhost>
date:      Thu Dec 04 17:22:31 2003 +0000

description:
pull in a set of patches from ntp bk to fix the
"Clock stepping messes up frequency." issue

diffstat:

 dist/ntp/libntp/systime.c      |   9 ++++++-
 dist/ntp/ntpd/ntp_loopfilter.c |  48 ++++++++++++++++++-----------------------
 dist/ntp/ntpd/ntp_proto.c      |  24 ++++++++++++++-------
 3 files changed, 44 insertions(+), 37 deletions(-)

diffs (214 lines):

diff -r 2a6037d79b8f -r 7c20e4e981f6 dist/ntp/libntp/systime.c
--- a/dist/ntp/libntp/systime.c Thu Dec 04 17:17:36 2003 +0000
+++ b/dist/ntp/libntp/systime.c Thu Dec 04 17:22:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: systime.c,v 1.3 2003/12/04 16:23:37 drochner Exp $     */
+/*     $NetBSD: systime.c,v 1.4 2003/12/04 17:22:31 drochner Exp $     */
 
 /*
  * systime -- routines to fiddle a UNIX clock.
@@ -426,7 +426,12 @@
         double now             /* step adjustment (s) */
         )
 {
-       ntp_node.adj = now;
+#ifdef DEBUG
+       if (debug)
+               printf("step_systime: time %.6f adj %.6f\n",
+                  ntp_node.ntp_time, now);
+#endif
+       ntp_node.ntp_time += now;
        return (1);
 }
 
diff -r 2a6037d79b8f -r 7c20e4e981f6 dist/ntp/ntpd/ntp_loopfilter.c
--- a/dist/ntp/ntpd/ntp_loopfilter.c    Thu Dec 04 17:17:36 2003 +0000
+++ b/dist/ntp/ntpd/ntp_loopfilter.c    Thu Dec 04 17:22:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_loopfilter.c,v 1.3 2003/12/04 16:23:37 drochner Exp $      */
+/*     $NetBSD: ntp_loopfilter.c,v 1.4 2003/12/04 17:22:31 drochner Exp $      */
 
 /*
  * ntp_loopfilter.c - implements the NTP loop filter algorithm
@@ -276,24 +276,6 @@
        }
 
        /*
-        * If the clock has never been set, set it and initialize the
-        * discipline parameters. We then switch to frequency mode to
-        * speed the inital convergence process. If lucky, after an hour
-        * the ntp.drift file is created and initialized and we don't
-        * get here again.
-        */
-       if (state == S_NSET) {
-               if (fabs(fp_offset) > clock_max && clock_max > 0) {
-                       step_systime(fp_offset);
-                       msyslog(LOG_NOTICE, "time reset %+.6f s",
-                           fp_offset);
-                       reinit_timer();
-               }
-               rstclock(S_FREQ, peer->epoch, 0);
-               return (1);
-       }
-
-       /*
         * Update the jitter estimate.
         */
        oerror = sys_jitter;
@@ -353,7 +335,7 @@
                 * to S_FREQ state.
                 */
                case S_TSET:
-                       state = S_FREQ;
+                       rstclock(S_FREQ, peer->epoch, fp_offset);
                        break;
 
                /*
@@ -375,6 +357,7 @@
                case S_FREQ:
                        if (mu < clock_minstep)
                                return (0);
+
                        /* fall through to S_SPIK */
 
                /*
@@ -388,16 +371,19 @@
                        /* fall through to default */
 
                /*
-                * We get here directly in S_FSET state and indirectly
-                * from S_FREQ and S_SPIK states. The clock is either
-                * reset or shaken, but never stirred.
+                * We get here directly in S_NSET and S_FSET states and
+                * indirectly from S_FREQ and S_SPIK states. The clock
+                * is either reset or shaken, but never stirred.
                 */
                default:
                        step_systime(fp_offset);
                        msyslog(LOG_NOTICE, "time reset %+.6f s",
                            fp_offset);
                        reinit_timer();
-                       rstclock(S_TSET, peer->epoch, 0);
+                       if (state == S_NSET)
+                               rstclock(S_FREQ, peer->epoch, 0);
+                       else
+                               rstclock(S_TSET, peer->epoch, 0);
                        retval = 1;
                        break;
                }
@@ -405,6 +391,14 @@
                switch (state) {
 
                /*
+                * If the frequency has not been initialized from the
+                * file, drop everything until it is.
+                */
+               case S_NSET:
+                       rstclock(S_FREQ, peer->epoch, fp_offset);
+                       break;
+
+               /*
                 * In S_FSET state this is the first update. Adjust the
                 * phase, but don't adjust the frequency until the next
                 * update.
@@ -665,7 +659,7 @@
                                tc_counter = CLOCK_LIMIT;
                                if (sys_poll < peer->maxpoll) {
                                        tc_counter = 0;
-                                       sys_poll++;
+                                       sys_poll++;
                                }
                        }
                } else {
@@ -788,8 +782,8 @@
        last_offset = clock_offset = offset;
 #ifdef DEBUG
        if (debug)
-               printf("local_clock: at %lu state %d\n", last_time,
-                   trans);
+               printf("local_clock: time %lu offset %.6f state %d\n",
+                   last_time, last_offset, trans);
 #endif
 }
 
diff -r 2a6037d79b8f -r 7c20e4e981f6 dist/ntp/ntpd/ntp_proto.c
--- a/dist/ntp/ntpd/ntp_proto.c Thu Dec 04 17:17:36 2003 +0000
+++ b/dist/ntp/ntpd/ntp_proto.c Thu Dec 04 17:22:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_proto.c,v 1.2 2003/12/04 16:23:37 drochner Exp $   */
+/*     $NetBSD: ntp_proto.c,v 1.3 2003/12/04 17:22:31 drochner Exp $   */
 
 /*
  * ntp_proto.c - NTP version 4 protocol machinery
@@ -43,6 +43,7 @@
 struct peer *sys_prefer;       /* our cherished peer */
 int    sys_kod;                /* kod credit */
 int    sys_kod_rate = 2;       /* max kod packets per second */
+u_long sys_clocktime;          /* last system clock update */
 #ifdef OPENSSL
 u_long sys_automax;            /* maximum session key lifetime */
 #endif /* OPENSSL */
@@ -239,6 +240,7 @@
                        else
                                peer->burst--;
                        if (peer->burst == 0) {
+
                                /*
                                 * If a broadcast client at this point,
                                 * the burst has concluded, so we switch
@@ -253,7 +255,8 @@
 #endif /* OPENSSL */
                                }
                                poll_update(peer, hpoll);
-                               clock_select();
+                               if (peer->reach & ((1 << NTP_BURST) - 1))
+                                       clock_select();
 
                                /*
                                 * If ntpdate mode and the clock has not
@@ -1274,7 +1277,8 @@
                return;
        }
        clock_filter(peer, p_offset, p_del, p_disp);
-       clock_select();
+       if (peer->burst == 0)
+               clock_select();
        record_peer_stats(&peer->srcadr, ctlpeerstatus(peer),
            peer->offset, peer->delay, peer->disp,
            SQRT(peer->jitter));
@@ -1297,8 +1301,11 @@
         */
        if (sys_peer == NULL)
                return;
-       if (sys_peer->epoch <= last_time)
+
+       if (sys_peer->epoch <= sys_clocktime)
                return;
+
+       sys_clocktime = sys_peer->epoch;
 #ifdef DEBUG
        if (debug)
                printf("clock_update: at %ld assoc %d \n", current_time,
@@ -1826,7 +1833,9 @@
                         * Leave the island immediately if the peer is
                         * unfit to synchronize.
                         */
-                       if (peer_unfit(peer))
+                       if (peer_unfit(peer) || root_distance(peer) >=
+                           MAXDISTANCE + 2. * clock_phi *
+                           ULOGTOD(sys_poll))
                                continue;
 
                        /*
@@ -2895,9 +2904,8 @@
 {
        return (!peer->reach || (peer->stratum > 1 && peer->refid ==
            peer->dstadr->addr_refid) || peer->leap == LEAP_NOTINSYNC ||
-           peer->stratum >= STRATUM_UNSPEC || root_distance(peer) >=
-           MAXDISTANCE + 2. * clock_phi * ULOGTOD(sys_poll) ||
-           peer->flags & FLAG_NOSELECT );
+           peer->stratum >= STRATUM_UNSPEC || peer->flags &
+           FLAG_NOSELECT);
 }
 
 



Home | Main Index | Thread Index | Old Index