Package: adjtimex
Version: 1.29-2.1

There are two (minor) problems that cause reduced precision when calculating 
the frequency error of the system clock by comparing the system clock with an 
external reference clock (NTP) and the CMOS clock (the first problem is more 
important):

Problem 1) Integer arithmetics truncate the value of the frequency kernel 
variable to full PPMs.

Source code fragments from adjtimex_1.29-2.1, file adjtimex.c:

  92   int freq;                     /* "freq" system parameter */
...
1249 #define SHIFT (1<<16)
...
1980           hacks[i]->relative_rate =
1981             diff_ppm = 1.e6*(sys_time - cmos_time)/sys_time
1982             - 100*(hacks[i]->tick - tick_mid) - hacks[i]->freq/SHIFT;
...
2047           hacks[i]->sys_rate =
2048             diff_ppm = 1.e6*(sys_time - ref_time)/sys_time
2049             - 100*(hacks[i]->tick - tick_mid) - hacks[i]->freq/SHIFT;

SHIFT (=65536) and hacks[i]->freq are integer values; therefore, 
hacks[i]->freq/SHIFT is computed using integer arithmetics, causing the 
current frequency correction in the kernel to be truncated to full PPMs when 
adding it to the frequency error calculated from clock comparisons.

Required correction: Convert SHIFT or hacks[i]->freq to double by casting, 
e.g. replace hacks[i]->freq/SHIFT with ((double)hacks[i]->freq)/SHIFT.

Problem 2) In the code that compares the system clock with a timeserver, the 
system clock is only used with a precision of seconds instead of (readily 
available) microseconds.

Source code fragment from adjtimex_1.29-2.1, file adjtimex.c:

1459       ftime_sys = tv_sys.tv_sec;

However, in the branch with label /* no absolute time reference */ the full 
precision is used:

1506       ftime_sys = tv_sys.tv_sec + tv_sys.tv_usec*.000001;

When comparing the NTP reference clock with the system clock in intervals of 
15 minutes, the error might be as large as 1/900, or just below 0.1%, so this 
effect is rather minor. As fetching the time offset from NTP by calling 
ntpdate (or even polling the RTC!) also takes some time (which, if I am not 
mistaken, is not taken into account currently), there are already other 
sources that degrade precision. However, the fix is really trivial (copy line 
1506 to line 1459), so I recommend to fix this, too.



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to