[LEAPSECS] JD & MJD, UT1 & UTC
Martin Burnicki
martin.burnicki at burnicki.net
Wed Jan 4 10:09:47 EST 2017
John Sauter wrote:
> 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 (John_Sauter at systemeyescomputerstore.com)
>>
>> 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.
Ah, OK, so the kernel handles this indeed dynamically.
> 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); }
Thanks. That's basically just how I would implement it.
> During the recent leap second I also verified that adjtimex returns
> TIME_OOP.
Yes, I've observed that, too. I just wasn't sure how STA_NANO is
handled by the kernel.
Martin
More information about the LEAPSECS
mailing list