DPDK patches and discussions
 help / color / mirror / Atom feed
From: Srikanth Yalavarthi <syalavarthi@marvell.com>
To: Jerin Jacob <jerinj@marvell.com>,
	Srikanth Yalavarthi <syalavarthi@marvell.com>
Cc: <dev@dpdk.org>, <aprabhu@marvell.com>, <sshankarnara@marvell.com>,
	<ptakkar@marvell.com>
Subject: [PATCH 05/11] event/ml: add adapter queue pair add and delete
Date: Sun, 7 Jan 2024 07:34:44 -0800	[thread overview]
Message-ID: <20240107153454.3909-6-syalavarthi@marvell.com> (raw)
In-Reply-To: <20240107153454.3909-1-syalavarthi@marvell.com>

Added ML adapter queue-pair add and delete functions

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
 lib/eventdev/eventdev_pmd.h         |  54 ++++++++
 lib/eventdev/rte_event_ml_adapter.c | 193 ++++++++++++++++++++++++++++
 2 files changed, 247 insertions(+)

diff --git a/lib/eventdev/eventdev_pmd.h b/lib/eventdev/eventdev_pmd.h
index 94d505753dc..48e970a5097 100644
--- a/lib/eventdev/eventdev_pmd.h
+++ b/lib/eventdev/eventdev_pmd.h
@@ -1549,6 +1549,56 @@ struct rte_ml_dev;
 typedef int (*eventdev_ml_adapter_caps_get_t)(const struct rte_eventdev *dev,
 					      const struct rte_ml_dev *mldev, uint32_t *caps);
 
