dcavalca / rpms / linuxptp

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