All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: gaetan.rivet@6wind.com
Cc: dev@dpdk.org, Stephen Hemminger <sthemmin@microsoft.com>
Subject: [dpdk-dev] [PATCH 2/2] failsafe: implement xstats
Date: Wed, 26 Jun 2019 15:21:35 -0700	[thread overview]
Message-ID: <20190626222135.11368-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20190626222135.11368-1-stephen@networkplumber.org>

From: Stephen Hemminger <sthemmin@microsoft.com>

Add support for extended statistics in failsafe driver.
Reports basic statistics for the failsafe driver, and detailed
statistics for each sub device.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/failsafe/failsafe_ops.c | 144 ++++++++++++++++++++++++++++
 1 file changed, 144 insertions(+)

diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c
index 96e05d4dc4b1..9ab32457983d 100644
--- a/drivers/net/failsafe/failsafe_ops.c
+++ b/drivers/net/failsafe/failsafe_ops.c
@@ -789,6 +789,147 @@ fs_stats_reset(struct rte_eth_dev *dev)
 	fs_unlock(dev, 0);
 }
 
+static int
+fs_xstats_count(struct rte_eth_dev *dev)
+{
+	struct sub_device *sdev;
+	int r, count;
+	uint8_t i;
+
+	count = rte_eth_basic_stats_count(dev);
+
+	fs_lock(dev, 0);
+	FOREACH_SUBDEV(sdev, i, dev) {
+		if (sdev->state < DEV_ACTIVE)
+			continue;
+
+		r = rte_eth_xstats_get_names(PORT_ID(sdev), NULL, 0);
+		if (r < 0) {
+			fs_unlock(dev, 0);
+			return r;
+		}
+
+		count += r;
+	}
+	fs_unlock(dev, 0);
+
+	return count;
+}
+
+static int
+fs_xstats_get_names(struct rte_eth_dev *dev,
+		    struct rte_eth_xstat_name *xstats_names,
+		    unsigned int limit)
+{
+	struct sub_device *sdev;
+	unsigned int count;
+	uint8_t i;
+	char tmp[RTE_ETH_XSTATS_NAME_SIZE];
+	int j,r;
+
+	if (!xstats_names)
+		return fs_xstats_count(dev);
+
+	r = rte_eth_basic_stats_get_names(dev, xstats_names);
+	if (r < 0)
+		return r;
+
+	count = r;
+
+	fs_lock(dev, 0);
+	FOREACH_SUBDEV(sdev, i, dev) {
+		struct rte_eth_xstat_name *sub_names = xstats_names + count;
+
+		if (sdev->state < DEV_ACTIVE)
+			continue;
+
+		if (count >= limit)
+			break;
+
+		r = rte_eth_xstats_get_names(PORT_ID(sdev), sub_names,
+					     count < limit ? limit - count: 0);
+		if (r < 0) {
+			fs_unlock(dev, 0);
+			return r;
+		}
+
+		/* add sub_ prefix to names */
+		for (j = 0; j < r; j++) {
+			snprintf(tmp, sizeof(tmp), "sub%u_%s",
+				 i, sub_names[j].name);
+			memcpy(sub_names[j].name, tmp,
+			       RTE_ETH_XSTATS_NAME_SIZE);
+		}
+
+		count += r;
+	}
+	fs_unlock(dev, 0);
+
+	return count;
+}
+
+static int
+fs_xstats_get(struct rte_eth_dev *dev,
+	      struct rte_eth_xstat *xstats,
+	      unsigned int n)
+{
+	unsigned int nstats, j, count, scount;
+	struct sub_device *sdev;
+	uint8_t i;
+	int ret;
+
+	nstats = fs_xstats_count(dev);
+	if (n < nstats || xstats == NULL)
+		return nstats;
+
+	ret = rte_eth_basic_stats_get(dev->data->port_id, xstats);
+	if (ret < 0)
+		return ret;
+
+	count = ret;
+	for (j = 0; j < count; j++)
+		xstats[j].id = j;
+
+	fs_lock(dev, 0);
+	FOREACH_SUBDEV(sdev, i, dev) {
+		if (sdev->state < DEV_ACTIVE)
+			continue;
+
+		ret = rte_eth_xstats_get(PORT_ID(sdev),
+					 xstats + count,
+					 n > count ? n - count : 0);
+		if (ret < 0) {
+			fs_unlock(dev, 0);
+			return ret;
+		}
+		scount = ret;
+
+		/* add offset to id's from sub-device */
+		for (j = 0; j < scount; j++)
+			xstats[count + j].id += count;
+
+		count += scount;
+	}
+	fs_unlock(dev, 0);
+
+	return count;
+}
+
+static void
+fs_xstats_reset(struct rte_eth_dev *dev)
+{
+	struct sub_device *sdev;
+	uint8_t i;
+
+	rte_eth_stats_reset(dev->data->port_id);
+
+	fs_lock(dev, 0);
+	FOREACH_SUBDEV(sdev, i, dev) {
+		rte_eth_xstats_reset(PORT_ID(sdev));
+	}
+	fs_unlock(dev, 0);
+}
+
 static void
 fs_dev_merge_desc_lim(struct rte_eth_desc_lim *to,
 		      const struct rte_eth_desc_lim *from)
