dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone
ab4723
commit 7e8eba5332671abfd95d06dd191059eded1d2cca
ab4723
Author: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
Date:   Mon May 31 11:07:52 2021 +0200
ab4723
ab4723
    clock: Reset state when switching port with same best clock.
ab4723
    
ab4723
    When the best port is changed, but the ID of the best clock doesn't
ab4723
    change (e.g. a passive port is activated on link failure), reset the
ab4723
    current delay and other master/link-specific state to avoid the switch
ab4723
    throwing the clock off.
ab4723
    
ab4723
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
ab4723
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
ab4723
diff --git a/clock.c b/clock.c
ab4723
index d428ae2..f14006f 100644
ab4723
--- a/clock.c
ab4723
+++ b/clock.c
ab4723
@@ -1940,7 +1940,7 @@ static void handle_state_decision_event(struct clock *c)
ab4723
 		best_id = c->dds.clockIdentity;
ab4723
 	}
ab4723
 
ab4723
-	if (!cid_eq(&best_id, &c->best_id)) {
ab4723
+	if (!cid_eq(&best_id, &c->best_id) || best != c->best) {
ab4723
 		clock_freq_est_reset(c);
ab4723
 		tsproc_reset(c->tsproc, 1);
ab4723
 		if (!tmv_is_zero(c->initial_delay))
ab4723
ab4723
commit 262a49b07eaccc0f0237e3cd4df01b185b8f664f
ab4723
Author: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
Date:   Mon May 31 11:07:53 2021 +0200
ab4723
ab4723
    clock: Reset clock check on best clock/port change.
ab4723
    
ab4723
    Reset the clock check when the best clock or port changes, together with
ab4723
    the other state like current estimated delay and frequency. This avoids
ab4723
    false positives if the clock is controlled by an external process when
ab4723
    not synchronized by PTP (e.g. phc2sys -rr).
ab4723
    
ab4723
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
ab4723
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
ab4723
diff --git a/clock.c b/clock.c
ab4723
index f14006f..7d0f985 100644
ab4723
--- a/clock.c
ab4723
+++ b/clock.c
ab4723
@@ -1942,6 +1942,8 @@ static void handle_state_decision_event(struct clock *c)
ab4723
 
ab4723
 	if (!cid_eq(&best_id, &c->best_id) || best != c->best) {
ab4723
 		clock_freq_est_reset(c);
ab4723
+		if (c->sanity_check)
ab4723
+			clockcheck_reset(c->sanity_check);
ab4723
 		tsproc_reset(c->tsproc, 1);
ab4723
 		if (!tmv_is_zero(c->initial_delay))
ab4723
 			tsproc_set_delay(c->tsproc, c->initial_delay);
ab4723
diff --git a/clockcheck.c b/clockcheck.c
ab4723
index d48a578..d0b4714 100644
ab4723
--- a/clockcheck.c
ab4723
+++ b/clockcheck.c
ab4723
@@ -47,9 +47,16 @@ struct clockcheck *clockcheck_create(int freq_limit)
ab4723
 	if (!cc)
ab4723
 		return NULL;
ab4723
 	cc->freq_limit = freq_limit;
ab4723
+	clockcheck_reset(cc);
ab4723
+	return cc;
ab4723
+}
ab4723
+
ab4723
+void clockcheck_reset(struct clockcheck *cc)
ab4723
+{
ab4723
+	cc->freq_known = 0;
ab4723
 	cc->max_freq = -CHECK_MAX_FREQ;
ab4723
 	cc->min_freq = CHECK_MAX_FREQ;
ab4723
-	return cc;
ab4723
+	cc->last_ts = 0;
ab4723
 }
ab4723
 
ab4723
 int clockcheck_sample(struct clockcheck *cc, uint64_t ts)
ab4723
diff --git a/clockcheck.h b/clockcheck.h
ab4723
index 78aca48..1ff86eb 100644
ab4723
--- a/clockcheck.h
ab4723
+++ b/clockcheck.h
ab4723
@@ -33,6 +33,12 @@ struct clockcheck;
ab4723
  */
ab4723
 struct clockcheck *clockcheck_create(int freq_limit);
ab4723
 
ab4723
+/**
ab4723
+ * Reset a clock check.
ab4723
+ * @param cc Pointer to a clock check obtained via @ref clockcheck_create().
ab4723
+ */
ab4723
+void clockcheck_reset(struct clockcheck *cc);
ab4723
+
ab4723
 /**
ab4723
  * Perform the sanity check on a time stamp.
ab4723
  * @param cc Pointer to a clock check obtained via @ref clockcheck_create().
ab4723
ab4723
commit e117e37e379556fa23337db2518bb44d8793e039
ab4723
Author: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
Date:   Mon May 31 11:07:54 2021 +0200
ab4723
ab4723
    port: Don't check timestamps from non-slave ports.
ab4723
    
ab4723
    Don't perform the sanity check on receive timestamps from ports in
ab4723
    non-slave states to avoid false positives in the jbod mode, where
ab4723
    the timestamps can be generated by different clocks.
ab4723
    
ab4723
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
ab4723
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
ab4723
diff --git a/port.c b/port.c
ab4723
index b5b775f..ec5c92e 100644
ab4723
--- a/port.c
ab4723
+++ b/port.c
ab4723
@@ -2749,7 +2749,10 @@ static enum fsm_event bc_event(struct port *p, int fd_index)
ab4723
 	}
ab4723
 	if (msg_sots_valid(msg)) {
ab4723
 		ts_add(&msg->hwts.ts, -p->rx_timestamp_offset);
ab4723
-		clock_check_ts(p->clock, tmv_to_nanoseconds(msg->hwts.ts));
ab4723
+		if (p->state == PS_SLAVE) {
ab4723
+			clock_check_ts(p->clock,
ab4723
+				       tmv_to_nanoseconds(msg->hwts.ts));
ab4723
+		}
ab4723
 	}
ab4723
 
ab4723
 	switch (msg_type(msg)) {
ab4723
ab4723
commit 6df84259647757bc53818a039734f8ff85618c02
ab4723
Author: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
Date:   Mon May 31 11:07:55 2021 +0200
ab4723
ab4723
    port: Don't renew raw transport.
ab4723
    
ab4723
    Renewing of the transport on announce/sync timeout is needed in the
ab4723
    client-only mode to avoid getting stuck with a broken multicast socket
ab4723
    when the link goes down.
ab4723
    
ab4723
    This shouldn't be necessary with the raw transport. Closing and binding
ab4723
    of raw sockets can apparently be so slow that it triggers a false
ab4723
    positive in the clock check.
ab4723
    
ab4723
    Reported-by: Amar Subramanyam <asubramanyam@altiostar.com>
ab4723
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
ab4723
ab4723
diff --git a/port.c b/port.c
ab4723
index ec5c92e..c057591 100644
ab4723
--- a/port.c
ab4723
+++ b/port.c
ab4723
@@ -1811,6 +1811,12 @@ static int port_renew_transport(struct port *p)
ab4723
 	if (!port_is_enabled(p)) {
ab4723
 		return 0;
ab4723
 	}
ab4723
+
ab4723
+	/* Closing and binding of raw sockets is too slow and unnecessary */
ab4723
+	if (transport_type(p->trp) == TRANS_IEEE_802_3) {
ab4723
+		return 0;
ab4723
+	}
ab4723
+
ab4723
 	transport_close(p->trp, &p->fda);
ab4723
 	port_clear_fda(p, FD_FIRST_TIMER);
ab4723
 	res = transport_open(p->trp, p->iface, &p->fda, p->timestamping);
ab4723
ab4723
commit a082bcd700e4955ebaa00d7039bf4bce92048ac4
ab4723
Author: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
Date:   Mon May 31 11:07:56 2021 +0200
ab4723
ab4723
    clockcheck: Increase minimum interval.
ab4723
    
ab4723
    Increase the minimum check interval to 1 second to measure the frequency
ab4723
    offset more accurately and with default configuration make false
ab4723
    positives less likely due to a heavily overloaded system.
ab4723
    
ab4723
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
ab4723
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
ab4723
ab4723
diff --git a/clockcheck.c b/clockcheck.c
ab4723
index d0b4714..f0141be 100644
ab4723
--- a/clockcheck.c
ab4723
+++ b/clockcheck.c
ab4723
@@ -23,7 +23,7 @@
ab4723
 #include "clockcheck.h"
ab4723
 #include "print.h"
ab4723
 
ab4723
-#define CHECK_MIN_INTERVAL 100000000
ab4723
+#define CHECK_MIN_INTERVAL 1000000000
ab4723
 #define CHECK_MAX_FREQ 900000000
ab4723
 
ab4723
 struct clockcheck {