Add collection of linuxptp patches

This commit applies several patches to the linuxptp srpm in order to
address an issue syncing multiple interfaces on a ptp node. The srpm
used is linuxptp-2.0-2.el7.src.rpm.

Patch descriptions:
base/linuxptp/centos/meta_patches:
0001 updates the srpm spec file to apply the patches during build
0002 updates the package versioning to comply with the STX format

base/linuxptp/centos/patches:
Patches 0001-0005 combine to correct a fault present when a ptp node is
configured with multiple clocks in jbod mode which results in the client
port getting stuck in the UNCALIBRATED state and unable to lock to the
Grandmaster clock. The root of the issue lies in the sanity check where
checking timestamps recieved on multiple ports will result in the
sanity_freq_limit threshold constantly being reached and the servo for
that port is repeatedly reset, preventing it from ever syncing.

The changes in patches 0001-0005 have been written by Miroslav Lichvar
on the linuxptp-devel mailing list. They are currently under review and
testing by the upstream linuxptp maintainers prior to merging. I was
able to apply them as-is to linuxptp v2.0. I have chosen to keep them as
individual patches, as that is how they will appear upstream.

Patch 0006 is my work and serves to address an issue in phc2sys
where the local ptp clocks are not synced together properly if the local
time is far behind the reference time. This issue ocurrs when phc2sys
starts and there is no client port currently synced to a grandmaster. In
the original behaviour, phc2sys selects the first configured port and
proceeds to sync all of the other clocks to it by performing the
first_step operation.

Then ptp4l will evenually lock to the Grandmaster clock, and that
single port will have its time updated to the correct value, but
phc2sys has already performed the first_step operation and will not
step the other clocks again.

My solution is to provide an option to disable the selection of a
default port by phc2sys. When no default port is selected, phc2sys waits
for ptp4l to sync to the Grandmaster before bringing the other clocks
into sync with the first_step operation.

This option is configured via the default_sync
parameter or the -D flag. The default_sync parameter is set to on by
default to in order to keep the behaviour the same as upstream linuxptp
but can be configured by users via
system service-parameter-add ptp global default_sync=0

Closes-Bug: 1930607

Signed-off-by: Cole Walker <cole.walker@windriver.com>
Change-Id: I2f660787c6753dcd4fc4c51da7b08ab9e6f197f4
This commit is contained in:
Cole Walker 2021-06-24 14:49:51 -04:00
parent 3cec8b6ac9
commit 1f4538df28
15 changed files with 380 additions and 0 deletions

18
base/linuxptp/PKG-INFO Normal file
View File

@ -0,0 +1,18 @@
Metadata-Version: 1.1
Name: linuxptp
Version: 2.0-2
Summary: linuxptp
Home-page: http://linuxptp.sourceforge.net/
Author:
Author-email:
License: GPLv2
Description:
This software is an implementation of the Precision Time Protocol (PTP)
according to IEEE standard 1588 for Linux. The dual design goals are to
provide a robust implementation of the standard and to use the most
relevant and modern Application Programming Interfaces (API) offered by
the Linux kernel. Supporting legacy APIs and other platforms is not a
goal.
Platform: UNKNOWN

View File

@ -0,0 +1 @@
TIS_PATCH_VER=PKG_GITREVCOUNT

View File

@ -0,0 +1,25 @@
From dce66cbf8eb0a132592039934629f4ceea6fed6f Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Mon, 21 Jun 2021 15:24:03 -0400
Subject: [PATCH] Update package versioning for STX format
---
SPECS/linuxptp.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SPECS/linuxptp.spec b/SPECS/linuxptp.spec
index 6d97f12..60f340f 100644
--- a/SPECS/linuxptp.spec
+++ b/SPECS/linuxptp.spec
@@ -3,7 +3,7 @@
%global clknetsim_ver 8b4842
Name: linuxptp
Version: 2.0
-Release: 2%{?dist}
+Release: 2%{?_tis_dist}.%{tis_patch_ver}
Summary: PTP implementation for Linux
Group: System Environment/Base
--
2.29.2

