Replace the constant 1-minute update interval and 3-minute subscription duration with a duration parameter of pmc_agent_subscribe().
Signed-off-by: Miroslav Lichvar <mlich...@redhat.com> --- phc2sys.c | 2 +- pmc_agent.c | 15 +++++---------- pmc_agent.h | 4 +++- ts2phc.c | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 7ea6929..4dc7a9a 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, 180); if (err) { pr_err("failed to subscribe"); return -1; diff --git a/pmc_agent.c b/pmc_agent.c index 62d1a86..59f031d 100644 --- a/pmc_agent.c +++ b/pmc_agent.c @@ -27,16 +27,10 @@ #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. - */ - struct pmc_agent { struct pmc *pmc; uint64_t pmc_last_update; + uint64_t subscribe_duration; struct defaultDS dds; bool dds_valid; @@ -56,7 +50,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 = node->subscribe_duration; event_bitmask_set(sen.bitmask, NOTIFY_PORT_STATE, TRUE); pmc_send_set_action(node->pmc, MID_SUBSCRIBE_EVENTS_NP, &sen, sizeof(sen)); } @@ -391,9 +385,10 @@ 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 duration) { node->stay_subscribed = true; + node->subscribe_duration = duration * NS_PER_SEC; return renew_subscription(node, timeout); } @@ -412,7 +407,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->subscribe_duration / 3) { if (node->stay_subscribed) { renew_subscription(node, 0); } diff --git a/pmc_agent.h b/pmc_agent.h index 2fb1cc8..fa53f56 100644 --- a/pmc_agent.h +++ b/pmc_agent.h @@ -138,9 +138,11 @@ 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 duration Subscription duration in seconds. @ref pmc_agent_update() + * must be called at least once per third of the interval. * @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 duration); /** * Polls for push notifications from the local ptp4l service. diff --git a/ts2phc.c b/ts2phc.c index 3bbbbd3..d02de3a 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, 180); 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