Skip to content

Commit

Permalink
phc2sys: Don't exit when reading of PHC fails with EBUSY.
Browse files Browse the repository at this point in the history
Reading of the PHC can occasionally fail with some drivers, e.g. the ice
driver returns EBUSY when it fails to get a lock. Continue in the loop
instead of exiting on the error.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
  • Loading branch information
mlichvar authored and richardcochran committed Jul 24, 2022
1 parent dadd259 commit e8dc364
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions phc2sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ static int do_pps_loop(struct phc2sys_private *priv, struct clock *clock,
int64_t pps_offset, phc_offset, phc_delay;
uint64_t pps_ts, phc_ts;
clockid_t src = priv->master->clkid;
int err;

priv->master->source_label = "pps";

Expand All @@ -640,10 +641,13 @@ static int do_pps_loop(struct phc2sys_private *priv, struct clock *clock,
/* If a PHC is available, use it to get the whole number
of seconds in the offset and PPS for the rest. */
if (src != CLOCK_INVALID) {
if (clockadj_compare(src, clock->clkid,
priv->phc_readings,
&phc_offset, &phc_ts,
&phc_delay))
err = clockadj_compare(src, clock->clkid,
priv->phc_readings,
&phc_offset, &phc_ts,
&phc_delay);
if (err == -EBUSY)
continue;
if (err)
return -1;

/* Convert the time stamp to the PHC time. */
Expand Down Expand Up @@ -691,6 +695,7 @@ static int do_loop(struct phc2sys_private *priv)
struct clock *clock;
uint64_t ts;
int64_t offset, delay;
int err;

interval.tv_sec = priv->phc_interval;
interval.tv_nsec = (priv->phc_interval - interval.tv_sec) * 1e9;
Expand Down Expand Up @@ -727,29 +732,32 @@ static int do_loop(struct phc2sys_private *priv)
if (clock->clkid == CLOCK_REALTIME &&
priv->master->sysoff_method >= 0) {
/* use sysoff */
if (sysoff_measure(CLOCKID_TO_FD(priv->master->clkid),
priv->master->sysoff_method,
priv->phc_readings,
&offset, &ts, &delay) < 0)
return -1;
err = sysoff_measure(CLOCKID_TO_FD(priv->master->clkid),
priv->master->sysoff_method,
priv->phc_readings,
&offset, &ts, &delay);
} else if (priv->master->clkid == CLOCK_REALTIME &&
clock->sysoff_method >= 0) {
/* use reversed sysoff */
if (sysoff_measure(CLOCKID_TO_FD(clock->clkid),
clock->sysoff_method,
priv->phc_readings,
&offset, &ts, &delay) < 0)
return -1;
offset = -offset;
ts += offset;
err = sysoff_measure(CLOCKID_TO_FD(clock->clkid),
clock->sysoff_method,
priv->phc_readings,
&offset, &ts, &delay);
if (!err) {
offset = -offset;
ts += offset;
}
} else {
/* use phc */
if (clockadj_compare(priv->master->clkid,
clock->clkid,
priv->phc_readings,
&offset, &ts, &delay))
return -1;
err = clockadj_compare(priv->master->clkid,
clock->clkid,
priv->phc_readings,
&offset, &ts, &delay);
}
if (err == -EBUSY)
continue;
if (err)
return -1;
update_clock(priv, clock, offset, ts, delay);
}
}
Expand Down

0 comments on commit e8dc364

Please sign in to comment.