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.

Also shorten the minimum subscription interval from 180 seconds to 30
seconds to react faster.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 phc2sys.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/phc2sys.c b/phc2sys.c
index d46184e..f2dc97e 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,18 @@ 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 +897,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;
@@ -942,8 +957,8 @@ static int auto_init_ports(struct domain *domain)
        }
 
        err = pmc_agent_subscribe(domain->agent, 1000,
-                                 (60 > domain->phc_interval ?
-                                  60 : domain->phc_interval) * 3);
+                                 (10 > domain->phc_interval ?
+                                  10 : domain->phc_interval) * 3);
        if (err) {
                pr_err("failed to subscribe");
                return -1;
-- 
2.41.0



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to