[time-nuts] Exact Time Mobile Phone Apps

Hal Murray hmurray at megapathdsl.net
Thu Sep 20 02:42:02 EDT 2018


> The timing must be very low level in the OS.

Yes, and it can get a bit complicated.

The desktop or server case is usually straightforward.  Modern CPUs have a 
cycle count register.  You can keep time with that if you know the clock 
frequency.  There is another register on Intel architectures that counts at a 
known frequency.  You can use that to calibrate the main clock that drives the 
cycle count register.

Most PCs crystals are off far enough to be annoying, so one of the main things 
that ntpd does is reach into the kernel via a side door to tell the kernel the 
correction for the clock frequency.  ntpd calls that drift.  It's in log files 
and/or stored in a file so it can be used on reboot.  ntpd can be good enough 
that you can use the drift as a thermometer.

Things get interesting when you want to change the clock frequency to save 
power.  I think some of the early cycle-counter implementations counted actual 
CPU cycles.  I think modern chips count at a fixed rate that may not be the 
same as the CPU clock frequency.

If you want to save more power, you can turn off the CPU clock.  Laptops do 
this when you close the lid.  Phones do it on a much finer grain.  Then you 
have to set the clock when you turn the CPU clock back on.  I'm not sure of 
the details in this area.  Most systems have a battery backed clock running 
off a 32 KHz crystal.  Typically, they can only be read to a granularity of 1 
second.  And they aren't drift-corrected, ...


-- 
These are my opinions.  I hate spam.






More information about the time-nuts mailing list