View File

@ -0,0 +1,48 @@
From 2b59f59616f4c9d27ee094f5099011f3015d90c8 Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 13:21:58 -0400
Subject: [PATCH] STX patches for default_sync and BC performance
---
SPECS/linuxptp.spec | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/SPECS/linuxptp.spec b/SPECS/linuxptp.spec
index 3f91582..63c4246 100644
--- a/SPECS/linuxptp.spec
+++ b/SPECS/linuxptp.spec
@@ -34,6 +34,18 @@ Patch5: linuxptp-team.patch
Patch6: linuxptp-addreq.patch
# don't leak memory when allocation fails
Patch7: linuxptp-msgput.patch
+# StarlingX
+Patch8: 0001-p1-Reset-state-when-switching-port-with-same-best-cl.patch
+# StarlingX
+Patch9: 0002-p2-Reset-clock-check-on-best-clock-port-change.patch
+# StarlingX
+Patch10: 0003-p3-Only-check-timestamps-from-uncalibrated-and-slave.patch
+# StarlingX
+Patch11: 0004-p4-Do-not-renew-raw-transport-sockets.patch
+# StarlingX
+Patch12: 0005-p5-Increase-the-minimum-clockcheck-interval-for-stab.patch
+# StarlingX
+Patch13: 0006-Add-option-to-disable-default-port-selection-in-phc2.patch
BuildRequires: kernel-headers > 3.10.0-1002
BuildRequires: systemd-units
@@ -58,6 +70,12 @@ Supporting legacy APIs and other platforms is not a goal.
%patch5 -p1 -b .team
%patch6 -p1 -b .addreq
%patch7 -p1 -b .msgput
+%patch8 -p1
+%patch9 -p1
+%patch10 -p1
+%patch11 -p1
+%patch12 -p1
+%patch13 -p1
mv linuxptp-testsuite-%{testsuite_ver}* testsuite
mv clknetsim-%{clknetsim_ver}* testsuite/clknetsim
--
2.29.2

View File

@ -0,0 +1,2 @@
0001-Update-package-versioning-for-STX-format.patch
0002-STX-patches-for-default_sync-and-BC-performance.patch

View File

