The fractional component of the ntptimeval.time structure is always currently returned in nanoseconds from the ntp_gettime system call. It should be returned in microseconds if the STA_NANO flag is not set. (See the ntp_adjtime() system call.) I have verified that this is the case in a recent exchange with David Mills. (the ntp author) http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=3D651789.CE68D7D%40internet2.edu&rnum=1&prev=/groups%3Fq%3Dfreebsd%2Bntp%2BSTA_NANO%26ie%3DISO-8859-1%26hl%3Den Fix: The simplest fix would be to hardcode the value of STA_NANO so that it is always returned from ntp_adjtime()'s timex.status field. However, as Mills points out, NTPv3 would no longer work then. However - NTPv3 will not currently work either since NTPv3 only understands microseconds, and FreeBSD is not currently doing microseconds... The next "simplest" fix would be to scale the return to microseconds unless STA_NANO is set. Basically, you would just need to re-include the code from the original nanokernel distribution from Mills. How-To-Repeat: The bug can be demonstrated using the /usr/sbin/ntptime command line utility. First call ntptime to put the clock in "microsecond" mode: % /usr/sbin/ntptime -M # as root (Ignore the timestamps reported this time around because they are reported before the actual call to ntp_adjtime().) Now, call ntptime again: % /usr/sbin/ntptime The output should look similar to:
> > The fractional component of the ntptimeval.time structure is always currently > returned in nanoseconds from the ntp_gettime system call. It should be > returned in microseconds if the STA_NANO flag is not set. (See the > ntp_adjtime() system call.) > > I have verified that this is the case in a recent exchange with David Mills. > (the ntp author) > > > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=3D651789.CE68D7D%40internet2.edu&rnum=1&prev=/groups%3Fq%3Dfreebsd%2Bntp%2BSTA_NANO%26ie%3DISO-8859-1%26hl%3Den That is not exactly what I read in that thread. > The next "simplest" fix would be to scale the return to microseconds unless > STA_NANO is set. Basically, you would just need to re-include the code from the > original nanokernel distribution from Mills. You are missing the part where Dave said that on FreeBSD NTP_NANO should be defined. The code you are talking about looks like this: #ifdef NTP_NANO ntv.time.tv_sec = atv.tv_sec; ntv.time.tv_nsec = atv.tv_nsec; #else if (!(time_status & STA_NANO)) atv.tv_nsec /= 1000; ntv.time.tv_sec = atv.tv_sec; ntv.time.tv_usec = atv.tv_nsec; #endif /* NTP_NANO */ But if NTP_NANO is defined we will end up with exactly the code that is currently in FreeBSD or do I miss something? Why don't you rather determine if the time element in struct ntptimeval is of type struct timespec or struct timeval? John -- John Hay -- John.Hay@icomtek.csir.co.za / jhay@FreeBSD.org
Responsible Changed From-To: freebsd-bugs->roberto Assign to ntp maintainer
Responsible Changed From-To: roberto->phk Poul-Henning knows the kernel part of ntp far more than me.
Responsible Changed From-To: phk->freebsd-bugs return to the pool (approved by phk)
State Changed From-To: open->analyzed I don't think this should work at all. The flag mentioned is read only.
Responsible Changed From-To: freebsd-bugs->gnn I don't think this should work at all. The flag mentioned is read only.
batch change: For bugs that match the following - Status Is In progress AND - Untouched since 2018-01-01. AND - Affects Base System OR Documentation DO: Reset to open status. Note: I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.