From 753c2fe35c69a7ea6d62cf916a251483a7e6d801 Mon Sep 17 00:00:00 2001 From: Yue Tao Date: Wed, 24 Nov 2021 15:49:14 +0800 Subject: [PATCH] linuxptp: add debian package Porting all patches from CentOS. Using the version 3.1.1-2 to align with CentOS version rather than the default version 3.1-2.1 of Debian Bullseye. Test Plan: building, install and booting Pass: build test Pass: install image Pass: boot up on qemu Story: 2009221 Task: 44053 Signed-off-by: Yue Tao Change-Id: I599f9244efe405a8b477d266696f4ac734aef6b5 --- base/linuxptp/debian/meta_data.yaml | 9 ++ ...e-when-switching-port-with-same-best.patch | 34 +++++ ...lock-check-on-best-clock-port-change.patch | 78 +++++++++++ ...heck-timestamps-from-non-slave-ports.patch | 39 ++++++ .../0004-port-Don-t-renew-raw-transport.patch | 45 +++++++ ...clockcheck-Increase-minimum-interval.patch | 36 ++++++ ...sable-default-port-selection-in-phc2.patch | 121 ++++++++++++++++++ base/linuxptp/debian/patches/series | 6 + 8 files changed, 368 insertions(+) create mode 100644 base/linuxptp/debian/meta_data.yaml create mode 100644 base/linuxptp/debian/patches/0001-clock-Reset-state-when-switching-port-with-same-best.patch create mode 100644 base/linuxptp/debian/patches/0002-clock-Reset-clock-check-on-best-clock-port-change.patch create mode 100644 base/linuxptp/debian/patches/0003-port-Don-t-check-timestamps-from-non-slave-ports.patch create mode 100644 base/linuxptp/debian/patches/0004-port-Don-t-renew-raw-transport.patch create mode 100644 base/linuxptp/debian/patches/0005-clockcheck-Increase-minimum-interval.patch create mode 100644 base/linuxptp/debian/patches/0006-Add-option-to-disable-default-port-selection-in-phc2.patch create mode 100644 base/linuxptp/debian/patches/series diff --git a/base/linuxptp/debian/meta_data.yaml b/base/linuxptp/debian/meta_data.yaml new file mode 100644 index 000000000..968041390 --- /dev/null +++ b/base/linuxptp/debian/meta_data.yaml @@ -0,0 +1,9 @@ +--- +debver: 3.1.1-2 +dl_path: + name: linuxptp-debian-3.1.1-2.tar.gz + url: https://salsa.debian.org/multimedia-team/linuxptp/-/archive/debian/3.1.1-2/linuxptp-debian-3.1.1-2.tar.gz + md5sum: 6b8a81cfe8dbb0fd031e892393db0519 +revision: + dist: $STX_DIST + PKG_GITREVCOUNT: true diff --git a/base/linuxptp/debian/patches/0001-clock-Reset-state-when-switching-port-with-same-best.patch b/base/linuxptp/debian/patches/0001-clock-Reset-state-when-switching-port-with-same-best.patch new file mode 100644 index 000000000..d2a0108ce --- /dev/null +++ b/base/linuxptp/debian/patches/0001-clock-Reset-state-when-switching-port-with-same-best.patch @@ -0,0 +1,34 @@ +From 63b43924294da6cb177d0509120b2e957580441c Mon Sep 17 00:00:00 2001 +From: Miroslav Lichvar +Date: Mon, 31 May 2021 11:07:52 +0200 +Subject: [PATCH] clock: Reset state when switching port with same best clock. + +When the best port is changed, but the ID of the best clock doesn't +change (e.g. a passive port is activated on link failure), reset the +current delay and other master/link-specific state to avoid the switch +throwing the clock off. + +Reviewed-by: Jacob Keller +Signed-off-by: Miroslav Lichvar +[commit 7e8eba5332671abfd95d06dd191059eded1d2cca upstream] +Signed-off-by: Jim Somerville +--- + clock.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/clock.c b/clock.c +index a66d189..96453f4 100644 +--- a/clock.c ++++ b/clock.c +@@ -1857,7 +1857,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.25.1 + diff --git a/base/linuxptp/debian/patches/0002-clock-Reset-clock-check-on-best-clock-port-change.patch b/base/linuxptp/debian/patches/0002-clock-Reset-clock-check-on-best-clock-port-change.patch new file mode 100644 index 000000000..e37c53295 --- /dev/null +++ b/base/linuxptp/debian/patches/0002-clock-Reset-clock-check-on-best-clock-port-change.patch @@ -0,0 +1,78 @@ +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 +Date: Mon, 31 May 2021 11:07:53 +0200 +Subject: [PATCH 2/6] 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 +Signed-off-by: Miroslav Lichvar +[commit 262a49b07eaccc0f0237e3cd4df01b185b8f664f upstream] +Signed-off-by: Jim Somerville +--- + 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 + diff --git a/base/linuxptp/debian/patches/0003-port-Don-t-check-timestamps-from-non-slave-ports.patch b/base/linuxptp/debian/patches/0003-port-Don-t-check-timestamps-from-non-slave-ports.patch new file mode 100644 index 000000000..f3dcde6c6 --- /dev/null +++ b/base/linuxptp/debian/patches/0003-port-Don-t-check-timestamps-from-non-slave-ports.patch @@ -0,0 +1,39 @@ +From a1ed560a712d611edf8b47756bc56542a57bff7d Mon Sep 17 00:00:00 2001 +Message-Id: +In-Reply-To: <0389752e3aecf8d2b2743f16ce1408a58088bea9.1630418391.git.Jim.Somerville@windriver.com> +References: <0389752e3aecf8d2b2743f16ce1408a58088bea9.1630418391.git.Jim.Somerville@windriver.com> +From: Miroslav Lichvar +Date: Mon, 31 May 2021 11:07:54 +0200 +Subject: [PATCH 3/6] port: Don't check timestamps from non-slave ports. + +Don't perform the sanity check on receive timestamps from ports in +non-slave states to avoid false positives in the jbod mode, where +the timestamps can be generated by different clocks. + +Reviewed-by: Jacob Keller +Signed-off-by: Miroslav Lichvar +[commit e117e37e379556fa23337db2518bb44d8793e039 upstream] +Signed-off-by: Jim Somerville +--- + port.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/port.c b/port.c +index 9e9d484..387d5a2 100644 +--- a/port.c ++++ b/port.c +@@ -2731,7 +2731,10 @@ static enum fsm_event bc_event(struct port *p, int fd_index) + } + 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 (p->state == PS_SLAVE) { ++ clock_check_ts(p->clock, ++ tmv_to_nanoseconds(msg->hwts.ts)); ++ } + } + + switch (msg_type(msg)) { +-- +2.29.2 + diff --git a/base/linuxptp/debian/patches/0004-port-Don-t-renew-raw-transport.patch b/base/linuxptp/debian/patches/0004-port-Don-t-renew-raw-transport.patch new file mode 100644 index 000000000..0675f3d99 --- /dev/null +++ b/base/linuxptp/debian/patches/0004-port-Don-t-renew-raw-transport.patch @@ -0,0 +1,45 @@ +From 5caa4d0a9161e6a33e269c8e445b322e4437e6b3 Mon Sep 17 00:00:00 2001 +Message-Id: <5caa4d0a9161e6a33e269c8e445b322e4437e6b3.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 +Date: Mon, 31 May 2021 11:07:55 +0200 +Subject: [PATCH 4/6] port: Don't renew raw transport. + +Renewing of the transport on announce/sync timeout is needed in the +client-only mode to avoid getting stuck with a broken multicast socket +when the link goes down. + +This shouldn't be necessary with the raw transport. Closing and binding +of raw sockets can apparently be so slow that it triggers a false +positive in the clock check. + +Reported-by: Amar Subramanyam +Signed-off-by: Miroslav Lichvar +Reviewed-by: Jacob Keller +[commit 6df84259647757bc53818a039734f8ff85618c02 upstream] +Signed-off-by: Jim Somerville +--- + port.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/port.c b/port.c +index 387d5a2..d26b87f 100644 +--- a/port.c ++++ b/port.c +@@ -1805,6 +1805,12 @@ 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 + diff --git a/base/linuxptp/debian/patches/0005-clockcheck-Increase-minimum-interval.patch b/base/linuxptp/debian/patches/0005-clockcheck-Increase-minimum-interval.patch new file mode 100644 index 000000000..eca0fdc2c --- /dev/null +++ b/base/linuxptp/debian/patches/0005-clockcheck-Increase-minimum-interval.patch @@ -0,0 +1,36 @@ +From 3bf4f1784fa0a03a252961f400a78d963773f8f5 Mon Sep 17 00:00:00 2001 +Message-Id: <3bf4f1784fa0a03a252961f400a78d963773f8f5.1630611367.git.Jim.Somerville@windriver.com> +In-Reply-To: <0389752e3aecf8d2b2743f16ce1408a58088bea9.1630611367.git.Jim.Somerville@windriver.com> +References: <0389752e3aecf8d2b2743f16ce1408a58088bea9.1630611367.git.Jim.Somerville@windriver.com> +From: Miroslav Lichvar +Date: Mon, 31 May 2021 11:07:56 +0200 +Subject: [PATCH 5/6] clockcheck: Increase minimum interval. + +Increase the minimum check interval to 1 second to measure the frequency +offset more accurately and with default configuration make false +positives less likely due to a heavily overloaded system. + +Signed-off-by: Miroslav Lichvar +Reviewed-by: Jacob Keller +[commit a082bcd700e4955ebaa00d7039bf4bce92048ac4 upstream] +Signed-off-by: Jim Somerville +--- + clockcheck.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/clockcheck.c b/clockcheck.c +index d0b4714..f0141be 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 + diff --git a/base/linuxptp/debian/patches/0006-Add-option-to-disable-default-port-selection-in-phc2.patch b/base/linuxptp/debian/patches/0006-Add-option-to-disable-default-port-selection-in-phc2.patch new file mode 100644 index 000000000..f609cd1a8 --- /dev/null +++ b/base/linuxptp/debian/patches/0006-Add-option-to-disable-default-port-selection-in-phc2.patch @@ -0,0 +1,121 @@ +From 3a6de7b6208ccc64a20474db15abaac08e99d10b Mon Sep 17 00:00:00 2001 +Message-Id: <3a6de7b6208ccc64a20474db15abaac08e99d10b.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: Cole Walker +Date: Wed, 23 Jun 2021 11:14:41 -0400 +Subject: [PATCH 6/6] Add option to disable default port selection in phc2sys + +This change 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 occurs 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. + +This solution provides 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 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 + +Signed-off-by: Jim Somerville +--- + config.c | 1 + + phc2sys.c | 15 ++++++++++++--- + 2 files changed, 13 insertions(+), 3 deletions(-) + +diff --git a/config.c b/config.c +index ef5e833..cab7e4f 100644 +--- a/config.c ++++ b/config.c +@@ -333,6 +333,7 @@ struct config_item config_tab[] = { + GLOB_ITEM_INT("utc_offset", CURRENT_UTC_OFFSET, 0, INT_MAX), + GLOB_ITEM_INT("verbose", 0, 0, 1), + GLOB_ITEM_INT("write_phase_mode", 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 a36cbe0..44d6872 100644 +--- a/phc2sys.c ++++ b/phc2sys.c +@@ -120,6 +120,7 @@ struct phc2sys_private { + 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; +@@ -437,7 +438,7 @@ static void reconfigure(struct phc2sys_private *priv) + } + last = c; + } +- if (dst_cnt > 1 && !src) { ++ if (dst_cnt > 1 && !src && priv->default_sync) { + if (!rt || rt->dest_only) { + priv->master = last; + /* Reset to original state in next reconfiguration. */ +@@ -1344,6 +1345,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" +@@ -1364,7 +1366,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 phc2sys_private priv = { +@@ -1388,7 +1390,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: +@@ -1540,6 +1542,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); +@@ -1588,6 +1596,7 @@ int main(int argc, char *argv[]) + } + priv.kernel_leap = config_get_int(cfg, NULL, "kernel_leap"); + priv.sanity_freq_limit = config_get_int(cfg, NULL, "sanity_freq_limit"); ++ priv.default_sync = config_get_int(cfg, NULL, "default_sync"); + + if (autocfg) { + if (init_pmc(cfg, &priv)) +-- +2.29.2 + diff --git a/base/linuxptp/debian/patches/series b/base/linuxptp/debian/patches/series new file mode 100644 index 000000000..a53e97388 --- /dev/null +++ b/base/linuxptp/debian/patches/series @@ -0,0 +1,6 @@ +0001-clock-Reset-state-when-switching-port-with-same-best.patch +0002-clock-Reset-clock-check-on-best-clock-port-change.patch +0003-port-Don-t-check-timestamps-from-non-slave-ports.patch +0004-port-Don-t-renew-raw-transport.patch +0005-clockcheck-Increase-minimum-interval.patch +0006-Add-option-to-disable-default-port-selection-in-phc2.patch