@ -0,0 +1,25 @@
From fe89b71514d21e296988c540ed8a11f98307c36c Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 10:20:19 -0400
Subject: [PATCH 1/6] p1 Reset state when switching port with same best clock
---
clock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clock.c b/clock.c
index 9bbcefa..9fad542 100644
--- a/clock.c
+++ b/clock.c
@@ -1737,7 +1737,7 @@ static void handle_state_decision_event(struct clock *c)
cid2str(&best_id));
}
- if (!cid_eq(&best_id, &c->best_id)) {
+ if (!cid_eq(&best_id, &c->best_id) || best != c->best) {
clock_freq_est_reset(c);
tsproc_reset(c->tsproc, 1);
if (!tmv_is_zero(c->initial_delay))
--
2.29.2

View File

@ -0,0 +1,67 @@
From da48222456566d63a940810733ff369895777bda Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 10:21:45 -0400
Subject: [PATCH 2/6] p2 Reset clock check on best clock port change
---
clock.c | 2 ++
clockcheck.c | 9 ++++++++-
clockcheck.h | 7 +++++++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/clock.c b/clock.c
index 9fad542..7a66770 100644
--- a/clock.c
+++ b/clock.c
@@ -1739,6 +1739,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..544ce9b 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..6c02ce3 100644
--- a/clockcheck.h
+++ b/clockcheck.h
@@ -33,6 +33,13 @@ 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

View File

@ -0,0 +1,35 @@
From 8b4e9d4aad5e3b997838e1186b00403393309d35 Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 10:25:11 -0400
Subject: [PATCH 3/6] p3 Only check timestamps from uncalibrated and slave
ports
---
port.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/port.c b/port.c
index c945c13..affa48b 100644
--- a/port.c
+++ b/port.c
@@ -2541,10 +2541,13 @@ static enum fsm_event bc_event(struct port *p, int fd_index)
msg_put(msg);
return EV_NONE;
}
- if (msg_sots_valid(msg)) {
- ts_add(&msg->hwts.ts, -p->rx_timestamp_offset);
- clock_check_ts(p->clock, tmv_to_nanoseconds(msg->hwts.ts));
- }
+ if (msg_sots_valid(msg)) {
+ ts_add(&msg->hwts.ts, -p->rx_timestamp_offset);
+ if (p->state == PS_SLAVE || p->state == PS_UNCALIBRATED) {
+ clock_check_ts(p->clock,
+ tmv_to_nanoseconds(msg->hwts.ts));
+ }
+ }
switch (msg_type(msg)) {
case SYNC:
--
2.29.2

View File

@ -0,0 +1,31 @@
From 9587b2ed9460a6c5fc50166d94cb43814c4c3a32 Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 10:32:41 -0400
Subject: [PATCH 4/6] p4 Do not renew raw transport sockets
---
port.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/port.c b/port.c
index affa48b..c96389a 100644
--- a/port.c
+++ b/port.c
@@ -1650,6 +1650,14 @@ static int port_renew_transport(struct port *p)
if (!port_is_enabled(p)) {
return 0;
}
+
+
+ /* Closing and binding of raw sockets is too slow and unnecessary */
+ if (transport_type(p->trp) == TRANS_IEEE_802_3) {
+ return 0;
+ }
+
+
transport_close(p->trp, &p->fda);
port_clear_fda(p, FD_FIRST_TIMER);
res = transport_open(p->trp, p->iface, &p->fda, p->timestamping);
--
2.29.2

View File

@ -0,0 +1,25 @@
From 6463b1a125e270d7bdb58d2bf4bc1156bf4aa993 Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 10:33:35 -0400
Subject: [PATCH 5/6] p5 Increase the minimum clockcheck interval for stability
---
clockcheck.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clockcheck.c b/clockcheck.c
index 544ce9b..2588f7b 100644
--- a/clockcheck.c
+++ b/clockcheck.c
@@ -23,7 +23,7 @@
#include "clockcheck.h"
#include "print.h"
-#define CHECK_MIN_INTERVAL 100000000
+#define CHECK_MIN_INTERVAL 1000000000
#define CHECK_MAX_FREQ 900000000
struct clockcheck {
--
2.29.2

View File

@ -0,0 +1,97 @@
From 9f3a0a3df4346fa15ed6573cc57092baba37354e Mon Sep 17 00:00:00 2001
From: Cole Walker <cole.walker@windriver.com>
Date: Wed, 23 Jun 2021 11:14:41 -0400
Subject: [PATCH 6/6] Add option to disable default port selection in phc2sys
---
config.c | 1 +
phc2sys.c | 19 ++++++++++++++-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/config.c b/config.c
index 7914ba4..de5e68e 100644
--- a/config.c
+++ b/config.c
@@ -273,6 +273,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_STR("userDescription", ""),
GLOB_ITEM_INT("utc_offset", CURRENT_UTC_OFFSET, 0, INT_MAX),
GLOB_ITEM_INT("verbose", 0, 0, 1),
+ GLOB_ITEM_INT("default_sync", 1, 0, 1),
};
static struct unicast_master_table *current_uc_mtab;
diff --git a/phc2sys.c b/phc2sys.c
index b8f1ea0..45dba55 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -120,6 +120,7 @@ struct node {
LIST_HEAD(clock_head, clock) clocks;
LIST_HEAD(dst_clock_head, clock) dst_clocks;
struct clock *master;
+ int default_sync;
};
static struct config *phc2sys_config;
@@ -465,7 +466,7 @@ static void reconfigure(struct node *node)
}
last = c;
}
- if (dst_cnt > 1 && !src) {
+ if (dst_cnt > 1 && !src && node->default_sync) {
if (!rt || rt->dest_only) {
node->master = last;
/* Reset to original state in next reconfiguration. */
@@ -1363,6 +1364,7 @@ static void usage(char *progname)
" -N [num] number of master clock readings per update (5)\n"
" -L [limit] sanity frequency limit in ppb (200000000)\n"
" -M [num] NTP SHM segment number (0)\n"
+ " -D [num] fall back to default clock in automatic mode (1)\n"
" -u [num] number of clock updates in summary stats (0)\n"
" -n [num] domain number (0)\n"
" -x apply leap seconds by servo instead of kernel\n"
@@ -1383,7 +1385,7 @@ int main(int argc, char *argv[])
struct clock *src, *dst;
struct config *cfg;
struct option *opts;
- int autocfg = 0, c, domain_number = 0, index, ntpshm_segment;
+ int autocfg = 0, c, domain_number = 0, default_sync = 1, index, ntpshm_segment;
int pps_fd = -1, print_level = LOG_INFO, r = -1, rt = 0, wait_sync = 0;
double phc_rate, tmp;
struct node node = {
@@ -1407,7 +1409,7 @@ int main(int argc, char *argv[])
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
while (EOF != (c = getopt_long(argc, argv,
- "arc:d:f:s:E:P:I:S:F:R:N:O:L:M:i:u:wn:xz:l:t:mqvh",
+ "arc:d:f:s:E:P:I:S:F:R:N:O:L:M:D:i:u:wn:xz:l:t:mqvh",
opts, &index))) {
switch (c) {
case 0:
@@ -1559,6 +1561,12 @@ int main(int argc, char *argv[])
version_show(stdout);
config_destroy(cfg);
return 0;
+ case 'D':
+ if (get_arg_val_i(c, optarg, &default_sync, 0, 1) ||
+ config_set_int(cfg, "default_sync", default_sync)) {
+ goto end;
+ }
+ break;
case 'h':
usage(progname);
config_destroy(cfg);
@@ -1607,8 +1615,9 @@ int main(int argc, char *argv[])
}
node.kernel_leap = config_get_int(cfg, NULL, "kernel_leap");
node.sanity_freq_limit = config_get_int(cfg, NULL, "sanity_freq_limit");
-
- if (autocfg) {
+ node.default_sync = config_get_int(cfg, NULL, "default_sync");
+
+ if (autocfg) {
if (init_pmc(cfg, &node))
goto end;
if (auto_init_ports(&node, rt) < 0)
--
2.29.2

View File

@ -0,0 +1 @@
mirror:Source/linuxptp-2.0-2.el7.src.rpm

View File

@ -112,6 +112,9 @@ lighttpd-fastcgi
lighttpd-mod_geoip lighttpd-mod_geoip
lighttpd-mod_mysql_vhost lighttpd-mod_mysql_vhost
# linuxptp
linuxptp
# logrotate # logrotate
logrotate logrotate

View File

@ -1,6 +1,7 @@
base/initscripts base/initscripts
base/setup base/setup
base/dhcp base/dhcp
base/linuxptp
base/openssh base/openssh
config/facter config/facter
virt/qemu virt/qemu

View File

@ -9,6 +9,7 @@ haproxy-1.5.18-8.el7.src.rpm
initscripts-9.49.46-1.el7.src.rpm initscripts-9.49.46-1.el7.src.rpm
libevent-2.0.21-4.el7.src.rpm libevent-2.0.21-4.el7.src.rpm
lighttpd-1.4.54-1.el7.src.rpm lighttpd-1.4.54-1.el7.src.rpm
linuxptp-2.0-2.el7.src.rpm
logrotate-3.8.6-17.el7.src.rpm logrotate-3.8.6-17.el7.src.rpm
net-tools-2.0-0.24.20131004git.el7.src.rpm net-tools-2.0-0.24.20131004git.el7.src.rpm
ntp-4.2.6p5-29.el7.centos.2.src.rpm ntp-4.2.6p5-29.el7.centos.2.src.rpm