[v7,21/21] net/cpfl: add xstats ops
Checks
Commit Message
Add support for these device ops:
- dev_xstats_get
- dev_xstats_get_names
- dev_xstats_reset
Signed-off-by: Mingxia Liu <mingxia.liu@intel.com>
---
drivers/net/cpfl/cpfl_ethdev.c | 80 ++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
Comments
On 2/16/2023 12:30 AM, Mingxia Liu wrote:
> Add support for these device ops:
> - dev_xstats_get
> - dev_xstats_get_names
> - dev_xstats_reset
>
> Signed-off-by: Mingxia Liu <mingxia.liu@intel.com>
> ---
> drivers/net/cpfl/cpfl_ethdev.c | 80 ++++++++++++++++++++++++++++++++++
> 1 file changed, 80 insertions(+)
>
> diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c
> index f959a2911d..543dbd60f0 100644
> --- a/drivers/net/cpfl/cpfl_ethdev.c
> +++ b/drivers/net/cpfl/cpfl_ethdev.c
> @@ -80,6 +80,30 @@ static const uint64_t cpfl_ipv6_rss = RTE_ETH_RSS_NONFRAG_IPV6_UDP |
> RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
> RTE_ETH_RSS_FRAG_IPV6;
>
> +struct rte_cpfl_xstats_name_off {
> + char name[RTE_ETH_XSTATS_NAME_SIZE];
> + unsigned int offset;
> +};
> +
> +static const struct rte_cpfl_xstats_name_off rte_cpfl_stats_strings[] = {
> + {"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)},
> + {"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats, rx_unicast)},
> + {"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats, rx_multicast)},
> + {"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, rx_broadcast)},
> + {"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats, rx_discards)},
> + {"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)},
> + {"rx_unknown_protocol_packets", offsetof(struct virtchnl2_vport_stats,
> + rx_unknown_protocol)},
> + {"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)},
> + {"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats, tx_unicast)},
> + {"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats, tx_multicast)},
> + {"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, tx_broadcast)},
> + {"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats, tx_discards)},
> + {"tx_error_packets", offsetof(struct virtchnl2_vport_stats, tx_errors)}};
> +
> +#define CPFL_NB_XSTATS (sizeof(rte_cpfl_stats_strings) / \
> + sizeof(rte_cpfl_stats_strings[0]))
> +
Can use RTE_DIM here.
> static int
> cpfl_dev_link_update(struct rte_eth_dev *dev,
> __rte_unused int wait_to_complete)
> @@ -313,6 +337,59 @@ cpfl_dev_stats_reset(struct rte_eth_dev *dev)
> return 0;
> }
>
> +static int cpfl_dev_xstats_reset(struct rte_eth_dev *dev)
> +{
> + cpfl_dev_stats_reset(dev);
> + return 0;
> +}
> +
> +static int cpfl_dev_xstats_get(struct rte_eth_dev *dev,
> + struct rte_eth_xstat *xstats, unsigned int n)
> +{
> + struct idpf_vport *vport =
> + (struct idpf_vport *)dev->data->dev_private;
> + struct virtchnl2_vport_stats *pstats = NULL;
> + unsigned int i;
> + int ret;
> +
> + if (n < CPFL_NB_XSTATS)
> + return CPFL_NB_XSTATS;
> +
> + if (!xstats)
> + return 0;
> +
if 'xstats' is NULL, it should return 'CPFL_NB_XSTATS'.
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Tuesday, February 28, 2023 5:53 AM
> To: Liu, Mingxia <mingxia.liu@intel.com>; dev@dpdk.org; Xing, Beilei
> <beilei.xing@intel.com>; Zhang, Yuying <yuying.zhang@intel.com>
> Subject: Re: [PATCH v7 21/21] net/cpfl: add xstats ops
>
> On 2/16/2023 12:30 AM, Mingxia Liu wrote:
> > Add support for these device ops:
> > - dev_xstats_get
> > - dev_xstats_get_names
> > - dev_xstats_reset
> >
> > Signed-off-by: Mingxia Liu <mingxia.liu@intel.com>
> > ---
> > drivers/net/cpfl/cpfl_ethdev.c | 80
> > ++++++++++++++++++++++++++++++++++
> > 1 file changed, 80 insertions(+)
> >
> > diff --git a/drivers/net/cpfl/cpfl_ethdev.c
> > b/drivers/net/cpfl/cpfl_ethdev.c index f959a2911d..543dbd60f0 100644
> > --- a/drivers/net/cpfl/cpfl_ethdev.c
> > +++ b/drivers/net/cpfl/cpfl_ethdev.c
> > @@ -80,6 +80,30 @@ static const uint64_t cpfl_ipv6_rss =
> RTE_ETH_RSS_NONFRAG_IPV6_UDP |
> > RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
> > RTE_ETH_RSS_FRAG_IPV6;
> >
> > +struct rte_cpfl_xstats_name_off {
> > + char name[RTE_ETH_XSTATS_NAME_SIZE];
> > + unsigned int offset;
> > +};
> > +
> > +static const struct rte_cpfl_xstats_name_off rte_cpfl_stats_strings[] = {
> > + {"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)},
> > + {"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats,
> rx_unicast)},
> > + {"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats,
> rx_multicast)},
> > + {"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats,
> rx_broadcast)},
> > + {"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats,
> rx_discards)},
> > + {"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)},
> > + {"rx_unknown_protocol_packets", offsetof(struct
> virtchnl2_vport_stats,
> > + rx_unknown_protocol)},
> > + {"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)},
> > + {"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats,
> tx_unicast)},
> > + {"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats,
> tx_multicast)},
> > + {"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats,
> tx_broadcast)},
> > + {"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats,
> tx_discards)},
> > + {"tx_error_packets", offsetof(struct virtchnl2_vport_stats,
> > +tx_errors)}};
> > +
> > +#define CPFL_NB_XSTATS (sizeof(rte_cpfl_stats_strings) / \
> > + sizeof(rte_cpfl_stats_strings[0]))
> > +
>
> Can use RTE_DIM here.
>
> > static int
> > cpfl_dev_link_update(struct rte_eth_dev *dev,
> > __rte_unused int wait_to_complete) @@ -313,6
> +337,59 @@
> > cpfl_dev_stats_reset(struct rte_eth_dev *dev)
> > return 0;
> > }
> >
> > +static int cpfl_dev_xstats_reset(struct rte_eth_dev *dev) {
> > + cpfl_dev_stats_reset(dev);
> > + return 0;
> > +}
> > +
> > +static int cpfl_dev_xstats_get(struct rte_eth_dev *dev,
> > + struct rte_eth_xstat *xstats, unsigned int n) {
> > + struct idpf_vport *vport =
> > + (struct idpf_vport *)dev->data->dev_private;
> > + struct virtchnl2_vport_stats *pstats = NULL;
> > + unsigned int i;
> > + int ret;
> > +
> > + if (n < CPFL_NB_XSTATS)
> > + return CPFL_NB_XSTATS;
> > +
> > + if (!xstats)
> > + return 0;
> > +
>
> if 'xstats' is NULL, it should return 'CPFL_NB_XSTATS'.
[Liu, Mingxia] ok thanks!
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Tuesday, February 28, 2023 5:53 AM
> To: Liu, Mingxia <mingxia.liu@intel.com>; dev@dpdk.org; Xing, Beilei
> <beilei.xing@intel.com>; Zhang, Yuying <yuying.zhang@intel.com>
> Subject: Re: [PATCH v7 21/21] net/cpfl: add xstats ops
>
> On 2/16/2023 12:30 AM, Mingxia Liu wrote:
> > Add support for these device ops:
> > - dev_xstats_get
> > - dev_xstats_get_names
> > - dev_xstats_reset
> >
> > Signed-off-by: Mingxia Liu <mingxia.liu@intel.com>
> > ---
> > drivers/net/cpfl/cpfl_ethdev.c | 80
> > ++++++++++++++++++++++++++++++++++
> > 1 file changed, 80 insertions(+)
> >
> > diff --git a/drivers/net/cpfl/cpfl_ethdev.c
> > b/drivers/net/cpfl/cpfl_ethdev.c index f959a2911d..543dbd60f0 100644
> > --- a/drivers/net/cpfl/cpfl_ethdev.c
> > +++ b/drivers/net/cpfl/cpfl_ethdev.c
> > @@ -80,6 +80,30 @@ static const uint64_t cpfl_ipv6_rss =
> RTE_ETH_RSS_NONFRAG_IPV6_UDP |
> > RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
> > RTE_ETH_RSS_FRAG_IPV6;
> >
> > +struct rte_cpfl_xstats_name_off {
> > + char name[RTE_ETH_XSTATS_NAME_SIZE];
> > + unsigned int offset;
> > +};
> > +
> > +static const struct rte_cpfl_xstats_name_off rte_cpfl_stats_strings[] = {
> > + {"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)},
> > + {"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats,
> rx_unicast)},
> > + {"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats,
> rx_multicast)},
> > + {"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats,
> rx_broadcast)},
> > + {"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats,
> rx_discards)},
> > + {"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)},
> > + {"rx_unknown_protocol_packets", offsetof(struct
> virtchnl2_vport_stats,
> > + rx_unknown_protocol)},
> > + {"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)},
> > + {"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats,
> tx_unicast)},
> > + {"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats,
> tx_multicast)},
> > + {"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats,
> tx_broadcast)},
> > + {"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats,
> tx_discards)},
> > + {"tx_error_packets", offsetof(struct virtchnl2_vport_stats,
> > +tx_errors)}};
> > +
> > +#define CPFL_NB_XSTATS (sizeof(rte_cpfl_stats_strings) / \
> > + sizeof(rte_cpfl_stats_strings[0]))
> > +
>
> Can use RTE_DIM here.
>
[Liu, Mingxia] Ok, it‘s better, thanks.
> > static int
> > cpfl_dev_link_update(struct rte_eth_dev *dev,
> > __rte_unused int wait_to_complete) @@ -313,6
> +337,59 @@
> > cpfl_dev_stats_reset(struct rte_eth_dev *dev)
> > return 0;
> > }
> >
> > +static int cpfl_dev_xstats_reset(struct rte_eth_dev *dev) {
> > + cpfl_dev_stats_reset(dev);
> > + return 0;
> > +}
> > +
> > +static int cpfl_dev_xstats_get(struct rte_eth_dev *dev,
> > + struct rte_eth_xstat *xstats, unsigned int n) {
> > + struct idpf_vport *vport =
> > + (struct idpf_vport *)dev->data->dev_private;
> > + struct virtchnl2_vport_stats *pstats = NULL;
> > + unsigned int i;
> > + int ret;
> > +
> > + if (n < CPFL_NB_XSTATS)
> > + return CPFL_NB_XSTATS;
> > +
> > + if (!xstats)
> > + return 0;
> > +
>
> if 'xstats' is NULL, it should return 'CPFL_NB_XSTATS'.
@@ -80,6 +80,30 @@ static const uint64_t cpfl_ipv6_rss = RTE_ETH_RSS_NONFRAG_IPV6_UDP |
RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
RTE_ETH_RSS_FRAG_IPV6;
+struct rte_cpfl_xstats_name_off {
+ char name[RTE_ETH_XSTATS_NAME_SIZE];
+ unsigned int offset;
+};
+
+static const struct rte_cpfl_xstats_name_off rte_cpfl_stats_strings[] = {
+ {"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)},
+ {"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats, rx_unicast)},
+ {"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats, rx_multicast)},
+ {"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, rx_broadcast)},
+ {"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats, rx_discards)},
+ {"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)},
+ {"rx_unknown_protocol_packets", offsetof(struct virtchnl2_vport_stats,
+ rx_unknown_protocol)},
+ {"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)},
+ {"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats, tx_unicast)},
+ {"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats, tx_multicast)},
+ {"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, tx_broadcast)},
+ {"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats, tx_discards)},
+ {"tx_error_packets", offsetof(struct virtchnl2_vport_stats, tx_errors)}};
+
+#define CPFL_NB_XSTATS (sizeof(rte_cpfl_stats_strings) / \
+ sizeof(rte_cpfl_stats_strings[0]))
+
static int
cpfl_dev_link_update(struct rte_eth_dev *dev,
__rte_unused int wait_to_complete)
@@ -313,6 +337,59 @@ cpfl_dev_stats_reset(struct rte_eth_dev *dev)
return 0;
}
+static int cpfl_dev_xstats_reset(struct rte_eth_dev *dev)
+{
+ cpfl_dev_stats_reset(dev);
+ return 0;
+}
+
+static int cpfl_dev_xstats_get(struct rte_eth_dev *dev,
+ struct rte_eth_xstat *xstats, unsigned int n)
+{
+ struct idpf_vport *vport =
+ (struct idpf_vport *)dev->data->dev_private;
+ struct virtchnl2_vport_stats *pstats = NULL;
+ unsigned int i;
+ int ret;
+
+ if (n < CPFL_NB_XSTATS)
+ return CPFL_NB_XSTATS;
+
+ if (!xstats)
+ return 0;
+
+ ret = idpf_vc_stats_query(vport, &pstats);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Get statistics failed");
+ return 0;
+ }
+
+ idpf_vport_stats_update(&vport->eth_stats_offset, pstats);
+
+ /* loop over xstats array and values from pstats */
+ for (i = 0; i < CPFL_NB_XSTATS; i++) {
+ xstats[i].id = i;
+ xstats[i].value = *(uint64_t *)(((char *)pstats) +
+ rte_cpfl_stats_strings[i].offset);
+ }
+ return CPFL_NB_XSTATS;
+}
+
+static int cpfl_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
+ struct rte_eth_xstat_name *xstats_names,
+ __rte_unused unsigned int limit)
+{
+ unsigned int i;
+
+ if (xstats_names)
+ for (i = 0; i < CPFL_NB_XSTATS; i++) {
+ snprintf(xstats_names[i].name,
+ sizeof(xstats_names[i].name),
+ "%s", rte_cpfl_stats_strings[i].name);
+ }
+ return CPFL_NB_XSTATS;
+}
+
static int cpfl_config_rss_hf(struct idpf_vport *vport, uint64_t rss_hf)
{
uint64_t hena = 0;
@@ -1121,6 +1198,9 @@ static const struct eth_dev_ops cpfl_eth_dev_ops = {
.reta_query = cpfl_rss_reta_query,
.rss_hash_update = cpfl_rss_hash_update,
.rss_hash_conf_get = cpfl_rss_hash_conf_get,
+ .xstats_get = cpfl_dev_xstats_get,
+ .xstats_get_names = cpfl_dev_xstats_get_names,
+ .xstats_reset = cpfl_dev_xstats_reset,
};
static uint16_t