[v1,09/12] mldev: support device statistics

Message ID 20221114120238.2143832-10-jerinj@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series mldev: introduce machine learning device library |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jerin Jacob Kollanukkaran Nov. 14, 2022, 12:02 p.m. UTC
  From: Srikanth Yalavarthi <syalavarthi@marvell.com>

Added functions to get and reset device stats.
Device stats include number of requests enqueued, dequeued and errors.
Added function prototypes to used by driver implementations.

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
Signed-off-by: Jerin Jacob <jerinj@marvell.com>
---
 lib/mldev/rte_mldev.c      | 40 ++++++++++++++++++++++++++++++++++++++
 lib/mldev/rte_mldev_core.h | 32 ++++++++++++++++++++++++++++++
 lib/mldev/version.map      |  2 ++
 3 files changed, 74 insertions(+)
  

Patch

diff --git a/lib/mldev/rte_mldev.c b/lib/mldev/rte_mldev.c
index adf8ab8cbc..41b2a0be84 100644
--- a/lib/mldev/rte_mldev.c
+++ b/lib/mldev/rte_mldev.c
@@ -355,6 +355,46 @@  rte_ml_dev_queue_pair_setup(int16_t dev_id, uint16_t queue_pair_id,
 	return (*dev->dev_ops->dev_queue_pair_setup)(dev, queue_pair_id, qp_conf, socket_id);
 }
 
+int
+rte_ml_dev_stats_get(int16_t dev_id, struct rte_ml_dev_stats *stats)
+{
+	struct rte_ml_dev *dev;
+
+	if (!rte_ml_dev_is_valid_dev(dev_id)) {
+		ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+		return -EINVAL;
+	}
+
+	dev = rte_ml_dev_pmd_get_dev(dev_id);
+	if (*dev->dev_ops->dev_stats_get == NULL)
+		return -ENOTSUP;
+
+	if (stats == NULL) {
+		ML_DEV_LOG(ERR, "Dev %d, stats cannot be NULL\n", dev_id);
+		return -EINVAL;
+	}
+	memset(stats, 0, sizeof(struct rte_ml_dev_stats));
+
+	return (*dev->dev_ops->dev_stats_get)(dev, stats);
+}
+
+void
+rte_ml_dev_stats_reset(int16_t dev_id)
+{
+	struct rte_ml_dev *dev;
+
+	if (!rte_ml_dev_is_valid_dev(dev_id)) {
+		ML_DEV_LOG(ERR, "Invalid dev_id = %d\n", dev_id);
+		return;
+	}
+
+	dev = rte_ml_dev_pmd_get_dev(dev_id);
+	if (*dev->dev_ops->dev_stats_reset == NULL)
+		return;
+
+	(*dev->dev_ops->dev_stats_reset)(dev);
+}
+
 int
 rte_ml_model_load(int16_t dev_id, struct rte_ml_model_params *params, int16_t *model_id)
 {
diff --git a/lib/mldev/rte_mldev_core.h b/lib/mldev/rte_mldev_core.h
index 9c19d7badf..3f05ecd9c6 100644
--- a/lib/mldev/rte_mldev_core.h
+++ b/lib/mldev/rte_mldev_core.h
@@ -195,6 +195,32 @@  typedef int (*mldev_queue_pair_setup_t)(struct rte_ml_dev *dev, uint16_t queue_p
  */
 typedef int (*mldev_queue_pair_release_t)(struct rte_ml_dev *dev, uint16_t queue_pair_id);
 
+/**
+ * @internal
+ *
+ * Function used to get device statistics.
+ *
+ * @param dev
+ *	ML device pointer.
+ * @param stats
+ *	Pointer to ML device stats structure to update.
+ *
+ * @return
+ *	- 0 on success.
+ *	- < 0, error on failure.
+ */
+typedef int (*mldev_stats_get_t)(struct rte_ml_dev *dev, struct rte_ml_dev_stats *stats);
+
+/**
+ * @internal
+ *
+ * Function used to reset device statistics.
+ *
+ * @param dev
+ *	ML device pointer.
+ */
+typedef void (*mldev_stats_reset_t)(struct rte_ml_dev *dev);
+
 /**
  * @internal
  *
@@ -420,6 +446,12 @@  struct rte_ml_dev_ops {
 	/** Release a device queue pair. */
 	mldev_queue_pair_release_t dev_queue_pair_release;
 
+	/** Get device statistics. */
+	mldev_stats_get_t dev_stats_get;
+
+	/** Reset device statistics. */
+	mldev_stats_reset_t dev_stats_reset;
+
 	/** Load an ML model. */
 	mldev_model_load_t model_load;
 
diff --git a/lib/mldev/version.map b/lib/mldev/version.map
index 5d44d210d7..d12263010b 100644
--- a/lib/mldev/version.map
+++ b/lib/mldev/version.map
@@ -10,6 +10,8 @@  EXPERIMENTAL {
 	rte_ml_dev_queue_pair_setup;
 	rte_ml_dev_socket_id;
 	rte_ml_dev_start;
+	rte_ml_dev_stats_get;
+	rte_ml_dev_stats_reset;
 	rte_ml_dev_stop;
 	rte_ml_enqueue_burst;
 	rte_ml_io_dequantize;