DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shani Peretz <shperetz@nvidia.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@amd.com>, <stephen@networkplumber.org>,
	Shani Peretz <shperetz@nvidia.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	"Andrew Rybchenko" <andrew.rybchenko@oktetlabs.ru>
Subject: [PATCH v2 1/3] ethdev: add new API to enable/disable xstat by counters ID
Date: Fri, 24 Jan 2025 13:43:33 +0200	[thread overview]
Message-ID: <20250124114336.16610-2-shperetz@nvidia.com> (raw)
In-Reply-To: <20250124114336.16610-1-shperetz@nvidia.com>

This patch introduces a new API to dynamically enable or disable
xstat counters by their IDs.
Some counters may require resources that are potentially limited,
so providing the ability to toggle them on or off makes sense.
In addition, adding an API to query the current state
(enabled, disabled, or not supported) of an xstat counter is added.

New APIs:
	- rte_eth_xstats_set_counter
		(struct rte_eth_dev *dev, uint64_t id, int on_off);
 	- rte_eth_xstats_query_state
		(struct rte_eth_dev *dev, uint64_t id);

Note that by default, generic stats (like those provided by
eth_basic_stats_get()) will be considered unsupported and
will not be toggleable.
Also all xstats will be considered unsupported for dynamic enable/disable,
and each PMD will be able to override this in its implementation.

Signed-off-by: Shani Peretz <shperetz@nvidia.com>
---
 lib/ethdev/ethdev_driver.h | 13 ++++++++++
 lib/ethdev/rte_ethdev.c    | 49 ++++++++++++++++++++++++++++++++++++++
 lib/ethdev/rte_ethdev.h    | 32 +++++++++++++++++++++++++
 lib/ethdev/version.map     |  2 ++
 4 files changed, 96 insertions(+)

diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h
index 1fd4562b40..74995df7f4 100644
--- a/lib/ethdev/ethdev_driver.h
+++ b/lib/ethdev/ethdev_driver.h
@@ -570,6 +570,15 @@ typedef const uint32_t *(*eth_dev_supported_ptypes_get_t)(struct rte_eth_dev *de
 typedef int (*eth_dev_ptypes_set_t)(struct rte_eth_dev *dev,
 				     uint32_t ptype_mask);
 
+/** @internal Enable an xstat of an Ethernet device. */
+typedef int (*eth_xstats_enable_counter_t)(struct rte_eth_dev *dev, uint64_t id);
+
+/** @internal Disable an xstat of an Ethernet device. */
+typedef int (*eth_xstats_disable_counter_t)(struct rte_eth_dev *dev, uint64_t id);
+
+/** @internal Query the state of an xstat the can be enabled and disabled in runtime. */
+typedef int (*eth_xstats_query_state_t)(struct rte_eth_dev *dev, uint64_t id);
+
 /** @internal Start Rx and Tx of a queue of an Ethernet device. */
 typedef int (*eth_queue_start_t)(struct rte_eth_dev *dev,
 				    uint16_t queue_id);
@@ -1528,6 +1537,10 @@ struct eth_dev_ops {
 	/** Get name of extended device statistics by ID */
 	eth_xstats_get_names_by_id_t xstats_get_names_by_id;
 
+	eth_xstats_enable_counter_t xstats_enable;
+	eth_xstats_disable_counter_t xstats_disable;
+	eth_xstats_query_state_t xstats_query_state;
+
 	/** Get Traffic Management (TM) operations */
 	eth_tm_ops_get_t tm_ops_get;
 
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 6413c54e3b..c0cfb35126 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -3776,6 +3776,55 @@ rte_eth_xstats_reset(uint16_t port_id)
 	return rte_eth_stats_reset(port_id);
 }
 
+int
+rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off)
+{
+	struct rte_eth_dev *dev;
+	unsigned int basic_count;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+	dev = &rte_eth_devices[port_id];
+	basic_count = eth_dev_get_xstats_basic_count(dev);
+	if (id < basic_count)
+		return -EINVAL;
+
+	if (on_off == 1) {
+		if (rte_eth_xstats_query_state(port_id, id) == 1)
+			return -EEXIST;
+		if (dev->dev_ops->xstats_enable != NULL)
+			return (*dev->dev_ops->xstats_enable)(dev, id - basic_count);
+	} else {
+		if (rte_eth_xstats_query_state(port_id, id) == 0)
+			return 0;
+		if (dev->dev_ops->xstats_disable != NULL)
+			return (*dev->dev_ops->xstats_disable)(dev, id - basic_count);
+	}
+
+	return -ENOTSUP;
+}
+
+
+int
+rte_eth_xstats_query_state(uint16_t port_id, uint64_t id)
+{
+	struct rte_eth_dev *dev;
+	unsigned int basic_count;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+	dev = &rte_eth_devices[port_id];
+	basic_count = eth_dev_get_xstats_basic_count(dev);
+	if (id < basic_count)
+		return -ENOTSUP;
+
+	/* implemented by the driver */
+	if (dev->dev_ops->xstats_query_state != NULL)
+		return (*dev->dev_ops->xstats_query_state)(dev, id - basic_count);
+
+	return -ENOTSUP;
+}
+
 static int
 eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id,
 		uint8_t stat_idx, uint8_t is_rx)
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 1f71cad244..06f8d8cbfa 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -3386,6 +3386,38 @@ int rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
 int rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
 		uint64_t *id);
 
