integ/base/linuxptp/debian/patches/0002-clock-Reset-clock-check-on-best-clock-port-change.patch
Andre Mauricio Zelak 4a94f788a4 Select the clock matching requirements
Fix clock selection algorithm behavior where a clock source starts
to match requirements but is not selected because it has the same
ha_priority than active.

In a HA configuration with two or more clocks configured with equal
ha_priority if no clock source matches the requirements the first one
in the configuration file is selected active. This is a standard
behavior to always have a clock source, even when they are not
synchronized.

When one of the clock sources starts to match the requirements it
must be selected active, regardless of the priority.

But when a second clock source starts to match the requirements and
has the same ha_priority as the active, the active remains the clock
source. There is no need to switch active when they have equal
ha_priority.

Test plan: two sources with the same priority
PASS: Verify a clock source is selected active when it starts to match
the requirements and the current active doesn't match them, even if
they have equal ha_priority.
PASS: Verify a clock source isn't selected active when it starts to
match the requirements and the current active also matches them.

Regression: two sources with different priority
PASS: Verify a clock source is selected active when it starts to match
the requirements and the current active doesn't match them, even if
their ha_priority is lower than the actives.
PASS: Verify a clock source is selected active when it starts to match
the requirements and the current active also matches them but has
lower ha_priority configured.
PASS: Verify a clock source isn't selected active when it starts to
match the requirements and the current active also matches them
and has higher ha_priority configured.

Story: 2010723
Task: 48699

Change-Id: If80532b7b8febcc164f7c748a8d4122b4f10fd3b
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
2023-09-05 11:26:10 -03:00

80 lines
2.6 KiB
Diff

From 1779482f39e6513995b13fdbd350f7aee8495b7e Mon Sep 17 00:00:00 2001
Message-Id: <1779482f39e6513995b13fdbd350f7aee8495b7e.1630418391.git.Jim.Somerville@windriver.com>
In-Reply-To: <0389752e3aecf8d2b2743f16ce1408a58088bea9.1630418391.git.Jim.Somerville@windriver.com>
References: <0389752e3aecf8d2b2743f16ce1408a58088bea9.1630418391.git.Jim.Somerville@windriver.com>
From: Miroslav Lichvar <mlichvar@redhat.com>
Date: Mon, 31 May 2021 11:07:53 +0200
Subject: [PATCH 2/50] clock: Reset clock check on best clock/port change.
Reset the clock check when the best clock or port changes, together with
the other state like current estimated delay and frequency. This avoids
false positives if the clock is controlled by an external process when
not synchronized by PTP (e.g. phc2sys -rr).
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
[commit 262a49b07eaccc0f0237e3cd4df01b185b8f664f upstream]
Signed-off-by: Jim Somerville <Jim.Somerville@windriver.com>
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
---
clock.c | 2 ++
clockcheck.c | 9 ++++++++-
clockcheck.h | 6 ++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/clock.c b/clock.c
index d955710..49bd4a9 100644
--- a/clock.c
+++ b/clock.c
@@ -1911,6 +1911,8 @@ static void handle_state_decision_event(struct clock *c)
if (!cid_eq(&best_id, &c->best_id) || best != c->best) {
clock_freq_est_reset(c);
+ if (c->sanity_check)
+ clockcheck_reset(c->sanity_check);
tsproc_reset(c->tsproc, 1);
if (!tmv_is_zero(c->initial_delay))
tsproc_set_delay(c->tsproc, c->initial_delay);
diff --git a/clockcheck.c b/clockcheck.c
index d48a578..d0b4714 100644
--- a/clockcheck.c
+++ b/clockcheck.c
@@ -47,9 +47,16 @@ struct clockcheck *clockcheck_create(int freq_limit)
if (!cc)
return NULL;
cc->freq_limit = freq_limit;
+ clockcheck_reset(cc);
+ return cc;
+}
+
+void clockcheck_reset(struct clockcheck *cc)
+{
+ cc->freq_known = 0;
cc->max_freq = -CHECK_MAX_FREQ;
cc->min_freq = CHECK_MAX_FREQ;
- return cc;
+ cc->last_ts = 0;
}
int clockcheck_sample(struct clockcheck *cc, uint64_t ts)
diff --git a/clockcheck.h b/clockcheck.h
index 78aca48..1ff86eb 100644
--- a/clockcheck.h
+++ b/clockcheck.h
@@ -33,6 +33,12 @@ struct clockcheck;
*/
struct clockcheck *clockcheck_create(int freq_limit);
+/**
+ * Reset a clock check.
+ * @param cc Pointer to a clock check obtained via @ref clockcheck_create().
+ */
+void clockcheck_reset(struct clockcheck *cc);
+
/**
* Perform the sanity check on a time stamp.
* @param cc Pointer to a clock check obtained via @ref clockcheck_create().
--
2.29.2