[ntp:hackers] smearing the leap second

Miroslav Lichvar mlichvar at redhat.com
Mon Jul 13 09:41:07 UTC 2015

On Sat, Jul 11, 2015 at 08:58:39PM -0700, Hal Murray wrote:
> >> Getting TAI using the tai_offset via adjtimex() isn't trivial, at least if
> >> you expect your code to do the right thing when running over a leap second.
> >> You have to do something like:
> >>  read tai_offset
> >>  read time in UTC
> >>  read tai_offset again
> >> If the tai_offsets differ, you were reading the clock close to the leap
> >> second.  Try again.

> The case I was trying to cover was when there wasn't a single call to get 
> TAI.  With two separate calls to get UTC and tai_offset, the simple approach 
> gets the wrong answer if the leap happens in between the two calls.  Yes, 
> that's a very small window.

You can actually get both UTC and TAI offset in a single
ntp_adjtime/adjtimex call. The current time is returned in the time
field of the timex struct. Its resolution is selected by the STA_NANO

The advantage of CLOCK_TAI is that its reading can be faster and it
can be used like the standard system clock in POSIX timers, etc.

Miroslav Lichvar

More information about the hackers mailing list