From: Jin Liu <jin....@corigine.com> Use rte_eal_alarm_set() function instead of clock cycle to implement meter stats timer, to make code more standard.
Signed-off-by: Jin Liu <jin....@corigine.com> Reviewed-by: Chaoyong He <chaoyong...@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderl...@corigine.com> --- drivers/net/nfp/flower/nfp_flower_ctrl.c | 20 ------------------ drivers/net/nfp/nfp_mtr.c | 27 +++++++++++++++++++++++- drivers/net/nfp/nfp_mtr.h | 2 -- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower_ctrl.c b/drivers/net/nfp/flower/nfp_flower_ctrl.c index 3e083d948e..9f069abe06 100644 --- a/drivers/net/nfp/flower/nfp_flower_ctrl.c +++ b/drivers/net/nfp/flower/nfp_flower_ctrl.c @@ -321,29 +321,15 @@ nfp_flower_cmsg_rx(struct nfp_app_fw_flower *app_fw_flower, } } -static void -nfp_mtr_stats_request(struct nfp_app_fw_flower *app_fw_flower) -{ - struct nfp_mtr *mtr; - - LIST_FOREACH(mtr, &app_fw_flower->mtr_priv->mtrs, next) - (void)nfp_flower_cmsg_qos_stats(app_fw_flower, &mtr->mtr_profile->conf.head); -} - void nfp_flower_ctrl_vnic_poll(struct nfp_app_fw_flower *app_fw_flower) { uint16_t count; - uint64_t cur_tsc; - uint64_t drain_tsc; - uint64_t pre_tsc = 0; struct nfp_net_rxq *rxq; struct nfp_net_hw *ctrl_hw; struct rte_eth_dev *ctrl_eth_dev; struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; - drain_tsc = app_fw_flower->mtr_priv->drain_tsc; - ctrl_hw = app_fw_flower->ctrl_hw; ctrl_eth_dev = ctrl_hw->eth_dev; @@ -357,11 +343,5 @@ nfp_flower_ctrl_vnic_poll(struct nfp_app_fw_flower *app_fw_flower) /* Process cmsgs here */ nfp_flower_cmsg_rx(app_fw_flower, pkts_burst, count); } - - cur_tsc = rte_rdtsc(); - if (unlikely(cur_tsc - pre_tsc > drain_tsc)) { - nfp_mtr_stats_request(app_fw_flower); - pre_tsc = cur_tsc; - } } } diff --git a/drivers/net/nfp/nfp_mtr.c b/drivers/net/nfp/nfp_mtr.c index 5f85106f9d..afc4de4cc7 100644 --- a/drivers/net/nfp/nfp_mtr.c +++ b/drivers/net/nfp/nfp_mtr.c @@ -6,6 +6,7 @@ #include <rte_mtr_driver.h> #include <bus_pci_driver.h> #include <rte_malloc.h> +#include <rte_alarm.h> #include "nfp_common.h" #include "nfp_mtr.h" @@ -18,6 +19,9 @@ #define NFP_FL_QOS_METER RTE_BIT32(10) #define NFP_FL_QOS_RFC2697 RTE_BIT32(0) +/* Alarm timeout value in microseconds */ +#define NFP_METER_STATS_INTERVAL 1000000 /* 1 second */ + /** * Callback to get MTR capabilities. * @@ -1072,9 +1076,22 @@ nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg) return 0; } +static void +nfp_mtr_stats_request(void *arg) +{ + struct nfp_mtr *mtr; + struct nfp_app_fw_flower *app_fw_flower = arg; + + LIST_FOREACH(mtr, &app_fw_flower->mtr_priv->mtrs, next) + nfp_flower_cmsg_qos_stats(app_fw_flower, &mtr->mtr_profile->conf.head); + + rte_eal_alarm_set(NFP_METER_STATS_INTERVAL, nfp_mtr_stats_request, arg); +} + int nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev) { + int ret; struct nfp_mtr_priv *priv; struct nfp_app_fw_flower *app_fw_flower; @@ -1087,7 +1104,13 @@ nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev) app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv); app_fw_flower->mtr_priv = priv; - priv->drain_tsc = rte_get_tsc_hz(); + ret = rte_eal_alarm_set(NFP_METER_STATS_INTERVAL, nfp_mtr_stats_request, + (void *)app_fw_flower); + if (ret < 0) { + PMD_INIT_LOG(ERR, "nfp mtr timer init failed."); + rte_free(priv); + return ret; + } LIST_INIT(&priv->mtrs); LIST_INIT(&priv->profiles); @@ -1110,6 +1133,8 @@ nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev) app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv); priv = app_fw_flower->mtr_priv; + rte_eal_alarm_cancel(nfp_mtr_stats_request, (void *)app_fw_flower); + LIST_FOREACH(mtr, &priv->mtrs, next) { LIST_REMOVE(mtr, next); rte_free(mtr); diff --git a/drivers/net/nfp/nfp_mtr.h b/drivers/net/nfp/nfp_mtr.h index 41c472f139..f5406381ab 100644 --- a/drivers/net/nfp/nfp_mtr.h +++ b/drivers/net/nfp/nfp_mtr.h @@ -159,14 +159,12 @@ struct nfp_mtr { * @policies: the head node of policy list * @mtrs: the head node of mtrs list * @mtr_stats_lock: spinlock for meter stats - * @drain_tsc: clock period */ struct nfp_mtr_priv { LIST_HEAD(, nfp_mtr_profile) profiles; LIST_HEAD(, nfp_mtr_policy) policies; LIST_HEAD(, nfp_mtr) mtrs; rte_spinlock_t mtr_stats_lock; - uint64_t drain_tsc; }; int nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg); -- 2.39.1