From: Harlan Stenn Date: Tue, 9 Oct 2001 02:36:23 +0000 (-0400) Subject: Cleanup and improvements from Dave Mills. X-Git-Tag: NTP_4_1_72~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76ae76dd40e6b730ff61317f128d2b9b35a8bca8;p=thirdparty%2Fntp.git Cleanup and improvements from Dave Mills. bk: 3bc262a7YU0QUoTkxoy6_FJ_ybT7dg --- diff --git a/html/clockopt.htm b/html/clockopt.htm index 18773f032e..a6266cc683 100644 --- a/html/clockopt.htm +++ b/html/clockopt.htm @@ -1,76 +1,219 @@ - -Reference Clock Options -

-Reference Clock Options -

- -from Pogo, Walt Kelly - -

See the radios, all in a row. -


- + + + + +Reference Clock Options + + +

Reference Clock Options

+ +giffrom Pogo, +Walt Kelly + +

See the radios, all in a row.
+

+ +

Reference Clock Support

-The NTP Version 4 daemon supports some three dozen different radio, satellite and modem reference clocks plus a special pseudo-clock used for backup or when no other clock source is available. Detailed descriptions of individual device drivers and options can be found in the Reference Clock Drivers page. Additional information can be found in the pages linked there, including the Debugging Hints for Reference Clock Drivers and How To Write a Reference Clock Driver pages. In addition, support for a PPS signal is available as described in Pulse-per-second (PPS) Signal Interfacing page. Many drivers support special line discipline/streams modules which can significantly improve the accuracy using the driver. These are described in the Line Disciplines and Streams Drivers -page. - -

A reference clock will generally (though not always) be a radio timecode receiver which is synchronized to a source of standard time such as the services offered by the NRC in Canada and NIST and USNO in the US. The interface between the computer and the timecode receiver is device dependent, but is usually a serial port. A device driver specific to each reference clock must be selected and compiled in the distribution; however, most common radio, satellite and modem clocks are included by default. Note that an attempt to configure a reference clock when the driver has not been compiled or the hardware port has not been appropriately configured results in a scalding remark to the system log file, but is otherwise non hazardous. - -

For the purposes of configuration, ntpd treats reference clocks in a manner analogous to normal NTP peers as much as possible. Reference clocks are identified by a syntactically correct but invalid IP address, in order to distinguish them from normal NTP peers. Reference clock addresses are of the form 127.127.t.u, where t is an integer denoting the clock type and u indicates the unit number in the range 0-3. While it may seem overkill, it is in fact sometimes useful to configure multiple reference clocks of the same type, in which case the unit numbers must be unique. - -

The server command is used to configure a reference clock, where the address argument in that command is the clock address. The key, version and ttl options are not used for reference clock support. The mode option is added for reference clock support, as described below. The prefer option can be useful to persuade the server to cherish a reference clock with somewhat more enthusiasm than other reference clocks or peers. Further information on this option can be found in the Mitigation Rules and the prefer Keyword page. The minpoll and maxpoll options have meaning only for selected clock drivers. See the individual clock driver document pages for additional information. +

The NTP Version 4 daemon supports some three dozen different +radio, satellite and modem reference clocks plus a special +pseudo-clock used for backup or when no other clock source is +available. Detailed descriptions of individual device drivers and +options can be found in the Reference Clock +Drivers page. Additional information can be found in the pages +linked there, including the Debugging Hints +for Reference Clock Drivers and How To +Write a Reference Clock Driver pages. In addition, support for +a PPS signal is available as described in +Pulse-per-second (PPS) Signal Interfacing page. Many drivers +support special line discipline/streams modules which can +significantly improve the accuracy using the driver. These are +described in the Line Disciplines and Streams +Drivers page.

+ +

A reference clock will generally (though not always) be a radio +timecode receiver which is synchronized to a source of standard +time such as the services offered by the NRC in Canada and NIST and +USNO in the US. The interface between the computer and the timecode +receiver is device dependent, but is usually a serial port. A +device driver specific to each reference clock must be selected and +compiled in the distribution; however, most common radio, satellite +and modem clocks are included by default. Note that an attempt to +configure a reference clock when the driver has not been compiled +or the hardware port has not been appropriately configured results +in a scalding remark to the system log file, but is otherwise non +hazardous.

+ +

For the purposes of configuration, ntpd treats +reference clocks in a manner analogous to normal NTP peers as much +as possible. Reference clocks are identified by a syntactically +correct but invalid IP address, in order to distinguish them from +normal NTP peers. Reference clock addresses are of the form +127.127.t.u, where t is an integer +denoting the clock type and u indicates the unit +number in the range 0-3. While it may seem overkill, it is in fact +sometimes useful to configure multiple reference clocks of the same +type, in which case the unit numbers must be unique.

+ +

