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 <mlich...@redhat.com> --- phc2sys.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 9a5a296..1745558 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -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 */ @@ -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; @@ -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; @@ -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; -- 2.41.0 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel