dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone
d25bfe
commit f32a8469a236728fb158ce997385b53f92b821cc
d25bfe
Author: Jacob Keller <jacob.e.keller@intel.com>
d25bfe
Date:   Tue Nov 23 14:43:26 2021 -0800
d25bfe
d25bfe
    phc2sys: move read_phc into clock_adj.c
d25bfe
    
d25bfe
    The read_phc function implemented in phc2sys.c is used to perform clock
d25bfe
    comparison between two arbitrary clocks using clock_gettime.
d25bfe
    
d25bfe
    This support is used to allow phc2sys to work on any pair of clocks and
d25bfe
    is implemented in a very similar manner as the kernel PTP_SYS_OFFSET
d25bfe
    ioctls.
d25bfe
    
d25bfe
    Make this function easier to re-use by moving it out of phc2sys.c and
d25bfe
    into a more accessible location. clockadj.c seems like a reasonable
d25bfe
    location as this file has many functions which deal with clockid_t
d25bfe
    values, and this functionality is tangentially related to adjusting
d25bfe
    clocks.
d25bfe
    
d25bfe
    Moving this function will allow using it in the phc_ctl program in a
d25bfe
    future change.
d25bfe
    
d25bfe
    Notice that read_phc returned 0 on failure and 1 on success. This is
d25bfe
    fairly non-standard, so lets update clockadj_compare to return 0 on
d25bfe
    success and -1 on failure. Fix the call sites to check correctly and
d25bfe
    report an error.
d25bfe
    
d25bfe
    Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
d25bfe
d25bfe
diff --git a/clockadj.c b/clockadj.c
d25bfe
index b5c78cd..e8c5789 100644
d25bfe
--- a/clockadj.c
d25bfe
+++ b/clockadj.c
d25bfe
@@ -139,6 +139,37 @@ int clockadj_max_freq(clockid_t clkid)
d25bfe
 	return f;
d25bfe
 }
d25bfe
 
d25bfe
+int clockadj_compare(clockid_t clkid, clockid_t sysclk, int readings,
d25bfe
+		     int64_t *offset, uint64_t *ts, int64_t *delay)
d25bfe
+{
d25bfe
+	struct timespec tdst1, tdst2, tsrc;
d25bfe
+	int i;
d25bfe
+	int64_t interval, best_interval = INT64_MAX;
d25bfe
+
d25bfe
+	/* Pick the quickest clkid reading. */
d25bfe
+	for (i = 0; i < readings; i++) {
d25bfe
+		if (clock_gettime(sysclk, &tdst1) ||
d25bfe
+				clock_gettime(clkid, &tsrc) ||
d25bfe
+				clock_gettime(sysclk, &tdst2)) {
d25bfe
+			pr_err("failed to read clock: %m");
d25bfe
+			return -1;
d25bfe
+		}
d25bfe
+
d25bfe
+		interval = (tdst2.tv_sec - tdst1.tv_sec) * NS_PER_SEC +
d25bfe
+			tdst2.tv_nsec - tdst1.tv_nsec;
d25bfe
+
d25bfe
+		if (best_interval > interval) {
d25bfe
+			best_interval = interval;
d25bfe
+			*offset = (tdst1.tv_sec - tsrc.tv_sec) * NS_PER_SEC +
d25bfe
+				tdst1.tv_nsec - tsrc.tv_nsec + interval / 2;
d25bfe
+			*ts = tdst2.tv_sec * NS_PER_SEC + tdst2.tv_nsec;
d25bfe
+		}
d25bfe
+	}
d25bfe
+	*delay = best_interval;
d25bfe
+
d25bfe
+	return 0;
d25bfe
+}
d25bfe
+
d25bfe
 void sysclk_set_leap(int leap)
