examples: use separate crypto session mempools

This patch uses the two session mempool approach to all cryptodev
sample applications. 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>
This commit is contained in:
Fan Zhang 2019-01-10 14:50:15 +00:00 committed by Pablo de Lara
parent 61826a1e48
commit 261bbff75e
11 changed files with 191 additions and 73 deletions

View File

@ -29,6 +29,8 @@ struct cryptodev_fips_validate_env {
uint32_t is_path_folder;
uint32_t dev_id;
struct rte_mempool *mpool;
struct rte_mempool *sess_mpool;
struct rte_mempool *sess_priv_mpool;
struct rte_mempool *op_pool;
struct rte_mbuf *mbuf;
struct rte_crypto_op *op;
@ -40,6 +42,8 @@ cryptodev_fips_validate_app_int(void)
{
struct rte_cryptodev_config conf = {rte_socket_id(), 1};
struct rte_cryptodev_qp_conf qp_conf = {128, NULL, NULL};
uint32_t sess_sz = rte_cryptodev_sym_get_private_session_size(
env.dev_id);
int ret;
ret = rte_cryptodev_configure(env.dev_id, &conf);
@ -58,6 +62,17 @@ cryptodev_fips_validate_app_int(void)
ret = -ENOMEM;
env.sess_mpool = rte_cryptodev_sym_session_pool_create(
"FIPS_SESS_MEMPOOL", 16, 0, 0, 0, rte_socket_id());
if (!env.sess_mpool)
goto error_exit;
env.sess_priv_mpool = rte_mempool_create("FIPS_SESS_PRIV_MEMPOOL",
16, sess_sz, 0, 0, NULL, NULL, NULL,
NULL, rte_socket_id(), 0);
if (!env.sess_priv_mpool)
goto error_exit;
env.op_pool = rte_crypto_op_pool_create(
"FIPS_OP_POOL",
RTE_CRYPTO_OP_TYPE_SYMMETRIC,
@ -75,10 +90,23 @@ cryptodev_fips_validate_app_int(void)
if (!env.op)
goto error_exit;
qp_conf.mp_session = env.sess_mpool;
qp_conf.mp_session_private = env.sess_priv_mpool;
ret = rte_cryptodev_queue_pair_setup(env.dev_id, 0, &qp_conf,
rte_socket_id());
if (ret < 0)
goto error_exit;
return 0;
error_exit:
rte_mempool_free(env.mpool);
if (env.sess_mpool)
rte_mempool_free(env.sess_mpool);
if (env.sess_priv_mpool)
rte_mempool_free(env.sess_priv_mpool);
if (env.op_pool)
rte_mempool_free(env.op_pool);
@ -93,6 +121,8 @@ cryptodev_fips_validate_app_uninit(void)
rte_cryptodev_sym_session_clear(env.dev_id, env.sess);
rte_cryptodev_sym_session_free(env.sess);
rte_mempool_free(env.mpool);
rte_mempool_free(env.sess_mpool);
rte_mempool_free(env.sess_priv_mpool);
rte_mempool_free(env.op_pool);
}
@ -797,12 +827,12 @@ fips_run_test(void)
if (ret < 0)
return ret;
env.sess = rte_cryptodev_sym_session_create(env.mpool);
env.sess = rte_cryptodev_sym_session_create(env.sess_mpool);
if (!env.sess)
return -ENOMEM;
ret = rte_cryptodev_sym_session_init(env.dev_id,
env.sess, &xform, env.mpool);
env.sess, &xform, env.sess_priv_mpool);
if (ret < 0) {
RTE_LOG(ERR, USER1, "Error %i: Init session\n",
ret);

View File

@ -790,7 +790,8 @@ cmd_kni(char **tokens,
static const char cmd_cryptodev_help[] =
"cryptodev <cryptodev_name>\n"
" dev <device_name> | dev_id <device_id>\n"
" queue <n_queues> <queue_size>\n";
" queue <n_queues> <queue_size>\n"
" max_sessions <n_sessions>";
static void
cmd_cryptodev(char **tokens,
@ -802,7 +803,7 @@ cmd_cryptodev(char **tokens,
char *name;
memset(&params, 0, sizeof(params));
if (n_tokens != 7) {
if (n_tokens != 9) {
snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
return;
}
@ -825,7 +826,7 @@ cmd_cryptodev(char **tokens,
if (strcmp(tokens[4], "queue")) {
snprintf(out, out_size, MSG_ARG_NOT_FOUND,
"4");
"queue");
return;
}
@ -841,6 +842,18 @@ cmd_cryptodev(char **tokens,
return;
}
if (strcmp(tokens[7], "max_sessions")) {
snprintf(out, out_size, MSG_ARG_NOT_FOUND,
"max_sessions");
return;
}
if (parser_read_uint32(&params.session_pool_size, tokens[8]) < 0) {
snprintf(out, out_size, MSG_ARG_INVALID,
"queue_size");
return;
}
if (cryptodev_create(name, &params) == NULL) {
snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
return;
@ -1030,9 +1043,7 @@ static const char cmd_table_action_profile_help[] =
" stats none | pkts]\n"
" [stats pkts | bytes | both]\n"
" [time]\n"
" [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset> "
" mempool_create <mempool_name>\n"
" mempool_init <mempool_name>]\n"
" [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
" [tag]\n"
" [decap]\n";
@ -1404,13 +1415,10 @@ cmd_table_action_profile(char **tokens,
if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
struct cryptodev *cryptodev;
struct mempool *mempool;
if (n_tokens < t0 + 9 ||
if (n_tokens < t0 + 5 ||
strcmp(tokens[t0 + 1], "dev") ||
strcmp(tokens[t0 + 3], "offset") ||
strcmp(tokens[t0 + 5], "mempool_create") ||
strcmp(tokens[t0 + 7], "mempool_init")) {
strcmp(tokens[t0 + 3], "offset")) {
snprintf(out, out_size, MSG_ARG_MISMATCH,
"table action profile sym_crypto");
return;
@ -1432,25 +1440,12 @@ cmd_table_action_profile(char **tokens,
return;
}
mempool = mempool_find(tokens[t0 + 6]);
if (mempool == NULL) {
snprintf(out, out_size, MSG_ARG_INVALID,
"table action profile sym_crypto");
return;
}
p.sym_crypto.mp_create = mempool->m;
mempool = mempool_find(tokens[t0 + 8]);
if (mempool == NULL) {
snprintf(out, out_size, MSG_ARG_INVALID,
"table action profile sym_crypto");
return;
}
p.sym_crypto.mp_init = mempool->m;
p.sym_crypto.mp_create = cryptodev->mp_create;
p.sym_crypto.mp_init = cryptodev->mp_init;
p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
t0 += 9;
t0 += 5;
} /* sym_crypto */
if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {

View File

@ -11,6 +11,8 @@
#include "cryptodev.h"
#define PIPELINE_CRYPTO_SESSION_CACHE_SIZE 128
static struct cryptodev_list cryptodev_list;
int
@ -53,13 +55,16 @@ cryptodev_create(const char *name, struct cryptodev_params *params)
struct cryptodev *cryptodev;
uint32_t dev_id, i;
uint32_t socket_id;
uint32_t cache_size;
char mp_name[NAME_SIZE];
int status;
/* Check input params */
if ((name == NULL) ||
cryptodev_find(name) ||
(params->n_queues == 0) ||
(params->queue_size == 0))
(params->queue_size == 0) ||
(params->session_pool_size == 0))
return NULL;
if (params->dev_name) {
@ -75,6 +80,11 @@ cryptodev_create(const char *name, struct cryptodev_params *params)
dev_id = params->dev_id;
}
cache_size = (params->session_pool_size / 2 <
PIPELINE_CRYPTO_SESSION_CACHE_SIZE) ?
(params->session_pool_size / 2) :
PIPELINE_CRYPTO_SESSION_CACHE_SIZE;
socket_id = rte_cryptodev_socket_id(dev_id);
rte_cryptodev_info_get(dev_id, &dev_info);
@ -111,7 +121,44 @@ cryptodev_create(const char *name, struct cryptodev_params *params)
cryptodev->dev_id = dev_id;
cryptodev->n_queues = params->n_queues;
snprintf(mp_name, NAME_SIZE, "%s_mp%u", name, dev_id);
cryptodev->mp_create = rte_cryptodev_sym_session_pool_create(
mp_name,
params->session_pool_size,
0,
cache_size,
0,
socket_id);
if (!cryptodev->mp_create)
goto error_exit;
snprintf(mp_name, NAME_SIZE, "%s_mp_priv%u", name, dev_id);
cryptodev->mp_init = rte_mempool_create(
NULL,
params->session_pool_size,
rte_cryptodev_sym_get_private_session_size(dev_id),
cache_size,
0,
NULL,
NULL,
NULL,
NULL,
socket_id,
0);
if (!cryptodev->mp_init)
goto error_exit;
TAILQ_INSERT_TAIL(&cryptodev_list, cryptodev, node);
return cryptodev;
error_exit:
if (cryptodev->mp_create)
rte_mempool_free(cryptodev->mp_create);
if (cryptodev->mp_init)
rte_mempool_free(cryptodev->mp_init);
free(cryptodev);
return NULL;
}

View File

@ -17,6 +17,8 @@ struct cryptodev {
char name[NAME_SIZE];
uint16_t dev_id;
uint32_t n_queues;
struct rte_mempool *mp_create;
struct rte_mempool *mp_init;
};
TAILQ_HEAD(cryptodev_list, cryptodev);
@ -35,6 +37,7 @@ struct cryptodev_params {
uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
uint32_t n_queues;
uint32_t queue_size;
uint32_t session_pool_size;
};
struct cryptodev *

View File

@ -21,14 +21,13 @@
; 5 Crypto Operation 1792 160
mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 1
mempool MEMPOOL_SESSION0 buffer 1024 pool 1024 cache 128 cpu 1
link LINK0 dev 0000:81:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
link LINK0 dev 81:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
#Cryptodev
cryptodev CRYPTO0 dev crypto_aesni_gcm0 queue 1 1024
cryptodev CRYPTO0 dev crypto_aesni_gcm0 queue 1 1024 max_sessions 512
table action profile AP0 ipv4 offset 270 fwd sym_crypto dev CRYPTO0 offset 1792 mempool_create MEMPOOL_SESSION0 mempool_init MEMPOOL_SESSION0
table action profile AP0 ipv4 offset 270 fwd sym_crypto dev CRYPTO0 offset 1792
table action profile AP1 ipv4 offset 270 fwd
pipeline PIPELINE0 period 10 offset_port_id 0 cpu 1
@ -46,7 +45,7 @@ pipeline PIPELINE0 table match stub action AP1
pipeline PIPELINE0 port in 0 table 0
pipeline PIPELINE0 port in 1 table 1
thread 24 pipeline PIPELINE0 enable
thread 2 pipeline PIPELINE0 enable
pipeline PIPELINE0 table 0 rule add match default action fwd port 2

View File

@ -55,7 +55,7 @@
#define CDEV_QUEUE_DESC 2048
#define CDEV_MAP_ENTRIES 16384
#define CDEV_MP_NB_OBJS 2048
#define CDEV_MP_NB_OBJS 1024
#define CDEV_MP_CACHE_SZ 64
#define MAX_QUEUE_PAIRS 1
@ -820,11 +820,15 @@ main_loop(__attribute__((unused)) void *dummy)
qconf->inbound.sa_ctx = socket_ctx[socket_id].sa_in;
qconf->inbound.cdev_map = cdev_map_in;
qconf->inbound.session_pool = socket_ctx[socket_id].session_pool;
qconf->inbound.session_priv_pool =
socket_ctx[socket_id].session_priv_pool;
qconf->outbound.sp4_ctx = socket_ctx[socket_id].sp_ip4_out;
qconf->outbound.sp6_ctx = socket_ctx[socket_id].sp_ip6_out;
qconf->outbound.sa_ctx = socket_ctx[socket_id].sa_out;
qconf->outbound.cdev_map = cdev_map_out;
qconf->outbound.session_pool = socket_ctx[socket_id].session_pool;
qconf->outbound.session_priv_pool =
socket_ctx[socket_id].session_priv_pool;
if (qconf->nb_rx_queue == 0) {
RTE_LOG(INFO, IPSEC, "lcore %u has nothing to do\n", lcore_id);
@ -1460,10 +1464,10 @@ cryptodevs_init(void)
dev_conf.nb_queue_pairs = qp;
uint32_t dev_max_sess = cdev_info.sym.max_nb_sessions;
if (dev_max_sess != 0 && dev_max_sess < (CDEV_MP_NB_OBJS / 2))
if (dev_max_sess != 0 && dev_max_sess < CDEV_MP_NB_OBJS)
rte_exit(EXIT_FAILURE,
"Device does not support at least %u "
"sessions", CDEV_MP_NB_OBJS / 2);
"sessions", CDEV_MP_NB_OBJS);
if (!socket_ctx[dev_conf.socket_id].session_pool) {
char mp_name[RTE_MEMPOOL_NAMESIZE];
@ -1471,6 +1475,19 @@ cryptodevs_init(void)
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_%u", dev_conf.socket_id);
sess_mp = rte_cryptodev_sym_session_pool_create(
mp_name, CDEV_MP_NB_OBJS,
0, CDEV_MP_CACHE_SZ, 0,
dev_conf.socket_id);
socket_ctx[dev_conf.socket_id].session_pool = sess_mp;
}
if (!socket_ctx[dev_conf.socket_id].session_priv_pool) {
char mp_name[RTE_MEMPOOL_NAMESIZE];
struct rte_mempool *sess_mp;
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_priv_%u", dev_conf.socket_id);
sess_mp = rte_mempool_create(mp_name,
CDEV_MP_NB_OBJS,
max_sess_sz,
@ -1478,25 +1495,28 @@ cryptodevs_init(void)
0, NULL, NULL, NULL,
NULL, dev_conf.socket_id,
0);
if (sess_mp == NULL)
rte_exit(EXIT_FAILURE,
"Cannot create session pool on socket %d\n",
dev_conf.socket_id);
else
printf("Allocated session pool on socket %d\n",
dev_conf.socket_id);
socket_ctx[dev_conf.socket_id].session_pool = sess_mp;
socket_ctx[dev_conf.socket_id].session_priv_pool =
sess_mp;
}
if (!socket_ctx[dev_conf.socket_id].session_priv_pool ||
!socket_ctx[dev_conf.socket_id].session_pool)
rte_exit(EXIT_FAILURE,
"Cannot create session pool on socket %d\n",
dev_conf.socket_id);
else
printf("Allocated session pool on socket %d\n",
dev_conf.socket_id);
if (rte_cryptodev_configure(cdev_id, &dev_conf))
rte_panic("Failed to initialize cryptodev %u\n",
cdev_id);
qp_conf.nb_descriptors = CDEV_QUEUE_DESC;
qp_conf.mp_session =
socket_ctx[dev_conf.socket_id].session_pool;
socket_ctx[dev_conf.socket_id].session_pool;
qp_conf.mp_session_private =
socket_ctx[dev_conf.socket_id].session_pool;
socket_ctx[dev_conf.socket_id].session_priv_pool;
for (qp = 0; qp < dev_conf.nb_queue_pairs; qp++)
if (rte_cryptodev_queue_pair_setup(cdev_id, qp,
&qp_conf, dev_conf.socket_id))
@ -1521,7 +1541,7 @@ cryptodevs_init(void)
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_%u", socket_id);
sess_mp = rte_mempool_create(mp_name,
CDEV_MP_NB_OBJS,
(CDEV_MP_NB_OBJS * 2),
max_sess_sz,
CDEV_MP_CACHE_SZ,
0, NULL, NULL, NULL,

View File

@ -323,7 +323,7 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
ipsec_ctx->session_pool);
rte_cryptodev_sym_session_init(ipsec_ctx->tbl[cdev_id_qp].id,
sa->crypto_session, sa->xforms,
ipsec_ctx->session_pool);
ipsec_ctx->session_priv_pool);
rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
&cdev_info);

View File

@ -144,6 +144,7 @@ struct ipsec_ctx {
uint16_t last_qp;
struct cdev_qp tbl[MAX_QP_PER_LCORE];
struct rte_mempool *session_pool;
struct rte_mempool *session_priv_pool;
struct rte_mbuf *ol_pkts[MAX_PKT_BURST] __rte_aligned(sizeof(void *));
uint16_t ol_pkts_cnt;
};
@ -166,6 +167,7 @@ struct socket_ctx {
struct rt_ctx *rt_ip6;
struct rte_mempool *mbuf_pool;
struct rte_mempool *session_pool;
struct rte_mempool *session_priv_pool;
};
struct cnt_blk {

View File

@ -48,6 +48,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)

View File

@ -221,7 +221,10 @@ static struct rte_eth_conf port_conf = {
struct rte_mempool *l2fwd_pktmbuf_pool;
struct rte_mempool *l2fwd_crypto_op_pool;
struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 };
static struct {
struct rte_mempool *sess_mp;
struct rte_mempool *priv_mp;
} session_pool_socket[RTE_MAX_NUMA_NODES];
/* Per-port statistics struct */
struct l2fwd_port_statistics {
@ -645,7 +648,6 @@ initialize_crypto_session(struct l2fwd_crypto_options *options, uint8_t cdev_id)
return NULL;
uint8_t socket_id = (uint8_t) retval;
struct rte_mempool *sess_mp = session_pool_socket[socket_id];
if (options->xform_chain == L2FWD_CRYPTO_AEAD) {
first_xform = &options->aead_xform;
@ -661,13 +663,14 @@ initialize_crypto_session(struct l2fwd_crypto_options *options, uint8_t cdev_id)
first_xform = &options->auth_xform;
}
session = rte_cryptodev_sym_session_create(sess_mp);
session = rte_cryptodev_sym_session_create(
session_pool_socket[socket_id].sess_mp);
if (session == NULL)
return NULL;
if (rte_cryptodev_sym_session_init(cdev_id, session,
first_xform, sess_mp) < 0)
first_xform,
session_pool_socket[socket_id].priv_mp) < 0)
return NULL;
return session;
@ -2267,38 +2270,54 @@ initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
rte_cryptodev_scheduler_slaves_get(cdev_id,
NULL);
sessions_needed = 2 * enabled_cdev_count * nb_slaves;
sessions_needed = enabled_cdev_count * nb_slaves;
#endif
} else
sessions_needed = 2 * enabled_cdev_count;
sessions_needed = enabled_cdev_count;
if (session_pool_socket[socket_id] == NULL) {
if (session_pool_socket[socket_id].priv_mp == NULL) {
char mp_name[RTE_MEMPOOL_NAMESIZE];
struct rte_mempool *sess_mp;
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_%u", socket_id);
"priv_sess_mp_%u", socket_id);
/*
* Create enough objects for session headers and
* device private data
*/
sess_mp = rte_mempool_create(mp_name,
session_pool_socket[socket_id].priv_mp =
rte_mempool_create(mp_name,
sessions_needed,
max_sess_sz,
SESSION_POOL_CACHE_SIZE,
0, NULL, NULL, NULL,
0, 0, NULL, NULL, NULL,
NULL, socket_id,
0);
if (sess_mp == NULL) {
printf("Cannot create session pool on socket %d\n",
if (session_pool_socket[socket_id].priv_mp == NULL) {
printf("Cannot create pool on socket %d\n",
socket_id);
return -ENOMEM;
}
printf("Allocated session pool on socket %d\n", socket_id);
session_pool_socket[socket_id] = sess_mp;
printf("Allocated pool \"%s\" on socket %d\n",
mp_name, socket_id);
}
if (session_pool_socket[socket_id].sess_mp == NULL) {
char mp_name[RTE_MEMPOOL_NAMESIZE];
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_%u", socket_id);
session_pool_socket[socket_id].sess_mp =
rte_cryptodev_sym_session_pool_create(
mp_name,
sessions_needed,
0, 0, 0, socket_id);
if (session_pool_socket[socket_id].sess_mp == NULL) {
printf("Cannot create pool on socket %d\n",
socket_id);
return -ENOMEM;
}
printf("Allocated pool \"%s\" on socket %d\n",
mp_name, socket_id);
}
/* Set AEAD parameters */
@ -2443,8 +2462,9 @@ initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
}
qp_conf.nb_descriptors = 2048;
qp_conf.mp_session = session_pool_socket[socket_id];
qp_conf.mp_session_private = session_pool_socket[socket_id];
qp_conf.mp_session = session_pool_socket[socket_id].sess_mp;
qp_conf.mp_session_private =
session_pool_socket[socket_id].priv_mp;
retval = rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf,
socket_id);

View File

@ -7,6 +7,7 @@
# DPDK instance, use 'make'
deps += 'cryptodev'
allow_experimental_apis = true
sources = files(
'main.c'
)