f



How application get precise time from Win NT/XP system time that synchronies to NTP

Hi,

My applications is to do time stamp that need 10 microsecond accuracy. Many
PCs in network environment will need ssme precise time stamp. One way to do
it is to install Trimble Acutime GPS for each PC. Because of cost
consideration, I installed a Win NT NTP server that use Trimble Acutime GPS
as reference clock and the rest of PCs synchronize to the server and I try
to find a way to get precise time from NT/ XP system. I head NT/XP system
time can only reach 10 millisecond resolution, if it is true? Or there is
another way to do it.

Thanks,

Roger
0
Roger
3/24/2005 8:35:59 AM
comp.protocols.time.ntp 4895 articles. 2 followers. Post Follow

11 Replies
1026 Views

Similar Articles

[PageSpeed] 30

Roger Chou <rgr.chou@gmail.com> writes:

> Hi,
> 
> My applications is to do time stamp that need 10 microsecond accuracy. Many
> PCs in network environment will need ssme precise time stamp. 

The requrement of 10us is going to cost you... 

>One way to do
> it is to install Trimble Acutime GPS for each PC. 


>Because of cost
> consideration, I installed a Win NT NTP server that use Trimble Acutime GPS
> as reference clock and the rest of PCs synchronize to the server and I try
> to find a way to get precise time from NT/ XP system.

You might be loosing on 10us on Windows. See table below from

        http://www.eecis.udel.edu/~mills/ntp/html/drivers/driver29.html

Platform 	Operating System        Accuracy
i386 (PC)  	Linux                   10 us
i386 (PC)  	Windows NT              1 ms
SUN             Solaris 2.x             50 us
Hewlett-Packard HPUX 9, 10, 11          50 us
Various 	Free BSD                20 us

Here is how my Accutime2000 is doing on Linux with nanokernel patch.

You will not be even close to 10us distributing time with NTP over a
network. Relaxing it to 1ms could be done if you stay clear of
Windows... 

# /usr/sbin/ntpq -c pe 
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+GPS_PALISADE(0) .GPS.            0 l   13   16  377    0.000    0.000   0.002
*GPS_JUPITER(0)  .GPS.            0 l   19   64  377    0.000   -0.001   0.002

My guess is that you need some way to distribute a PPS-pulse to all
your computers. Computers might have to run kernel PPS API, which is
available (mostly) on FreeBSD and Linux.

My 2 cents,

-- Bj�rn
0
Bjorn
3/26/2005 2:10:35 PM
In article <mailman.0.1111835963.588.questions@lists.ntp.isc.org>,
Roger Chou <rgr.chou@gmail.com> wrote:

> My applications is to do time stamp that need 10 microsecond accuracy. Many

The only thing that you will timestamp to that accuracy on a general
purpose OS is the reading of the cycle counter or the residual count
in the CTC.  NT is probably one of the worst OSes in this respect, as it
has a reputation for losing clock ticks, which means interrupt latencies of
over 10 milli-seconds.

You need a special purpose hard real time operating system, with fully
pre-emptive scheduling and even then you will need to evaluate the 
consequences of interrupt latencies.

You may need special hardware that timestamps the external event so as
to remove the time dependency in subsequent processing.

(If you disable interrupts (not an option for application level code on NT)
you can avoid the latencies in timing outgoing events, but you can't,
sensibly, disable interrupts for detecting incoming events (unless they always
follow an outgoing event by only about a milli-second), without destroying the
operating system's ability to function.  You would have to be a device driver
to disable interrupts on NT.)

You may well need the full source code of the OS to work to 10 microseconds
(NTP may manage to keep time to that accuracy, but only because its corrections
are averaged over a long period of time).

0
david
3/26/2005 8:02:24 PM
david@djwhome.demon.co.uk (David Woolley) writes:

> In article <mailman.0.1111835963.588.questions@lists.ntp.isc.org>,
> Roger Chou <rgr.chou@gmail.com> wrote:
> 
> > My applications is to do time stamp that need 10 microsecond accuracy. Many
> 
> The only thing that you will timestamp to that accuracy on a general
> purpose OS is the reading of the cycle counter or the residual count
> in the CTC. 

True if you need that accuracy 99.9999% of the samples. If 95-98% is
enough, I have done it on Linux with the TIOCMIWAIT ioctl. I got
inspiration from Jonathan Buzzards radioclkd. phk has an excellent
paper on

        http://phk.freebsd.dk/soekris/pps/

> You may need special hardware that timestamps the external event so as
> to remove the time dependency in subsequent processing.

Roger's Trimble does just that.

> You may well need the full source code of the OS to work to 10 microseconds
> (NTP may manage to keep time to that accuracy, but only because its corrections
> are averaged over a long period of time).

NTP timestamps most PPS pulses better than 1us on a suitable
configured OS.

-- Bj�rn
0
Bjorn
3/26/2005 9:00:13 PM
In article <m3y8ca6rwi.fsf@lysator.liu.se>,
Bjorn Gabrielsson <bg@lysator.liu.se> wrote:

