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