From 8142da41b61fb5b9ee4ad8f5ab56adb0447cd37b Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 12 Nov 2018 17:28:02 +0100 Subject: [PATCH] phc2sys: Use reversed sysoff when synchronizing to system clock. 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 --- 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,