add option to set clockClass threshold

Resolves: #1979954
This commit is contained in:
Miroslav Lichvar 2021-08-02 16:08:53 +02:00
parent a83fd1a167
commit 0c71bd4bc2
2 changed files with 143 additions and 1 deletions

View File

@ -0,0 +1,138 @@
Backported commit f774703cb1eee058a346aec3341fee0be329bd6d
Author: Karthikkumar V <kvaloor@altiostar.com>
Date: Fri Feb 26 06:54:07 2021 +0000
Clock Class Threshold Feature addition for PTP4L
This code changes brings in the ability to program the acceptable
clockClass threshold beyond which device will move to holdover/free-run.
Default clockClass threshold is 248.
Example Use-Case:
This is needed in the cases where T-SC/T-BC Slave might want to listen
only on PRC clockCLass and anything beyond that might not be acceptible
and would want to go to holdover (with SyncE backup or internal oscillator).
Signed-off-by: Karthikkumar V <kvaloor@altiostar.com>
Signed-off-by: Ramana Reddy <rreddy@altiostar.com>
diff --git a/clock.c b/clock.c
index c1fcff6..d584748 100644
--- a/clock.c
+++ b/clock.c
@@ -114,6 +114,7 @@ struct clock {
int utc_offset;
int time_flags; /* grand master role */
int time_source; /* grand master role */
+ UInteger8 clock_class_threshold;
UInteger8 max_steps_removed;
enum servo_state servo_state;
enum timestamp_type timestamping;
@@ -978,6 +979,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
c->default_dataset.localPriority =
config_get_int(config, NULL, "G.8275.defaultDS.localPriority");
c->max_steps_removed = config_get_int(config, NULL,"maxStepsRemoved");
+ c->clock_class_threshold = config_get_int(config, NULL, "clock_class_threshold");
/* Harmonize the twoStepFlag with the time_stamping option. */
if (config_harmonize_onestep(config)) {
@@ -1711,6 +1713,11 @@ UInteger8 clock_max_steps_removed(struct clock *c)
return c->max_steps_removed;
}
+UInteger8 clock_get_clock_class_threshold(struct clock *c)
+{
+ return c->clock_class_threshold;
+}
+
UInteger16 clock_steps_removed(struct clock *c)
{
return c->cur.stepsRemoved;
diff --git a/clock.h b/clock.h
index e7daf97..845d54f 100644
--- a/clock.h
+++ b/clock.h
@@ -289,6 +289,13 @@ int clock_slave_only(struct clock *c);
*/
UInteger8 clock_max_steps_removed(struct clock *c);
+/**
+ * Obtain the clock class threshold field from a clock's default data set.
+ * @param c The clock instance.
+ * @return Configured clock class threshold value.
+ */
+UInteger8 clock_get_clock_class_threshold(struct clock *c);
+
/**
* Obtain the steps removed field from a clock's current data set.
* @param c The clock instance.
diff --git a/config.c b/config.c
index c3deddb..bf1049f 100644
--- a/config.c
+++ b/config.c
@@ -231,6 +231,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
GLOB_ITEM_STR("clockIdentity", "000000.0000.000000"),
+ GLOB_ITEM_INT("clock_class_threshold", CLOCK_CLASS_THRESHOLD_DEFAULT, 6, CLOCK_CLASS_THRESHOLD_DEFAULT),
GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu),
GLOB_ITEM_ENU("dataset_comparison", DS_CMP_IEEE1588, dataset_comp_enu),
diff --git a/configs/default.cfg b/configs/default.cfg
index 9604219..b2ffa94 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -60,6 +60,7 @@ verbose 0
summary_interval 0
kernel_leap 1
check_fup_sync 0
+clock_class_threshold 248
#
# Servo Options
#
diff --git a/ds.h b/ds.h
index 9d9c417..dff6d5e 100644
--- a/ds.h
+++ b/ds.h
@@ -87,6 +87,7 @@ struct parent_ds {
#define CURRENT_UTC_OFFSET 37 /* 1 Jan 2017 */
#define INTERNAL_OSCILLATOR 0xA0
+#define CLOCK_CLASS_THRESHOLD_DEFAULT 248
struct timePropertiesDS {
Integer16 currentUtcOffset;
diff --git a/port.c b/port.c
index 2bb974c..eb3b319 100644
--- a/port.c
+++ b/port.c
@@ -1870,6 +1870,14 @@ int process_announce(struct port *p, struct ptp_message *m)
return result;
}
+ if (m->announce.grandmasterClockQuality.clockClass >
+ clock_get_clock_class_threshold(p->clock)) {
+ pl_err(60, "port %hu: Master clock quality received is "
+ "greater than configured, ignoring master!",
+ portnum(p));
+ return result;
+ }
+
switch (p->state) {
case PS_INITIALIZING:
case PS_FAULTY:
diff --git a/ptp4l.8 b/ptp4l.8
index b04936a..ca76175 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -455,6 +455,11 @@ message is greater than or equal to the value of maxStepsRemoved the
Announce message is not considered in the operation of the BMCA.
The default value is 255.
.TP
+.B clock_class_threshold
+The maximum clock class value from master, acceptible to sub-ordinate
+clock beyond which it moves out of lock state.
+The default value is 248.
+.TP
.B domainNumber
The domain attribute of the local clock.

View File

@ -23,6 +23,8 @@ Source11: https://github.com/mlichvar/clknetsim/archive/%{clknetsim_ver}/clknets
# don't repeat some log messages in multi-port configuration
Patch1: linuxptp-logmsgs.patch
# add option to set clockClass threshold
Patch2: linuxptp-classthreshold.patch
# limit unicast message rate per address and grant duration
Patch4: linuxptp-ucastrate.patch
# fix quoting in ptp4l man page
@ -48,6 +50,7 @@ Supporting legacy APIs and other platforms is not a goal.
%prep
%setup -q -a 10 -a 11 -n %{name}-%{!?gitfullver:%{version}}%{?gitfullver}
%patch1 -p1 -b .logmsgs
%patch2 -p1 -b .classthreshold
%patch4 -p1 -b .ucastrate
%patch7 -p1 -b .manfix
%patch8 -p1 -b .fclose
@ -75,7 +78,8 @@ echo 'OPTIONS="-a -r"' > $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/phc2sys
echo '.so man8/ptp4l.8' > $RPM_BUILD_ROOT%{_mandir}/man5/ptp4l.conf.5
echo '.so man8/timemaster.8' > $RPM_BUILD_ROOT%{_mandir}/man5/timemaster.conf.5
rm -f configs/snmpd.conf
# Remove patch backup files and non-linuxptp configuration
find configs -type f ! -name '*.cfg' -delete
%check
cd testsuite