@@ -1233,6 +1374,9 @@ const struct eth_dev_ops failsafe_ops = {
 	.link_update = fs_link_update,
 	.stats_get = fs_stats_get,
 	.stats_reset = fs_stats_reset,
+	.xstats_get = fs_xstats_get,
+	.xstats_get_names = fs_xstats_get_names,
+	.xstats_reset = fs_xstats_reset,
 	.dev_infos_get = fs_dev_infos_get,
 	.dev_supported_ptypes_get = fs_dev_supported_ptypes_get,
 	.mtu_set = fs_mtu_set,
-- 
2.20.1


  parent reply	other threads:[~2019-06-26 22:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26 22:21 [dpdk-dev] [PATCH 0/2] failsafe: add xstats Stephen Hemminger
2019-06-26 22:21 ` [dpdk-dev] [PATCH 1/2] ethdev: expose basic xstats for driver use Stephen Hemminger
2019-06-26 22:21 ` Stephen Hemminger [this message]
2019-06-26 23:33 ` [dpdk-dev] [PATCH v2 0/2] failsafe: add xstats Stephen Hemminger
2019-06-26 23:33   ` [dpdk-dev] [PATCH v2 1/2] ethdev: expose basic xstats for driver use Stephen Hemminger
2019-07-01 10:54     ` Andrew Rybchenko
2019-07-01 14:59       ` Stephen Hemminger
2019-06-26 23:33   ` [dpdk-dev] [PATCH v2 2/2] failsafe: implement xstats Stephen Hemminger
2019-07-01 12:33     ` Gaëtan Rivet
2019-07-03 17:25 ` [dpdk-dev] [PATCH v2 0/2] *failsafe: add xstats Stephen Hemminger
2019-07-03 17:25   ` [dpdk-dev] [PATCH v2 1/2] ethdev: expose basic xstats for driver use Stephen Hemminger
2019-07-03 17:25   ` [dpdk-dev] [PATCH v2 2/2] failsafe: implement xstats Stephen Hemminger
2019-07-04  9:56   ` [dpdk-dev] [PATCH v2 0/2] *failsafe: add xstats Gaëtan Rivet
2019-08-11 16:06 ` [dpdk-dev] [PATCH v3 0/2] failsafe: " Stephen Hemminger
2019-08-11 16:06   ` [dpdk-dev] [PATCH v3 1/2] ethdev: expose basic xstats for driver use Stephen Hemminger
2019-08-11 16:06   ` [dpdk-dev] [PATCH v3 2/2] net/failsafe: implement xstats Stephen Hemminger
2019-09-19 12:56   ` [dpdk-dev] [PATCH v4 0/2] failsafe: add xstats Stephen Hemminger
2019-09-19 12:56     ` [dpdk-dev] [PATCH 1/2] ethdev: expose basic xstats for driver use Stephen Hemminger
2019-09-19 12:56     ` [dpdk-dev] [PATCH 2/2] net/failsafe: implement xstats Stephen Hemminger
2019-09-19 13:17   ` [dpdk-dev] [PATCH v5 0/2] failsafe: add xstats Stephen Hemminger
2019-09-19 13:17     ` [dpdk-dev] [PATCH v5 1/2] ethdev: expose basic xstats for driver use Stephen Hemminger
2019-09-26 12:46       ` Andrew Rybchenko
2019-09-26 16:09         ` Stephen Hemminger
2019-10-31 16:40         ` Stephen Hemminger
2019-09-19 13:17     ` [dpdk-dev] [PATCH v5 2/2] net/failsafe: implement xstats Stephen Hemminger
2019-10-17 14:54       ` Ferruh Yigit
2019-10-14 17:04     ` [dpdk-dev] [PATCH v5 0/2] failsafe: add xstats Stephen Hemminger
2019-10-15  9:08       ` Ferruh Yigit
  -- strict thread matches above, loose matches on Subject: below --
2019-11-01 20:12 [dpdk-dev] [PATCH 0/2] xstats related patches Stephen Hemminger
2019-11-01 20:12 ` [dpdk-dev] [PATCH 2/2] failsafe: implement xstats Stephen Hemminger
2019-11-08 18:13   ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190626222135.11368-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=gaetan.rivet@6wind.com \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.