Re: [PATCH] net: lan743x_ptp: convert to ktime_get_clocktai_ts64
From: Richard Cochran
Date: Fri Aug 17 2018 - 20:09:59 EST
On Fri, Aug 17, 2018 at 09:29:56PM +0200, Arnd Bergmann wrote:
> This certainly seems to be an "interesting" problem, given that the Linux
> implementations (other than the new lan743x) then start out with UTC,
> while the PTP spec mandates TAI. So even if the system clock is
> perfectly synchronized to UTC at boot,
When the system boots, it is not synchronized. Only after ntpd or
ptp4l start their work can we say that.
> we set the PTP hardware 37
> seconds slow.
s/slow/behind/
> It would not be hard to change all PTP drivers to explicitly initialize to
> TAI, but that might create its own set of problems if random code
> depends on the current behavior.
Right. (But there was never any guarantee.)
Also, devices that don't have an RTC (like many embedded) start with
1970 anyhow. So you really can't have "correct" time at boot. The
question is, which incorrect time would you prefer?
IHMO a clearly wrong value is more useful than one that might be
mistaken as correct by a casual glance from the sysadmin.
> I also see that "phc_ctl /dev/ptp0 set" defaults to CLOCK_REALTIME
> and has no option to use CLOCK_TAI instead. How is this meant to
> work? I see a lot of other code that tries to deal with leap seconds and
> the tai offset, so I hope I was just misreading that code.
You *can* set UTC and then jump the clock by 37 in two steps.
But I don't see an simple solution for setting the TAI-UTC offset at
boot without actually consulting an outside source. Even if you have
the NTP leap seconds file, how does the system know the file is up to
date?
For PTP and PHC devices, there are two use cases.
1. The device is a slave. In this case, applications need to wait
until the PTP status bits say that the time is valid. The invalid
time before shouldn't be trusted at all.
2. The device is a grand master. In this case, the PTP stack has to
wait until its global time source (like GPS) is ready. Then it
will synchronize the local PHC to the global source, and only then
should it advertise the valid bits.
So I don't think the particular kind of wrong start-up value makes
much difference in practice.
You could argue that if
a) the system has an RTC, and
b) the battery isn't dead, and
c) there is a leap seconds file that isn't out of date,
then the initial PHC time will be less wrong (for some definition of
wrong) using TAI than if the driver had used UTC or 1970.
I myself can't get too excited about having "less wrong" time, but I
wouldn't mind trying to set TAI in the PHC layer if people feel
strongly about it.
Thanks,
Richard