From: Harlan Stenn Date: Tue, 14 Sep 1999 23:56:28 +0000 (-0000) Subject: Many files: X-Git-Tag: NTP_4_0_98~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d865c0d08e22d66da00c2bffed9c59e78e765b01;p=thirdparty%2Fntp.git Many files: * ntpd/refclock_atom.c: PPS cleanup * ntpd/ntp_refclock.c (refclock_ioctl): PPS cleanup From: Dave Mills * ntptrace/ntptrace.c (ReceiveBuf): addserver() can return NIL. Reported by: "Alan J. Wylie" * libntp/ieee754io.c: * ntpd/ntp_proto.c: * ntpd/ntp_refclock.c: Lint cleanup. From: Marc.Brett@westgeo.com bk: 37dee0acScPndV55d-ps3sJcusb8QQ --- diff --git a/ChangeLog b/ChangeLog index 47ecc291d..4e08e5308 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +1999-09-14 Harlan Stenn + + * ntpd/refclock_atom.c: PPS cleanup + * ntpd/ntp_refclock.c (refclock_ioctl): PPS cleanup + From: Dave Mills + + * ntptrace/ntptrace.c (ReceiveBuf): addserver() can return NIL. + Reported by: "Alan J. Wylie" + + * libntp/ieee754io.c: + * ntpd/ntp_proto.c: + * ntpd/ntp_refclock.c: + Lint cleanup. + From: Marc.Brett@westgeo.com + 1999-09-12 Harlan Stenn * ntpd/ntp_refclock.c (refclock_ioctl): Declaration cleanup. diff --git a/libntp/ieee754io.c b/libntp/ieee754io.c index 54eebf9f9..4aa9920a3 100644 --- a/libntp/ieee754io.c +++ b/libntp/ieee754io.c @@ -144,21 +144,27 @@ fetch_ieee754( u_long mantissa_high; u_long characteristic; long exponent; +#ifdef LIBDEBUG int length; +#endif unsigned char val; int fieldindex = 0; switch (size) { case IEEE_DOUBLE: +#ifdef LIBDEBUG length = 8; +#endif mbits = 52; bias = 1023; maxexp = 2047; break; case IEEE_SINGLE: +#ifdef LIBDEBUG length = 4; +#endif mbits = 23; bias = 127; maxexp = 255; @@ -369,15 +375,19 @@ put_ieee754( ) { l_fp outlfp; +#ifdef LIBDEBUG unsigned int sign; unsigned int bias; +#endif /*unsigned int maxexp;*/ int mbits; int msb; u_long mantissa_low = 0; u_long mantissa_high = 0; +#ifdef LIBDEBUG u_long characteristic = 0; long exponent; +#endif /*int length;*/ unsigned long mask; @@ -388,14 +398,18 @@ put_ieee754( case IEEE_DOUBLE: /*length = 8;*/ mbits = 52; +#ifdef LIBDEBUG bias = 1023; +#endif /*maxexp = 2047;*/ break; case IEEE_SINGLE: /*length = 4;*/ mbits = 23; +#ifdef LIBDEBUG bias = 127; +#endif /*maxexp = 255;*/ break; @@ -409,16 +423,22 @@ put_ieee754( if (L_ISNEG(&outlfp)) { L_NEG(&outlfp); +#ifdef LIBDEBUG sign = 1; +#endif } else { +#ifdef LIBDEBUG sign = 0; +#endif } if (L_ISZERO(&outlfp)) { +#ifdef LIBDEBUG exponent = mantissa_high = mantissa_low = 0; /* true zero */ +#endif } else { @@ -475,10 +495,10 @@ put_ieee754( } } +#ifdef LIBDEBUG exponent = msb - 32; characteristic = exponent + bias; - -#ifdef LIBDEBUG + if (debug > 4) printf("FP: %s\n", fmt_flt(sign, mantissa_high, mantissa_low, characteristic)); #endif diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index ff006fe82..d691b27e2 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -220,7 +220,8 @@ receive( int is_authentic; /* cryptosum ok */ int is_mystic; /* session key exists */ int is_error; /* parse error */ - u_long skeyid, pkeyid, tkeyid; +/* u_long pkeyid; */ + u_long skeyid, tkeyid; struct peer *peer2; int retcode = AM_NOMATCH; @@ -295,7 +296,8 @@ receive( * the extension field and the MAC follows that. */ has_mac = 0; - skeyid = pkeyid = tkeyid = 0; +/* pkeyid = 0; */ + skeyid = tkeyid = 0; authlen = LEN_PKT_NOMAC; has_mac = rbufp->recv_length - authlen; if (has_mac <= 5 * sizeof(u_int32)) { @@ -312,7 +314,7 @@ receive( * Note that keyid3 is actually the key ident of the * MAC itself. */ - pkeyid = (u_long)ntohl(pkt->keyid2) & 0xffffffff; +/* pkeyid = (u_long)ntohl(pkt->keyid2) & 0xffffffff; */ skeyid = tkeyid = (u_long)ntohl(pkt->keyid3) & 0xffffffff; } diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index bfdfdce3a..58b19b759 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -950,6 +950,7 @@ refclock_ioctl( #ifndef SYS_VXWORKS #if defined(HAVE_TERMIOS) || defined(HAVE_SYSV_TTYS) || defined(HAVE_BSD_TTYS) +#ifdef TTYCLK #ifdef HAVE_TERMIOS struct termios ttyb, *ttyp; #endif /* HAVE_TERMIOS */ @@ -959,6 +960,7 @@ refclock_ioctl( #ifdef HAVE_BSD_TTYS struct sgttyb ttyb, *ttyp; #endif /* HAVE_BSD_TTYS */ +#endif /* TTYCLK */ #ifdef DEBUG if (debug) @@ -993,7 +995,9 @@ refclock_ioctl( return (0); } #endif /* HAVE_TERMIOS HAVE_BSD_TTYS */ +#ifdef TTYCLK ttyp = &ttyb; +#endif /* TTYCLK */ #ifdef STREAM #ifdef TTYCLK /* @@ -1104,9 +1108,10 @@ refclock_ioctl( pps_params_t pp; int mode; + memset((char *)&pp, 0, sizeof(pp)); if (fdpps > 0) { msyslog(LOG_ERR, - "refclock_ioctl: ppsclock already configured"); + "refclock_ioctl: ppsapi already configured"); return (0); } if (time_pps_create(fd, &fdpps) < 0) { @@ -1121,12 +1126,13 @@ refclock_ioctl( fdpps = 0; return (0); } - if(pps_assert) - pp.mode = PPS_CAPTUREASSERT; + pp.mode = PPS_TSFMT_TSPEC; + if (pps_assert) + pp.mode |= PPS_CAPTUREASSERT; else - pp.mode = PPS_CAPTURECLEAR; - if(pps_hardpps) { - if(pps_assert) + pp.mode |= PPS_CAPTURECLEAR; + if (pps_hardpps) { + if (pps_assert) pp.mode |= PPS_HARDPPSONASSERT; else pp.mode |= PPS_HARDPPSONCLEAR; diff --git a/ntpd/refclock_atom.c b/ntpd/refclock_atom.c index 196781254..e40c4781d 100644 --- a/ntpd/refclock_atom.c +++ b/ntpd/refclock_atom.c @@ -35,24 +35,26 @@ * In order for this driver to work, the local clock must be set to * within +-500 ms by another means, such as a radio clock or NTP * itself. The 1-pps signal is connected via a serial port and gadget - * box consisting of a one-shot and RS232 level converter. When operated - * at 38.4 kbps with a SPARCstation IPC, this arrangement has a worst- - * case jitter less than 26 us. + * box consisting of a one-shot flopflop and RS232 level converter. + * Conntection is either via the carrier detect (DCD) lead or via the + * receive data (RD) lead. The incidental jitter using the DCD lead is + * essentially the interrupt latency. The incidental jitter using the RD + * lead has an additional component due to the line sampling clock. When + * operated at 38.4 kbps, this arrangement has a worst-case jitter less + * than 26 us. * - * There are three ways in which this driver can be used. The first way - * uses the LDISC_PPS line discipline and works only for the baseboard - * serial ports of the Sun SPARCstation. The PPS signal is connected via - * a gadget box to the carrier detect (CD) line of a serial port and - * flag3 of the driver configured for that port is set. This causes the - * ppsclock streams module to be configured for that port and capture a - * timestamp at the on-time transition of the PPS signal. This driver - * then reads the timestamp directly by a designated ioctl() system - * call. This provides the most accurate time and least jitter of any - * other scheme. There is no need to configure a dedicated device for - * this purpose, which ordinarily is the device used for the associated - * radio clock. + * There are four ways in which this driver can be used. They are + * described in decreasing order of merit below. The first way uses the + * ppsapi STREAMS module and the LDISC_PPS line discipline, while the + * second way uses the ppsclock STREAMS module and the LDISC_PPS line + * discipline. Either of these works only for the baseboard serial ports + * of the Sun SPARC IPC and clones. However, the ppsapi uses the + * proposed IETF interface expected to become standard for PPS signals. + * The serial port to be used is specified by the pps command in the + * configuration file. This driver reads the timestamp directly by a + * designated ioctl() system call. * - * The second way uses the LDISC_CLKPPS line discipline and works for + * The third way uses the LDISC_CLKPPS line discipline and works for * any architecture supporting a serial port. If after a few seconds * this driver finds no ppsclock module configured, it attempts to open * a serial port device /dev/pps%d, where %d is the unit number, and @@ -63,23 +65,22 @@ * discipline, this produces an ASCII DEL character ('\377') followed by * a timestamp at each seconds epoch. * - * The third way involves an auxiliary radio clock driver which calls + * The fourth way involves an auxiliary radio clock driver which calls * the PPS driver with a timestamp captured by that driver. This use is * documented in the source code for the driver(s) involved. Note that * some drivers collect the sample information themselves before calling - * our pps_sample(), and others call us knowing only that they are running - * shortly after an on-time tick and they expect us to retrieve the PPS + * pps_sample(), and others call knowing only that they are running + * shortly after an on-time tick and they expect to retrieve the PPS * offset, fudge their result, and insert it into the timestream. * * Fudge Factors * - * There are no special fudge factors other than the generic and those - * explicitly defined above. The fudge time1 parameter can be used to - * compensate for miscellaneous UART and OS delays. Allow about 247 us - * for uart delays at 38400 bps and about 1 ms for SunOS streams - * nonsense. + * There are no special fudge factors other than the generic. The fudge + * time1 parameter can be used to compensate for miscellaneous UART and + * OS delays. Allow about 247 us for uart delays at 38400 bps and about + * 1 ms for STREAMS nonsense with older workstations. Velocities may + * vary with modern workstations. */ - /* * Interface definitions */ @@ -267,7 +268,7 @@ atom_pps( { register struct atomunit *up; struct refclockproc *pp; - struct timespec *tsp; + struct timespec ts; l_fp lftmp; double doffset; int i; @@ -285,7 +286,8 @@ atom_pps( * Convert the timeval to l_fp and save for billboards. Sign- * extend the fraction and stash in the buffer. No harm is done * if previous data are overwritten. If the discipline comes bum - * or the data grow stale, just forget it. + * or the data grow stale, just forget it. Round the nanoseconds + * to microseconds with great care. */ #ifdef HAVE_PPSAPI i = up->pps_info.assert_sequence; @@ -295,17 +297,18 @@ atom_pps( return (1); if (i == up->pps_info.assert_sequence) return (2); - if(pps_assert) - tsp = &up->pps_info.assert_timestamp; + if (pps_assert) + ts = up->pps_info.assert_timestamp; else - tsp = &up->pps_info.clear_timestamp; - pp->lastrec.l_ui = tsp->tv_sec + JAN_1970; - TVUTOTSF(tsp->tv_nsec, pp->lastrec.l_uf); - -printf("pps %d %s\n", up->pps_info.assert_sequence, lfptoa(&pp->lastrec, 6)); - + ts = up->pps_info.clear_timestamp; + pp->lastrec.l_ui = ts.tv_sec + JAN_1970; + ts.tv_nsec = (ts.tv_nsec + 500) / 1000; + if (ts.tv_nsec > 1000000) { + ts.tv_nsec -= 1000000; + ts.tv_sec++; + } + TVUTOTSF(ts.tv_nsec, pp->lastrec.l_uf); #else - i = up->ev.serial; if (fdpps <= 0) return (1); @@ -320,7 +323,8 @@ printf("pps %d %s\n", up->pps_info.assert_sequence, lfptoa(&pp->lastrec, 6)); L_CLR(&lftmp); L_ADDF(&lftmp, pp->lastrec.l_f); LFPTOD(&lftmp, doffset); - pp->filter[pp->coderecv++ % pp->nstages] = -doffset + pp->fudgetime1; + pp->filter[pp->coderecv++ % pp->nstages] = -doffset + + pp->fudgetime1; up->pollcnt = 2 * 60; return (0); } @@ -356,7 +360,8 @@ atom_receive( /* * Save the timestamp for billboards. Sign-extend the fraction * and stash in the buffer. No harm is done if previous data are - * overwritten. Do this only if the ppsclock gizmo is not working. + * overwritten. Do this only if the ppsclock gizmo is not + * working. */ if (up->flags & FLAG_PPS) return; @@ -385,16 +390,14 @@ pps_sample( double doffset; /* - * This routine is called once per second when the external clock driver - * processes PPS information. It processes the pps timestamp - * and saves the sign-extended fraction in a circular + * This routine is called once per second when the external + * clock driver processes PPS information. It processes the pps + * timestamp and saves the sign-extended fraction in a circular * buffer for processing at the next poll event. */ peer = pps_peer; - if (peer == 0) /* nobody home */ return 1; - pp = peer->procptr; up = (struct atomunit *)pp->unitptr; @@ -409,7 +412,8 @@ pps_sample( L_CLR(&lftmp); L_ADDF(&lftmp, pp->lastrec.l_f); LFPTOD(&lftmp, doffset); - pp->filter[pp->coderecv++ % pp->nstages] = -doffset + pp->fudgetime1; + pp->filter[pp->coderecv++ % pp->nstages] = -doffset + + pp->fudgetime1; up->pollcnt = 2 * 60; return (0); } @@ -429,14 +433,15 @@ atom_poll( /* * Accumulate samples in the median filter. At the end of each - * poll interval, do a little bookeeping and process the samples. + * poll interval, do a little bookeeping and process the + * samples. */ pp = peer->procptr; up = (struct atomunit *)pp->unitptr; #if defined(PPS) || defined(HAVE_PPSAPI) if (!(up->flags & FLAG_AUX)) { - if (atom_pps(peer)) - return; + if (atom_pps(peer)) + return; } if (peer->burst > 0) return; @@ -455,9 +460,9 @@ atom_poll( * the pps time is within +-0.5 s of the local time and the * seconds numbering is unambiguous. */ - if (pps_update) + if (pps_update) { pp->leap = LEAP_NOWARNING; - else { + } else { pp->leap = LEAP_NOTINSYNC; return; } diff --git a/ntptrace/ntptrace.c b/ntptrace/ntptrace.c index 93622c198..d7a4140c0 100644 --- a/ntptrace/ntptrace.c +++ b/ntptrace/ntptrace.c @@ -503,7 +503,8 @@ ReceiveBuf( nextia.s_addr = server->refid; nextserver = addserver(&nextia); - DoTrace(nextserver); + if (nextserver) + DoTrace(nextserver); return(1); }