Xref: utzoo comp.arch:3860 comp.dcom.lans:1111 Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.arch,comp.dcom.lans Subject: Re: Time synchronization in a Distributed Environment Message-ID: <1075@PT.CS.CMU.EDU> Date: 9 Mar 88 15:07:23 GMT References: <1571@ogcvax.UUCP> <276@fallst.UUCP> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 93 > > I am looking for articles, references, implementations, > > etc. for solving the problem of keeping N machines within > > a specified time of one another. I appreciate any and all > > pointers. Here's a procedure that I designed and coded. If anyone has any question, complaints or criticism mail me. /************************************************************************** * * * sync_clocks * * * ************************************************************************** Purpose : This function helps syncronize the times between the module and lmb. Lmb time is consider the correct time. It also determines if the time unit is in seconds or in milliseconds. The method used is is follows : t1 = clock value on lmb side at message sending time t2 = clock value on module side at message receiving time m = time disparity between lmb clock and module clock (this is the value of interest) N = distribute representing the network transmittion time M = distribution representing the time to send a message to a machine and getting a response (round trip) Assumption - processing time is negligible. t1 = t2 + m + N E[M] = E[N + N] = E[N] + E[N] = 2*E[N] E[m + N] = E[m] + E[N] = m + E[M]/2 m = E[m + N] - E[M]/2 Programmer :Eddie Wyatt Date : December 1986 (Feb 1987) Input : None Output : None Locals : i - loop increment send_time - the module time that a message is sent receive_time - the module time that a message is receive (receive_time - send_time ~= M) lmb_time - the time on time lmb side (lmb_time ~= m + N) Globals : time_units - time is in seconds or milliseconds. time_disp - is modified to be equal to the time disparity between the lmb clock and the module clock port - not modified ************************************************************************/ LIB_EXPORT void sync_clocks(port) { register int i, send_time, receive_time, lmb_time; time_disp = 0; time_units = (TIME_UNITS) Nreceiveint(port); for (i = 0; i < NUMOFCLOCKSAMPLES; i++) { send_time = (time_units == INSECONDS) ? (int) time(NULLPTR(long)) : get_time_in_msec(); Nsendint(1,port); lmb_time = Nreceiveint(port); receive_time = (time_units == INSECONDS) ? (int) time(NULLPTR(long)) : get_time_in_msec(); time_disp += 2*lmb_time - receive_time - send_time; } time_disp /=(2*NUMOFCLOCKSAMPLES); } -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu