[ntp:questions] Re: NTP for dummies

David Woolley david at djwhome.demon.co.uk
Sat Oct 1 08:42:03 UTC 2005


In article <jrrrj15lkhpb5v2kn313lcd962rtputop1 at 4ax.com>,
Ephraim F. Moya <spam_mesg at microdrive.com> wrote:

> My problem is even simpler. I want my computer to periodically read a
> time standard someplace and set the pc/xp hardware clock

You probably don't want ntpd then.  ntpd is about maintaining good time
all the time, not about occasionally correcting the CMOS clock.  I'm not
actually sure that there is an off the shelf program that does this.
Most will only set the software clock.  Setting the hardware clock without
also setting the software clock doesn't seem very useful.

If the xp in pc/xp is supposed to mean Windows XP, Windows provides some
software that is broken in terms of standards compliance but will do
what you want with the exception that I don't know if it updates the hardware
clock.  This is W32Time and it is possibly better known by the command

    set time/sntp

(It is actually a broken implementation of Simple NTP, although it will
often work with NTP servers.)

If you want confirmation as to whether it updates the hardware clock, 
ask Microsoft as we would have to do the same tests as you would have
to do to find out.

> appropriately. I haven't been able to find out whether ntp sets the
> local clock or replaces it. I know how to set the cmos clock manually.
> Does ntp know how?

I think you are somewhat confused about how computers maintain time.  In
all the systems that I know of, that are capable of maintaining the time,
there is simple hardware that interrupts the system at fixed intervals
(on early machines, this was done using the mains frequency as a reference).
The operating system then adds a fixed amount onto its idea of the current
time every interrupt.  This is generally referred to as the software clock
and is what ntpd calls the local clock.  It is this software count that
is read when normal programs ask for the time.

Modern systems often get the interrupts from a counter that is run
faster than the interrupt rate, and some (not Windows) will read the
counter to interpolate between interrupts.  Some may read instruction
cycle counters in the processor, to do the same thing, although it is
possible that only ntpd itself does that.

Modern machines often have what is effectively an electronic watch, that
is maintained by standby power supplies, and which is read into the software
clock when the machine is booted (some operating systems will periodically
re-read it, but if you are asking the question, it is unlikely that you
have one of those, and, in any case, this has to be disabled for ntpd to
work).  This is called the hardware clock, or CMOS clock (because of
the technology used in the chip that normally provides this function).

How ntpd maintains the local clock is operating system dependent.  However,
as it is a user space program, it can never replace the local software
clock.  The basic way it does this is by varying the amount that is
added on each interrupt, but different operating systems provide different
levels of support for this, e.g. modern Linux systems have quite sophisticated
support.  This means that, in normal operation, the clock runs slightly
faster or slower but is never abruptly changed.

Whether the hardware clock is also updated is also operating system dependent.
In general, for Unix and Linux this is the responsibility of the operating
system, or a user space utility that is run periodically.  In Linux, if
the software clock is being actively corrected, the operating system updates
the hardware clock every 11 minutes.  Note that NTP interpolates between
polls to the time server, so doesn't just update when it makes a poll, 
and typically the hardware clock update is not synchronised with the
software clock corrections.

Danny says that the latest Windows version of ntpd itself takes responsibility
for updating the hardware clock, probably because Windows itself is lacking
in this respect.  I have a feeling though that it only does this when the
system is shut down.  Unix systems also often do this on a shutdown.




More information about the questions mailing list