On Wed, 2017-01-04 at 15:22 +0100, Martin Burnicki wrote: > John Sauter wrote: > > I did some experimenting with this on Fedora 25, Linux kernel > > 4.8.15- 300.fc25.x86_64. I found that adjtimex sets STA_NANO and > > returns nanoseconds only when NTP has been running for a while. > > John Sauter ([email protected]) > > Ah, interesting. > > Did you also have a chance to see if the kernel returns microseconds > rather then nanoseconds if ntpd has *not* set this flag? > > Thanks, > Martin
Yes. I determined that if NTPD has been running for only a short time
the value returned is microseconds and the STA_NANO flag is not set.
The code looks like this:
/* Subroutine to return the current UTC time in a tm structure
* and the number of nanoseconds since the start of the last second.
*/
int
time_current_tm_nano (struct tm *current_tm, int *nanoseconds)
{
struct timex current_timex;
int adjtimex_result;
/* Fetch time information from the kernel. */
current_timex.status = 0;
current_timex.modes = 0;
adjtimex_result = adjtimex (¤t_timex);
/* Format that information into a tm structure. */
gmtime_r (¤t_timex.time.tv_sec, current_tm);
/* If the kernel told us we are in a leap second, increment
* the seconds value. This will change it from 59 to 60. */
if (adjtimex_result == TIME_OOP)
{
current_tm->tm_sec = current_tm->tm_sec + 1;
}
/* Return the number of nanoseconds since the start of the last
* second. If the kernel's clock is not being controlled by
* NTP it will return microseconds instead of nanoseconds. */
if (current_timex.status & STA_NANO)
*nanoseconds = current_timex.time.tv_usec;
else
*nanoseconds = current_timex.time.tv_usec * 1e3;
return (0);
}
During the recent leap second I also verified that adjtimex returns TIME_OOP.
John Sauter ([email protected])
--
PGP fingerprint E24A D25B E5FE 4914 A603 49EC 7030 3EA1 9A0B 511E
signature.asc
Description: This is a digitally signed message part
_______________________________________________ LEAPSECS mailing list [email protected] https://pairlist6.pair.net/mailman/listinfo/leapsecs
