From fbfe90ed4a300487dc82ab36d5b4b99cefacdb43 Mon Sep 17 00:00:00 2001 From: Sergio Gonzalez Monroy Date: Wed, 15 Nov 2017 15:43:35 +0000 Subject: dpdk/ipsec: use physmem when creating pools Change-Id: Ic4f797cea6fa21fb29d646256210357cf5267b38 Signed-off-by: Sergio Gonzalez Monroy --- src/plugins/dpdk/buffer.c | 108 +++++++++++++++++++++++------------------ src/plugins/dpdk/device/dpdk.h | 6 +++ src/plugins/dpdk/ipsec/ipsec.c | 86 ++++++++++++++++++-------------- 3 files changed, 116 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/plugins/dpdk/buffer.c b/src/plugins/dpdk/buffer.c index 34afd7c2a5f..d0e13ae001a 100644 --- a/src/plugins/dpdk/buffer.c +++ b/src/plugins/dpdk/buffer.c @@ -490,6 +490,49 @@ dpdk_packet_template_init (vlib_main_t * vm, vlib_worker_thread_barrier_release (vm); } +clib_error_t * +dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size, + u32 num_elts, u32 pool_priv_size, u16 cache_size, u8 numa, + struct rte_mempool **_mp, vlib_physmem_region_index_t * pri) +{ + struct rte_mempool *mp; + vlib_physmem_region_t *pr; + clib_error_t *error = 0; + u32 size, obj_size; + i32 ret; + + obj_size = rte_mempool_calc_obj_size (elt_size, 0, 0); + size = rte_mempool_xmem_size (num_elts, obj_size, 21); + + error = + vlib_physmem_region_alloc (vm, (i8 *) pool_name, size, numa, 0, pri); + if (error) + return error; + + pr = vlib_physmem_get_region (vm, pri[0]); + + mp = + rte_mempool_create_empty ((i8 *) pool_name, num_elts, elt_size, + 512, pool_priv_size, numa, 0); + if (!mp) + return clib_error_return (0, "failed to create %s", pool_name); + + rte_mempool_set_ops_byname (mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS, NULL); + + ret = + rte_mempool_populate_phys_tab (mp, pr->mem, pr->page_table, pr->n_pages, + pr->log2_page_size, NULL, NULL); + if (ret != (i32) mp->size) + { + rte_mempool_free (mp); + return clib_error_return (0, "failed to populate %s", pool_name); + } + + _mp[0] = mp; + + return 0; +} + clib_error_t * dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs, unsigned socket_id) @@ -497,12 +540,10 @@ dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs, dpdk_main_t *dm = &dpdk_main; struct rte_mempool *rmp; dpdk_mempool_private_t priv; - vlib_physmem_region_t *pr; vlib_physmem_region_index_t pri; + clib_error_t *error = 0; u8 *pool_name; - unsigned elt_size; - u32 size, obj_size; - i32 i, ret; + u32 elt_size, i; vec_validate_aligned (dm->pktmbuf_pools, socket_id, CLIB_CACHE_LINE_BYTES); @@ -516,61 +557,34 @@ dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs, VLIB_BUFFER_HDR_SIZE /* priv size */ + VLIB_BUFFER_PRE_DATA_SIZE + VLIB_BUFFER_DATA_SIZE; /*data room size */ - obj_size = rte_mempool_calc_obj_size (elt_size, 0, 0); - size = rte_mempool_xmem_size (num_mbufs, obj_size, 21); - - clib_error_t *error = 0; - error = vlib_physmem_region_alloc (vm, (char *) pool_name, size, socket_id, - 0, &pri); - if (error) - clib_error_report (error); - - pr = vlib_physmem_get_region (vm, pri); + error = + dpdk_pool_create (vm, pool_name, elt_size, num_mbufs, + sizeof (dpdk_mempool_private_t), 512, socket_id, + &rmp, &pri); - priv.mbp_priv.mbuf_data_room_size = VLIB_BUFFER_PRE_DATA_SIZE + - VLIB_BUFFER_DATA_SIZE; - priv.mbp_priv.mbuf_priv_size = VLIB_BUFFER_HDR_SIZE; + vec_free (pool_name); -#if 0 - /* Check that pg_shift parameter is valid. */ - if (pg_shift > MEMPOOL_PG_SHIFT_MAX) + if (!error) { - rte_errno = EINVAL; - return NULL; - } -#endif - rmp = rte_mempool_create_empty ((char *) pool_name, /* pool name */ - num_mbufs, /* number of mbufs */ - elt_size, 512, /* cache size */ - sizeof (dpdk_mempool_private_t), /* private data size */ - socket_id, 0); /* flags */ - if (rmp) - { - rte_mempool_set_ops_byname (rmp, RTE_MBUF_DEFAULT_MEMPOOL_OPS, NULL); + priv.mbp_priv.mbuf_data_room_size = VLIB_BUFFER_PRE_DATA_SIZE + + VLIB_BUFFER_DATA_SIZE; + priv.mbp_priv.mbuf_priv_size = VLIB_BUFFER_HDR_SIZE; /* call the mempool priv initializer */ rte_pktmbuf_pool_init (rmp, &priv); - ret = rte_mempool_populate_phys_tab (rmp, pr->mem, pr->page_table, - pr->n_pages, pr->log2_page_size, - NULL, NULL); - if (ret == (i32) rmp->size) - { - /* call the object initializers */ - rte_mempool_obj_iter (rmp, rte_pktmbuf_init, 0); + /* call the object initializers */ + rte_mempool_obj_iter (rmp, rte_pktmbuf_init, 0); - dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp); - privp->buffer_pool_index = vlib_buffer_add_physmem_region (vm, pri); + dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp); + privp->buffer_pool_index = vlib_buffer_add_physmem_region (vm, pri); - dm->pktmbuf_pools[socket_id] = rmp; + dm->pktmbuf_pools[socket_id] = rmp; - return 0; - } - - rte_mempool_free (rmp); + return 0; } - vec_free (pool_name); + clib_error_report (error); /* no usable pool for this socket, try to use pool from another one */ for (i = 0; i < vec_len (dm->pktmbuf_pools); i++) diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h index 1ed3b280385..2e17d635efb 100644 --- a/src/plugins/dpdk/device/dpdk.h +++ b/src/plugins/dpdk/device/dpdk.h @@ -465,6 +465,12 @@ uword admin_up_down_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f); +clib_error_t *dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, + u32 elt_size, u32 num_elts, + u32 pool_priv_size, u16 cache_size, u8 numa, + struct rte_mempool **_mp, + vlib_physmem_region_index_t * pri); + clib_error_t *dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs, unsigned socket_id); diff --git a/src/plugins/dpdk/ipsec/ipsec.c b/src/plugins/dpdk/ipsec/ipsec.c index dfbda5ba473..fdfe0e65c70 100644 --- a/src/plugins/dpdk/ipsec/ipsec.c +++ b/src/plugins/dpdk/ipsec/ipsec.c @@ -855,7 +855,7 @@ crypto_op_init (struct rte_mempool *mempool, } static clib_error_t * -crypto_create_crypto_op_pool (u8 numa) +crypto_create_crypto_op_pool (vlib_main_t * vm, u8 numa) { dpdk_crypto_main_t *dcm = &dpdk_crypto_main; dpdk_config_main_t *conf = &dpdk_config_main; @@ -863,39 +863,42 @@ crypto_create_crypto_op_pool (u8 numa) u8 *pool_name; u32 pool_priv_size = sizeof (struct rte_crypto_op_pool_private); struct rte_crypto_op_pool_private *priv; + struct rte_mempool *mp; clib_error_t *error = NULL; + vlib_physmem_region_index_t pri; data = vec_elt_at_index (dcm->data, numa); + /* Already allocated */ if (data->crypto_op) return NULL; pool_name = format (0, "crypto_pool_numa%u%c", numa, 0); - data->crypto_op = - rte_mempool_create ((i8 *) pool_name, conf->num_mbufs, crypto_op_len (), - 512, pool_priv_size, NULL, NULL, crypto_op_init, NULL, - numa, 0); + error = + dpdk_pool_create (vm, pool_name, crypto_op_len (), conf->num_mbufs, + pool_priv_size, 512, numa, &mp, &pri); - if (!data->crypto_op) - { - error = clib_error_return (0, "failed to allocate %s", pool_name); - goto done; - } + vec_free (pool_name); - priv = rte_mempool_get_priv (data->crypto_op); + if (error) + return error; + /* Initialize mempool private data */ + priv = rte_mempool_get_priv (mp); priv->priv_size = pool_priv_size; priv->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC; -done: - vec_free (pool_name); + /* call the object initializers */ + rte_mempool_obj_iter (mp, crypto_op_init, 0); + + data->crypto_op = mp; - return error; + return NULL; } static clib_error_t * -crypto_create_session_h_pool (u8 numa) +crypto_create_session_h_pool (vlib_main_t * vm, u8 numa) { #if DPDK_NO_AEAD return NULL; @@ -903,8 +906,10 @@ crypto_create_session_h_pool (u8 numa) dpdk_crypto_main_t *dcm = &dpdk_crypto_main; crypto_data_t *data; u8 *pool_name; - u32 elt_size; + struct rte_mempool *mp; clib_error_t *error = NULL; + vlib_physmem_region_index_t pri; + u32 elt_size; data = vec_elt_at_index (dcm->data, numa); @@ -912,23 +917,26 @@ crypto_create_session_h_pool (u8 numa) return NULL; pool_name = format (0, "session_h_pool_numa%u%c", numa, 0); - elt_size = rte_cryptodev_get_header_session_size (); - data->session_h = - rte_mempool_create ((i8 *) pool_name, DPDK_CRYPTO_NB_SESS_OBJS, elt_size, - 512, 0, NULL, NULL, NULL, NULL, numa, 0); + elt_size = rte_cryptodev_get_header_session_size (); - if (!data->session_h) - error = clib_error_return (0, "failed to allocate %s", pool_name); + error = + dpdk_pool_create (vm, pool_name, elt_size, DPDK_CRYPTO_NB_SESS_OBJS, + 0, 512, numa, &mp, &pri); vec_free (pool_name); - return error; + if (error) + return error; + + data->session_h = mp; + + return NULL; #endif } static clib_error_t * -crypto_create_session_drv_pool (crypto_dev_t * dev) +crypto_create_session_drv_pool (vlib_main_t * vm, crypto_dev_t * dev) { #if DPDK_NO_AEAD return NULL; @@ -936,8 +944,10 @@ crypto_create_session_drv_pool (crypto_dev_t * dev) dpdk_crypto_main_t *dcm = &dpdk_crypto_main; crypto_data_t *data; u8 *pool_name; - u32 elt_size; + struct rte_mempool *mp; clib_error_t *error = NULL; + vlib_physmem_region_index_t pri; + u32 elt_size; u8 numa = dev->numa; data = vec_elt_at_index (dcm->data, numa); @@ -951,21 +961,23 @@ crypto_create_session_drv_pool (crypto_dev_t * dev) pool_name = format (0, "session_drv%u_pool_numa%u%c", dev->drv_id, numa, 0); elt_size = rte_cryptodev_get_private_session_size (dev->id); - data->session_drv[dev->drv_id] = - rte_mempool_create ((i8 *) pool_name, DPDK_CRYPTO_NB_SESS_OBJS, elt_size, - 512, 0, NULL, NULL, NULL, NULL, numa, 0); - - if (!data->session_drv[dev->drv_id]) - error = clib_error_return (0, "failed to allocate %s", pool_name); + error = + dpdk_pool_create (vm, pool_name, elt_size, DPDK_CRYPTO_NB_SESS_OBJS, + 0, 512, numa, &mp, &pri); vec_free (pool_name); - return error; + if (error) + return error; + + data->session_drv[dev->drv_id] = mp; + + return NULL; #endif } static clib_error_t * -crypto_create_pools (void) +crypto_create_pools (vlib_main_t * vm) { dpdk_crypto_main_t *dcm = &dpdk_crypto_main; clib_error_t *error = NULL; @@ -976,15 +988,15 @@ crypto_create_pools (void) { vec_validate_aligned (dcm->data, dev->numa, CLIB_CACHE_LINE_BYTES); - error = crypto_create_crypto_op_pool (dev->numa); + error = crypto_create_crypto_op_pool (vm, dev->numa); if (error) return error; - error = crypto_create_session_h_pool (dev->numa); + error = crypto_create_session_h_pool (vm, dev->numa); if (error) return error; - error = crypto_create_session_drv_pool (dev); + error = crypto_create_session_drv_pool (vm, dev); if (error) return error; } @@ -1067,7 +1079,7 @@ dpdk_ipsec_process (vlib_main_t * vm, vlib_node_runtime_t * rt, crypto_auto_placement (); - error = crypto_create_pools (); + error = crypto_create_pools (vm); if (error) { clib_error_report (error); -- cgit 1.2.3-korg