dcavalca / rpms / linuxptp

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