1 .\" $NetBSD: timed.ms,v 1.2 1998/01/09 08:12:02 perry Exp $
3 .\" Copyright (c) 1986, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)timed.ms 8.1 (Berkeley) 6/8/93
33 Timed Installation and Operation Guide
35 Riccardo Gusella, Stefano Zatti, James M. Bloom
37 Computer Systems Research Group
38 Computer Science Division
39 Department of Electrical Engineering and Computer Science
40 University of California, Berkeley
45 Engineering Computer Network
46 Department of Electrical Engineering
48 West Lafayette, IN 47906
50 This work was sponsored by the Defense Advanced Research Projects Agency
51 (DoD), monitored by the Naval Electronics Systems
52 Command under contract No. N00039-84-C-0089, and by the CSELT
54 The views and conclusions contained in this document are those of the
55 authors and should not be interpreted as representing official policies,
56 either expressed or implied, of the Defense Research Projects Agency,
57 of the US Government, or of CSELT.
60 .EH 'SMM:11-%''Timed Installation and Operation'
61 .OH 'Timed Installation and Operation''SMM:11-%'
65 The clock synchronization service for
66 the UNIX 4.3BSD operating system is composed of a collection of
67 time daemons (\fItimed\fP) running on the machines in a local
69 The algorithms implemented by the service is based on a master-slave scheme.
70 The time daemons communicate with each other using the
71 \fITime Synchronization Protocol\fP (TSP) which
72 is built on the DARPA UDP protocol and described in detail in [4].
74 A time daemon has a twofold function.
75 First, it supports the synchronization of the clocks
76 of the various hosts in a local area network.
77 Second, it starts (or takes part in) the election that occurs
78 among slave time daemons when, for any reason, the master disappears.
79 The synchronization mechanism and the election procedure
80 employed by the program \fItimed\fP are described
81 in other documents [1,2,3].
82 The next paragraphs are a brief overview of how the time daemon works.
83 This document is mainly concerned with the administrative and technical
84 issues of running \fItimed\fP at a particular site.
86 A \fImaster time daemon\fP measures the time
87 differences between the clock of the machine on which it
88 is running and those of all other machines.
89 The master computes the \fInetwork time\fP as the average of the
90 times provided by nonfaulty clocks.\**
92 A clock is considered to be faulty when its value
93 is more than a small specified
94 interval apart from the majority of the clocks
95 of the other machines [1,2].
97 It then sends to each \fIslave time daemon\fP the
98 correction that should be performed on the clock of its machine.
99 This process is repeated periodically.
100 Since the correction is expressed as a time difference rather than an
101 absolute time, transmission delays do not interfere with
102 the accuracy of the synchronization.
103 When a machine comes up and joins the network,
104 it starts a slave time daemon which
105 will ask the master for the correct time and will reset the machine's clock
106 before any user activity can begin.
107 The time daemons are able to maintain a single network time in spite of
108 the drift of clocks away from each other.
109 The present implementation keeps processor clocks synchronized
110 within 20 milliseconds.
112 To ensure that the service provided is continuous and reliable,
113 it is necessary to implement an election algorithm to elect a
114 new master should the machine running the current master crash, the master
115 terminate (for example, because of a run-time error), or
116 the network be partitioned.
117 Under our algorithm, slaves are able to realize when the master has
118 stopped functioning and to elect a new master from among themselves.
119 It is important to note that, since the failure of the master results
120 only in a gradual divergence of clock values, the election
121 need not occur immediately.
123 The machines that are gateways between distinct local area
124 networks require particular care.
125 A time daemon on such machines may act as a \fIsubmaster\fP.
126 This artifact depends on the current inability of
127 transmission protocols to broadcast a message on a network
128 other than the one to which the broadcasting machine is connected.
129 The submaster appears as a slave on one network, and as a master
130 on one or more of the other networks to which it is connected.
132 A submaster classifies each network as one of three types.
133 A \fIslave network\fP is a network on which the submaster acts as a slave.
134 There can only be one slave network.
135 A \fImaster network\fP is a network on which the submaster acts as a master.
136 An \fIignored network\fP is any other network which already has a valid master.
137 The submaster tries periodically to become master on an ignored
138 network, but gives up immediately if a master already exists.
142 While the synchronization algorithm is quite general, the election
143 one, requiring a broadcast mechanism, puts constraints on
144 the kind of network on which time daemons can run.
145 The time daemon will only work on networks with broadcast capability
146 augmented with point-to-point links.
147 Machines that are only connected to point-to-point,
148 non-broadcast networks may not use the time daemon.
150 If we exclude submasters, there will normally be, at most, one master time
151 daemon in a local area internetwork.
152 During an election, only one of the slave time daemons
153 will become the new master.
154 However, because of the characteristics of its machine,
155 a slave can be prevented from becoming the master.
156 Therefore, a subset of machines must be designated as potential
158 A master time daemon will require CPU resources
159 proportional to the number of slaves, in general, more than
160 a slave time daemon, so it may be advisable to limit master time
161 daemons to machines with more powerful processors or lighter loads.
162 Also, machines with inaccurate clocks should not be used as masters.
163 This is a purely administrative decision: an organization may
164 well allow all of its machines to run master time daemons.
166 At the administrative level, a time daemon on a machine
167 with multiple network interfaces, may be told to ignore all
168 but one network or to ignore one network.
169 This is done with the \fI\-n network\fP and \fI\-i network\fP
170 options respectively at start-up time.
171 Typically, the time daemon would be instructed to ignore all but
172 the networks belonging to the local administrative control.
174 There are some limitations to the current
175 implementation of the time daemon.
176 It is expected that these limitations will be removed in future releases.
177 The constant NHOSTS in /usr/src/etc/timed/globals.h limits the
178 maximum number of machines that may be directly controlled by one
180 The current maximum is 29 (NHOSTS \- 1).
181 The constant must be changed and the program recompiled if a site wishes to
182 run \fItimed\fP on a larger (inter)network.
184 In addition, there is a \fIpathological situation\fP to
185 be avoided at all costs, that might occur when
186 time daemons run on multiply-connected local area networks.
187 In this case, as we have seen, time daemons running on gateway machines
188 will be submasters and they will act on some of those
189 networks as master time daemons.
190 Consider machines A and B that are both gateways between
192 If time daemons were started on both A and B without constraints, it would be
193 possible for submaster time daemon A to be a slave on network X
194 and the master on network Y, while submaster time daemon B is a slave on
195 network Y and the master on network X.
196 This \fIloop\fP of master time daemons will not function properly
197 or guarantee a unique time on both networks, and will cause
198 the submasters to use large amounts of system resources in the form
199 of network bandwidth and CPU time.
200 In fact, this kind of \fIloop\fP can also be generated with more
201 than two master time daemons,
202 when several local area networks are interconnected.
206 In order to start the time daemon on a given machine,
207 the following lines should be
208 added to the \fIlocal daemons\fP section in the file \fI/etc/rc.local\fP:
212 if [ -f /etc/timed ]; then
213 /etc/timed \fIflags\fP & echo -n ' timed' >/dev/console
219 In any case, they must appear after the network
220 is configured via ifconfig(8).
222 Also, the file \fI/etc/services\fP should contain the following
226 timed 525/udp timeserver
231 to consider the named network.
233 to ignore the named network.
235 to place tracing information in \fI/usr/adm/timed.log\fP.
237 to allow this time daemon to become a master.
238 A time daemon run without this option will be forced in the state of
239 slave during an election.
243 \fITimedc(8)\fP is used to control the operation of the time daemon.
246 measure the differences between machines' clocks,
248 find the location where the master \fItimed\fP is running,
250 cause election timers on several machines to expire at the same time,
252 enable or disable tracing of messages received by \fItimed\fP.
254 See the manual page on \fItimed\fP\|(8) and \fItimedc\fP\|(8)
255 for more detailed information.
257 The \fIdate(1)\fP command can be used to set the network date.
258 In order to set the time on a single machine, the \fI-n\fP flag
259 can be given to date(1).
264 R. Gusella and S. Zatti,
265 \fITEMPO: A Network Time Controller for Distributed Berkeley UNIX System\fP,
266 USENIX Summer Conference Proceedings, Salt Lake City, June 1984.
268 R. Gusella and S. Zatti, \fIClock Synchronization in a Local Area Network\fP,
269 University of California, Berkeley, Technical Report, \fIto appear\fP.
271 R. Gusella and S. Zatti,
272 \fIAn Election Algorithm for a Distributed Clock Synchronization Program\fP,
273 University of California, Berkeley, CS Technical Report #275, Dec. 1985.
275 R. Gusella and S. Zatti,
276 \fIThe Berkeley UNIX 4.3BSD Time Synchronization Protocol\fP,
277 UNIX Programmer's Manual, 4.3 Berkeley Software Distribution, Volume 2c.