> True if you need that accuracy 99.9999% of the samples. If 95-98% is

I would hope that anyone aware enough of the issues would have specified
the percentile that had to be within 10 microseconds.  To me, not
specifying it suggests that they really expect to get 100% of 
measurements within that limit.

> enough, I have done it on Linux with the TIOCMIWAIT ioctl. I got
> inspiration from Jonathan Buzzards radioclkd. phk has an excellent

We are not talking about timestamping NTP messages or PPS but about
timestamping something (currently unspecified) in the application domain.
One has to assume that there are some inbound events, in which case 
interrupts is the only way of getting close on a general purpose OS, but
we don't know what device is interrupting.
0
david
3/27/2005 8:15:58 AM
Roger,

Roger Chou wrote:
> My applications is to do time stamp that need 10 microsecond accuracy.
> Many PCs in network environment will need ssme precise time stamp. One way
> to do it is to install Trimble Acutime GPS for each PC. Because of cost
> consideration, I installed a Win NT NTP server that use Trimble Acutime
> GPS as reference clock and the rest of PCs synchronize to the server and I
> try to find a way to get precise time from NT/ XP system. I head NT/XP
> system time can only reach 10 millisecond resolution, if it is true? Or
> there is another way to do it.

The Windows API to read the system time provides a resolution of
nanoseconds. However, the value returned by those APIs is updated once
every timer tick, so if your application polls the system time
continuously, it will read the same time between two ticks, and after each
tick it will find the system time has been incremented by the tick
interval, i.e. 10 or 15 milliseconds.

In order to increase the resolution of the Windows system clock beyound that
tick interval, the NTP service under Windows runs a special high priority
thread which interpolates the time between two clock ticks using the
Windows performance counter API. Unfortunately, you are unable to access
that interpolated time from your application.

Even worse, if you start any application that uses the Windows multimedia
timer API and sets the multimedia timers to highest resolution of 1
millisecond, the normal system clock is delayed by 10 to 20 milliseconds as
long as that application is running. You can simply test it by letting NTP
adjusting your system time until synchronization has settled, then start
such an application like Quicktime, and use the ntpq command to see how the
offset suddenly changes by several milliseconds if you start Quicktime, and
the offset falls back close to the initial value if you exit Quicktime.
Note that this is _not_ a problem of Quicktime, neither of NTP, but of the
implementation of the Windows system clock, and task scheduling.

Meinberg provides GPS PCI cards which provide an API which lets your
application read time stamps with better than 1 microsecond resolution and
accuracy directly from the board. 

The API call even accounts for the latency due to the execution time of the
driver when calling the device driver to access the PCI board.

Martin
-- 
Martin Burnicki

Meinberg Funkuhren
Bad Pyrmont
Germany
0
Martin
3/29/2005 10:27:51 AM
Martin,

If my application polls the system time once every tick, i.e. 10
millisecond, can I get nanosecond resolution and accuracy that NTP can
provide?

Roger

"Martin Burnicki" <martin.burnicki@meinberg.de> ???
news:76nnh2-6js.ln1@gateway.py.meinberg.de ???...
> Roger,
>
> Roger Chou wrote:
> > My applications is to do time stamp that need 10 microsecond accuracy.
> > Many PCs in network environment will need ssme precise time stamp. One
way
> > to do it is to install Trimble Acutime GPS for each PC. Because of cost
> > consideration, I installed a Win NT NTP server that use Trimble Acutime
> > GPS as reference clock and the rest of PCs synchronize to the server and
I
> > try to find a way to get precise time from NT/ XP system. I head NT/XP
> > system time can only reach 10 millisecond resolution, if it is true? Or
> > there is another way to do it.
>
> The Windows API to read the system time provides a resolution of
> nanoseconds. However, the value returned by those APIs is updated once
> every timer tick, so if your application polls the system time
> continuously, it will read the same time between two ticks, and after each
> tick it will find the system time has been incremented by the tick
> interval, i.e. 10 or 15 milliseconds.
>
> In order to increase the resolution of the Windows system clock beyound
that
> tick interval, the NTP service under Windows runs a special high priority
> thread which interpolates the time between two clock ticks using the
> Windows performance counter API. Unfortunately, you are unable to access
> that interpolated time from your application.
>
> Even worse, if you start any application that uses the Windows multimedia
> timer API and sets the multimedia timers to highest resolution of 1
> millisecond, the normal system clock is delayed by 10 to 20 milliseconds
as
> long as that application is running. You can simply test it by letting NTP
> adjusting your system time until synchronization has settled, then start
> such an application like Quicktime, and use the ntpq command to see how
the
> offset suddenly changes by several milliseconds if you start Quicktime,
and
> the offset falls back close to the initial value if you exit Quicktime.
> Note that this is _not_ a problem of Quicktime, neither of NTP, but of the
> implementation of the Windows system clock, and task scheduling.
>
> Meinberg provides GPS PCI cards which provide an API which lets your
> application read time stamps with better than 1 microsecond resolution and
> accuracy directly from the board.
>
> The API call even accounts for the latency due to the execution time of
the
> driver when calling the device driver to access the PCI board.
>
> Martin
> -- 
> Martin Burnicki
>
> Meinberg Funkuhren
> Bad Pyrmont
> Germany


