Subject: Re: RTC and clocks
To: Peter Seebach <seebs@plethora.net>
From: Jared D. McNeill <jmcneill@invisible.ca>
List: port-i386
Date: 09/18/2006 22:37:46
On 18-Sep-06, at 10:18 PM, Peter Seebach wrote:

> Hi!  I have a mystery.  Well, sort of.
>
> The original mystery was that "date; sleep 60; date" on my laptop  
> would
> take exactly 60 seconds, and print timestamps 35 seconds apart.
>
> I replaced the laptop's CMOS battery, and this no longer happens.
>
> However, in the process, I started trying to understand the i386  
> clock code,
> and I cannot for the life of me figure out how this is possible.   
> So far as
> I can tell, the system's clock is read only at boot.  At runtime, I  
> can
> imagine the system getting regular i8254 interrupts (and thus  
> keeping good
> time), or I can imagine problems (making the clock slip).
>
> What I can't figure out is how the kernel can keep flawless time in  
> terms
> of the duration of timers (such as sleep), while still having the  
> clock
> slip.

Are you by any chance using enhanced speedstep, powernow, (not  
enhanced) speedstep, etc with the TSC timecounter on 4.0+?

A simple ``sysctl kern.timecounter'' will tell you the available  
timecounters, as well as the selected one, ie:

discovery# sysctl kern.timecounter
kern.timecounter.choice = clockinterrupt(q=0, f=100 Hz) TSC(q=800,  
f=266673970 Hz) geodecounter(q=1000, f=27000000 Hz) i8254(q=100,  
f=1193182 Hz) dummy(q=-1000000, f=1000000 Hz)
kern.timecounter.hardware = geodecounter
kern.timecounter.timestepwarnings = 0

Cheers,
Jared