[time-nuts] NTP API on Linux 2.6.26

Magnus Danielson magnus at rubidium.dyndns.org
Tue Jan 6 23:48:13 EST 2009


As I have been investigating the ways of NTPD to fiddle with time in the 
LINUX kernel I discovered that /usr/include/linux/timex.h (as supplied 
by the kernel) is not in sync with /usr/include/sys/timex.h (as supplied 
by glibc 2.7). Since it is the sys/timex.h which is the interface to 
NTPD and anyone else (it is actually a neat little interface if 
correctly supported).

The fluke is that glibc duplicates the timex.h but has not been updated 
since oh... Linux 2.2.0. The linux/timex.h is up to date with the NTP 
API as far as I can see (have not checked the details).

There are some links that may be handy:

However a small test-program:
#include <stdio.h>
//#include <sys/timex.h>
#include "timex.h"

int main()
	struct timex foo;
	printf("TAI Offset %i\n", foo.tai);
	return 0;

(Notice my quick and dirty hack to use a hacked variant of timex.h as if 
the patch was being applied, also notice that the .c part does not apply 
to the adjtimex() call but to the ntp_gettime() call which I am not 
using, so I do not require that patch for this purpose.)

This should be the kernels feeling of the TAI-UTC difference. I do not 
think it reflects that:
magnus at heaven:~/gcc/ntptest$ ./tai
TAI Offset -1553771440
magnus at heaven:~/gcc/ntptest$ ./tai
TAI Offset -263060400
magnus at heaven:~/gcc/ntptest$ ./tai
TAI Offset 238212176
magnus at heaven:~/gcc/ntptest$ ./tai
TAI Offset 658158672
magnus at heaven:~/gcc/ntptest$ ./tai
TAI Offset 1551639632

So I guess there is more to it than that patch alone.

If someone could run the above test-program on some *BSD box or whatever 
implementing the NTP API version 4 I would be interested in seeing what 
the result would be. It surely isn't the definitive test on the API, but 
seems to detect one (of possible several) flaws.


More information about the time-nuts mailing list