> + ts += offset; I think there is a sign error here. This line of code is attempting to reconstruct the 'tp' variable in sysoff_estimate(). In other words, ts should become the ethernet device's PHC timestamp at the time of the best sample.
sysoff_measure writes the approximate CLOCK_REALTIME timestamp ((t1 + t2) / 2) into the 'ts' variable. However, as written, the line code quoted above will adjust that timestamp in the wrong direction. An example: Inside sysoff_estimate() with SYSOFF_BASIC: t1=1576539849164524663 t2=1576539849164526165 tp=1576539849919759249 sysoff_measure() writes: offset=-755233835 delay=1502 ts=1576539849164525414 (halfway between t1 and t2) so ts += offset is meant to recover tp, 1576539849919759249. Instead, the code is doing 1576539849164525414 + -755233835 = 1576539848409291579. Flipping the sign of the offset produces the correct result: 1576539849164525414 + 755233835 = 1576539849919759249 I discovered this because the clock servo would sometimes get unrecoverably out-of-sync if the offset suddenly dramatically changed, and I think this is the root cause. Could you please check my work? Thanks, -cliff On Mon, Nov 12, 2018 at 8:30 AM Miroslav Lichvar <mlich...@redhat.com> wrote: > > If synchronizing a PHC to the system clock, use one of the > PTP_SYS_OFFSET ioctls (if supported) to measure the offset between the > two clocks. Negate the offset and switch the timestamp before passing > them to the servo. > > This makes the synchronization between PHC and system clock symmetric. > > Signed-off-by: Miroslav Lichvar <mlich...@redhat.com> > --- > phc2sys.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/phc2sys.c b/phc2sys.c > index 2cd477a..b8f1ea0 100644 > --- a/phc2sys.c > +++ b/phc2sys.c > @@ -790,6 +790,16 @@ static int do_loop(struct node *node, int subscriptions) > node->phc_readings, > &offset, &ts, &delay) < 0) > return -1; > + } else if (node->master->clkid == CLOCK_REALTIME && > + clock->sysoff_method >= 0) { > + /* use reversed sysoff */ > + if > (sysoff_measure(CLOCKID_TO_FD(clock->clkid), > + clock->sysoff_method, > + node->phc_readings, > + &offset, &ts, &delay) < 0) > + return -1; > + ts += offset; > + offset = -offset; > } else { > /* use phc */ > if (!read_phc(node->master->clkid, > clock->clkid, > -- > 2.17.2 > > > > _______________________________________________ > Linuxptp-devel mailing list > Linuxptp-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linuxptp-devel _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel