DPDK patches and discussions
 help / color / mirror / Atom feed
From: Arek Kusztal <arkadiuszx.kusztal@intel.com>
To: dev@dpdk.org
Cc: akhil.goyal@nxp.com, fiona.trahe@intel.com,
	Arek Kusztal <arkadiuszx.kusztal@intel.com>
Subject: [dpdk-dev] [PATCH v3 3/5] app/mp_crypto: add function to allocatie mempools
Date: Wed, 15 Jul 2020 17:50:41 +0200
Message-ID: <20200715155043.12476-4-arkadiuszx.kusztal@intel.com> (raw)
In-Reply-To: <20200715155043.12476-1-arkadiuszx.kusztal@intel.com>

Add mempool allocation functions to multi process crypto
applcation which will be needed for crypto processing.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 app/test-mp-crypto/main.c      | 205 +++++++++++++++++++++++++++++++++++++++++
 app/test-mp-crypto/mp_crypto.c |  19 ++++
 app/test-mp-crypto/mp_crypto.h |  15 +++
 3 files changed, 239 insertions(+)

diff --git a/app/test-mp-crypto/main.c b/app/test-mp-crypto/main.c
index 680faf0..46c8055 100644
--- a/app/test-mp-crypto/main.c
+++ b/app/test-mp-crypto/main.c
@@ -117,6 +117,12 @@ void mp_crypto_exit_app(void)
 	if (mp_shared_data == NULL)
 		return;
 
+/*	rte_mempool_free(mp_crypto_op_pool);
+ *	rte_mempool_free(mp_crypto_mbuf_pool);
+ */
+	rte_mempool_free(mp_crypto_session_mempool_local);
+	rte_mempool_free(mp_crypto_priv_session_mp_local);
+
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		/* Inform of exit intention,
 		 * wait until all processes finish
@@ -146,6 +152,9 @@ void mp_crypto_exit_app(void)
 			"One or more processes did not exit normally");
 		}
 
+		rte_mempool_free(mp_crypto_session_mempool);
+		rte_mempool_free(mp_crypto_priv_session_mp);
+
 		mp_shared_data->proc_counter = 0;
 	} else {
 		/* Inform primary of exiting */
@@ -366,8 +375,198 @@ mp_crypto_setup_qps(void)
 	return 0;
 }
 
+int mp_crypto_setup_mpool(void)
+{
+	int i;
+	char crypto_op_mpool_name[RTE_MEMZONE_NAMESIZE];
+	char mbuf_pool_name[RTE_MEMZONE_NAMESIZE];
+	char session_mpool_name_local[RTE_MEMZONE_NAMESIZE];
+	char session_priv_name_local[RTE_MEMZONE_NAMESIZE];
+
+	/* Op pool */
+	int n = snprintf(crypto_op_mpool_name, sizeof(crypto_op_mpool_name),
+				"%s_%hu", MP_APP_CRYPTO_OP_POOL_NAME,
+					mp_shared_data->proc_counter_total);
+
+	if (n >= (int)sizeof(crypto_op_mpool_name)) {
+		MP_APP_LOG_2(ERR, COL_RED, "Failed to create mpool name");
+		return -1;
+	}
+
+	/* mbuf pool */
+	n = snprintf(mbuf_pool_name, sizeof(mbuf_pool_name),
+				"%s_%hu", MP_APP_MBUFPOOL_NAME,
+				mp_shared_data->proc_counter_total);
+
+	if (n >= (int)sizeof(mbuf_pool_name)) {
+		RTE_LOG(ERR, USER1, "Failed to create mbuf pool name");
+		return -1;
+	}
+
+	/* Local session pool */
+	n = snprintf(session_mpool_name_local,
+			sizeof(session_mpool_name_local),
+			"%s_%hu", MP_APP_SESSION_POOL_NAME_LOC,
+			mp_shared_data->proc_counter_total);
+
+	if (n >= (int)sizeof(session_mpool_name_local)) {
+		MP_APP_LOG_2(ERR, COL_RED,
+			"Failed to local session mpool name");
+		return -1;
+	}
+
+	/* Local priv session pool */
+	n = snprintf(session_priv_name_local, sizeof(session_priv_name_local),
+				"%s_%hu", MP_APP_PRIV_SESSION_POOL_NAME_LOC,
+				mp_shared_data->proc_counter_total);
+
+	if (n >= (int)sizeof(session_priv_name_local)) {
+		MP_APP_LOG_2(ERR, COL_RED,
+		"Failed to local session private mpool name");
+		return -1;
+	}
+
+	/* Op pool */
+	mp_crypto_op_pool =
+		rte_mempool_lookup(crypto_op_mpool_name);
+
+	if (!mp_crypto_op_pool) {
+		mp_crypto_op_pool = rte_crypto_op_pool_create(
+			crypto_op_mpool_name,
+			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
+			MP_APP_NUM_MBUFS, MP_APP_MBUF_CACHE_SIZE,
+			MP_APP_DEFAULT_NUM_XFORMS *
+			sizeof(struct rte_crypto_sym_xform) +
+			MP_APP_MAXIMUM_IV_LENGTH,
+			rte_socket_id());
+	}
+
+	if (mp_crypto_op_pool == NULL) {
+		MP_APP_LOG_2(ERR, COL_RED, "Error in mempool creation for ops");
+		return -1;
+	}
+
+	/* Set session pools for this process */
+	mp_crypto_session_mempool_local =
+		rte_cryptodev_sym_session_pool_create(
+		session_mpool_name_local, MAX_NUM_OF_SESSIONS,
+		sizeof(struct rte_cryptodev_sym_session), 0, 0,
+		SOCKET_ID_ANY);
+
+	if (!mp_crypto_session_mempool_local) {
+		MP_APP_LOG_2(ERR, COL_RED,
+		"Failed to create local session mpool");
+		return -1;
+	}
+
+	/* Set private session pool for this process */
+	mp_crypto_priv_session_mp_local = rte_mempool_create(
+			session_priv_name_local,
+			MAX_NUM_OF_SESSIONS,
+			rte_cryptodev_sym_get_private_session_size(
+				mp_app_device_id),
+			0, 0, NULL, NULL, NULL,
+			NULL, SOCKET_ID_ANY,
+			0);
+	if (!mp_crypto_priv_session_mp_local) {
+		MP_APP_LOG_2(ERR, COL_RED,
+			"Failed to create local session priv mpool");
+		return -1;
+	}
+
+	int dev_id = mp_app_devs[0].id;
+	/* All devices use same driver so the same size of private data */
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		/* Set mempools for sessions */
+		mp_crypto_session_mempool =
+			rte_cryptodev_sym_session_pool_create(
+			MP_APP_SESSION_POOL_NAME, MAX_NUM_OF_SESSIONS,
+			sizeof(struct rte_cryptodev_sym_session), 0, 0,
+			SOCKET_ID_ANY);
+
+		if (!mp_crypto_session_mempool) {
+			MP_APP_LOG_2(ERR, COL_RED,
+				"Failed to create session mpool");
+			return -1;
+		}
+
+		mp_crypto_priv_session_mp = rte_mempool_create(
+			MP_APP_PRIV_SESSION_POOL_NAME,
+			MAX_NUM_OF_SESSIONS,
+			rte_cryptodev_sym_get_private_session_size(dev_id),
+			0, 0, NULL, NULL, NULL,
+			NULL, SOCKET_ID_ANY,
+			0);
+		if (!mp_crypto_priv_session_mp) {
+			MP_APP_LOG_2(ERR, COL_RED,
+			"Failed to create priv mpool");
+			return -1;
+		}
+		/* Set mempools for ops */
+
+	} else {
+		mp_crypto_session_mempool =
+			rte_mempool_lookup(MP_APP_SESSION_POOL_NAME);
+		if (!mp_crypto_session_mempool) {
+			MP_APP_LOG_2(ERR, COL_RED,
+			"Failed to get sess mpool, was it allocated?");
+			return -1;
+		}
+		mp_crypto_priv_session_mp =
+			rte_mempool_lookup(MP_APP_PRIV_SESSION_POOL_NAME);
+		if (!mp_crypto_session_mempool) {
+			MP_APP_LOG_2(ERR, COL_RED,
+			"Failed to get priv session mpool, was it allocated?");
+			return -1;
+		}
+	}
+
+	/* Mbuf pool */
+	mp_crypto_mbuf_pool =
+		rte_mempool_lookup(mbuf_pool_name);
+	if (mp_crypto_mbuf_pool == NULL) {
+		mp_crypto_mbuf_pool = rte_pktmbuf_pool_create(
+				mbuf_pool_name,
+				MP_APP_NUM_MBUFS, MP_APP_MBUF_CACHE_SIZE, 0,
+				MP_APP_MBUF_SIZE,
+				rte_socket_id());
+	}
+	if (mp_crypto_mbuf_pool == NULL) {
+		MP_APP_LOG_2(ERR, COL_RED,
+			"Error in pool creation for mbuf data");
+		return -1;
+	}
+
+	/* Create ops and mbufs */
+	for (i = 0; i < MP_CRYPTO_QP_DESC_NUM; i++)	{
+		mp_crypto_mbufs[i] = rte_pktmbuf_alloc(mp_crypto_mbuf_pool);
+		if (mp_crypto_mbufs[i] == NULL)	{
+			MP_APP_LOG_2(ERR, COL_RED, "Error allocating mbufs");
+			return -1;
+		}
+		memset(rte_pktmbuf_mtod(mp_crypto_mbufs[i], uint8_t *), 0,
+			rte_pktmbuf_data_len(mp_crypto_mbufs[i]));
+	}
+
+	for (i = 0; i < MP_CRYPTO_QP_DESC_NUM; i++) {
+		mp_crypto_ops[i] = rte_crypto_op_alloc(mp_crypto_op_pool,
+			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+		if (mp_crypto_ops[i] == NULL) {
+			MP_APP_LOG_2(ERR, COL_RED,
+				"Error allocating crypto op");
+			return -1;
+		}
+		mp_crypto_ops[i]->sym->m_src = mp_crypto_mbufs[i];
+	}
+
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
+
+	int ret = 0;
+
 	if (mp_app_init(argc, argv) < 0) {
 		MP_APP_LOG_2(ERR, COL_RED, "Error when initializing");
 		goto err;
@@ -383,6 +582,12 @@ int main(int argc, char *argv[])
 		goto err;
 	};
 
+	ret = mp_crypto_setup_mpool();
+	if (ret < 0) {
+		MP_APP_LOG_2(ERR, COL_RED, "Cannot create mempools");
+		goto err;
+	}
+
 	mp_crypto_exit_app();
 	return 0;
 err:
diff --git a/app/test-mp-crypto/mp_crypto.c b/app/test-mp-crypto/mp_crypto.c
index 3437397..b996cf5 100644
--- a/app/test-mp-crypto/mp_crypto.c
+++ b/app/test-mp-crypto/mp_crypto.c
@@ -24,3 +24,22 @@ struct mp_app_process_data *mp_shared_data;
 
 int mp_crypto_exit_flag;
 /* Global exit flag */
+
+struct rte_mempool *mp_crypto_session_mempool;
+/* Global crypto mempool used by all processes */
+struct rte_mempool *mp_crypto_session_mempool_local;
+/* Local crypto mempool used by this process */
+struct rte_mempool *mp_crypto_priv_session_mp;
+/* Global crypto private session mempool used by all processes */
+struct rte_mempool *mp_crypto_priv_session_mp_local;
+/* Local crypto private session mempool used by this process */
+struct rte_mempool *mp_crypto_op_pool;
+/* Per process op pool */
+struct rte_mempool *mp_crypto_mbuf_pool;
+/* Per process mbuf pool */
+struct rte_crypto_op *mp_crypto_ops[MP_CRYPTO_OPS_NUM];
+/* Per process set of rte crypto ops */
+struct rte_crypto_op *mp_crypto_ops_ret[MP_CRYPTO_OPS_NUM];
+/* Per process set of return rte crypto ops */
+struct rte_mbuf *mp_crypto_mbufs[MP_CRYPTO_OPS_NUM];
+/* Per process set of rte mbufs */
diff --git a/app/test-mp-crypto/mp_crypto.h b/app/test-mp-crypto/mp_crypto.h
index fa6dc44..fad0230 100644
--- a/app/test-mp-crypto/mp_crypto.h
+++ b/app/test-mp-crypto/mp_crypto.h
@@ -70,6 +70,18 @@ extern struct rte_crypto_op *mp_crypto_ops_ret[];
 /* Per process set of return rte crypto ops */
 extern struct rte_mbuf *mp_crypto_mbufs[];
 /* Per process set of rte mbufs */
+extern struct rte_mempool *mp_crypto_session_mempool;
+/* Global crypto session mempool used by all processes */
+extern struct rte_mempool *mp_crypto_session_mempool_local;
+/* Local crypto mempool used by this process */
+extern struct rte_mempool *mp_crypto_priv_session_mp;
+/* Global crypto private session mempool used by all processes */
+extern struct rte_mempool *mp_crypto_priv_session_mp_local;
+/* Local crypto private session mempool used by this process */
+extern struct rte_mempool *mp_crypto_op_pool;
+/* Per process op pool */
+extern struct rte_mempool *mp_crypto_mbuf_pool;
+/* Per process mbuf pool */
 
 /* Name of the device */
 struct mp_app_dev_name {
@@ -174,6 +186,9 @@ int mp_crypto_setup_qps(void);
 int mp_crypto_init_devs(void);
 /* Function to setup devices according to mask */
 
+int mp_crypto_setup_mpool(void);
+/* Function to set or lookup for mempools */
+
 #define IV_OFFSET			(sizeof(struct rte_crypto_op) + \
 		sizeof(struct rte_crypto_sym_op) + DEFAULT_NUM_XFORMS * \
 		sizeof(struct rte_crypto_sym_xform))
-- 
2.1.0


  parent reply	other threads:[~2020-07-15 15:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-15 15:50 [dpdk-dev] [PATCH v3 0/5] app: add multi process crypto application Arek Kusztal
2020-07-15 15:50 ` [dpdk-dev] [PATCH v3 1/5] app: add muli " Arek Kusztal
2020-07-15 15:50 ` [dpdk-dev] [PATCH v3 2/5] app/mp_crypto: add device configuration functions Arek Kusztal
2020-07-15 15:50 ` Arek Kusztal [this message]
2020-07-15 15:50 ` [dpdk-dev] [PATCH v3 4/5] app/mp_crypto: add enqueue-dequeue functions Arek Kusztal
2020-07-15 15:50 ` [dpdk-dev] [PATCH v3 5/5] doc: add documentation for multi process crypto app Arek Kusztal
2020-07-15 18:22   ` Akhil Goyal
2020-07-22 14:20     ` Kusztal, ArkadiuszX
2020-07-23  8:45       ` Akhil Goyal
2020-07-15 18:26 ` [dpdk-dev] [PATCH v3 0/5] app: add multi process crypto application Akhil Goyal
2020-07-15 19:11   ` Thomas Monjalon
2020-07-15 19:25     ` Akhil Goyal
2020-07-15 20:06       ` Thomas Monjalon
2020-07-15 20:15         ` Akhil Goyal
2020-07-15 20:20           ` Thomas Monjalon
2020-08-31 11:50           ` Kusztal, ArkadiuszX
2020-10-08 13:16           ` Kusztal, ArkadiuszX

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=20200715155043.12476-4-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=akhil.goyal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git