Re: [Ntp] Leap second draft

Warner Losh <imp@bsdimp.com> Sat, 30 March 2019 19:44 UTC

Return-Path: <wlosh@bsdimp.com>
X-Original-To: ntp@ietfa.amsl.com
Delivered-To: ntp@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 9BD6E120267 for <ntp@ietfa.amsl.com>; Sat, 30 Mar 2019 12:44:04 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.899
X-Spam-Level:
X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=bsdimp-com.20150623.gappssmtp.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QDUT2SJmgVB0 for <ntp@ietfa.amsl.com>; Sat, 30 Mar 2019 12:44:01 -0700 (PDT)
Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id EDEAB12025A for <ntp@ietf.org>; Sat, 30 Mar 2019 12:44:00 -0700 (PDT)
Received: by mail-qk1-x72a.google.com with SMTP id k130so3392777qke.3 for <ntp@ietf.org>; Sat, 30 Mar 2019 12:44:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jQZu6Xr73mrD+TyCpRbBU7Av1Eg/8sDT00G1XwGzpQk=; b=UbPD5ov+RcXxaeaLfEFYOzrK4RWpqHJCoX+NBfioy7CgIFeednjPSLQUmnrrIuG9cA QrQYZVX9q3p9zDPfcZTFrA+hWomUh3J5gKBIr1SjQQhJu+AX9/IMOIPkmCFlcBY7HT8G PNmIPDKTt8lkIdJ0STEhdHPaJX2JNvCEnhdO2bi0IeOmePkKL97kJsKc8eW0coMy/iZU ijn2VYsneGwq3H/oWJ/mMLD1YtFIGID3x58dAVa1fpRNp7/GzanCXucypzV0VU4VKDH0 2Zzmb3j+9dbp6Ei8GKt6CnZT71maSCYdtQl+s5zgWmawNmQn1B2elXDKMQ12mhcqEuG5 AYVA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jQZu6Xr73mrD+TyCpRbBU7Av1Eg/8sDT00G1XwGzpQk=; b=V42a7SAYSOhAMfW2zwnXVy/i28IdevgHemimn+Ivwn3K/0Ajb9Wyq7d5UrYdUXqYgT ojV8TvXAJaA4snPYY1UXnYbuvQesbgvG6/FhtxMDxIqxQv+vpk9tQyfGHQ0rg5oQn3Xr pCDb14LSYa7Hk/Bd28bj+PAHAmbKWr803qTjCoRv6LuEzKXrdZ+YNGT33iuxGNQAY51g yGCCL9rWfwo+5cm+yiKUemi9tg/iMMnvEuPZfOogXPXMoDYPopddsABLUEKhSB2HzjGP +vM1/d7GZAptDmGhMKrJuKDbE6/dIrDifvjSRMJMdNx7JJ04Ffko0ppuibkpsWqoiW7o uKYA==
X-Gm-Message-State: APjAAAXzYY2Oo0+hYSflze0q3FFUPnruDoT5+epbFA/InfMTZUZOcacn zebPegYS6WMpoFpY7hNECyoMQza27YmPrkDxzaKxYw==
X-Google-Smtp-Source: APXvYqzeGdA0icudrWcsDsBfVUUg1sCM3GfX1OekmQ8b+4ZkfdZbRdMWvxVLSRnu7xz/YLL7fM9HbBLztfeDRn57gIE=
X-Received: by 2002:a37:a02:: with SMTP id 2mr28559406qkk.258.1553975039727; Sat, 30 Mar 2019 12:43:59 -0700 (PDT)
MIME-Version: 1.0
References: <CAJm83bD5Ozkpg5TpkogOW6xeeNQL3ZziLO9URM7haqN8Wrp=Wg@mail.gmail.com> <CAJm83bCbVzO3NNCbjTy+O_16T7DBeA7O6018WWGu_-GyuN-8UA@mail.gmail.com> <20190330045928.GA31550@ucolick.org> <20190330133348.GA20646@ucolick.org> <20190330152948.GI7706@roeckx.be> <CAJm83bB6BF4_Ked5rVRdGmgYECz5gDrb+_7JeOUe1Lmq2ysVQQ@mail.gmail.com> <CANCZdfrbJhVsVJrsw5QRxDWmpHLJdsMMXi=Z=XvJDi1bGvnk=w@mail.gmail.com> <CAJm83bCRW4dDcZZFL1kqhKyWH_PszGjvmqyyt_E1HgOPw_bktQ@mail.gmail.com>
In-Reply-To: <CAJm83bCRW4dDcZZFL1kqhKyWH_PszGjvmqyyt_E1HgOPw_bktQ@mail.gmail.com>
From: Warner Losh <imp@bsdimp.com>
Date: Sat, 30 Mar 2019 13:43:48 -0600
Message-ID: <CANCZdfoomAn6NX2Nya4QEW4pXBwGNfZ6ZqcTD1jQy-h=b659VA@mail.gmail.com>
To: Daniel Franke <dfoxfranke@gmail.com>
Cc: Kurt Roeckx <kurt@roeckx.be>, Steve Allen <sla@ucolick.org>, NTP WG <ntp@ietf.org>
Content-Type: multipart/alternative; boundary="0000000000003bb05f05855502e0"
Archived-At: <https://mailarchive.ietf.org/arch/msg/ntp/HYTaSPJ_bEYxTip1D37q87QF7WM>
Subject: Re: [Ntp] Leap second draft
X-BeenThere: ntp@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <ntp.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/ntp>, <mailto:ntp-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/ntp/>
List-Post: <mailto:ntp@ietf.org>
List-Help: <mailto:ntp-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/ntp>, <mailto:ntp-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 30 Mar 2019 19:44:05 -0000

