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