+/**
+ * Enable/Disable the xstat counter of the given id.
+ *
+ * @param port_id The port to look up statistics from
+ * @param id The ID of the counter to enable
+ * @param on_off The state to set the counter to.
+ * @return
+ *    - (0) on success
+ *    - (-EEXIST) counter already enabled
+ *    - (-ENOTSUP) enable/disable is not implemented
+ *    - (-EINVAL) xstat id is invalid
+ *    - (-EPERM) enabling this counter is not permitted
+ *    - (-ENOSPC) no resources
+ */
+__rte_experimental
+int rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off);
+
+
+/**
+ * Query the state of the xstat counter.
+ *
+ * @param port_id The port to look up statistics from
+ * @param id The ID of the counter to query
+ * @return
+ *    - (0) xstat is enabled
+ *    - (1) xstat is disabled
+ *    - (-ENOTSUP) enable/disabling is not implemented
+ *    - (-EINVAL) xstat id is invalid
+ */
+__rte_experimental
+int rte_eth_xstats_query_state(uint16_t port_id, uint64_t id);
+
 /**
  * Reset extended statistics of an Ethernet device.
  *
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 12f48c70a0..f96b9e5712 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -337,6 +337,8 @@ EXPERIMENTAL {
 	rte_eth_timesync_adjust_freq;
 	rte_flow_async_create_by_index_with_pattern;
 	rte_tm_node_query;
+	rte_eth_xstats_set_counter;
+	rte_eth_xstats_query_state;
 };
 
 INTERNAL {
-- 
2.34.1


  reply	other threads:[~2025-01-24 11:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-22 15:38 [RFC PATCH] ethdev: add new API for enable/disable xstat counters by ID Shani Peretz
2024-12-22 16:46 ` Stephen Hemminger
2024-12-23 10:46   ` Shani Peretz
2024-12-24 17:19     ` Stephen Hemminger
2025-01-01 19:05       ` Shani Peretz
2025-01-10  4:36 ` Stephen Hemminger
2025-01-24 11:43 ` [PATCH v2 0/3] add new API to enable/disable xstat counters Shani Peretz
2025-01-24 11:43   ` Shani Peretz [this message]
2025-01-24 11:43   ` [PATCH v2 2/3] app/testpmd: added testpmd commands to enable/disable xstat Shani Peretz
2025-01-24 11:43   ` [PATCH v2 3/3] net/mlx5: add port and queue level counters of hairpin drops Shani Peretz

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=20250124114336.16610-2-shperetz@nvidia.com \
    --to=shperetz@nvidia.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).