d25bfe
 {
d25bfe
 	clockid_t clkid = CLOCK_REALTIME;
d25bfe
diff --git a/clockadj.h b/clockadj.h
d25bfe
index 43325c8..b63ae38 100644
d25bfe
--- a/clockadj.h
d25bfe
+++ b/clockadj.h
d25bfe
@@ -63,6 +63,24 @@ void clockadj_step(clockid_t clkid, int64_t step);
d25bfe
  */
d25bfe
 int clockadj_max_freq(clockid_t clkid);
d25bfe
 
d25bfe
+/**
d25bfe
+ * Compare offset between two clocks
d25bfe
+ * @param clkid     A clock ID obtained using phc_open() or CLOCK_REALTIME
d25bfe
+ * @param sysclk    A clock ID obtained using phc_open() or CLOCK_REALTIME
d25bfe
+ * @param readings  Number of readings to try
d25bfe
+ * @param offset    On return, the nanoseconds offset between the clocks
d25bfe
+ * @param ts        On return, the time of sysclk in nanoseconds that was used
d25bfe
+ * @param delay     On return, the interval between two reads of sysclk
d25bfe
+ * @return Zero on success and non-zero on failure.
d25bfe
+ *
d25bfe
+ * Compare the offset between two clocks in a similar manner as the
d25bfe
+ * PTP_SYS_OFFSET ioctls. Performs multiple reads of sysclk with a read of
d25bfe
+ * clkid between in order to calculate the time difference of sysclk minus
d25bfe
+ * clkid.
d25bfe
+ */
d25bfe
+int clockadj_compare(clockid_t clkid, clockid_t sysclk, int readings,
d25bfe
+		     int64_t *offset, uint64_t *ts, int64_t *delay);
d25bfe
+
d25bfe
 /**
d25bfe
  * Set the system clock to insert/delete leap second at midnight.
d25bfe
  * @param leap  +1 to insert leap second, -1 to delete leap second,
d25bfe
diff --git a/phc2sys.c b/phc2sys.c
d25bfe
index a36cbe0..7a547fa 100644
d25bfe
--- a/phc2sys.c
d25bfe
+++ b/phc2sys.c
d25bfe
@@ -486,37 +486,6 @@ static void reconfigure(struct phc2sys_private *priv)
d25bfe
 	pr_info("selecting %s as the master clock", src->device);
d25bfe
 }
d25bfe
 
d25bfe
-static int read_phc(clockid_t clkid, clockid_t sysclk, int readings,
d25bfe
-		    int64_t *offset, uint64_t *ts, int64_t *delay)
d25bfe
-{
d25bfe
-	struct timespec tdst1, tdst2, tsrc;
d25bfe
-	int i;
d25bfe
-	int64_t interval, best_interval = INT64_MAX;
d25bfe
-
d25bfe
-	/* Pick the quickest clkid reading. */
d25bfe
-	for (i = 0; i < readings; i++) {
d25bfe
-		if (clock_gettime(sysclk, &tdst1) ||
d25bfe
-				clock_gettime(clkid, &tsrc) ||
d25bfe
-				clock_gettime(sysclk, &tdst2)) {
d25bfe
-			pr_err("failed to read clock: %m");
d25bfe
-			return 0;
d25bfe
-		}
d25bfe
-
d25bfe
-		interval = (tdst2.tv_sec - tdst1.tv_sec) * NS_PER_SEC +
d25bfe
-			tdst2.tv_nsec - tdst1.tv_nsec;
d25bfe
-
d25bfe
-		if (best_interval > interval) {
d25bfe
-			best_interval = interval;
d25bfe
-			*offset = (tdst1.tv_sec - tsrc.tv_sec) * NS_PER_SEC +
d25bfe
-				tdst1.tv_nsec - tsrc.tv_nsec + interval / 2;
d25bfe
-			*ts = tdst2.tv_sec * NS_PER_SEC + tdst2.tv_nsec;
d25bfe
-		}
d25bfe
-	}
d25bfe
-	*delay = best_interval;
d25bfe
-
d25bfe
-	return 1;
d25bfe
-}
d25bfe
-
d25bfe
 static int64_t get_sync_offset(struct phc2sys_private *priv, struct clock *dst)
d25bfe
 {
d25bfe
 	int direction = priv->forced_sync_offset;
d25bfe
@@ -672,8 +641,10 @@ static int do_pps_loop(struct phc2sys_private *priv, struct clock *clock,
d25bfe
 		/* If a PHC is available, use it to get the whole number
d25bfe
 		   of seconds in the offset and PPS for the rest. */
d25bfe
 		if (src != CLOCK_INVALID) {
d25bfe
-			if (!read_phc(src, clock->clkid, priv->phc_readings,
d25bfe
-				      &phc_offset, &phc_ts, &phc_delay))
d25bfe
+			if (clockadj_compare(src, clock->clkid,
d25bfe
+					     priv->phc_readings,
d25bfe
+					     &phc_offset, &phc_ts,
d25bfe
+					     &phc_delay))
d25bfe
 				return -1;
d25bfe
 
d25bfe
 			/* Convert the time stamp to the PHC time. */
d25bfe
@@ -781,10 +752,11 @@ static int do_loop(struct phc2sys_private *priv, int subscriptions)
d25bfe
 				ts += offset;
d25bfe
 			} else {
d25bfe
 				/* use phc */
d25bfe
-				if (!read_phc(priv->master->clkid, clock->clkid,
d25bfe
-					      priv->phc_readings,
d25bfe
-					      &offset, &ts, &delay))
d25bfe
-					continue;
d25bfe
+				if (clockadj_compare(priv->master->clkid,
d25bfe
+						     clock->clkid,
d25bfe
+						     priv->phc_readings,
d25bfe
+						     &offset, &ts, &delay))
d25bfe
+					return -1;
d25bfe
 			}
d25bfe
 			update_clock(priv, clock, offset, ts, delay);
d25bfe
 		}
d25bfe
d25bfe
commit 96486bda9ac1613fb36feb84d76ababd8972bba6
d25bfe
Author: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
Date:   Tue May 17 12:31:45 2022 +0200
d25bfe
d25bfe
    clockadj: Change clockadj_compare() to return errno.
d25bfe
    
d25bfe
    Return -errno from the failed clock_gettime() to allow the callers to
d25bfe
    check for specific errors.
d25bfe
    
d25bfe
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
d25bfe
diff --git a/clockadj.c b/clockadj.c
d25bfe
index e8c5789..957dc57 100644
d25bfe
--- a/clockadj.c
d25bfe
+++ b/clockadj.c
d25bfe
@@ -17,6 +17,7 @@
d25bfe
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d25bfe
  */
d25bfe
 
d25bfe
+#include <errno.h>
d25bfe
 #include <math.h>
d25bfe
 #include <string.h>
d25bfe
 #include <unistd.h>
d25bfe
@@ -152,7 +153,7 @@ int clockadj_compare(clockid_t clkid, clockid_t sysclk, int readings,
d25bfe
 				clock_gettime(clkid, &tsrc) ||
d25bfe
 				clock_gettime(sysclk, &tdst2)) {
d25bfe
 			pr_err("failed to read clock: %m");
d25bfe
-			return -1;
d25bfe
+			return -errno;
d25bfe
 		}
d25bfe
 
d25bfe
 		interval = (tdst2.tv_sec - tdst1.tv_sec) * NS_PER_SEC +
d25bfe
diff --git a/clockadj.h b/clockadj.h
d25bfe
index b63ae38..6db1d79 100644
d25bfe
--- a/clockadj.h
d25bfe
+++ b/clockadj.h
d25bfe
@@ -71,7 +71,7 @@ int clockadj_max_freq(clockid_t clkid);
d25bfe
  * @param offset    On return, the nanoseconds offset between the clocks
d25bfe
  * @param ts        On return, the time of sysclk in nanoseconds that was used
d25bfe
  * @param delay     On return, the interval between two reads of sysclk
d25bfe
- * @return Zero on success and non-zero on failure.
d25bfe
+ * @return Zero on success, or negative error code on failure.
d25bfe
  *
d25bfe
  * Compare the offset between two clocks in a similar manner as the
d25bfe
  * PTP_SYS_OFFSET ioctls. Performs multiple reads of sysclk with a read of
d25bfe
d25bfe
commit a523e893a15001025379e3c2dedb231e99cc886f
d25bfe
Author: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
Date:   Thu Mar 24 11:55:35 2022 +0100
d25bfe
d25bfe
    sysoff: Change sysoff_measure() to return errno.
d25bfe
    
d25bfe
    Return -errno from failed ioctl instead of the SYSOFF_* enum from the
d25bfe
    measurement functions to allow the callers to check for specific errors.
d25bfe
    
d25bfe
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
d25bfe
diff --git a/sysoff.c b/sysoff.c
d25bfe
index 2743859..5d3b907 100644
d25bfe
--- a/sysoff.c
d25bfe
+++ b/sysoff.c
d25bfe
@@ -17,6 +17,7 @@
d25bfe
  * with this program; if not, write to the Free Software Foundation, Inc.,
d25bfe
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d25bfe
  */
d25bfe
+#include <errno.h>
d25bfe
 #include <stdio.h>
d25bfe
 #include <string.h>
d25bfe
 #include <sys/ioctl.h>
d25bfe
@@ -38,11 +39,11 @@ static int sysoff_precise(int fd, int64_t *result, uint64_t *ts)
d25bfe
 	memset(&pso, 0, sizeof(pso));
d25bfe
 	if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, &pso)) {
d25bfe
 		pr_debug("ioctl PTP_SYS_OFFSET_PRECISE: %m");
d25bfe
-		return SYSOFF_RUN_TIME_MISSING;
d25bfe
+		return -errno;
d25bfe
 	}
d25bfe
 	*result = pctns(&pso.sys_realtime) - pctns(&pso.device);
d25bfe
 	*ts = pctns(&pso.sys_realtime);
d25bfe
-	return SYSOFF_PRECISE;
d25bfe
+	return 0;
d25bfe
 }
d25bfe
 
d25bfe
 static int64_t sysoff_estimate(struct ptp_clock_time *pct, int extended,
d25bfe
@@ -98,10 +99,10 @@ static int sysoff_extended(int fd, int n_samples,
d25bfe
 	pso.n_samples = n_samples;
d25bfe
 	if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, &pso)) {
d25bfe
 		pr_debug("ioctl PTP_SYS_OFFSET_EXTENDED: %m");
d25bfe
-		return SYSOFF_RUN_TIME_MISSING;
d25bfe
+		return -errno;
d25bfe
 	}
d25bfe
 	*result = sysoff_estimate(&pso.ts[0][0], 1, n_samples, ts, delay);
d25bfe
-	return SYSOFF_EXTENDED;
d25bfe
+	return 0;
d25bfe
 }
d25bfe
 
d25bfe
 static int sysoff_basic(int fd, int n_samples,
d25bfe
@@ -112,10 +113,10 @@ static int sysoff_basic(int fd, int n_samples,
d25bfe
 	pso.n_samples = n_samples;
d25bfe
 	if (ioctl(fd, PTP_SYS_OFFSET, &pso)) {
d25bfe
 		perror("ioctl PTP_SYS_OFFSET");
d25bfe
-		return SYSOFF_RUN_TIME_MISSING;
d25bfe
+		return -errno;
d25bfe
 	}
d25bfe
 	*result = sysoff_estimate(pso.ts, 0, n_samples, ts, delay);
d25bfe
-	return SYSOFF_BASIC;
d25bfe
+	return 0;
d25bfe
 }
d25bfe
 
d25bfe
 int sysoff_measure(int fd, int method, int n_samples,
d25bfe
@@ -130,7 +131,7 @@ int sysoff_measure(int fd, int method, int n_samples,
d25bfe
 	case SYSOFF_BASIC:
d25bfe
 		return sysoff_basic(fd, n_samples, result, ts, delay);
d25bfe
 	}
d25bfe
-	return SYSOFF_RUN_TIME_MISSING;
d25bfe
+	return -EOPNOTSUPP;
d25bfe
 }
d25bfe
 
d25bfe
 int sysoff_probe(int fd, int n_samples)
d25bfe
diff --git a/sysoff.h b/sysoff.h
d25bfe
index e4de919..5480f8f 100644
d25bfe
--- a/sysoff.h
d25bfe
+++ b/sysoff.h
d25bfe
@@ -44,7 +44,7 @@ int sysoff_probe(int fd, int n_samples);
d25bfe
  * @param result     The estimated offset in nanoseconds.
d25bfe
  * @param ts         The system time corresponding to the 'result'.
d25bfe
  * @param delay      The delay in reading of the clock in nanoseconds.
d25bfe
- * @return  One of the SYSOFF_ enumeration values.
d25bfe
+ * @return  Zero on success, negative error code otherwise.
d25bfe
  */
d25bfe
 int sysoff_measure(int fd, int method, int n_samples,
d25bfe
 		   int64_t *result, uint64_t *ts, int64_t *delay);
d25bfe
d25bfe
commit 25b340eb1daad807d9485728f0917ec25a376e0c
d25bfe
Author: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
Date:   Wed May 18 10:21:29 2022 +0200
d25bfe
d25bfe
    sysoff: Change log level of ioctl error messages.
d25bfe
    
d25bfe
    Change the log level of ioctl error messages to the error level to make
d25bfe
    them visible in default configuration, with the exception of EOPNOTSUPP
d25bfe
    which is expected in probing and should stay at the debug level to avoid
d25bfe
    confusing users.
d25bfe
    
d25bfe
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
d25bfe
diff --git a/sysoff.c b/sysoff.c
d25bfe
index 5d3b907..a425275 100644
d25bfe
--- a/sysoff.c
d25bfe
+++ b/sysoff.c
d25bfe
@@ -28,6 +28,14 @@
d25bfe
 
d25bfe
 #define NS_PER_SEC 1000000000LL
d25bfe
 
d25bfe
+static void print_ioctl_error(const char *name)
d25bfe
+{
d25bfe
+	if (errno == EOPNOTSUPP)
d25bfe
+		pr_debug("ioctl %s: %s", name, strerror(errno));
d25bfe
+	else
d25bfe
+		pr_err("ioctl %s: %s", name, strerror(errno));
d25bfe
+}
d25bfe
+
d25bfe
 static int64_t pctns(struct ptp_clock_time *t)
d25bfe
 {
d25bfe
 	return t->sec * NS_PER_SEC + t->nsec;
d25bfe
@@ -38,7 +46,7 @@ static int sysoff_precise(int fd, int64_t *result, uint64_t *ts)
d25bfe
 	struct ptp_sys_offset_precise pso;
d25bfe
 	memset(&pso, 0, sizeof(pso));
d25bfe
 	if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, &pso)) {
d25bfe
-		pr_debug("ioctl PTP_SYS_OFFSET_PRECISE: %m");
d25bfe
+		print_ioctl_error("PTP_SYS_OFFSET_PRECISE");
d25bfe
 		return -errno;
d25bfe
 	}
