dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-clockcheck.patch

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