Bug 42089 - ntp_gettime returns time in wrong scale
Summary: ntp_gettime returns time in wrong scale
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 4.5-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: George V. Neville-Neil
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-27 18:30 UTC by Jeff W. Boote
Modified: 2018-05-28 19:43 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff W. Boote 2002-08-27 18:30:03 UTC
	
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:
Comment 1 jhay 2002-08-27 20:43:14 UTC
> 	
> 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
Comment 2 Kris Kennaway freebsd_committer freebsd_triage 2003-07-18 23:15:53 UTC
Responsible Changed
From-To: freebsd-bugs->roberto

Assign to ntp maintainer
Comment 3 Ollivier Robert freebsd_committer freebsd_triage 2003-09-01 21:39:48 UTC
Responsible Changed
From-To: roberto->phk

Poul-Henning knows the kernel part of ntp far more than me.
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2011-09-24 18:44:12 UTC
Responsible Changed
From-To: phk->freebsd-bugs

return to the pool (approved by phk)
Comment 5 George V. Neville-Neil freebsd_committer freebsd_triage 2012-07-28 22:20:28 UTC
State Changed
From-To: open->analyzed

I don't think this should work at all. The flag mentioned is read only. 


Comment 6 George V. Neville-Neil freebsd_committer freebsd_triage 2012-07-28 22:20:28 UTC
Responsible Changed
From-To: freebsd-bugs->gnn

I don't think this should work at all. The flag mentioned is read only.
Comment 7 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:43:38 UTC
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.