0
Roger
3/30/2005 7:42:40 AM
Roger Chou ??? wrote:

> Martin,
> 
> If my application polls the system time once every tick, i.e. 10
> millisecond, can I get nanosecond resolution and accuracy that NTP can
> provide?

No. No way. Never.

What you might get is millisecond.

WinNT started out with a beautiful system clock definition, using 100 ps 
(yes, 0.1 ns!) as the resolution, then they immediately destroyed it by 
a combination of two mistakes:

1) Interpolation between ticks simply isn't done.

2) The clock is in the HAL (Hardware Abstraction Layer) below the OS, so 
even a regular kernel driver cannot fix it.

Terje

-- 
- <Terje.Mathisen@hda.hydro.com>
"almost all programming can be viewed as an exercise in caching"
0
Terje
3/30/2005 10:03:23 AM
Roger,

Roger Chou ??? wrote:

> Martin,
> 
> If my application polls the system time once every tick, i.e. 10
> millisecond, can I get nanosecond resolution and accuracy that NTP can
> provide?

As Terje already mentioned in his reply, the problem is in the Windows
implementation. Since the code is in the HAL, and the HAL is different for
uniprocessor machines and multiprocessor machines, the program behaves
differently if running on DMP or non-SMP machines.

If you try to interpolate using a timer callback function, that function may
be called immediately after a timer tick, or just a few milliseconds later,
if another application uses the multimedia timers as described in my
original post. Unfortunately I've found that there's still a jitter of 1
millisecond in the callback rate while the multimedia timers are active.

Martin
-- 
Martin Burnicki

Meinberg Funkuhren
Bad Pyrmont
Germany
0
Martin
3/30/2005 1:21:11 PM
"Martin Burnicki" <martin.burnicki@meinberg.de> ???
news:7nlqh2-vtb.ln1@gateway.py.meinberg.de ???...
> Roger,
>
> Roger Chou ??? wrote:
>
> > Martin,
> >
> > If my application polls the system time once every tick, i.e. 10
> > millisecond, can I get nanosecond resolution and accuracy that NTP can
> > provide?
>
> As Terje already mentioned in his reply, the problem is in the Windows
> implementation. Since the code is in the HAL, and the HAL is different for
> uniprocessor machines and multiprocessor machines, the program behaves
> differently if running on DMP or non-SMP machines.
>
> If you try to interpolate using a timer callback function, that function
may
> be called immediately after a timer tick, or just a few milliseconds
later,
> if another application uses the multimedia timers as described in my
> original post. Unfortunately I've found that there's still a jitter of 1
> millisecond in the callback rate while the multimedia timers are active.
>
> Martin
> -- 
> Martin Burnicki
>
> Meinberg Funkuhren
> Bad Pyrmont
> Germany

Martin,

I would like to try polls Windows 2000/ XP system time. Can you tell me how
to do it? Only poll once every tick, see if I can get 1ms resolution?

Thanks,

Roger Chou



0
Roger
3/30/2005 4:00:08 PM
At 11:00 AM 3/30/2005, Roger Chou wrote:
>Martin,
>
>I would like to try polls Windows 2000/ XP system time. Can you tell me how
>to do it? Only poll once every tick, see if I can get 1ms resolution?
>
>Thanks,
>
>Roger Chou

Please don't send me private email on this. The discussion belongs
here.

I think you really don't understand. Ask yourself this question: How long
does it take to request the time and get the answer back? On Windows
that time is not determinable, it depends on too many variables. Once the
error overwelms the measurement it's not even clear anymore what's
getting measured. You cannot possibly poll every tick. You can only get
the accuracy that you are asking about by throwing hardware at the
problem, and very expensive hardware at that. Does this application have
that kind of need? If you don't understand this you need to take a basic
course in experimental physics where this kind of thing is taught as part
of how to measure things.

You really need to tell us what it is that you are trying to do in a way
that it makes sense to an outsider. There may be a better solution.

Danny


0
Danny
3/31/2005 3:20:23 AM
Roger,

Roger Chou wrote:
[...]
> Martin,
> 
> I would like to try polls Windows 2000/ XP system time. Can you tell me
> how to do it? Only poll once every tick, see if I can get 1ms resolution?
> 
> Thanks,
> 
> Roger Chou

Please have a look at the NTP sources. The Windows port does it.

Martin
-- 
Martin Burnicki

Meinberg Funkuhren
Bad Pyrmont
Germany
0
Martin
3/31/2005 9:51:27 AM
Reply: