DPDK patches and discussions
 help / color / mirror / Atom feed
From: Fan Zhang <roy.fan.zhang@intel.com>
To: dev@dpdk.org
Cc: pablo.de.lara.guarch@intel.com
Subject: [dpdk-dev] [PATCH] crypto/scheduler: improve commandline parsing
Date: Mon, 20 Feb 2017 12:14:09 +0000	[thread overview]
Message-ID: <1487592849-45645-1-git-send-email-roy.fan.zhang@intel.com> (raw)

This patch improves the cryptodev scheduler PMD's commandline
parsing capability. Originally, the scheduler's slave option
requires the slave vdev(s) being declared prior to it. This
patch removes this limitation by storing the slave names
temporarily and attaching them later.

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
---
 drivers/crypto/scheduler/scheduler_pmd.c         | 90 ++++++++++++++----------
 drivers/crypto/scheduler/scheduler_pmd_ops.c     | 72 ++++++++++++++++++-
 drivers/crypto/scheduler/scheduler_pmd_private.h |  9 +++
 3 files changed, 132 insertions(+), 39 deletions(-)

diff --git a/drivers/crypto/scheduler/scheduler_pmd.c b/drivers/crypto/scheduler/scheduler_pmd.c
index eeafbe6..3b33387 100644
--- a/drivers/crypto/scheduler/scheduler_pmd.c
+++ b/drivers/crypto/scheduler/scheduler_pmd.c
@@ -44,7 +44,8 @@
 struct scheduler_init_params {
 	struct rte_crypto_vdev_init_params def_p;
 	uint32_t nb_slaves;
-	uint8_t slaves[MAX_SLAVES_NUM];
+	char slave_names[MAX_SLAVES_NUM]
+			[RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN];
 };
 
 #define RTE_CRYPTODEV_VDEV_NAME				("name")
@@ -88,37 +89,13 @@ scheduler_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
 }
 
 static int
-attach_init_slaves(uint8_t scheduler_id,
-		const uint8_t *slaves, const uint8_t nb_slaves)
-{
-	uint8_t i;
-
-	for (i = 0; i < nb_slaves; i++) {
-		struct rte_cryptodev *dev =
-				rte_cryptodev_pmd_get_dev(slaves[i]);
-		int status = rte_cryptodev_scheduler_slave_attach(
-				scheduler_id, slaves[i]);
-
-		if (status < 0 || !dev) {
-			CS_LOG_ERR("Failed to attach slave cryptodev "
-					"%u.\n", slaves[i]);
-			return status;
-		}
-
-		RTE_LOG(INFO, PMD, "  Attached slave cryptodev %s\n",
-				dev->data->name);
-	}
-
-	return 0;
-}
-
-static int
 cryptodev_scheduler_create(const char *name,
 	struct scheduler_init_params *init_params)
 {
 	char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN] = {0};
 	struct rte_cryptodev *dev;
 	struct scheduler_ctx *sched_ctx;
+	uint32_t i;
 
 	if (init_params->def_p.name[0] == '\0') {
 		int ret = rte_cryptodev_pmd_create_dev_name(
@@ -153,8 +130,52 @@ cryptodev_scheduler_create(const char *name,
 	sched_ctx->max_nb_queue_pairs =
 			init_params->def_p.max_nb_queue_pairs;
 
-	return attach_init_slaves(dev->data->dev_id, init_params->slaves,
-			init_params->nb_slaves);
+	for (i = 0; i < init_params->nb_slaves; i++) {
+		struct rte_cryptodev *slave_dev =
+				rte_cryptodev_pmd_get_named_dev(
+					init_params->slave_names[i]);
+
+		/* if the slave dev exists in the system, attach it */
+		if (slave_dev) {
+			int ret = rte_cryptodev_scheduler_slave_attach(
+				dev->data->dev_id,
+				slave_dev->data->dev_id);
+
+			if (ret < 0)
+				return ret;
+
+			CS_LOG_INFO("Scheduler %s attached slave %s\n",
+					dev->data->name,
+					init_params->slave_names[i]);
+
+			continue;
+		}
+
+		/* if the slave dev yet to exist, record it and attach
+		 * later
+		 */
+		sched_ctx->init_slave_names[sched_ctx->nb_init_slaves] =
+			rte_zmalloc_socket(
+				NULL,
+				RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN, 0,
+				SOCKET_ID_ANY);
+
+		if (!sched_ctx->init_slave_names[
+				sched_ctx->nb_init_slaves]) {
+			CS_LOG_ERR("driver %s: Insufficient memory",
+					name);
+			return -ENOMEM;
+		}
+
+		strncpy(sched_ctx->init_slave_names[
+					sched_ctx->nb_init_slaves],
+				init_params->slave_names[i],
+				RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN - 1);
+
+		sched_ctx->nb_init_slaves++;
+	}
+
+	return 0;
 }
 
 static int
@@ -243,21 +264,14 @@ parse_slave_arg(const char *key __rte_unused,
 		const char *value, void *extra_args)
 {
 	struct scheduler_init_params *param = extra_args;
-	struct rte_cryptodev *dev =
-			rte_cryptodev_pmd_get_named_dev(value);
-
-	if (!dev) {
-		RTE_LOG(ERR, PMD, "Invalid slave name %s.\n", value);
-		return -1;
-	}
 
 	if (param->nb_slaves >= MAX_SLAVES_NUM - 1) {
 		CS_LOG_ERR("Too many slaves.\n");
 		return -1;
 	}
 
-	param->slaves[param->nb_slaves] = dev->data->dev_id;
-	param->nb_slaves++;
+	strncpy(param->slave_names[param->nb_slaves++], value,
+			RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN - 1);
 
 	return 0;
 }
@@ -332,7 +346,7 @@ cryptodev_scheduler_probe(const char *name, const char *input_args)
 			""
 		},
 		.nb_slaves = 0,
-		.slaves = {0}
+		.slave_names = { {0} }
 	};
 
 	scheduler_parse_init_params(&init_params, input_args);
diff --git a/drivers/crypto/scheduler/scheduler_pmd_ops.c b/drivers/crypto/scheduler/scheduler_pmd_ops.c
index 56624c7..4518daf 100644
--- a/drivers/crypto/scheduler/scheduler_pmd_ops.c
+++ b/drivers/crypto/scheduler/scheduler_pmd_ops.c
@@ -41,13 +41,60 @@
 
 #include "scheduler_pmd_private.h"
 
+/** attaching the slaves predefined by scheduler's EAL options */
+int
+scheduler_attach_init_slave(struct rte_cryptodev *dev)
+{
+	struct scheduler_ctx *sched_ctx = dev->data->dev_private;
+	uint8_t scheduler_id = dev->data->dev_id;
+	int i;
+
+	for (i = sched_ctx->nb_init_slaves - 1; i >= 0; i--) {
+		const char *dev_name = sched_ctx->init_slave_names[i];
+		struct rte_cryptodev *slave_dev =
+				rte_cryptodev_pmd_get_named_dev(dev_name);
+		int status;
+
+		if (!slave_dev) {
+			CS_LOG_ERR("Failed to locate slave dev %s",
+					dev_name);
+			return -EINVAL;
+		}
+
+		status = rte_cryptodev_scheduler_slave_attach(
+				scheduler_id, slave_dev->data->dev_id);
+
+		if (status < 0) {
+			CS_LOG_ERR("Failed to attach slave cryptodev %u",
+					slave_dev->data->dev_id);
+			return status;
+		}
+
+		CS_LOG_INFO("Scheduler %s attached slave %s\n",
+				dev->data->name,
+				sched_ctx->init_slave_names[i]);
+
+		rte_free(sched_ctx->init_slave_names[i]);
+
+		sched_ctx->nb_init_slaves -= 1;
+	}
+
+	return 0;
+}
 /** Configure device */
 static int
 scheduler_pmd_config(struct rte_cryptodev *dev)
 {
 	struct scheduler_ctx *sched_ctx = dev->data->dev_private;
 	uint32_t i;
-	int ret = 0;
+	int ret;
+
+	/* although scheduler_attach_init_slave presents multiple times,
+	 * there will be only 1 meaningful execution.
+	 */
+	ret = scheduler_attach_init_slave(dev);
+	if (ret < 0)
+		return ret;
 
 	for (i = 0; i < sched_ctx->nb_slaves; i++) {
 		uint8_t slave_dev_id = sched_ctx->slaves[i].dev_id;
@@ -115,6 +162,13 @@ scheduler_pmd_start(struct rte_cryptodev *dev)
 	if (dev->data->dev_started)
 		return 0;
 
+	/* although scheduler_attach_init_slave presents multiple times,
+	 * there will be only 1 meaningful execution.
+	 */
+	ret = scheduler_attach_init_slave(dev);
+	if (ret < 0)
+		return ret;
+
 	for (i = 0; i < dev->data->nb_queue_pairs; i++) {
 		ret = update_reorder_buff(dev, i);
 		if (ret < 0) {
@@ -297,6 +351,11 @@ scheduler_pmd_info_get(struct rte_cryptodev *dev,
 	if (!dev_info)
 		return;
 
+	/* although scheduler_attach_init_slave presents multiple times,
+	 * there will be only 1 meaningful execution.
+	 */
+	scheduler_attach_init_slave(dev);
+
 	for (i = 0; i < sched_ctx->nb_slaves; i++) {
 		uint8_t slave_dev_id = sched_ctx->slaves[i].dev_id;
 		struct rte_cryptodev_info slave_info;
@@ -343,6 +402,7 @@ scheduler_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 	struct scheduler_ctx *sched_ctx = dev->data->dev_private;
 	struct scheduler_qp_ctx *qp_ctx;
 	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+	int ret;
 
 	if (snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN,
 			"CRYTO_SCHE PMD %u QP %u",
@@ -363,6 +423,16 @@ scheduler_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 
 	dev->data->queue_pairs[qp_id] = qp_ctx;
 
+	/* although scheduler_attach_init_slave presents multiple times,
+	 * there will be only 1 meaningful execution.
+	 */
+	ret = scheduler_attach_init_slave(dev);
+	if (ret < 0) {
+		CS_LOG_ERR("Failed to attach slave");
+		scheduler_pmd_qp_release(dev, qp_id);
+		return ret;
+	}
+
 	if (*sched_ctx->ops.config_queue_pair) {
 		if ((*sched_ctx->ops.config_queue_pair)(dev, qp_id) < 0) {
 			CS_LOG_ERR("Unable to configure queue pair");
diff --git a/drivers/crypto/scheduler/scheduler_pmd_private.h b/drivers/crypto/scheduler/scheduler_pmd_private.h
index ac4690e..e9eb90f 100644
--- a/drivers/crypto/scheduler/scheduler_pmd_private.h
+++ b/drivers/crypto/scheduler/scheduler_pmd_private.h
@@ -93,6 +93,9 @@ struct scheduler_ctx {
 
 	char name[RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN];
 	char description[RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN];
+
+	char *init_slave_names[MAX_SLAVES_NUM];
+	int nb_init_slaves;
 } __rte_cache_aligned;
 
 struct scheduler_qp_ctx {
@@ -109,6 +112,12 @@ struct scheduler_session {
 	struct rte_cryptodev_sym_session *sessions[MAX_SLAVES_NUM];
 };
 
+/** internal function, attaching the slaves predefined
+ *  by scheduler's EAL options
+ */
+int
+scheduler_attach_init_slave(struct rte_cryptodev *dev);
+
 /** device specific operations function pointer structure */
 extern struct rte_cryptodev_ops *rte_crypto_scheduler_pmd_ops;
 
-- 
2.7.4

             reply	other threads:[~2017-02-20 12:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20 12:14 Fan Zhang [this message]
2017-03-30 16:53 ` [dpdk-dev] [PATCH v2] " Fan Zhang
2017-04-18 11:28   ` [dpdk-dev] [PATCH v3] " Fan Zhang
2017-04-18 15:36     ` De Lara Guarch, Pablo
2017-04-18 15:51       ` De Lara Guarch, Pablo

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=1487592849-45645-1-git-send-email-roy.fan.zhang@intel.com \
    --to=roy.fan.zhang@intel.com \
    --cc=dev@dpdk.org \
    --cc=pablo.de.lara.guarch@intel.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).