Implemented the code review comments.

This code changes brings in the ability to program delay response timeout
within which, if the upstream master does not send a valid delay response
within the configurable delay response timeout duration, device will move
out of lock state.Default delay_response_timeout is 0 (disabled).

Signed-off-by: Karthikkumar V <kval...@altiostar.com>
Signed-off-by: Ramana Reddy <rre...@altiostar.com>
Reviewed-by: Miroslav Lichvar <mlich...@redhat.com>
---
 clock.c             |  5 +++++
 clock.h             |  7 +++++++
 config.c            |  1 +
 configs/default.cfg |  1 +
 port.c              | 23 ++++++++++++++++++++++-
 port_private.h      |  2 ++
 ptp4l.8             |  6 ++++++
 7 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/clock.c b/clock.c
index ec70f91..7333313 100644
--- a/clock.c
+++ b/clock.c
@@ -1730,6 +1730,11 @@ UInteger16 clock_steps_removed(struct clock *c)
        return c->cur.stepsRemoved;
 }
 
+struct tsproc *clock_get_tsproc(struct clock *c)
+{
+       return c->tsproc;
+}
+
 int clock_switch_phc(struct clock *c, int phc_index)
 {
        struct servo *servo;
diff --git a/clock.h b/clock.h
index 845d54f..e2a3e36 100644
--- a/clock.h
+++ b/clock.h
@@ -304,6 +304,13 @@ UInteger8 clock_get_clock_class_threshold(struct clock *c);
 UInteger16 clock_steps_removed(struct clock *c);
 
 /**
+ * Obtain the Time Stamp Processor instance from a clock.
+ * @param c The clock instance.
+ * @return  The Time Stamp Processor associated with the clock.
+ */
+struct tsproc *clock_get_tsproc(struct clock *c);
+
+/**
  * Switch to a new PTP Hardware Clock, for use with the "jbod" mode.
  * @param c          The clock instance.
  * @param phc_index  The index of the PHC device to use.
diff --git a/config.c b/config.c
index eb8b988..f3c52ba 100644
--- a/config.c
+++ b/config.c
@@ -239,6 +239,7 @@ struct config_item config_tab[] = {
        PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
        PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
        PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu),
+       PORT_ITEM_INT("delay_response_timeout", 0, 0, UINT8_MAX),
        GLOB_ITEM_INT("dscp_event", 0, 0, 63),
        GLOB_ITEM_INT("dscp_general", 0, 0, 63),
        GLOB_ITEM_INT("domainNumber", 0, 0, 127),
diff --git a/configs/default.cfg b/configs/default.cfg
index d615610..cd383b5 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -30,6 +30,7 @@ logMinPdelayReqInterval       0
 operLogPdelayReqInterval 0
 announceReceiptTimeout 3
 syncReceiptTimeout     0
+delay_response_timeout 0
 delayAsymmetry         0
 fault_reset_interval   4
 neighborPropDelayThresh        20000000
diff --git a/port.c b/port.c
index c82bdaf..85cb9fa 100644
--- a/port.c
+++ b/port.c
@@ -1732,6 +1732,7 @@ int port_initialize(struct port *p)
        p->operLogPdelayReqInterval = config_get_int(cfg, p->name, 
"operLogPdelayReqInterval");
        p->neighborPropDelayThresh = config_get_int(cfg, p->name, 
"neighborPropDelayThresh");
        p->min_neighbor_prop_delay = config_get_int(cfg, p->name, 
"min_neighbor_prop_delay");
+       p->delay_response_timeout  = config_get_int(cfg, p->name, 
"delay_response_timeout");
 
        if (config_get_int(cfg, p->name, "asCapable") == AS_CAPABLE_TRUE) {
                p->asCapable = ALWAYS_CAPABLE;
@@ -1997,6 +1998,9 @@ void process_delay_resp(struct port *p, struct 
ptp_message *m)
                return;
        }
 
+       /* Valid Delay Response received, reset the counter */
+       p->delay_response_counter = 0;
+
        c3 = correction_to_tmv(m->header.correction);
        t3 = req->hwts.ts;
        t4 = timestamp_to_tmv(m->ts.pdu);
@@ -2680,7 +2684,24 @@ static enum fsm_event bc_event(struct port *p, int 
fd_index)
                pr_debug("%s: delay timeout", p->log_name);
                port_set_delay_tmo(p);
                delay_req_prune(p);
-               return port_delay_request(p) ? EV_FAULT_DETECTED : EV_NONE;
+               if (port_delay_request(p)) {
+                       return EV_FAULT_DETECTED;
+               }
+               /* Successfully send Delay Request,
+                * increment delay response counter
+                */
+               p->delay_response_counter++;
+
+               if (p->delay_response_counter >= p->delay_response_timeout) {
+                       p->delay_response_counter = 0;
+                       if ((p->delay_response_timeout != 0) &&
+                               (p->state == PS_SLAVE)) {
+                               tsproc_reset(clock_get_tsproc(p->clock), 1);
+                               pr_err("%s: delay response timeout", 
p->log_name);
+                               return EV_SYNCHRONIZATION_FAULT;
+                       }
+               }
+               return EV_NONE;
 
        case FD_QUALIFICATION_TIMER:
                pr_debug("%s: qualification timeout", p->log_name);
diff --git a/port_private.h b/port_private.h
index 2a98ef4..5391879 100644
--- a/port_private.h
+++ b/port_private.h
@@ -143,6 +143,8 @@ struct port {
        struct fault_interval flt_interval_pertype[FT_CNT];
        enum fault_type     last_fault_type;
        UInteger8           versionNumber; /* UInteger4 */
+       UInteger8           delay_response_counter;
+       UInteger8           delay_response_timeout;
        struct PortStats    stats;
        /* foreignMasterDS */
        LIST_HEAD(fm, foreign_clock) foreign_masters;
diff --git a/ptp4l.8 b/ptp4l.8
index a0779ef..9e95de3 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -204,6 +204,12 @@ running in gPTP mode according to the 802.1AS-2011 
standard. Setting
 this option to zero will disable the sync message timeout.
 The default is 0 or disabled.
 .TP
+.B delay_response_timeout
+The number of delay response messages that may go missing before
+triggering a Best Master Clock election. Setting this option to
+zero will disable the delay response timeout.
+The default is 0 or disabled.
+.TP
 .B transportSpecific
 The transport specific field. Must be in the range 0 to 255.
 The default is 0.
-- 
1.8.3.1



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

Reply via email to