The server command is used to configure a reference +clock, where the address argument in that command +is the clock address. The key, version and +ttl options are not used for reference clock support. The +mode option is added for reference clock support, as described +below. The prefer option can be useful to persuade the +server to cherish a reference clock with somewhat more enthusiasm +than other reference clocks or peers. Further information on this +option can be found in the Mitigation Rules +and the prefer Keyword page. The minpoll and +maxpoll options have meaning only for selected clock +drivers. See the individual clock driver document pages for +additional information.

+ +

The fudge command is used to provide additional +information for individual clock drivers and normally follows +immediately after the server command. The +address argument specifies the clock address. The +refid and stratum options control can be used to +override the defaults for the device. There are two optional +device-dependent time offsets and four flags that can be included +in the fudge command as well.

+ +

The stratum number of a reference clock is by default zero. +Since the ntpd daemon adds one to the stratum of each +peer, a primary server ordinarily displays an external stratum of +one. In order to provide engineered backups, it is often useful to +specify the reference clock stratum as greater than zero. The +stratum option is used for this purpose. Also, in cases +involving both a reference clock and a pulse-per-second (PPS) +discipline signal, it is useful to specify the reference clock +identifier as other than the default, depending on the driver. The +refid option is used for this purpose. Except where noted, +these options apply to all clock drivers.

-

The fudge command is used to provide additional information for individual clock drivers and normally follows immediately after the server command. The address argument specifies the clock address. The refid and stratum options control can be used to override the defaults for the device. There are two optional device-dependent time offsets and four flags that can be included in the fudge command as well. +

Reference Clock Commands

-

The stratum number of a reference clock is by default zero. Since the ntpd daemon adds one to the stratum of each peer, a primary server ordinarily displays an external stratum of one. In order to provide engineered backups, it is often useful to specify the reference clock stratum as greater than zero. The stratum option is used for this purpose. Also, in cases involving both a reference clock and a pulse-per-second (PPS) discipline signal, it is useful to specify the reference clock identifier as other than the default, depending on the driver. The refid option is used for this purpose. Except where noted, these options apply to all clock drivers. +

+
server 127.127.t.u [prefer] [mode int] +[minpoll int] [maxpoll int]
-

Reference Clock Commands

+
This command can be used to configure reference clocks in +special ways. The options are interpreted as follows:
-
server 127.127.t.u [prefer] [mode int] [minpoll int] [maxpoll int]
This command can be used to configure reference clocks in special ways. The options are interpreted as follows:
+
+
+
prefer
-
prefer
-
Marks the reference clock as preferred. All other things being equal, this host will be chosen for synchronization among a set of correctly operating hosts. See the Mitigation Rules and the prefer Keyword page for further information.
+
Marks the reference clock as preferred. All other things being +equal, this host will be chosen for synchronization among a set of +correctly operating hosts. See the Mitigation +Rules and the prefer Keyword page for further +information.
mode int
-
Specifies a mode number which is interpreted in a device-specific fashion. For instance, it selects a dialing protocol in the ACTS driver and a device subtype in the parse drivers.
+ +
Specifies a mode number which is interpreted in a +device-specific fashion. For instance, it selects a dialing +protocol in the ACTS driver and a device subtype in the +parse drivers.
minpoll int
-
maxpoll int
-
These options specify the minimum and maximum polling interval for reference clock messages, in seconds to the power of two. For most directly connected reference clocks, both minpoll and maxpoll default to 6 (64 s). For modem reference clocks, minpoll defaults to 10 (17.1 m) and maxpoll defaults to 14 (4.5 h). The allowable range is 4 (16 s) to 17 (36.4 h) inclusive.
+
maxpoll int
+ +
These options specify the minimum and maximum polling interval +for reference clock messages, in seconds to the power of two. For +most directly connected reference clocks, both minpoll and +maxpoll default to 6 (64 s). For modem reference clocks, +minpoll defaults to 10 (17.1 m) and maxpoll +defaults to 14 (4.5 h). The allowable range is 4 (16 s) to 17 (36.4 +h) inclusive.
+
-
fudge 127.127.t.u [time1 sec] [time2 sec] -[stratum int] [refid string] [mode int] [flag1 0|1] -[flag2 0|1] [flag3 0|1] [flag4 0|1]
-
This command can be used to configure reference clocks in special -ways. It must immediately follow the server command which -configures the driver. Note that the same capability is possible at run -time using the ntpdc program. The -options are interpreted as follows:
+
fudge 127.127.t.u [time1 sec] [time2 +sec] [stratum int] [refid string] [mode +int] [flag1 0|1] [flag2 0|1] [flag3 0|1] [flag4 0|1]
-
+
This command can be used to configure reference clocks in +special ways. It must immediately follow the server +command which configures the driver. Note that the same capability +is possible at run time using the +ntpdc program. The options are interpreted as +follows:
+
+
time1 sec
-
Specifies a constant to be added to the time offset produced by the driver, a fixed-point decimal number in seconds. This is used as a calibration constant to adjust the nominal time offset of a particular clock to agree with an external standard, such as a precision PPS signal. It also provides a way to correct a systematic error or bias due to serial port or operating system latencies, different cable lengths or receiver internal delay. The specified offset is in addition to the propagation delay provided by other means, such as internal DIPswitches. Where a calibration for an individual system and driver is available, an approximate correction is noted in the driver documentation pages.
-

Note: in order to facilitate calibration when more than one radio clock or PPS signal is supported, a special calibration feature is available. It takes the form of an argument to the enable command described in the Miscellaneous Options page and operates as described in the Reference Clock Drivers page.
+
Specifies a constant to be added to the time offset produced by +the driver, a fixed-point decimal number in seconds. This is used +as a calibration constant to adjust the nominal time offset of a +particular clock to agree with an external standard, such as a +precision PPS signal. It also provides a way to correct a +systematic error or bias due to serial port or operating system +latencies, different cable lengths or receiver internal delay. The +specified offset is in addition to the propagation delay provided +by other means, such as internal DIPswitches. Where a calibration +for an individual system and driver is available, an approximate +correction is noted in the driver documentation pages.
+ +
Note: in order to facilitate calibration when more than one +radio clock or PPS signal is supported, a special calibration +feature is available. It takes the form of an argument to the +enable command described in the +Miscellaneous Options page and operates as described in the Reference Clock Drivers page.
time2 secs
-
Specifies a fixed-point decimal number in seconds, which is interpreted in a driver-dependent way. See the descriptions of specific drivers in the reference clock drivers page.
+ +
Specifies a fixed-point decimal number in seconds, which is +interpreted in a driver-dependent way. See the descriptions of +specific drivers in the reference clock +drivers page.
stratum int
-
Specifies the stratum number assigned to the driver, an integer between 0 and 15. This number overrides the default stratum number ordinarily assigned by the driver itself, usually zero.
+ +
Specifies the stratum number assigned to the driver, an integer +between 0 and 15. This number overrides the default stratum number +ordinarily assigned by the driver itself, usually zero.
refid string
-
Specifies an ASCII string of from one to four characters which defines the reference identifier used by the driver. This string overrides the default identifier ordinarily assigned by the driver itself.
-
mode int
-
Specifies a mode number which is interpreted in a device-specific fashion. For instance, it selects a dialing protocol in the ACTS driver and a device subtype in the parse drivers.
+
Specifies an ASCII string of from one to four characters which +defines the reference identifier used by the driver. This string +overrides the default identifier ordinarily assigned by the driver +itself.
-
flag1 flag2 flag3 flag4
-
These four flags are used for customizing the clock driver. The interpretation of these values, and whether they are used at all, is a function of the particular clock driver. However, by convention flag4 is used to enable recording monitoring data to the clockstats file configured with the filegen command. Further information on the filegen command can be found in the Monitoring Options page.
+
mode int
+
Specifies a mode number which is interpreted in a +device-specific fashion. For instance, it selects a dialing +protocol in the ACTS driver and a device subtype in the +parse drivers.
+ +
flag1 flag2 flag3 +flag4
+ +
These four flags are used for customizing the clock driver. The +interpretation of these values, and whether they are used at all, +is a function of the particular clock driver. However, by +convention flag4 is used to enable recording monitoring +data to the clockstats file configured with the +filegen command. Further information on the filegen +command can be found in the Monitoring +Options page.
+
+
-
David L. Mills <mills@udel.edu>/address> +
++"gif" + +
David L. Mills +<mills@udel.edu>
+ + + diff --git a/html/driver40.htm b/html/driver40.htm index 2fcc181722..db7a401fa2 100644 --- a/html/driver40.htm +++ b/html/driver40.htm @@ -1,232 +1,141 @@ - - - - - - + JJY Receivers - - - - - -

JJY Receiver

+

JJY Receivers


+

Synopsis

-

Synopsis

+Address: 127.127.40.u
+Reference ID: JJY
+Driver ID: JJY
+Serial Port: /dev/jjyu; 9600 baud, 8-bits, no +parity, 1 stop bit - - - - - - -
Address 127.127.40.X
Reference ID JJY
Driver ID JJY
Serial Device/dev/jjyX
Serial Port 9600 BPS, 8-bits, No parity, 1-stop-bit
+

Description

-

Description

+

This driver supports the following JJY receivers sold in +Japan.

-