On Sat, Mar 30, 2019 at 12:24 PM Daniel Franke <dfoxfranke@gmail.com> wrote:

> On Sat, Mar 30, 2019 at 1:46 PM Warner Losh <imp@bsdimp.com> wrote:
> > https://www.itu.int/rec/r-rec-tf.460/en says the latest version is
> TF.460-6 published in 2002. There's a TF.460.5 published in 1997, but
> nothing published in 1996. You should reference this.
>
> I've already fixed this, and that's the document I've been working
> from the whole time. The citation was messed up because I forgot to
> change some copypasta that I took from the xml2rfc citation library.
>
> > I'm not sure that the definition of SI second adds anything to the
> explanation of TAI time.
> >
> > I'm not sure that saying TAI time is a physical manifestation of TT time
> is useful, and later references to it.
> >
> > I'd omit that these clocks are authoritative. TAI is a paper time scale
> that's based on the input of these clocks, but no one clock in it is
> authoritative and there's no real-time realization of TAI anywhere, just
> national standard's lab's UTC. If you are going for simplicity, these
> details can be omitted because they won't affect the implementation, nor
> the necessary bits of timekeeping needed to understand the rest of the
> document.
>
> No, these details aren't strictly necessary, but neither do they
> excessively complicate things and I think keeping them in leads to
> better ontological clarity. I'd especially like to keep the
> map/territory distinction between TAI and TT intact.
>
> > TAI did not measure solar seconds prior to 1972. You should not mention
> that, as it is misleading. I'd opt instead for the more bland "The NTP
> timescales assume nothing about TAI and UTC prior to 1972." instead. There
> will be no NTP time exchanges for those times, so keeping it simple and
> reducing the fiction here would be good.
>
> The existing text already characterizes this as a "fiction". And I do
> think it's important to mention, considering that the NTP epoch
> predates 1972 and the reader needs to be able to make sense of that.
>
> > A reference to the POSIX standard would be likely be helpful.
> http://pubs.opengroup.org/onlinepubs/9699919799/ has the definition, and
> the reference on all the pages is "The Open Group Base Specifications Issue
> 7, 2018 edition IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)"
>
> Already on my to-do list; I've promised an email to the RFC editor
> about getting it included in the citation library.
>
> > POSIX does not assign a value to the leap second. To say it embraces the
> ambiguity by giving it any specific value goes farther than POSIX actually
> goes. Since it doesn't exist in the POSIX world view, you cannot say the
> standard assigns a value to it. You can read the section on time conversion
> to maybe imply this, but it's not explicit as leap seconds simply do not
> exist in the POSIX time scale (the reading is by setting seconds to 60
> which is the second after 59 which does translate to the first second of
> the next day, but the POSIX standard makes no statement on the value of
> leap seconds in a time_t because leap seconds don't exist in that time
> scale: this is the crux of all the heartburn we have today with them).
> POSIX totally punted on leap seconds, alas.
>
> POSIX does in fact specify exactly what I claim. The definition of
> `struct tm` provides for tm_sec to range over [0..60], and in section
> "4.16 Seconds Since the Epoch" it specifies how this is to be
> translated into a time_t. There's some further discussion in the
> rationale volume, section A.4.16.
>

