[LEAPSECS] JD & MJD, UT1 & UTC

John Sauter John_Sauter at systemeyescomputerstore.com
Wed Jan 4 09:42:45 EST 2017


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.

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 (&current_timex);

  /* Format that information into a tm structure.  */
  gmtime_r (&current_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 (John_Sauter at systemeyescomputerstore.com)
-- 
PGP fingerprint E24A D25B E5FE 4914 A603  49EC 7030 3EA1 9A0B 511E
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part
URL: <https://pairlist6.pair.net/pipermail/leapsecs/attachments/20170104/042963fd/attachment-0001.pgp>


More information about the LEAPSECS mailing list