+/**
+ * This API may change without prior notice
+ *
+ * Add ML queue pair to event device. This callback is invoked if
+ * the caps returned from rte_event_ml_adapter_caps_get(, mldev_id)
+ * has RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_* set.
+ *
+ * @param dev
+ *   Event device pointer
+ *
+ * @param mldev
+ *   MLDEV pointer
+ *
+ * @param queue_pair_id
+ *   MLDEV queue pair identifier.
+ *
+ * @param event
+ *  Event information required for binding mldev queue pair to event queue.
+ * This structure will have a valid value for only those HW PMDs supporting
+ * @see RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND capability.
+ *
+ * @return
+ *   - 0: Success, mldev queue pair added successfully.
+ *   - <0: Error code returned by the driver function.
+ *
+ */
+typedef int (*eventdev_ml_adapter_queue_pair_add_t)(const struct rte_eventdev *dev,
+						    const struct rte_ml_dev *mldev,
+						    int32_t queue_pair_id,
+						    const struct rte_event *event);
+
+/**
+ * This API may change without prior notice
+ *
+ * Delete ML queue pair to event device. This callback is invoked if
+ * the caps returned from rte_event_ml_adapter_caps_get(, mldev_id)
+ * has RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_* set.
+ *
+ * @param queue_pair_id
+ *   mldev queue pair identifier.
+ *
+ * @return
+ *   - 0: Success, mldev queue pair deleted successfully.
+ *   - <0: Error code returned by the driver function.
+ *
+ */
+typedef int (*eventdev_ml_adapter_queue_pair_del_t)(const struct rte_eventdev *dev,
+						    const struct rte_ml_dev *cdev,
+						    int32_t queue_pair_id);
+
 /** Event device operations function pointer table */
 struct eventdev_ops {
 	eventdev_info_get_t dev_infos_get;	/**< Get device info. */
@@ -1690,6 +1740,10 @@ struct eventdev_ops {
 
 	eventdev_ml_adapter_caps_get_t ml_adapter_caps_get;
 	/**< Get ML adapter capabilities */
+	eventdev_ml_adapter_queue_pair_add_t ml_adapter_queue_pair_add;
+	/**< Add queue pair to ML adapter */
+	eventdev_ml_adapter_queue_pair_del_t ml_adapter_queue_pair_del;
+	/**< Delete queue pair from ML adapter */
 
 	eventdev_selftest dev_selftest;
 	/**< Start eventdev Selftest */
diff --git a/lib/eventdev/rte_event_ml_adapter.c b/lib/eventdev/rte_event_ml_adapter.c
index 93ba58b3e9e..9d441c5d967 100644
--- a/lib/eventdev/rte_event_ml_adapter.c
+++ b/lib/eventdev/rte_event_ml_adapter.c
@@ -33,10 +33,27 @@ struct ml_ops_circular_buffer {
 	struct rte_ml_op **op_buffer;
 } __rte_cache_aligned;
 
+/* Queue pair information */
+struct ml_queue_pair_info {
+	/* Set to indicate queue pair is enabled */
+	bool qp_enabled;
+
+	/* Circular buffer for batching ML ops to mldev */
+	struct ml_ops_circular_buffer mlbuf;
+} __rte_cache_aligned;
+
 /* ML device information */
 struct ml_device_info {
 	/* Pointer to mldev */
 	struct rte_ml_dev *dev;
+
+	/* Pointer to queue pair info */
+	struct ml_queue_pair_info *qpairs;
+
+	/* If num_qpairs > 0, the start callback will
+	 * be invoked if not already invoked
+	 */
+	uint16_t num_qpairs;
 } __rte_cache_aligned;
 
 struct event_ml_adapter {
@@ -72,6 +89,9 @@ struct event_ml_adapter {
 
 	/* Set if  default_cb is being used */
 	int default_cb_arg;
+
+	/* No. of queue pairs configured */
+	uint16_t nb_qps;
 } __rte_cache_aligned;
 
 static struct event_ml_adapter **event_ml_adapter;
@@ -340,3 +360,176 @@ rte_event_ml_adapter_event_port_get(uint8_t id, uint8_t *event_port_id)
 
 	return 0;
 }
+
+static void
+emla_update_qp_info(struct event_ml_adapter *adapter, struct ml_device_info *dev_info,
+		    int32_t queue_pair_id, uint8_t add)
+{
+	struct ml_queue_pair_info *qp_info;
+	int enabled;
+	uint16_t i;
+
+	if (dev_info->qpairs == NULL)
+		return;
+
+	if (queue_pair_id == -1) {
+		for (i = 0; i < dev_info->dev->data->nb_queue_pairs; i++)
+			emla_update_qp_info(adapter, dev_info, i, add);
+	} else {
+		qp_info = &dev_info->qpairs[queue_pair_id];
+		enabled = qp_info->qp_enabled;
+		if (add) {
+			adapter->nb_qps += !enabled;
+			dev_info->num_qpairs += !enabled;
+		} else {
+			adapter->nb_qps -= enabled;
+			dev_info->num_qpairs -= enabled;
+		}
+		qp_info->qp_enabled = !!add;
+	}
+}
+
+int
+rte_event_ml_adapter_queue_pair_add(uint8_t id, int16_t mldev_id, int32_t queue_pair_id,
+				    const struct rte_event *event)
+{
+	struct event_ml_adapter *adapter;
+	struct ml_device_info *dev_info;
+	struct rte_eventdev *dev;
+	uint32_t cap;
+	int ret;
+
+	if (!emla_valid_id(id)) {
+		RTE_EDEV_LOG_ERR("Invalid ML adapter id = %d", id);
+		return -EINVAL;
+	}
+
+	if (!rte_ml_dev_is_valid_dev(mldev_id)) {
+		RTE_EDEV_LOG_ERR("Invalid mldev_id = %" PRIu8, mldev_id);
+		return -EINVAL;
+	}
+
+	adapter = emla_id_to_adapter(id);
+	if (adapter == NULL)
+		return -EINVAL;
+
+	dev = &rte_eventdevs[adapter->eventdev_id];
+	ret = rte_event_ml_adapter_caps_get(adapter->eventdev_id, mldev_id, &cap);
+	if (ret) {
+		RTE_EDEV_LOG_ERR("Failed to get adapter caps dev %u mldev %u", id, mldev_id);
+		return ret;
+	}
+
+	if ((cap & RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) && (event == NULL)) {
+		RTE_EDEV_LOG_ERR("Event can not be NULL for mldev_id = %u", mldev_id);
+		return -EINVAL;
+	}
+
+	dev_info = &adapter->mldevs[mldev_id];
+	if (queue_pair_id != -1 && (uint16_t)queue_pair_id >= dev_info->dev->data->nb_queue_pairs) {
+		RTE_EDEV_LOG_ERR("Invalid queue_pair_id %u", (uint16_t)queue_pair_id);
+		return -EINVAL;
+	}
+
+	/* In case HW cap is RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_OP_FWD, no
+	 * need of service core as HW supports event forward capability.
+	 */
+	if ((cap & RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) ||
+	    (cap & RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND &&
+	     adapter->mode == RTE_EVENT_ML_ADAPTER_OP_NEW) ||
+	    (cap & RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_OP_NEW &&
+	     adapter->mode == RTE_EVENT_ML_ADAPTER_OP_NEW)) {
+		if (*dev->dev_ops->ml_adapter_queue_pair_add == NULL)
+			return -ENOTSUP;
+
+		if (dev_info->qpairs == NULL) {
+			dev_info->qpairs =
+				rte_zmalloc_socket(adapter->mem_name,
+						   dev_info->dev->data->nb_queue_pairs *
+							   sizeof(struct ml_queue_pair_info),
+						   0, adapter->socket_id);
+			if (dev_info->qpairs == NULL)
+				return -ENOMEM;
+		}
+
+		ret = (*dev->dev_ops->ml_adapter_queue_pair_add)(dev, dev_info->dev, queue_pair_id,
+								 event);
+		if (ret == 0)
+			emla_update_qp_info(adapter, &adapter->mldevs[mldev_id], queue_pair_id, 1);
+	}
+
+	return ret;
+}
+
+int
+rte_event_ml_adapter_queue_pair_del(uint8_t id, int16_t mldev_id, int32_t queue_pair_id)
+{
+	struct event_ml_adapter *adapter;
+	struct ml_device_info *dev_info;
+	struct rte_eventdev *dev;
+	int ret;
+	uint32_t cap;
+	uint16_t i;
+
+	if (!emla_valid_id(id)) {
+		RTE_EDEV_LOG_ERR("Invalid ML adapter id = %d", id);
+		return -EINVAL;
+	}
+
+	if (!rte_ml_dev_is_valid_dev(mldev_id)) {
+		RTE_EDEV_LOG_ERR("Invalid mldev_id = %" PRIu8, mldev_id);
+		return -EINVAL;
+	}
+
+	adapter = emla_id_to_adapter(id);
+	if (adapter == NULL)
+		return -EINVAL;
+
+	dev = &rte_eventdevs[adapter->eventdev_id];
+	ret = rte_event_ml_adapter_caps_get(adapter->eventdev_id, mldev_id, &cap);
+	if (ret)
+		return ret;
+
+	dev_info = &adapter->mldevs[mldev_id];
+
+	if (queue_pair_id != -1 && (uint16_t)queue_pair_id >= dev_info->dev->data->nb_queue_pairs) {
+		RTE_EDEV_LOG_ERR("Invalid queue_pair_id %" PRIu16, (uint16_t)queue_pair_id);
+		return -EINVAL;
+	}
+
+	if ((cap & RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_OP_FWD) ||
+	    (cap & RTE_EVENT_ML_ADAPTER_CAP_INTERNAL_PORT_OP_NEW &&
+	     adapter->mode == RTE_EVENT_ML_ADAPTER_OP_NEW)) {
+		if (*dev->dev_ops->ml_adapter_queue_pair_del == NULL)
+			return -ENOTSUP;
+
+		ret = (*dev->dev_ops->ml_adapter_queue_pair_del)(dev, dev_info->dev, queue_pair_id);
+		if (ret == 0) {
+			emla_update_qp_info(adapter, &adapter->mldevs[mldev_id], queue_pair_id, 0);
+			if (dev_info->num_qpairs == 0) {
+				rte_free(dev_info->qpairs);
+				dev_info->qpairs = NULL;
+			}
+		}
+	} else {
+		if (adapter->nb_qps == 0)
+			return 0;
+
+		rte_spinlock_lock(&adapter->lock);
+		if (queue_pair_id == -1) {
+			for (i = 0; i < dev_info->dev->data->nb_queue_pairs; i++)
+				emla_update_qp_info(adapter, dev_info, queue_pair_id, 0);
+		} else {
+			emla_update_qp_info(adapter, dev_info, (uint16_t)queue_pair_id, 0);
+		}
+
+		if (dev_info->num_qpairs == 0) {
+			rte_free(dev_info->qpairs);
+			dev_info->qpairs = NULL;
+		}
+
+		rte_spinlock_unlock(&adapter->lock);
+	}
+
+	return ret;
+}
-- 
2.42.0


  parent reply	other threads:[~2024-01-07 15:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-07 15:34 [PATCH 00/11] Introduce Event ML Adapter Srikanth Yalavarthi
2024-01-07 15:34 ` [PATCH 01/11] eventdev: introduce ML event adapter library Srikanth Yalavarthi
2024-02-02  8:51   ` Jerin Jacob
2024-02-07  9:17   ` Naga Harish K, S V
2024-01-07 15:34 ` [PATCH 02/11] event/ml: add ml adapter capabilities get Srikanth Yalavarthi
2024-01-07 15:34 ` [PATCH 03/11] event/ml: add adapter create and free Srikanth Yalavarthi
2024-01-07 15:34 ` [PATCH 04/11] event/ml: add adapter port get Srikanth Yalavarthi
2024-01-07 15:34 ` Srikanth Yalavarthi [this message]
2024-01-07 15:34 ` [PATCH 06/11] event/ml: add support for service function Srikanth Yalavarthi
2024-01-07 15:34 ` [PATCH 07/11] event/ml: add adapter start and stop Srikanth Yalavarthi
2024-01-07 15:34 ` [PATCH 08/11] event/ml: add support to get adapter service ID Srikanth Yalavarthi
2024-01-07 15:34 ` [PATCH 09/11] event/ml: add support for runtime params Srikanth Yalavarthi

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=20240107153454.3909-6-syalavarthi@marvell.com \
    --to=syalavarthi@marvell.com \
    --cc=aprabhu@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=ptakkar@marvell.com \
    --cc=sshankarnara@marvell.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 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).