I've read that several times. It does not specify what a leap second is
encoded as, because leap seconds do not exist in POSIX time_t timescale.
Section A.4.16 just talks about encoding the broken down time into a
time_t. Since leap seconds do not exist in the posix world (and are not
mentioned in A.4.16). The relevant bit is not the formula, but the
following text:

"How any changes to the value of seconds since the Epoch are made to align
to a desired relationship with the current actual time is
implementation-defined. As represented in seconds since the Epoch, each and
every day shall be accounted for by exactly 86400 seconds."

Since leap seconds involve an actual time not handled by time_t, how they
are mapped to seconds since the epoch are implementation-defined. This
point has been well litigated in the leap-second mailing list. There is no
canonical encoding of leap seconds in posix. Many implementations do what
you say, but it is not a standard's defined behavior. There are several
implementations that map the leap second to the last second of the day as
to preserve the day of week of the leap second which properly occurs on the
day of the leap second, not the day following (FreeBSD does this, for
example). Days with leap seconds have 86401 seconds as well, which is at
odds with the seconds since epoch. This is the crux of the problem with
leap seconds: there's many interpretations and no proper way to encode the
leap second. Since POSIX forces multiple seconds to be mapped to the same
value, there's no way for a naive application to get things right if it
assume things like time is monotonic.

I'd love for there to be a single, unambiguous mapping here, but that's
simply not how it's actually implemented. It's a common mistake. I'll have
to check the archives of the leap second mailing list to find where Guy
Steele posted about how the committee explicitly rejected the notion of the
leap second having a prescribed value because time_t doesn't have leap
seconds in it at all.

It's a common reading of thee standard, but POSIX since stays silent about
leap seconds (apart from the one reference to 1 value going to 60), it's
really undefined. It's a fundamental problem, imho, with the standard.

> POSIX does not specify that time_t is 32-bit. It merely specifies it must
> be an integer type (which is a narrowing of the allowed types from ISO C's
> numeric type). There are many implementations that have 64-bit time_t. So
> strictly speaking, it's not a POSIX 2036 problem, but rather a historic
> representation of time_t problem. There are many system that are POSIX
> compliant that don't have the 32-bit issues.
>
> I'm already qualifying with "32-bit systems", which to be slightly
> more correct I'll revise to say "systems that use a 32-bit time_t".
>
> > ELI likely should be specified relative to the receive timestamp. It
> would be good to specify what happens in the next second after the leap
> second. Some historic implementations kept these values on for some number
> of hours after the transition because their upstream sources kept them on
> due to bugs or ignorance. In the past, I've had to filter this data on the
> first day of the month to prevent inferring a leap second that's not really
> there, for example. This has been a decade ago, but the ambiguity stuck
> with me. Adding that it SHALL be cleared after the leap second will
> suffice, though it could be set to '11' as well (though given at least 3
> months between leaps, clearing will give the right answer for the month).
> It may be important to note as well if the ELI in this extension tracks the
> LEAP INDICATOR or not, since '00' means we don't know the if there's a leap
> at the end of the month, and the leap indicator is a SHOULD be cleared all
> days but the last day of the month.
>
> I think I'm already saying all this, am I not?



> "The current month is the Gregorian calendar month determined by the
> Receive Timestamp".
>
> "The Leap Indicator SHALL be set to 01 while a inserted leap second is
> in progress, and then cleared only after the leap second has ended."
> -- okay, I guess I can put a second SHALL in there and/or drop the
> word "only", but you'd have to be pretty dense to think some other
> behavior was acceptable.
>
> "the semantics of 00 also differ: a 00 in the ELI is an affirmative
> statement that no leap second is coming, while a 00 in the LI might
> indicate lack of data."
>

Ah yes. That's there. I'm not sure how I missed it the first time through.

Warner