vhost/crypto: use separate session mempools
authorFan Zhang <roy.fan.zhang@intel.com>
Thu, 10 Jan 2019 14:50:16 +0000 (14:50 +0000)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 10 Jan 2019 15:57:22 +0000 (16:57 +0100)
This patch uses the two session mempool approach to vhost crypto.
One mempool is for session header objects, and the other is for
session private data.

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
examples/vhost_crypto/main.c
lib/librte_vhost/rte_vhost_crypto.h
lib/librte_vhost/vhost_crypto.c

index cb30f84..8bdcb3a 100644 (file)
@@ -46,6 +46,7 @@ struct vhost_crypto_info {
        int vids[MAX_NB_SOCKETS];
        uint32_t nb_vids;
        struct rte_mempool *sess_pool;
+       struct rte_mempool *sess_priv_pool;
        struct rte_mempool *cop_pool;
        uint8_t cid;
        uint32_t qid;
@@ -289,6 +290,7 @@ new_device(int vid)
        }
 
        ret = rte_vhost_crypto_create(vid, info->cid, info->sess_pool,
+                       info->sess_priv_pool,
                        rte_lcore_to_socket_id(options.los[i].lcore_id));
        if (ret) {
                RTE_LOG(ERR, USER1, "Cannot create vhost crypto\n");
@@ -448,6 +450,7 @@ free_resource(void)
 
                rte_mempool_free(info->cop_pool);
                rte_mempool_free(info->sess_pool);
+               rte_mempool_free(info->sess_priv_pool);
 
                for (j = 0; j < lo->nb_sockets; j++) {
                        rte_vhost_driver_unregister(lo->socket_files[i]);
@@ -528,11 +531,17 @@ main(int argc, char *argv[])
                }
 
                snprintf(name, 127, "SESS_POOL_%u", lo->lcore_id);
-               info->sess_pool = rte_mempool_create(name, SESSION_MAP_ENTRIES,
+               info->sess_pool = rte_cryptodev_sym_session_pool_create(name,
+                               SESSION_MAP_ENTRIES, 0, 0, 0,
+                               rte_lcore_to_socket_id(lo->lcore_id));
+
+               snprintf(name, 127, "SESS_POOL_PRIV_%u", lo->lcore_id);
+               info->sess_priv_pool = rte_mempool_create(name,
+                               SESSION_MAP_ENTRIES,
                                rte_cryptodev_sym_get_private_session_size(
                                info->cid), 64, 0, NULL, NULL, NULL, NULL,
                                rte_lcore_to_socket_id(lo->lcore_id), 0);
-               if (!info->sess_pool) {
+               if (!info->sess_priv_pool || info->sess_pool) {
                        RTE_LOG(ERR, USER1, "Failed to create mempool");
                        goto error_exit;
                }
index f9fbc05..d08e0ff 100644 (file)
@@ -26,8 +26,9 @@ enum rte_vhost_crypto_zero_copy {
  *  The identifier of DPDK Cryptodev, the same cryptodev_id can be assigned to
  *  multiple Vhost-crypto devices.
  * @param sess_pool
- *  The pointer to the created cryptodev session pool with the private data size
- *  matches the target DPDK Cryptodev.
+ *  The pointer to the created cryptodev session pool.
+ * @param sess_priv_pool
+ *  The pointer to the created cryptodev session private data mempool.
  * @param socket_id
  *  NUMA Socket ID to allocate resources on. *
  * @return
@@ -36,7 +37,9 @@ enum rte_vhost_crypto_zero_copy {
  */
 int __rte_experimental
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
-               struct rte_mempool *sess_pool, int socket_id);
+               struct rte_mempool *sess_pool,
+               struct rte_mempool *sess_priv_pool,
+               int socket_id);
 
 /**
  *  Free the Vhost-crypto instance
index dd01afc..598196f 100644 (file)
@@ -198,6 +198,7 @@ struct vhost_crypto {
        struct rte_hash *session_map;
        struct rte_mempool *mbuf_pool;
        struct rte_mempool *sess_pool;
+       struct rte_mempool *sess_priv_pool;
        struct rte_mempool *wb_pool;
 
        /** DPDK cryptodev ID */
@@ -369,7 +370,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,
        }
 
        if (rte_cryptodev_sym_session_init(vcrypto->cid, session, &xform1,
-                       vcrypto->sess_pool) < 0) {
+                       vcrypto->sess_priv_pool) < 0) {
                VC_LOG_ERR("Failed to initialize session");
                sess_param->session_id = -VIRTIO_CRYPTO_ERR;
                return;
@@ -1293,7 +1294,9 @@ vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,
 
 int __rte_experimental
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
-               struct rte_mempool *sess_pool, int socket_id)
+               struct rte_mempool *sess_pool,
+               struct rte_mempool *sess_priv_pool,
+               int socket_id)
 {
        struct virtio_net *dev = get_device(vid);
        struct rte_hash_parameters params = {0};
@@ -1321,6 +1324,7 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
        }
 
        vcrypto->sess_pool = sess_pool;
+       vcrypto->sess_priv_pool = sess_priv_pool;
        vcrypto->cid = cryptodev_id;
        vcrypto->cache_session_id = UINT64_MAX;
        vcrypto->last_session_id = 1;