From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 21971A0547; Wed, 15 Jul 2020 17:51:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3465A1BDFD; Wed, 15 Jul 2020 17:50:57 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 8D83F1BDFD for ; Wed, 15 Jul 2020 17:50:55 +0200 (CEST) IronPort-SDR: 6qekRj28V21NaYyaHM5WKBuNF60iIwptMIrc527p4cl1f0+Gz9VoR9mGTbaAwza+ufn4UKSCSn fF7DjA06NS/A== X-IronPort-AV: E=McAfee;i="6000,8403,9683"; a="167303564" X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="167303564" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2020 08:50:55 -0700 IronPort-SDR: aAm5GC7SNsOV5wr+YlqJnR9d3o9tF0mdbufJmjgT53gqQ6jIX41wF3ctNgQiIyncJM5dzwYc+x t1URYP30dhQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="318102543" Received: from akusztax-mobl.ger.corp.intel.com ([10.104.121.32]) by fmsmga002.fm.intel.com with ESMTP; 15 Jul 2020 08:50:53 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: akhil.goyal@nxp.com, fiona.trahe@intel.com, Arek Kusztal Date: Wed, 15 Jul 2020 17:50:41 +0200 Message-Id: <20200715155043.12476-4-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.19.1.windows.1 In-Reply-To: <20200715155043.12476-1-arkadiuszx.kusztal@intel.com> References: <20200715155043.12476-1-arkadiuszx.kusztal@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 3/5] app/mp_crypto: add function to allocatie mempools X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add mempool allocation functions to multi process crypto applcation which will be needed for crypto processing. Signed-off-by: Arek Kusztal --- 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