06c396fbe3
The issue reported is a particular case of a BC configured with redundant PTP clocks with same priority. When a clock recovers from a failure, as both clock were configured with same priority it's expected the active clock source to remain active. But if the recovered clock presented a better local clock class than active, it was being selected active. This specific case was fixed. Closes-bug: 2084723 Test plan: BC with same priority PASS: Start the PTP service with all clocks out of requirements, one is selected, no matter which one. PASS: Then, when the backup clock recovers from failure it is selected active. PASS: Then, when the other clock recovers from failure it remains as backup, no matter the local clock class. PASS: Then, when the active goes out of requirement, the backup is set active. Test plan: GM with same priority PASS: Start the PTP service with all clocks out of requirements, one is selected, no matter which one. PASS: Then, when the backup clock recovers from failure it is selected active. PASS: Then, when the other clock recovers from failure it remains as backup, no matter the local clock class. PASS: Then, when the active goes out of requirement, the backup is set active. Change-Id: Id2568bc8bbaad4cbf15070314f7904d3c3bbd53d Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
150 lines
4.5 KiB
Diff
150 lines
4.5 KiB
Diff
From: Andre Mauricio Zelak <andre.zelak@windriver.com>
|
|
Date: Mon, 12 Jun 2023 15:08:01 -0300
|
|
Subject: [PATCH 20/61] pmc_agent: Convert the subscribe method into the
|
|
canonical form.
|
|
|
|
This patch renames the function to have the module prefix and corrects the
|
|
return code semantics.
|
|
|
|
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
|
|
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
|
|
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
|
|
|
|
[commit cc98d39f58adc1fd05db0038acfdcc5669f2ba8c upstream]
|
|
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
|
|
---
|
|
phc2sys.c | 4 ++--
|
|
pmc_agent.c | 48 +++++++++++++++++++++++++++++++++++-------------
|
|
pmc_agent.h | 9 ++++++++-
|
|
3 files changed, 45 insertions(+), 16 deletions(-)
|
|
|
|
diff --git a/phc2sys.c b/phc2sys.c
|
|
index 280e249..f61e699 100644
|
|
--- a/phc2sys.c
|
|
+++ b/phc2sys.c
|
|
@@ -875,8 +875,8 @@ static int auto_init_ports(struct phc2sys_private *priv, int add_rt)
|
|
return -1;
|
|
}
|
|
|
|
- res = run_pmc_subscribe(priv->node, 1000);
|
|
- if (res <= 0) {
|
|
+ res = pmc_agent_subscribe(priv->node, 1000);
|
|
+ if (res) {
|
|
pr_err("failed to subscribe");
|
|
return -1;
|
|
}
|
|
diff --git a/pmc_agent.c b/pmc_agent.c
|
|
index 22d9c5b..9c5eb71 100644
|
|
--- a/pmc_agent.c
|
|
+++ b/pmc_agent.c
|
|
@@ -17,6 +17,7 @@
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
+#include <errno.h>
|
|
#include <net/if.h>
|
|
#include <poll.h>
|
|
#include <stdlib.h>
|
|
@@ -98,6 +99,26 @@ static int get_mgt_err_id(struct ptp_message *msg)
|
|
#define RUN_PMC_NODEV -1
|
|
#define RUN_PMC_INTR -2
|
|
|
|
+static bool is_run_pmc_error(int code)
|
|
+{
|
|
+ return code != RUN_PMC_OKAY;
|
|
+}
|
|
+
|
|
+static int run_pmc_err2errno(int code)
|
|
+{
|
|
+ switch (code) {
|
|
+ case RUN_PMC_TMO:
|
|
+ return -ETIMEDOUT;
|
|
+ case RUN_PMC_NODEV:
|
|
+ return -ENODEV;
|
|
+ case RUN_PMC_INTR:
|
|
+ return -EINTR;
|
|
+ case RUN_PMC_OKAY:
|
|
+ default:
|
|
+ return 0;
|
|
+ }
|
|
+}
|
|
+
|
|
static int run_pmc(struct pmc_agent *node, int timeout, int ds_id,
|
|
struct ptp_message **msg)
|
|
{
|
|
@@ -239,18 +260,6 @@ int run_pmc_get_number_ports(struct pmc_agent *node, int timeout)
|
|
return res;
|
|
}
|
|
|
|
-int run_pmc_subscribe(struct pmc_agent *node, int timeout)
|
|
-{
|
|
- struct ptp_message *msg;
|
|
- int res;
|
|
-
|
|
- res = run_pmc(node, timeout, TLV_SUBSCRIBE_EVENTS_NP, &msg);
|
|
- if (res <= 0)
|
|
- return res;
|
|
- msg_put(msg);
|
|
- return 1;
|
|
-}
|
|
-
|
|
void run_pmc_events(struct pmc_agent *node)
|
|
{
|
|
struct ptp_message *msg;
|
|
@@ -329,7 +338,7 @@ int update_pmc_node(struct pmc_agent *node, int subscribe)
|
|
!(ts > node->pmc_last_update &&
|
|
ts - node->pmc_last_update < PMC_UPDATE_INTERVAL)) {
|
|
if (subscribe)
|
|
- run_pmc_subscribe(node, 0);
|
|
+ pmc_agent_subscribe(node, 0);
|
|
if (run_pmc_get_utc_offset(node, 0) > 0)
|
|
node->pmc_last_update = ts;
|
|
}
|
|
@@ -382,6 +391,19 @@ void pmc_agent_set_sync_offset(struct pmc_agent *agent, int offset)
|
|
agent->sync_offset = offset;
|
|
}
|
|
|
|
+int pmc_agent_subscribe(struct pmc_agent *node, int timeout)
|
|
+{
|
|
+ struct ptp_message *msg;
|
|
+ int res;
|
|
+
|
|
+ res = run_pmc(node, timeout, TLV_SUBSCRIBE_EVENTS_NP, &msg);
|
|
+ if (is_run_pmc_error(res)) {
|
|
+ return run_pmc_err2errno(res);
|
|
+ }
|
|
+ msg_put(msg);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
bool pmc_agent_utc_offset_traceable(struct pmc_agent *agent)
|
|
{
|
|
return agent->utc_offset_traceable;
|
|
diff --git a/pmc_agent.h b/pmc_agent.h
|
|
index f3a26fe..9dc684e 100644
|
|
--- a/pmc_agent.h
|
|
+++ b/pmc_agent.h
|
|
@@ -34,7 +34,6 @@ typedef int pmc_node_recv_subscribed_t(void *context, struct ptp_message *msg,
|
|
int init_pmc_node(struct config *cfg, struct pmc_agent *agent, const char *uds,
|
|
pmc_node_recv_subscribed_t *recv_subscribed, void *context);
|
|
int update_pmc_node(struct pmc_agent *agent, int subscribe);
|
|
-int run_pmc_subscribe(struct pmc_agent *agent, int timeout);
|
|
int run_pmc_clock_identity(struct pmc_agent *agent, int timeout);
|
|
int run_pmc_wait_sync(struct pmc_agent *agent, int timeout);
|
|
int run_pmc_get_number_ports(struct pmc_agent *agent, int timeout);
|
|
@@ -78,6 +77,14 @@ int pmc_agent_get_sync_offset(struct pmc_agent *agent);
|
|
*/
|
|
void pmc_agent_set_sync_offset(struct pmc_agent *agent, int offset);
|
|
|
|
+/**
|
|
+ * Subscribes to push notifications of changes in port state.
|
|
+ * @param agent Pointer to a PMC instance obtained via @ref pmc_agent_create().
|
|
+ * @param timeout Transmit and receive timeout in milliseconds.
|
|
+ * @return Zero on success, negative error code otherwise.
|
|
+ */
|
|
+int pmc_agent_subscribe(struct pmc_agent *agent, int timeout);
|
|
+
|
|
/**
|
|
* Tests whether the current UTC offset is traceable.
|
|
* @param agent Pointer to a PMC instance obtained via @ref pmc_agent_create().
|