Feed on Posts or Comments

Driving simulator & Software & Technology & Tips and tools Alexander Shyrokov on 16 Jan 2008 02:52 pm

Time synchronization on LAN

Between our new eye tracker and not so new dirving simulator the total number of computers that we use during our experiments goes to 8. We are analyzing data logs from at least 3 different computers. So here we go:

Situation: There are three computers connected to a local network, let’s call them m1, p1, and p2. m1 and p1 are running Windows XP (SP2), p2 is running Linux FedoreCore 3. Programs running on these computers provide us with log files. We are interested in the relationship between timestamps of log entries in these files.

Problem: Time stamps in log files are not synchronized.

Previous solution: Ad-hoc methods with low accuracy, for example, sending a message with a time stamp from one computer to be logged on another.

New solution: Use ntp (Network Time Protocol) to synchronize all the computers with accuracy better than 500 micro seconds. Ntp implementation is available for both Windows and Linux. In our case m1 has two network cards and is connected to the local network and to the Internet. This allows us to synchronize m1 with public time servers, though we are interested in time synchronization between the local computers.

The following is the procedure one can follow to synchronize thier computers if they have similar situation:

For m1 (Windows, connected to the Internet and local network) and p1 (Windows, local network):

  1. Download binaries for ntp server.
  2. Unzip to some directory. I used C:\Program files\ntp-4.2.0.
  3. Install ntp server as service by calling Instsrv.exe with the full path to ntpd.exe. In my case it was: Instsrv.exe “C:\Program Files\ntp-4.2.0\ntpd.exe”.
  4. Make sure that your firewall allows ntpd to connect to the Internet and that port 123 UDP can be accessed by other computers.
  5. Create configuration file C:\Windows\system32\drivers\etc\ntp.conf (see bellow).
  6. Go to Control Panel->Date and Time Properties->Internet Time tab and uncheck Automatically synchronize with an Internet time server.
  7. Go to Control Panel->Administrative tools->Services applet and
    1. Disable Windows Time service.
    2. Set Network Time Protocol to start automatically.
    3. Start Network Time Protocol service.
  8. Check the status of ntp server (see below).

For p2 (Linux, connected to the local network):

  1. Check if you already have ntp daemon installed. In our case it was /etc/init.d/ntpd. Chances are that you have it, otherwise you need to install it (let your package manger or google help you).
  2. Edit configuration file /etc/ntp.conf (sudo vi /etc/ntp.conf) (see below).
  3. Restart the daemon: sudo /etc/init.d/ntpd restart. You should get “Starting ntpd: [OK]”.
  4. Make sure that the daemon starts automatically.
    1. Look at your /etc/inittab to see what init level your system starts in. Line id:X:initdefault: says that the level is X. It was 3 for us. If it’s different for you replace 3 in rc3.d to whatever your number is.
    2. Create (or make sure it’s already there) a symbolic link to the ntpd server in /etc/rc3.d by running ln -s /etc/init.d/ntpd /etc/rc3.d/S96ntpd.
  5. Check the status of ntp server (see below).

Configuration files:

  1. For m1:
    # iburst option is used to make sure that time is synchronized as quickly as possible
    server some.public.server.1 iburst
    server some.public.server.X iburst
    driftfile /WINDOWS/system32/drivers/etc/ntp.drift
    peer p1
    peer p2
  2. For p1:
    server m1 iburst
    driftfile /WINDOWS/system32/drivers/etc/ntp.drift
    peer p1
    peer p2
  3. For p2:
    server m1 iburst
    driftfile /var/lib/ntp/drift
    peer p1
    peer p2


To check the status of your ntp server/client execute ntpq -c peers after a few minutes. (Not that ntpq could be located /usr/sbin directory in Linux) The result should be similar to the following output if you run it on p1 (time values are in milliseconds for 4.2.0 release):

remote refid st t when poll reach delay offset jitter
==============================================================================
*m1 192.168.10.50 2 u 26 1024 377 17.505 -30.113 6.225
p1 .STEP. 16 u - 1024 0 0.000 0.000 4000.00
+p2 192.168.10.52 3 u 86 1024 207 8.254 3.189 1.473

Now you should have your m1, p1, and p2 synchronized. I used Getting Started tutorial to get ntp running on Windows. All credit for Linux side goes to Andras Fekete.

Alexander Shyrokov

4 Responses to “Time synchronization on LAN”

  1. on 16 Jan 2008 at 3:27 pm 1.oszkar said …

    This is great! This solves all of our problems with data collection. It was a very time consuming process to solve the synchronization of every new device we start using in the simulator. The solution is so great because it is a general solution for all possible future devices. Congats Alex (father of the idea) and Andras (the Linux master).

  2. on 17 Jan 2008 at 2:29 pm 2.Alexander said …

    Now we need another solution like that to address the problem of data analysis.

  3. on 20 Feb 2008 at 5:18 am 3.jagdish said …

    please send me any method to time synchronisation on two LAN connected pc

  4. on 20 Oct 2008 at 3:00 pm 4.Alexander Shyrokov said …

    Another good hint about how to configure the ntp server to be synced to itself (in case there is no internet access and no special devices): http://ubuntuforums.org/showthread.php?t=579418

Subscribe to the comments through RSS Feed

Leave a Reply