Skip to content

Commit

Permalink
phc2sys: Stop synchronization when ptp4l stops responding.
Browse files Browse the repository at this point in the history
phc2sys in the automatic mode waits for ptp4l on start, but doesn't care
if it stopped providing state notifications and responding to UTC offset
requests, e.g. if it stopped, crashed, freezed, or its socket was
removed by a misconfigured ptp4l instance.

To better handle broken communication with ptp4l and make it evident,
if the pmc subscription runs out, log an error message and stop
synchronization in the domain until the pmc agent is subscribed again.

Signed-off-by: Miroslav Lichvar <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Nov 22, 2023
1 parent 523890e commit e46a28c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions phc2sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ static int reconfigure_domain(struct domain *domain)
LIST_REMOVE(LIST_FIRST(&domain->dst_clocks), dst_list);
}

if (!domain->has_rt_clock && !domain->agent_subscribed) {
domain->src_clock = NULL;
return 0;
}

LIST_FOREACH(c, &domain->clocks, list) {
if (c->clkid == CLOCK_REALTIME) {
/* If present, it can always be a sink clock */
Expand Down Expand Up @@ -803,9 +808,9 @@ static int update_domain_clocks(struct domain *domain)

static int do_loop(struct domain *domains, int n_domains)
{
int i, state_changed, prev_sub;
struct timespec interval;
struct domain *domain;
int i, state_changed;

/* All domains have the same interval */
interval.tv_sec = domains[0].phc_interval;
Expand All @@ -821,6 +826,17 @@ static int do_loop(struct domain *domains, int n_domains)
continue;
}

prev_sub = domain->agent_subscribed;
domain->agent_subscribed =
pmc_agent_is_subscribed(domain->agent);
if (!domain->has_rt_clock && !domain->agent_subscribed) {
if (prev_sub) {
pr_err("Lost connection to ptp4l #%d", i + 1);
state_changed = 1;
}
continue;
}

if (domain->state_changed) {
state_changed = 1;

Expand Down Expand Up @@ -880,8 +896,6 @@ static int phc2sys_recv_subscribed(void *context, struct ptp_message *msg,
struct port *port;
struct clock *clock;

domain->agent_subscribed = 1;

mgt_id = management_tlv_id(msg);
if (mgt_id == excluded)
return 0;
Expand Down

0 comments on commit e46a28c

Please sign in to comment.