-This driver supports following JJY receivers sold in Japan.
+

    +
  • +

    Tristate Ltd. JJY01 +http://www.tristate.ne.jp/rf-clock.htm (Japanese only)
    +Time code format

    -
      + + + + + -
    • Tristate Ltd. JJY01

      -Information
      -http://www.tristate.ne.jp/rf-clock.htm   ( Written in Japanese only )
      -
      -Time code format
      -
    • CommandReply
      - - - + + + + + + + + +
      CommandReply
      date<CR><LF>YYYY/MM/DD WWW<CR><LF>
      stim<CR><LF>HH:MM:SS<CR><LF>
      date<CR><LF>YYYY/MM/DD WWW<CR><LF>
      stim<CR><LF>HH:MM:SS<CR><LF>
      -

      -
    • C-DEX Co.,Ltd. JST2000

      -Information
      -http://www.c-dex.co.jp/   ( Written in Japanese only )
      -
      +
    • +

      C-DEX Co.,Ltd. JST2000 +http://www.c-dex.co.jp/ (Japanese only)
      Time code format
      - - - +

      + +
      CommandReply
      <ENQ>1J<ETX><STX>JYYMMDD HHMMSSS<ETX>
      + + + + + + + + +
      CommandReply
      <ENQ>1J<ETX><STX>JYYMMDD HHMMSSS<ETX>
      -

    • -
    -

    -The JJY is the radio station which transmites the JST ( Japan Standard Time ) in long wave radio.
    -The station JJY is operated by the Communication Research Laboratory.
    -An operating announcement and some information are avaiable from as follows;
    -http://www.crl.go.jp/   ( English and Japanese )
    -http://jjy.crl.go.jp/   ( Written in Japanese only )
    -

    +

    JJY is the radio station which transmites the JST (Japan +Standard Time) in long wave radio. The station JJY is operated by +the Communication Research Laboratory. An operating announcement +and some information are avaiable from http://www.crl.go.jp/ (English and +Japanese)http://jjy.crl.go.jp/ +(Written in Japanese only

    -

    Serial Port Configuration

    +

    The user is expected to provide a symbolic link to an available +serial port device. This is typically performed by a command such +as:

    -

    -The driver attempts to open the device /dev/jjyX -where X is the NTP refclock unit number as defined by the LSB of the refclock address.
    -Valid refclock unit numbers are 0 - 3. -

    -

    -The user is expected to provide a symbolic link to an available serial port device.
    -This is typically performed by a command such as: -

    -

    ln -s /dev/ttyS0 /dev/jjy0

    -

    -Windows NT does not support symbolic links to device files.
    -COMX: is used by the driver, based on the refclock unit number, -where unit 1 corresponds to COM1: and unit 3 corresponds to COM3: -

    +

    ln -s /dev/ttyS0 /dev/jjy0

    -

    NTP Configuration

    +

    Windows NT does not support symbolic links to device files. +COMX: is the unit used by the driver, based on the refclock +unit number, where unit 1 corresponds to COM1: and unit 3 +corresponds to COM3:

    -

    -The server command is used to configure the JJY receiver, where the address argument in that command is the "127.127.40.X".
    -The mode option must be added for the supported JJY receiver.
    -

    -
    -# JJY receiver 
    -server 127.127.40.X mode N
    -#
    -#   Where
    -#       X = 0 to 3
    -#       N = 1 for Tristate TS-JJY01
    -#           2 for C-DEX JST2000
    -
    -# Drift file
    -driftfile /var/ntp/ntp.drift
    -
    -# Monitor data ( Optional )
    -statsdir /var/ntp/
    -filegen peerstats  file  peerstats  type day enable
    -filegen loopstats  file  loopstats  type day enable
    -filegen clockstats file  clockstats type day enable
    -
    - -

    -Samples of the configuration file "ntp.conf" for the JJY receiver. -

    +

    Monitor Data

    -
      +

      The driver writes each timecode as received to the +clockstats file.

      -
    • Tristate Ltd. JJY01

      - - - - -
      -
      +

      Fudge Factors

      -# JJY receiver ( Tristate JJY01 ) -server 127.127.40.0 mode 1 +
      +
      time1 time
      -# Drift file -driftfile /var/ntp/ntp.drift -
      -

      -
    • +
      Specifies the time offset calibration factor, in seconds and +fraction, with default 0.0.
      -
    • C-DEX Co.,Ltd. JST2000

      - - - - -
      -
      +
      time2 time
      -# JJY receiver ( C-DEX JST2000 ) -server 127.127.40.0 mode 2 +
      Not used by this driver.
      -# Drift file -driftfile /var/ntp/ntp.drift -
      -

      -
    • +
      stratum number
      -
    +
    Specifies the driver stratum, in decimal from 0 to 15, with +default 0.
    +
    refid string
    -

    Fudge Factors

    -
    +
    Specifies the driver reference identifier, an ASCII string from +one to four characters, with default WWVB.
    -
    time1 time
    -
    Specifies the time offset calibration factor, in seconds and fraction, with default 0.0.
    +
    flag1 0 | 1
    -
    time2 time
    Not used by this driver.
    -
    stratum number
    -
    Specifies the driver stratum, in decimal from 0 to 15, with default 0.
    +
    flag2 0 | 1
    -
    refid string
    -
    Specifies the driver reference identifier, an ASCII string, with default JJY.
    - -
    flag1 0 | 1
    Not used by this driver.
    -
    flag2 0 | 1
    -
    Not used by this driver.
    +
    flag3 0 | 1
    -
    flag3 0 | 1
    Not used by this driver.
    -
    flag4 0 | 1
    -
    Not used by this driver.
    +
    flag4 0 | 1
    +
    Enable verbose clockstats recording if set.
    -

    Monitor Data

    - -

    -A timecode is written to the clockstats file, if the ntpd is configured to enable writing of statistics records
    -

    -
    ++"gif" -

    -Copyright (C) 2001, Takao Abe. All rights reserved.
    -Questions or Comments : abetakao@bea.hi-ho.ne.jp -

    - -

    -This driver is developed in my private time, and is opened as voluntary contributions for the NTP.
    -The manufacturer of the JJY receiver has not participated in a development of this driver.
    -The manufacturer does not warrant anything about this driver, and is not liable for anything about this driver. -

    - +
    David L. Mills +<mills@udel.edu>
    - + diff --git a/html/qth.htm b/html/qth.htm index 47a29f33eb..200d3fb1f6 100644 --- a/html/qth.htm +++ b/html/qth.htm @@ -1,20 +1,6 @@ - - - - +<html><head><title> Stations, Frequencies and Geographic Coordinates - - - - -

    +

    Stations, Frequencies and Geographic Coordinates


    @@ -71,18 +57,6 @@ published by the ITU and other sources. 47:10N 2:12E - -JJY ( Fukushima, JAPAN ) -40 KHz -37:22 N   140:51 E - - - -JJY ( Saga, JAPAN ) -60 KHz -33:28 N   130:11 E - -
    GPS_HP)
    (GPS_ONCORE)
    Type 31 Rockwell Jupiter GPS (GPS_JUPITER)
    Type 32 Chrono-log K-series WWVB -receiver Type 33 Dumb Clock Type 34 Ultralink WWVB Receivers
    +receiver (CHRONOLOG)
    +Type 33 Dumb Clock (DUMBCLOCK)
    +Type 34 Ultralink WWVB Receivers (ULINK)
    Type 35 Conrad Parallel Port Radio Clock (PCF)
    Type 36 Radio WWV/H Audio -Demodulator/Decoder(WWV)
    +Demodulator/Decoder (WWV)
    Type 37 Forum Graphic GPS Dating station (FG)
    Type 38 hopf GPS/DCF77 6021/komp for Serial Line (HOPF_S)
    Type 39 hopf GPS/DCF77 6039 for PCI-Bus (HOPF_P)
    -Type 40 The Tristate Ltd. JJY receiver -(JJY)
    +Type 40 JJY Receivers (JJY)

    +

    * All TrueTime receivers are now supported by one driver, type 5. Types 15 and 25 will be retained only for a limited time and may diff --git a/include/ntp.h b/include/ntp.h index 349dd53c7a..9a332738fa 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -364,7 +364,7 @@ struct peer { /* * Values for peer.stratum, sys_stratum */ -#define STRATUM_REFCLOCK ((u_char)0) /* stratum claimed by primary clock */ +#define STRATUM_REFCLOCK ((u_char)0) /* default stratum */ /* A stratum of 0 in the packet is mapped to 16 internally */ #define STRATUM_PKT_UNSPEC ((u_char)0) /* unspecified in packet */ #define STRATUM_UNSPEC ((u_char)16) /* unspecified */ diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h index 3995e9a1af..812251ae6a 100644 --- a/include/ntp_refclock.h +++ b/include/ntp_refclock.h @@ -204,6 +204,7 @@ struct refclockproc { */ double fudgetime1; /* fudge time1 */ double fudgetime2; /* fudge time2 */ + u_char stratum; /* server stratum */ u_int32 refid; /* reference identifier */ u_char sloppyclockflag; /* fudge flags */ diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 91b3388709..c3a0b264d9 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -1467,16 +1467,20 @@ ctl_putpeer( break; case CP_REFID: - if (peer->stratum > 1) { - if (peer->flags & FLAG_REFCLOCK) - ctl_putadr(peer_var[CP_REFID].text, - peer->srcadr.sin_addr.s_addr); - else + if (peer->flags & FLAG_REFCLOCK) { + if (peer->stratum > 0) ctl_putadr(peer_var[CP_REFID].text, peer->refid); + else + ctl_putid(peer_var[CP_REFID].text, + (char *)&peer->refid); } else { - ctl_putid(peer_var[CP_REFID].text, - (char *)&peer->refid); + if (peer->stratum > 1) + ctl_putadr(peer_var[CP_REFID].text, + peer->refid); + else + ctl_putid(peer_var[CP_REFID].text, + (char *)&peer->refid); } break; diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index e87b6ff980..33e6ff1dbb 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -498,7 +498,7 @@ local_clock( etemp = fll[i]; dtemp = max(mu, ULOGTOD(allan_xpt)); flladj = ((fp_offset - last_offset) + - (fp_offset - clock_offset)) * etemp / + (clock_offset - last_offset)) * etemp / (dtemp * CLOCK_FLL); dtemp = ULOGTOD(SHIFT_PLL + 2 + sys_poll); etemp = min(mu, ULOGTOD(sys_poll)); diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 192276421f..505be2d880 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -1779,8 +1779,8 @@ clock_select(void) /* * If no survivors remain at this point, check if the local * clock or modem drivers have been found. If so, nominate one - * of them as the only survivor. Otherwise, give up and declare - * us unsynchronized. + * of them as the only survivor. Otherwise, give up and leave + * the island to the rats. */ if ((allow << 1) >= nlist) { if (typeacts != 0) { @@ -1814,17 +1814,16 @@ clock_select(void) /* * Clustering algorithm. Construct candidate list in order first - * by stratum then by root distance. If we have more than - * MAXCLOCK peers, keep only the best MAXCLOCK of them. Scan the - * list to find falsetickers, who leave the island immediately. - * If a falseticker is not configured, his association raft is - * drowned as well, but only if at at least eight poll intervals - * have gone by. We must leave at least one peer to collect the - * million bucks. + * by stratum then by root distance, but keep only the best + * MAXCLOCK of them. Scan the list to find falsetickers, who + * leave the island immediately. If a falseticker is not + * configured, his association raft is drowned as well, but only + * if at at least eight poll intervals have gone. We must leave + * at least one peer to collect the million bucks. * - * Note the hysteresis gimmick that decreases the effective - * distance for those rascals that previously have made the - * final cut. This to discourage clockhopping. + * Note the hysteresis gimmick that increases the effective + * distance for those rascals that have not made the final cut. + * This is to discourage clockhopping. */ j = 0; for (i = 0; i < nlist; i++) { @@ -1892,15 +1891,14 @@ clock_select(void) peer_list[i]->offset); f /= nlist - 1; } - f = max(f, SQUARE(LOGTOD(sys_precision))); if (f * synch[i] > e) { sys_selerr = f; e = f * synch[i]; k = i; } } - - if (nlist <= NTP_MINCLOCK || sys_selerr <= d || + f = max(sys_selerr, SQUARE(LOGTOD(sys_precision))); + if (nlist <= NTP_MINCLOCK || f <= d || peer_list[k]->flags & FLAG_PREFER) break; #ifdef DEBUG @@ -1922,7 +1920,7 @@ clock_select(void) #ifdef OPENSSL /* * In manycast client mode we may have spooked a sizeable number - * of servers that we don't need. If there are at least + * of peers that we don't need. If there are at least * NTP_MINCLOCK of them, the manycast message will be turned * off. By the time we get here we nay be ready to prune some of * them back, but we want to make sure all the candicates have @@ -1950,14 +1948,12 @@ clock_select(void) * peers. We want only a peer at the lowest stratum to become * the system peer, although all survivors are eligible for the * combining algorithm. First record their order, diddle the - * flags and clamp the poll intervals. Then, consider the peers - * at the lowest stratum. Of these, OR the leap bits on the - * assumption that, if some of them honk nonzero bits, they must - * know what they are doing. Also, check for prefer and pps - * peers. If a prefer peer is found within clock_max, update the - * pps switch. Of the other peers not at the lowest stratum, - * check if the system peer is among them and, if found, zap - * him. We note that the head of the list is at the lowest + * flags and clamp the poll intervals. Then, consider each peer + * in turn and OR the leap bits on the assumption that, if some + * of them honk nonzero bits, they must know what they are + * doing. Check for prefer and pps peers at any stratum. Check + * if the old system peer is among the peers at the lowest + * stratum. Note that the head of the list is at the lowest * stratum and that unsynchronized peers cannot survive this * far. * @@ -1965,7 +1961,7 @@ clock_select(void) * a majority of the suckers that have been found reachable and * no prior source is available. This avoids the transient when * one of a flock of sources is out to lunch and just happens - * to be the first survivor. + * to be the first survivor found. */ if (osys_peer == NULL && 2 * nlist < min(nreach, NTP_MINCLOCK)) return; @@ -1975,16 +1971,15 @@ clock_select(void) peer->status = CTL_PST_SEL_SYNCCAND; peer->flags |= FLAG_SYSPEER; peer->hyst = HYST; - if (peer->stratum == peer_list[0]->stratum) { - leap_consensus |= peer->leap; - if (peer->refclktype == REFCLK_ATOM_PPS && - peer->stratum < STRATUM_UNSPEC) - typepps = peer; - if (peer == osys_peer) + leap_consensus |= peer->leap; + if (peer->flags & FLAG_PREFER) + sys_prefer = peer; + if (peer->refclktype == REFCLK_ATOM_PPS && + peer->stratum < STRATUM_UNSPEC) + typepps = peer; + if (peer->stratum == peer_list[0]->stratum && peer == + osys_peer) typesystem = peer; - if (peer->flags & FLAG_PREFER) - sys_prefer = peer; - } } /* @@ -2568,105 +2563,64 @@ key_expire( /* * Find the precision of this particular machine */ -#define DUSECS 1000000 /* us in a s */ -#define HUSECS (1 << 20) /* approx DUSECS for shifting etc */ -#define MINSTEP 5 /* minimum clock increment (us) */ -#define MAXSTEP 20000 /* maximum clock increment (us) */ -#define MINLOOPS 5 /* minimum number of step samples */ +#define MINSTEP 100e-9 /* minimum clock increment (s) */ +#define MAXSTEP 20e-3 /* maximum clock increment (s) */ +#define MINLOOPS 5 /* minimum number of step samples */ /* - * This routine calculates the differences between successive calls to - * gettimeofday(). If a difference is less than zero, the us field - * has rolled over to the next second, so we add a second in us. If - * the difference is greater than zero and less than MINSTEP, the - * clock has been advanced by a small amount to avoid standing still. - * If the clock has advanced by a greater amount, then a timer interrupt - * has occurred and this amount represents the precision of the clock. - * In order to guard against spurious values, which could occur if we - * happen to hit a fat interrupt, we do this for MINLOOPS times and - * keep the minimum value obtained. + * This routine calculates the system precision, defined as the minimum + * of a sequency of differences between successive readings of the + * system clock. However, if the system clock can be read more than once + * during a tick interval, the difference can be zero or one LSB unit, + * where the LSB corresponds to one nanosecond or one microsecond. + * Conceivably, if some other process preempts this one and reads the + * clock, the difference can be more than one LSB unit. + * + * For hardware clock frequencies of 10 MHz or less, we assume the + * logical clock advances only at the hardware clock tick. For higher + * frequencies, we assume the logical clock can advance no more than 100 + * nanoseconds between ticks. */ int default_get_precision(void) { - struct timeval tp; -#if !defined(SYS_WINNT) && !defined(VMS) && !defined(_SEQUENT_) && \ - !defined(MPE) - struct timezone tzp; -#elif defined(VMS) || defined(_SEQUENT_) - struct timezone { - int tz_minuteswest; - int tz_dsttime; - } tzp; -#endif /* defined(VMS) || defined(_SEQUENT_) */ - long last; - int i; - long diff; - long val; - long usec; -#ifdef HAVE_GETCLOCK - struct timespec ts; -#endif -#if defined(__FreeBSD__) && __FreeBSD__ >= 3 - u_long freq; - size_t j; - - /* Try to see if we can find the frequency of of the counter - * which drives our timekeeping - */ - j = sizeof freq; - i = sysctlbyname("kern.timecounter.frequency", &freq, &j , 0, - 0); - if (i) - i = sysctlbyname("machdep.tsc_freq", &freq, &j , 0, 0); - if (i) - i = sysctlbyname("machdep.i586_freq", &freq, &j , 0, 0); - if (i) - i = sysctlbyname("machdep.i8254_freq", &freq, &j , 0, - 0); - if (!i) { - for (i = 1; freq ; i--) - freq >>= 1; - return (i); - } -#endif - usec = 0; - val = MAXSTEP; -#ifdef HAVE_GETCLOCK - (void) getclock(TIMEOFDAY, &ts); - tp.tv_sec = ts.tv_sec; - tp.tv_usec = ts.tv_nsec / 1000; -#else /* not HAVE_GETCLOCK */ - GETTIMEOFDAY(&tp, &tzp); -#endif /* not HAVE_GETCLOCK */ - last = tp.tv_usec; - for (i = 0; i < MINLOOPS && usec < HUSECS;) { -#ifdef HAVE_GETCLOCK - (void) getclock(TIMEOFDAY, &ts); - tp.tv_sec = ts.tv_sec; - tp.tv_usec = ts.tv_nsec / 1000; -#else /* not HAVE_GETCLOCK */ - GETTIMEOFDAY(&tp, &tzp); -#endif /* not HAVE_GETCLOCK */ - diff = tp.tv_usec - last; - last = tp.tv_usec; - if (diff < 0) - diff += DUSECS; - usec += diff; - if (diff > MINSTEP) { - i++; - if (diff < val) - val = diff; - } + l_fp val; /* current seconds fraction */ + l_fp last; /* last seconds fraction */ + l_fp diff; /* difference */ + double tick; /* computed tick value */ + double dtemp; /* scratch */ + int i; /* log2 precision */ + + /* + * Loop to find tick value in nanoseconds. Toss out outlyer + * values less than the minimun tick value. In wacky cases, use + * the default maximum value. + */ + get_systime(&last); + tick = MAXSTEP; + for (i = 0; i < MINLOOPS;) { + get_systime(&val); + diff = val; + L_SUB(&diff, &last); + last = val; + LFPTOD(&diff, dtemp); + if (dtemp < MINSTEP) + continue; + i++; + if (dtemp < tick) + tick = dtemp; } + + /* + * Find the nearest power of two. + */ NLOG(NLOG_SYSINFO) - msyslog(LOG_INFO, "precision = %ld usec", val); - if (usec >= HUSECS) - val = MINSTEP; /* val <= MINSTEP; fast machine */ - diff = HUSECS; - for (i = 0; diff > val; i--) - diff >>= 1; - return (i); + msyslog(LOG_INFO, "precision = %.3f usec", tick * 1e6); + for (i = 0; tick <= 1; i++) + tick *= 2;; + if (tick - 1. > 1. - tick / 2) + i--; + return (-i); } /* diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index cc75284df0..2b3a19d8b1 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -217,10 +217,8 @@ refclock_newpeer( peer->refclktype = clktype; peer->refclkunit = unit; peer->flags |= FLAG_REFCLOCK; - peer->stratum = STRATUM_REFCLOCK; - peer->refid = peer->srcadr.sin_addr.s_addr; peer->maxpoll = peer->minpoll; - + peer->stratum = STRATUM_REFCLOCK; pp->type = clktype; pp->timestarted = current_time; @@ -228,12 +226,11 @@ refclock_newpeer( * Set peer.pmode based on the hmode. For appearances only. */ switch (peer->hmode) { - - case MODE_ACTIVE: + case MODE_ACTIVE: peer->pmode = MODE_PASSIVE; break; - default: + default: peer->pmode = MODE_SERVER; break; } @@ -248,10 +245,7 @@ refclock_newpeer( } peer->hpoll = peer->minpoll; peer->ppoll = peer->maxpoll; - if (peer->stratum <= 1) - peer->refid = pp->refid; - else - peer->refid = peer->srcadr.sin_addr.s_addr; + peer->refid = pp->refid; return (1); } @@ -989,10 +983,11 @@ refclock_control( if (in->haveflags & CLK_HAVETIME2) pp->fudgetime2 = in->fudgetime2; if (in->haveflags & CLK_HAVEVAL1) - peer->stratum = (u_char) in->fudgeval1; + pp->stratum = (u_char) in->fudgeval1; if (in->haveflags & CLK_HAVEVAL2) pp->refid = in->fudgeval2; - if (peer->stratum <= 1) + peer->stratum = pp->stratum; + if (peer->stratum == 0) peer->refid = pp->refid; else peer->refid = peer->srcadr.sin_addr.s_addr; @@ -1022,7 +1017,7 @@ refclock_control( CLK_HAVEVAL2 | CLK_HAVEFLAG4; out->fudgetime1 = pp->fudgetime1; out->fudgetime2 = pp->fudgetime2; - out->fudgeval1 = peer->stratum; + out->fudgeval1 = pp->stratum; out->fudgeval2 = pp->refid; out->flags = (u_char) pp->sloppyclockflag; diff --git a/ntpd/refclock_atom.c b/ntpd/refclock_atom.c index 56f86b35ec..cb3592eee3 100644 --- a/ntpd/refclock_atom.c +++ b/ntpd/refclock_atom.c @@ -1,3 +1,4 @@ + /* * refclock_atom - clock driver for 1-pps signals */ @@ -159,9 +160,9 @@ atom_start( pp = peer->procptr; peer->precision = PRECISION; pp->clockdesc = DESCRIPTION; + pp->stratum = STRATUM_UNSPEC; memcpy((char *)&pp->refid, REFID, 4); peer->burst = ASTAGE; - peer->stratum = STRATUM_UNSPEC; #ifdef HAVE_PPSAPI up = emalloc(sizeof(struct ppsunit)); memset(up, 0, sizeof(struct ppsunit)); @@ -459,17 +460,17 @@ atom_poll( * +-0.5 s of the local time and the seconds numbering is * unambiguous. Note that the leap bits are set no-warning on * the first valid update and the stratum is set at the prefer - * peer. + * peer, unless overriden by a fudge command. */ if (peer->burst > 0) return; - peer->stratum = STRATUM_UNSPEC; + peer->leap = LEAP_NOTINSYNC; if (pp->codeproc == pp->coderecv) { refclock_report(peer, CEVNT_TIMEOUT); peer->burst = ASTAGE; return; - } else if (!sys_prefer) { + } else if (sys_prefer == NULL) { pp->codeproc = pp->coderecv; peer->burst = ASTAGE; return; @@ -479,12 +480,15 @@ atom_poll( peer->burst = ASTAGE; return; } - peer->stratum = sys_prefer->stratum; - if (peer->stratum <= 1) + pp->leap = LEAP_NOWARNING; + if (pp->stratum >= STRATUM_UNSPEC) + peer->stratum = sys_prefer->stratum; + else + peer->stratum = pp->stratum; + if (peer->stratum == 0) peer->refid = pp->refid; else - peer->refid = peer->srcadr.sin_addr.s_addr; - pp->leap = LEAP_NOWARNING; + peer->refid = sys_prefer->srcadr.sin_addr.s_addr; refclock_receive(peer); peer->burst = ASTAGE; } diff --git a/ntpd/refclock_local.c b/ntpd/refclock_local.c index a3e5773872..4f131cd196 100644 --- a/ntpd/refclock_local.c +++ b/ntpd/refclock_local.c @@ -160,7 +160,7 @@ local_start( * Initialize miscellaneous variables */ peer->precision = sys_precision; - peer->stratum = STRATUM; + pp->stratum = STRATUM; pp->clockdesc = DESCRIPTION; memcpy((char *)&pp->refid, REFID, 4); #if defined(VMS) && defined(VMS_LOCALUNIT)