[ntp:questions] adj_systime frequency adjustment calculations

Kemal Oral CANSIZLAR ocansizlar at comcast.net
Wed Mar 30 01:10:11 UTC 2005

Hi all,

I have an implementation question regarding time adjustment (clock slewing) 
on Windows XP. It  is about the function

adj_systime(double now)

under "nt_clockstuff.c" source file. I am in need of explanation on what the 
parameter "now" stands for. As far as I understood, it is the offset between 
reference time and the system time. However, is it the offset of system time 
relative to reference time or the other way around? I believe the value 
"now" is in seconds and is determined to be the offset/difference between 
two clocks over one second interval.

Also, can somebody explain what exactly is going on inside adj_systime() 
routine? I am basically trying to adapt the frequency adjustment 
calculations to the high resolution performance counter, instead of the 
system clock. Performance counter has a very high frequency (in my system, 
it is the same as my CPU; 3.2 GHz) relative to low frequency system clock... 
I am having problems on the calculations. I guess there is some 
misinterpretation of some parameters in my code, since my performance 
counter readings (which I use to simulate the system clock) tend to deviate 
largely after about 15 minutes, and causing NTP to give the error "frequency 
error X PPM exceeds tolerance 500 PPM". So, how can I go about calculating 
the frequency adjustment needed for any general counter (performance counter 
in my case) given the values "now" and the frequency the counter is 
operating at. My calculations were as below:

In my case, I am only holding a double value for frequency, and treat the 
performance counter as a continuous, utopic time provider. So, in Time 

Freq(offset) = Delta_T / T.

Delta_T is the offset parameter passed by NTP to adj_systime() routine. T is 
1 second in our case. Having Freq(offset) computed, we also have in 
Frequency domain;

Freq(offset) = [ Freq(measured) - Freq(current) ] / Freq(current).

>From here, we can find Freq(measured) which is the actual frequency our 
counter should operate at to compensate for the offset. We know 
Freq(current) - it is the freq that our counter operates at. So, in our 

Freq(offset) = Delta_T because T = 1,

and then we should reach the desired frequency by

Freq(new) = (1+Delta_T)*Freq(current)

And this is not working...  I guess I am misinterpreting some internal 
variables that NTP provides me, or my calculations are nonsense...?

I would greatly appreciate any input.


More information about the questions mailing list