d25bfe
 	*result = pctns(&pso.sys_realtime) - pctns(&pso.device);
d25bfe
@@ -98,7 +106,7 @@ static int sysoff_extended(int fd, int n_samples,
d25bfe
 	memset(&pso, 0, sizeof(pso));
d25bfe
 	pso.n_samples = n_samples;
d25bfe
 	if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, &pso)) {
d25bfe
-		pr_debug("ioctl PTP_SYS_OFFSET_EXTENDED: %m");
d25bfe
+		print_ioctl_error("PTP_SYS_OFFSET_EXTENDED");
d25bfe
 		return -errno;
d25bfe
 	}
d25bfe
 	*result = sysoff_estimate(&pso.ts[0][0], 1, n_samples, ts, delay);
d25bfe
@@ -112,7 +120,7 @@ static int sysoff_basic(int fd, int n_samples,
d25bfe
 	memset(&pso, 0, sizeof(pso));
d25bfe
 	pso.n_samples = n_samples;
d25bfe
 	if (ioctl(fd, PTP_SYS_OFFSET, &pso)) {
d25bfe
-		perror("ioctl PTP_SYS_OFFSET");
d25bfe
+		print_ioctl_error("PTP_SYS_OFFSET");
d25bfe
 		return -errno;
d25bfe
 	}
d25bfe
 	*result = sysoff_estimate(pso.ts, 0, n_samples, ts, delay);
d25bfe
d25bfe
commit 755cf11ad6e5d02e11519b6e2644ee0f71da91ea
d25bfe
Author: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
Date:   Thu Mar 24 12:41:49 2022 +0100
d25bfe
d25bfe
    sysoff: Retry on EBUSY when probing supported ioctls.
d25bfe
    
d25bfe
    Handle EBUSY when probing support for a PTP_SYS_OFFSET ioctl. Try each
d25bfe
    ioctl up to three times before giving up on it to make the detection
d25bfe
    more reliable.
d25bfe
    
d25bfe
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
d25bfe
diff --git a/sysoff.c b/sysoff.c
d25bfe
index a425275..fc1f7ca 100644
d25bfe
--- a/sysoff.c
d25bfe
+++ b/sysoff.c
d25bfe
@@ -145,8 +145,8 @@ int sysoff_measure(int fd, int method, int n_samples,
d25bfe
 int sysoff_probe(int fd, int n_samples)
d25bfe
 {
d25bfe
 	int64_t junk, delay;
d25bfe
+	int i, j, err;
d25bfe
 	uint64_t ts;
d25bfe
-	int i;
d25bfe
 
d25bfe
 	if (n_samples > PTP_MAX_SAMPLES) {
d25bfe
 		fprintf(stderr, "warning: %d exceeds kernel max readings %d\n",
d25bfe
@@ -156,9 +156,15 @@ int sysoff_probe(int fd, int n_samples)
d25bfe
 	}
d25bfe
 
d25bfe
 	for (i = 0; i < SYSOFF_LAST; i++) {
d25bfe
-		if (sysoff_measure(fd, i, n_samples, &junk, &ts, &delay) < 0)
d25bfe
-			continue;
d25bfe
-		return i;
d25bfe
+		for (j = 0; j < 3; j++) {
d25bfe
+			err = sysoff_measure(fd, i, n_samples, &junk, &ts,
d25bfe
+					     &delay);
d25bfe
+			if (err == -EBUSY)
d25bfe
+				continue;
d25bfe
+			if (err)
d25bfe
+				break;
d25bfe
+			return i;
d25bfe
+		}
d25bfe
 	}
d25bfe
 
d25bfe
 	return SYSOFF_RUN_TIME_MISSING;
d25bfe
d25bfe
commit d1e8ea2405a42b42bcaf2166717fe0da6e9871ae
d25bfe
Author: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
Date:   Tue Mar 8 12:18:31 2022 +0100
d25bfe
d25bfe
    phc2sys: Don't exit when reading of PHC fails with EBUSY.
d25bfe
    
d25bfe
    Reading of the PHC can occasionally fail with some drivers, e.g. the ice
d25bfe
    driver returns EBUSY when it fails to get a lock. Continue in the loop
d25bfe
    instead of exiting on the error.
d25bfe
    
d25bfe
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
d25bfe
d25bfe
diff --git a/phc2sys.c b/phc2sys.c
d25bfe
index 7a547fa..b4e2e87 100644
d25bfe
--- a/phc2sys.c
d25bfe
+++ b/phc2sys.c
d25bfe
@@ -623,6 +623,7 @@ static int do_pps_loop(struct phc2sys_private *priv, struct clock *clock,
d25bfe
 	int64_t pps_offset, phc_offset, phc_delay;
d25bfe
 	uint64_t pps_ts, phc_ts;
d25bfe
 	clockid_t src = priv->master->clkid;
d25bfe
+	int err;
d25bfe
 
d25bfe
 	priv->master->source_label = "pps";
d25bfe
 
d25bfe
@@ -641,10 +642,13 @@ static int do_pps_loop(struct phc2sys_private *priv, struct clock *clock,
d25bfe
 		/* If a PHC is available, use it to get the whole number
d25bfe
 		   of seconds in the offset and PPS for the rest. */
d25bfe
 		if (src != CLOCK_INVALID) {
d25bfe
-			if (clockadj_compare(src, clock->clkid,
d25bfe
-					     priv->phc_readings,
d25bfe
-					     &phc_offset, &phc_ts,
d25bfe
-					     &phc_delay))
d25bfe
+			err = clockadj_compare(src, clock->clkid,
d25bfe
+					       priv->phc_readings,
d25bfe
+					       &phc_offset, &phc_ts,
d25bfe
+					       &phc_delay);
d25bfe
+			if (err == -EBUSY)
d25bfe
+				continue;
d25bfe
+			if (err)
d25bfe
 				return -1;
d25bfe
 
d25bfe
 			/* Convert the time stamp to the PHC time. */
d25bfe
@@ -692,6 +696,7 @@ static int do_loop(struct phc2sys_private *priv, int subscriptions)
d25bfe
 	struct clock *clock;
d25bfe
 	uint64_t ts;
d25bfe
 	int64_t offset, delay;
d25bfe
+	int err;
d25bfe
 
d25bfe
 	interval.tv_sec = priv->phc_interval;
d25bfe
 	interval.tv_nsec = (priv->phc_interval - interval.tv_sec) * 1e9;
d25bfe
@@ -735,29 +740,32 @@ static int do_loop(struct phc2sys_private *priv, int subscriptions)
d25bfe
 			if (clock->clkid == CLOCK_REALTIME &&
d25bfe
 			    priv->master->sysoff_method >= 0) {
d25bfe
 				/* use sysoff */
d25bfe
-				if (sysoff_measure(CLOCKID_TO_FD(priv->master->clkid),
d25bfe
-						   priv->master->sysoff_method,
d25bfe
-						   priv->phc_readings,
d25bfe
-						   &offset, &ts, &delay) < 0)
d25bfe
-					return -1;
d25bfe
+				err = sysoff_measure(CLOCKID_TO_FD(priv->master->clkid),
d25bfe
+						     priv->master->sysoff_method,
d25bfe
+						     priv->phc_readings,
d25bfe
+						     &offset, &ts, &delay);
d25bfe
 			} else if (priv->master->clkid == CLOCK_REALTIME &&
d25bfe
 				   clock->sysoff_method >= 0) {
d25bfe
 				/* use reversed sysoff */
d25bfe
-				if (sysoff_measure(CLOCKID_TO_FD(clock->clkid),
d25bfe
-						   clock->sysoff_method,
d25bfe
-						   priv->phc_readings,
d25bfe
-						   &offset, &ts, &delay) < 0)
d25bfe
-					return -1;
d25bfe
-				offset = -offset;
d25bfe
-				ts += offset;
d25bfe
+				err = sysoff_measure(CLOCKID_TO_FD(clock->clkid),
d25bfe
+						     clock->sysoff_method,
d25bfe
+						     priv->phc_readings,
d25bfe
+						     &offset, &ts, &delay);
d25bfe
+				if (!err) {
d25bfe
+					offset = -offset;
d25bfe
+					ts += offset;
d25bfe
+				}
d25bfe
 			} else {
d25bfe
 				/* use phc */
d25bfe
-				if (clockadj_compare(priv->master->clkid,
d25bfe
-						     clock->clkid,
d25bfe
-						     priv->phc_readings,
d25bfe
-						     &offset, &ts, &delay))
d25bfe
-					return -1;
d25bfe
+				err = clockadj_compare(priv->master->clkid,
d25bfe
+						       clock->clkid,
d25bfe
+						       priv->phc_readings,
d25bfe
+						       &offset, &ts, &delay);
d25bfe
 			}
d25bfe
+			if (err == -EBUSY)
d25bfe
+				continue;
d25bfe
+			if (err)
d25bfe
+				return -1;
d25bfe
 			update_clock(priv, clock, offset, ts, delay);
d25bfe
 		}
d25bfe
 	}