All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Krawczyk <mk@semihalf.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, shaibran@amazon.com,
	upstream@semihalf.com, Michal Krawczyk <mk@semihalf.com>,
	Dawid Gorecki <dgr@semihalf.com>
Subject: [PATCH v3 14/21] net/ena: add API for probing xstat names by ID
Date: Wed, 23 Feb 2022 13:19:37 +0100	[thread overview]
Message-ID: <20220223121944.24156-15-mk@semihalf.com> (raw)
In-Reply-To: <20220223121944.24156-1-mk@semihalf.com>

ENA was only supporting retrieval of all the xstats name and wasn't
implementing the eth_xstats_get_names_by_id API.

As this API may be more efficient than retrieving all the names, it
tries to avoid excessive string copying.

Signed-off-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Dawid Gorecki <dgr@semihalf.com>
Reviewed-by: Shai Brandes <shaibran@amazon.com>
---
 doc/guides/rel_notes/release_22_03.rst |   1 +
 drivers/net/ena/ena_ethdev.c           | 130 ++++++++++++++++++++-----
 2 files changed, 108 insertions(+), 23 deletions(-)

diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 95b31fc372..1746abddbb 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -115,6 +115,7 @@ New Features
   * Added optimized memcpy support for the ARM platforms.
   * Added ENA admin queue support for the MP applications.
   * Added free Tx mbuf on demand feature support.
+  * Added ``rte_eth_xstats_get_names_by_id`` API support.
 
 * **Updated Cisco enic driver.**
 
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 5e7b964995..11c9bb05e6 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -230,6 +230,10 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev);
 static int ena_xstats_get_names(struct rte_eth_dev *dev,
 				struct rte_eth_xstat_name *xstats_names,
 				unsigned int n);
+static int ena_xstats_get_names_by_id(struct rte_eth_dev *dev,
+				      const uint64_t *ids,
+				      struct rte_eth_xstat_name *xstats_names,
+				      unsigned int size);
 static int ena_xstats_get(struct rte_eth_dev *dev,
 			  struct rte_eth_xstat *stats,
 			  unsigned int n);
@@ -254,29 +258,30 @@ static int ena_mp_primary_handle(const struct rte_mp_msg *mp_msg,
 				 const void *peer);
 
 static const struct eth_dev_ops ena_dev_ops = {
-	.dev_configure        = ena_dev_configure,
-	.dev_infos_get        = ena_infos_get,
-	.rx_queue_setup       = ena_rx_queue_setup,
-	.tx_queue_setup       = ena_tx_queue_setup,
-	.dev_start            = ena_start,
-	.dev_stop             = ena_stop,
-	.link_update          = ena_link_update,
-	.stats_get            = ena_stats_get,
-	.xstats_get_names     = ena_xstats_get_names,
-	.xstats_get	      = ena_xstats_get,
-	.xstats_get_by_id     = ena_xstats_get_by_id,
-	.mtu_set              = ena_mtu_set,
-	.rx_queue_release     = ena_rx_queue_release,
-	.tx_queue_release     = ena_tx_queue_release,
-	.dev_close            = ena_close,
-	.dev_reset            = ena_dev_reset,
-	.reta_update          = ena_rss_reta_update,
-	.reta_query           = ena_rss_reta_query,
-	.rx_queue_intr_enable = ena_rx_queue_intr_enable,
-	.rx_queue_intr_disable = ena_rx_queue_intr_disable,
-	.rss_hash_update      = ena_rss_hash_update,
-	.rss_hash_conf_get    = ena_rss_hash_conf_get,
-	.tx_done_cleanup      = ena_tx_cleanup,
+	.dev_configure          = ena_dev_configure,
+	.dev_infos_get          = ena_infos_get,
+	.rx_queue_setup         = ena_rx_queue_setup,
+	.tx_queue_setup         = ena_tx_queue_setup,
+	.dev_start              = ena_start,
+	.dev_stop               = ena_stop,
+	.link_update            = ena_link_update,
+	.stats_get              = ena_stats_get,
+	.xstats_get_names       = ena_xstats_get_names,
+	.xstats_get_names_by_id = ena_xstats_get_names_by_id,
+	.xstats_get             = ena_xstats_get,
+	.xstats_get_by_id       = ena_xstats_get_by_id,
+	.mtu_set                = ena_mtu_set,
+	.rx_queue_release       = ena_rx_queue_release,
+	.tx_queue_release       = ena_tx_queue_release,
+	.dev_close              = ena_close,
+	.dev_reset              = ena_dev_reset,
+	.reta_update            = ena_rss_reta_update,
+	.reta_query             = ena_rss_reta_query,
+	.rx_queue_intr_enable   = ena_rx_queue_intr_enable,
+	.rx_queue_intr_disable  = ena_rx_queue_intr_disable,
+	.rss_hash_update        = ena_rss_hash_update,
+	.rss_hash_conf_get      = ena_rss_hash_conf_get,
+	.tx_done_cleanup        = ena_tx_cleanup,
 };
 
 /*********************************************************************
@@ -3165,6 +3170,85 @@ static int ena_xstats_get_names(struct rte_eth_dev *dev,
 	return xstats_count;
 }
 
+/**
+ * DPDK callback to retrieve names of extended device statistics for the given
+ * ids.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param[out] xstats_names
+ *   Buffer to insert names into.
+ * @param ids
+ *   IDs array for which the names should be retrieved.
+ * @param size
+ *   Number of ids.
+ *
+ * @return
+ *   Positive value: number of xstats names. Negative value: error code.
+ */
+static int ena_xstats_get_names_by_id(struct rte_eth_dev *dev,
+				      const uint64_t *ids,
+				      struct rte_eth_xstat_name *xstats_names,
+				      unsigned int size)
+{
+	uint64_t xstats_count = ena_xstats_calc_num(dev->data);
+	uint64_t id, qid;
+	unsigned int i;
+
+	if (xstats_names == NULL)
+		return xstats_count;
+
+	for (i = 0; i < size; ++i) {
+		id = ids[i];
+		if (id > xstats_count) {
+			PMD_DRV_LOG(ERR,
+				"ID value out of range: id=%" PRIu64 ", xstats_num=%" PRIu64 "\n",
+				 id, xstats_count);
+			return -EINVAL;
+		}
+
+		if (id < ENA_STATS_ARRAY_GLOBAL) {
+			strcpy(xstats_names[i].name,
+			       ena_stats_global_strings[id].name);
+			continue;
+		}
+
+		id -= ENA_STATS_ARRAY_GLOBAL;
+		if (id < ENA_STATS_ARRAY_ENI) {
+			strcpy(xstats_names[i].name,
+			       ena_stats_eni_strings[id].name);
+			continue;
+		}
+
+		id -= ENA_STATS_ARRAY_ENI;
+		if (id < ENA_STATS_ARRAY_RX) {
+			qid = id / dev->data->nb_rx_queues;
+			id %= dev->data->nb_rx_queues;
+			snprintf(xstats_names[i].name,
+				 sizeof(xstats_names[i].name),
+				 "rx_q%" PRIu64 "d_%s",
+				 qid, ena_stats_rx_strings[id].name);
+			continue;
+		}
+
+		id -= ENA_STATS_ARRAY_RX;
+		/* Although this condition is not needed, it was added for
+		 * compatibility if new xstat structure would be ever added.
+		 */
+		if (id < ENA_STATS_ARRAY_TX) {
+			qid = id / dev->data->nb_tx_queues;
+			id %= dev->data->nb_tx_queues;
+			snprintf(xstats_names[i].name,
+				 sizeof(xstats_names[i].name),
+				 "tx_q%" PRIu64 "_%s",
+				 qid, ena_stats_tx_strings[id].name);
+			continue;
+		}
+	}
+
+	return i;
+}
+
 /**
  * DPDK callback to get extended device statistics.
  *
-- 
2.25.1


  parent reply	other threads:[~2022-02-23 12:21 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22 16:06 [PATCH 00/21] net/ena: v2.6.0 driver update Michal Krawczyk
2022-02-22 16:06 ` [PATCH 01/21] net/ena: remove linearization function Michal Krawczyk
2022-02-22 16:06 ` [PATCH 02/21] net/ena: add assertion on Tx info mbuf Michal Krawczyk
2022-02-22 16:06 ` [PATCH 03/21] net/ena: remove unused enumeration Michal Krawczyk
2022-02-22 16:06 ` [PATCH 04/21] net/ena: remove unused offloads variables Michal Krawczyk
2022-02-22 16:06 ` [PATCH 05/21] net/ena: add extra Rx checksum related xstats Michal Krawczyk
2022-02-22 16:06 ` [PATCH 06/21] net/ena: make LSC configurable Michal Krawczyk
2022-02-22 16:06 ` [PATCH 07/21] net/ena: skip timer if the reset is triggered Michal Krawczyk
2022-02-22 16:06 ` [PATCH 08/21] net/ena: perform Tx cleanup before sending pkts Michal Krawczyk
2022-02-22 16:06 ` [PATCH 09/21] net/ena/base: use optimized memcpy version also on Arm Michal Krawczyk
2022-02-22 16:06 ` [PATCH 10/21] net/ena: proxy AQ calls to primary process Michal Krawczyk
2022-02-22 16:06 ` [PATCH 11/21] net/ena: enable stats get function for MP mode Michal Krawczyk
2022-02-22 16:06 ` [PATCH 12/21] net/ena/base: make IO memzone unique per port Michal Krawczyk
2022-02-22 16:06 ` [PATCH 13/21] net/ena: expose Tx cleanup function Michal Krawczyk
2022-02-22 16:06 ` [PATCH 14/21] net/ena: add API for probing xstat names by ID Michal Krawczyk
2022-02-22 16:06 ` [PATCH 15/21] net/ena: check if reset was already triggered Michal Krawczyk
2022-02-22 16:06 ` [PATCH 16/21] net/ena: make Tx completion timeout configurable Michal Krawczyk
2022-02-22 16:06 ` [PATCH 17/21] net/ena: fix meta-desc DF flag setup Michal Krawczyk
2022-02-22 16:06 ` [PATCH 18/21] net/ena: extend debug prints for invalid req ID resets Michal Krawczyk
2022-02-22 16:06 ` [PATCH 19/21] net/ena: don't initialize LLQ when membar isn't exposed Michal Krawczyk
2022-02-22 16:06 ` [PATCH 20/21] net/ena: don't indicate bad csum for L4 csum error Michal Krawczyk
2022-02-22 16:06 ` [PATCH 21/21] net/ena: update version to 2.6.0 Michal Krawczyk
2022-02-22 18:11 ` [PATCH v2 00/21] net/ena: v2.6.0 driver update Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 01/21] net/ena: remove linearization function Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 02/21] net/ena: add assertion on Tx info mbuf Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 03/21] net/ena: remove unused enumeration Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 04/21] net/ena: remove unused offloads variables Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 05/21] net/ena: add extra Rx checksum related xstats Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 06/21] net/ena: make LSC configurable Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 07/21] net/ena: skip timer if the reset is triggered Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 08/21] net/ena: perform Tx cleanup before sending pkts Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 09/21] net/ena/base: use optimized memcpy version also on Arm Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 10/21] net/ena: proxy AQ calls to primary process Michal Krawczyk
2022-02-22 22:24     ` Ferruh Yigit
2022-02-23  0:50       ` Ferruh Yigit
2022-02-22 18:11   ` [PATCH v2 11/21] net/ena: enable stats get function for MP mode Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 12/21] net/ena/base: make IO memzone unique per port Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 13/21] net/ena: expose Tx cleanup function Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 14/21] net/ena: add API for probing xstat names by ID Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 15/21] net/ena: check if reset was already triggered Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 16/21] net/ena: make Tx completion timeout configurable Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 17/21] net/ena: fix meta-desc DF flag setup Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 18/21] net/ena: extend debug prints for invalid req ID resets Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 19/21] net/ena: don't initialize LLQ when membar isn't exposed Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 20/21] net/ena: don't indicate bad csum for L4 csum error Michal Krawczyk
2022-02-22 18:11   ` [PATCH v2 21/21] net/ena: update version to 2.6.0 Michal Krawczyk
2022-02-22 22:21   ` [PATCH v2 00/21] net/ena: v2.6.0 driver update Ferruh Yigit
2022-02-23 10:07     ` Michał Krawczyk
2022-02-23 12:19   ` [PATCH v3 " Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 01/21] net/ena: remove linearization function Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 02/21] net/ena: add assertion on Tx info mbuf Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 03/21] net/ena: remove unused enumeration Michal Krawczyk
2022-02-23 17:25       ` Ferruh Yigit
2022-02-23 12:19     ` [PATCH v3 04/21] net/ena: remove unused offloads variables Michal Krawczyk
2022-02-23 17:25       ` Ferruh Yigit
2022-02-23 17:47         ` Michał Krawczyk
2022-02-23 18:12           ` Ferruh Yigit
2022-02-23 12:19     ` [PATCH v3 05/21] net/ena: add extra Rx checksum related xstats Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 06/21] net/ena: make LSC configurable Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 07/21] net/ena: skip timer if the reset is triggered Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 08/21] net/ena: perform Tx cleanup before sending pkts Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 09/21] net/ena/base: use optimized memcpy version also on Arm Michal Krawczyk
2022-02-23 17:25       ` Ferruh Yigit
2022-02-23 17:40         ` Michał Krawczyk
2022-02-23 12:19     ` [PATCH v3 10/21] net/ena: proxy AQ calls to primary process Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 11/21] net/ena: enable stats get function for MP mode Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 12/21] net/ena/base: make IO memzone unique per port Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 13/21] net/ena: expose Tx cleanup function Michal Krawczyk
2022-02-23 12:19     ` Michal Krawczyk [this message]
2022-02-23 12:19     ` [PATCH v3 15/21] net/ena: check if reset was already triggered Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 16/21] net/ena: make Tx completion timeout configurable Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 17/21] net/ena: fix meta-desc DF flag setup Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 18/21] net/ena: extend debug prints for invalid req ID resets Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 19/21] net/ena: don't initialize LLQ when membar isn't exposed Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 20/21] net/ena: don't indicate bad csum for L4 csum error Michal Krawczyk
2022-02-23 12:19     ` [PATCH v3 21/21] net/ena: update version to 2.6.0 Michal Krawczyk
2022-02-23 18:12     ` [PATCH v3 00/21] net/ena: v2.6.0 driver update 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=20220223121944.24156-15-mk@semihalf.com \
    --to=mk@semihalf.com \
    --cc=dev@dpdk.org \
    --cc=dgr@semihalf.com \
    --cc=ferruh.yigit@intel.com \
    --cc=shaibran@amazon.com \
    --cc=upstream@semihalf.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.