integ/base/linuxptp/debian/patches/0046-Robustness-improvements-to-phc2sys-socket.patch
Cole Walker aca42c6d4c Implement logic to skip updates with offset spike in ts2phc.
This change allows ts2phc to be configured to ignore timing updates that
have a large offset spike in order to mitigate the resulting timing
skew.

In some circumstances on realtime systems with high CPU load, the
timestamp consumed by ts2phc can be delayed in reaching ts2phc and
results in the offset calculation attempting to speed the clock up by a
large margin.

This change causes ts2phc to ignore updates that would greatly skew the
clock when ts2phc is already in a synchronized state.

The global configuration option "max_phc_update_skip_cnt" is provided to
allow users to specify how many consecutive offset spike incidents will
be ignored before adjusting the clock. The default value is 120. The
behaviour can be disabled by setting max_phc_update_skip_cnt to 0.

This code is ported from a proposed upstream patch found here:
https://sourceforge.net/p/linuxptp/mailman/message/44114092/

Test-plan:
Pass: Verify linuxptp package build
Pass: Deploy ts2phc binary and verify system time sync
Pass: Manually trigger offset spike and verify that ts2phc maintains
stable time sync

Closes-bug: https://bugs.launchpad.net/starlingx/+bug/2059955

Change-Id: I13cd5c3440682ec9256e11449fe62d5fe28f66fa
Signed-off-by: Cole Walker <cole.walker@windriver.com>
2024-04-01 14:53:06 -04:00

79 lines
2.5 KiB
Diff

From d14df9d1f0b239c2a5fbe587875448a2d10b12a6 Mon Sep 17 00:00:00 2001
From: Andre Mauricio Zelak <andre.zelak@windriver.com>
Date: Tue, 8 Aug 2023 14:06:55 -0300
Subject: [PATCH 46/58] Robustness improvements to phc2sys socket
When phc2sys abnormally exits the socket file might remain created.
To avoid error when phc2sys is relaunched, the exixting file is
deleted before recriating the socket.
If the peer application closes the socket before sending the
response completely, it will cause a broken pipe error. The
send function generates a SIGPIPE on broken pipe errors,
killing the phc2sys process unless MSG_NOSIGNAL flag is set.
Test plan: socket file
PASS: Verify that phc2sys can restart normally after killing it.
Test plan: SIGPIPE
PASS: Verify the phc2sys application don't exit when client socket
is closed before the respose is sent.
Reviewed-by: Cole Walker <cole.walker@windriver.com>
Reviewed-by: Andre Fernando Zanella Kantek
<andrefernandozanella.kantek@windriver.com>
[commit 8b3765b3f104a90a487fbcb0f61074c7677c215e upstream]
[commit 50ad1c6f81a706b8be6689bea2ba2db215cf3dc3 upstream]
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
---
phc2sys.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/phc2sys.c b/phc2sys.c
index 6965162..edc626f 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1218,7 +1218,9 @@ static int ha_com_socket_open(int *fd_out, struct config *cfg)
int fd, err;
struct sockaddr_un sa;
const int backlog = 50;
- const char *name = config_get_string(cfg, NULL, "ha_phc2sys_com_socket");
+ const char *path = config_get_string(cfg, NULL, "ha_phc2sys_com_socket");
+
+ unlink(path);
fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (fd < 0) {
@@ -1228,7 +1230,7 @@ static int ha_com_socket_open(int *fd_out, struct config *cfg)
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_LOCAL;
- strncpy(sa.sun_path, name, sizeof(sa.sun_path) - 1);
+ strncpy(sa.sun_path, path, sizeof(sa.sun_path) - 1);
err = bind(fd, (struct sockaddr *) &sa, sizeof(sa));
if (err < 0) {
@@ -1245,7 +1247,7 @@ static int ha_com_socket_open(int *fd_out, struct config *cfg)
}
*fd_out = fd;
- chmod(name, HA_SCK_FILEMODE);
+ chmod(path, HA_SCK_FILEMODE);
return 0;
}
@@ -1269,7 +1271,7 @@ static int ha_com_socket_send(int fd, void *buf, size_t buflen)
{
int cnt;
- cnt = send(fd, buf, buflen, 0);
+ cnt = send(fd, buf, buflen, MSG_NOSIGNAL);
if (cnt < 0) {
pr_err("ha_com_socket: send failed: %m");
return -errno;
--
2.30.2