Add a new parameter to pmc_agent_subscribe() to specify the maximum expected interval between pmc_agent_update() calls to avoid gaps in the subscription coverage when phc2sys is configured with an update rate smaller than 1 per minute.
Define a minimum update interval of 10 seconds (corresponding to 30 second subscription duration) to avoid unnecessarily frequent renewals with the default update intervals of phc2sys and ts2phc, but still be reasonably fast in detecting missing responses. Signed-off-by: Miroslav Lichvar <mlich...@redhat.com> --- phc2sys.c | 2 +- pmc_agent.c | 24 ++++++++++++++---------- pmc_agent.h | 5 ++++- ts2phc.c | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 7ea6929..3c94673 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -942,7 +942,7 @@ static int auto_init_ports(struct domain *domain) return -1; } - err = pmc_agent_subscribe(domain->agent, 1000); + err = pmc_agent_subscribe(domain->agent, 1000, domain->phc_interval); if (err) { pr_err("failed to subscribe"); return -1; diff --git a/pmc_agent.c b/pmc_agent.c index 370b27b..494c174 100644 --- a/pmc_agent.c +++ b/pmc_agent.c @@ -27,16 +27,16 @@ #include "print.h" #include "util.h" -#define PMC_UPDATE_INTERVAL (60 * NS_PER_SEC) -#define PMC_SUBSCRIBE_DURATION 180 /* 3 minutes */ -/* Note that PMC_SUBSCRIBE_DURATION has to be longer than - * PMC_UPDATE_INTERVAL otherwise subscription will time out before it is - * renewed. - */ +/* The subscription duration needs to be longer than the update interval to be + able to process the messages in time without losing notifications. Define + a minimum interval to avoid renewing the subscription too frequently. */ +#define UPDATES_PER_SUBSCRIPTION 3 +#define MIN_UPDATE_INTERVAL 10 struct pmc_agent { struct pmc *pmc; uint64_t pmc_last_update; + uint64_t update_interval; struct defaultDS dds; bool dds_valid; @@ -56,7 +56,7 @@ static void send_subscription(struct pmc_agent *node) struct subscribe_events_np sen; memset(&sen, 0, sizeof(sen)); - sen.duration = PMC_SUBSCRIBE_DURATION; + sen.duration = UPDATES_PER_SUBSCRIPTION * node->update_interval; event_bitmask_set(sen.bitmask, NOTIFY_PORT_STATE, TRUE); pmc_send_set_action(node->pmc, MID_SUBSCRIBE_EVENTS_NP, &sen, sizeof(sen)); } @@ -391,9 +391,12 @@ 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) +int pmc_agent_subscribe(struct pmc_agent *node, int timeout, int interval) { node->stay_subscribed = true; + if (interval < MIN_UPDATE_INTERVAL) + interval = MIN_UPDATE_INTERVAL; + node->update_interval = interval * NS_PER_SEC; return renew_subscription(node, timeout); } @@ -412,7 +415,7 @@ int pmc_agent_update(struct pmc_agent *node) } ts = tp.tv_sec * NS_PER_SEC + tp.tv_nsec; - if (ts - node->pmc_last_update >= PMC_UPDATE_INTERVAL) { + if (ts - node->pmc_last_update >= node->update_interval) { if (node->stay_subscribed) { renew_subscription(node, 0); } @@ -438,7 +441,8 @@ int pmc_agent_is_subscribed(struct pmc_agent *agent) ts = tp.tv_sec * NS_PER_SEC + tp.tv_nsec; return agent->pmc_last_update > 0 && - ts - agent->pmc_last_update <= PMC_SUBSCRIBE_DURATION * NS_PER_SEC; + ts - agent->pmc_last_update <= UPDATES_PER_SUBSCRIPTION * + agent->update_interval; } bool pmc_agent_utc_offset_traceable(struct pmc_agent *agent) diff --git a/pmc_agent.h b/pmc_agent.h index 93b1e8a..ef5552e 100644 --- a/pmc_agent.h +++ b/pmc_agent.h @@ -138,9 +138,12 @@ 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. + * @param interval Maximum expected interval between @ref pmc_agent_update() + * calls in seconds. This value controls the ptp4l subscription + * duration. * @return Zero on success, negative error code otherwise. */ -int pmc_agent_subscribe(struct pmc_agent *agent, int timeout); +int pmc_agent_subscribe(struct pmc_agent *agent, int timeout, int interval); /** * Polls for push notifications from the local ptp4l service. diff --git a/ts2phc.c b/ts2phc.c index 3bbbbd3..03c88b1 100644 --- a/ts2phc.c +++ b/ts2phc.c @@ -279,7 +279,7 @@ static int ts2phc_auto_init_ports(struct ts2phc_private *priv) return -1; } - err = pmc_agent_subscribe(priv->agent, 1000); + err = pmc_agent_subscribe(priv->agent, 1000, 1); if (err) { pr_err("failed to subscribe"); return -1; -- 2.41.0 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel