Thread (18 messages) 18 messages, 5 authors, 2019-08-22

Re: [PATCH net-next v3 2/4] net: mdio: add PTP offset compensation to mdiobus_write_sts

flat view

From: Hubert Feurstein <hidden>
Date: 2019-08-20 12:29:43
Also in: lkml

Hi Miroslav,

Am Di., 20. Aug. 2019 um 11:49 Uhr schrieb Miroslav Lichvar
[off-list ref]:
On Tue, Aug 20, 2019 at 10:48:31AM +0200, Hubert Feurstein wrote:
quoted
+     /* PTP offset compensation:
+      * After the MDIO access is completed (from the chip perspective), the
+      * switch chip will snapshot the PHC timestamp. To make sure our system
+      * timestamp corresponds to the PHC timestamp, we have to add the
+      * duration of this MDIO access to sts->post_ts. Linuxptp's phc2sys
+      * takes the average of pre_ts and post_ts to calculate the final
+      * system timestamp. With this in mind, we have to add ptp_sts_offset
+      * twice to post_ts, in order to not introduce an constant time offset.
+      */
+     if (sts)
+             timespec64_add_ns(&sts->post_ts, 2 * bus->ptp_sts_offset);
This correction looks good to me.

Is the MDIO write delay constant in reality, or does it at least have
an upper bound? That is, is it always true that the post_ts timestamp
does not point to a time before the PHC timestamp was actually taken?

This is important to not break the estimation of maximum error in the
measured offset. Applications using the ioctl may assume that the
maximum error is (post_ts-pre_ts)/2 (i.e. half of the delay printed by
phc2sys). That would not work if the delay could be occasionally 50
microseconds for instance, i.e. the post_ts timestamp would be earlier
than the PHC timestamp.
If the timestamps are taken in the MDIO driver (imx-fec in my case), then
everything is quite deterministic (see results in the cover letter). Of course,
it still can be improved slightly, by splitting up the writel into iowmb and
write_relaxed and disable the interrupts while capturing the timestamps
(as I did in my original RFC patch). But phc2sys takes by default 5 measurements
and uses the one with the smallest delay, so this shouldn't be necessary.

Although, by adding 2 * ptp_sts_offset the system timestamp to post_ts
the timestamp is aligned with the PHC timestamp, but this also increases
the delay which is reported by phc2sys (~26us). But the maximum error
which must be expected is definitely much less (< 1us). So maybe it is better
to shift both timestamps pre_ts and post_ts by ptp_sts_offset.

Hubert
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help