[time-nuts] NTP API on Linux 2.6.26

M. Warner Losh imp at bsdimp.com
Wed Jan 7 04:58:35 UTC 2009


In message: <4964340D.8030909 at rubidium.dyndns.org>
            Magnus Danielson <magnus at rubidium.dyndns.org> writes:
: Hi!
: 
: 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:
: http://bugs.gentoo.org/attachment.cgi?id=165913&action=view
: http://sources.redhat.com/bugzilla/show_bug.cgi?id=9690
: http://sourceware.org/ml/libc-alpha/2008-03/msg00076.html
: 
: However a small test-program:
: #include <stdio.h>
: //#include <sys/timex.h>
: #include "timex.h"
: 
: int main()
: {
: 	struct timex foo;
: 	adjtimex(&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.

That didn't work.

% cc -o y y.c -Wall
y.c: In function 'main':
y.c:9: warning: implicit declaration of function 'adjtimex'
y.c:10: error: 'struct timex' has no member named 'tai'

But this does:

#include <stdio.h>
#include <sys/time.h>
#include <sys/timex.h>

int
main(int argc, char **argv)
{
    int rv;
    struct ntptimeval ntv;
    struct timeval tv1;
    struct timeval tv2;
    
    gettimeofday(&tv1, NULL);
    rv = ntp_gettime(&ntv);
    gettimeofday(&tv2, NULL);
    printf("System: %ld.%06ld\nntp:    %ld.%09ld (err %ld)\nntp*:   %ld.%09ld\nsystem: %ld.%06ld\n",
      (long)tv1.tv_sec, (long)tv1.tv_usec,
      (long)ntv.time.tv_sec, (long)ntv.time.tv_nsec, ntv.esterror * 1000,
      (long)ntv.time.tv_sec, (long)ntv.time.tv_nsec + ntv.esterror * 1000,
      (long)tv2.tv_sec, (long)tv2.tv_usec);
    printf("TAI Offset is %ld\n", ntv.tai);
}



Warner




More information about the Time-nuts_lists.febo.com mailing list