dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame linuxptp-clockcheck.patch

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