@@ -20,15 +20,14 @@ pdcp_cnt_bitmap_get_memory_footprint(const struct rte_pdcp_entity_conf *conf)
}
int
-pdcp_cnt_bitmap_create(struct entity_priv_dl_part *dl, void *bitmap_mem, uint32_t window_size)
+pdcp_cnt_bitmap_create(struct entity_priv_dl_part *dl, uint32_t nb_elem,
+ void *bitmap_mem, uint32_t mem_size)
{
- uint32_t mem_size = rte_bitmap_get_memory_footprint(window_size);
-
- dl->bitmap.bmp = rte_bitmap_init(window_size, bitmap_mem, mem_size);
+ dl->bitmap.bmp = rte_bitmap_init(nb_elem, bitmap_mem, mem_size);
if (dl->bitmap.bmp == NULL)
return -EINVAL;
- dl->bitmap.size = window_size;
+ dl->bitmap.size = nb_elem;
return 0;
}
@@ -10,7 +10,8 @@
#include "pdcp_entity.h"
uint32_t pdcp_cnt_bitmap_get_memory_footprint(const struct rte_pdcp_entity_conf *conf);
-int pdcp_cnt_bitmap_create(struct entity_priv_dl_part *dl, void *bitmap_mem, uint32_t window_size);
+int pdcp_cnt_bitmap_create(struct entity_priv_dl_part *dl, uint32_t nb_elem,
+ void *bitmap_mem, uint32_t mem_size);
void pdcp_cnt_bitmap_set(struct pdcp_cnt_bitmap bitmap, uint32_t count);
bool pdcp_cnt_bitmap_is_set(struct pdcp_cnt_bitmap bitmap, uint32_t count);
@@ -132,7 +132,7 @@ struct pdcp_cnt_bitmap {
};
/*
- * Layout of PDCP entity: [rte_pdcp_entity] [entity_priv] [entity_dl/ul]
+ * Layout of PDCP entity: [rte_pdcp_entity] [entity_priv] [entity_dl/ul] [reorder/bitmap]
*/
struct entity_priv {
@@ -8,20 +8,13 @@
#include "pdcp_reorder.h"
int
-pdcp_reorder_create(struct pdcp_reorder *reorder, uint32_t window_size)
+pdcp_reorder_create(struct pdcp_reorder *reorder, size_t nb_elem, void *mem, size_t mem_size)
{
- reorder->buf = rte_reorder_create("reorder_buffer", SOCKET_ID_ANY, window_size);
+ reorder->buf = rte_reorder_init(mem, mem_size, "reorder_buffer", nb_elem);
if (reorder->buf == NULL)
return -rte_errno;
- reorder->window_size = window_size;
reorder->is_active = false;
return 0;
}
-
-void
-pdcp_reorder_destroy(const struct pdcp_reorder *reorder)
-{
- rte_reorder_free(reorder->buf);
-}
@@ -9,12 +9,18 @@
struct pdcp_reorder {
struct rte_reorder_buffer *buf;
- uint32_t window_size;
bool is_active;
};
-int pdcp_reorder_create(struct pdcp_reorder *reorder, uint32_t window_size);
-void pdcp_reorder_destroy(const struct pdcp_reorder *reorder);
+int pdcp_reorder_create(struct pdcp_reorder *reorder, size_t nb_elem, void *mem, size_t mem_size);
+
+/* NOTE: replace with `rte_reorder_memory_footprint_get` after DPDK 23.07 */
+#define SIZE_OF_REORDER_BUFFER (4 * RTE_CACHE_LINE_SIZE)
+static inline size_t
+pdcp_reorder_memory_footprint_get(size_t nb_elem)
+{
+ return SIZE_OF_REORDER_BUFFER + (2 * nb_elem * sizeof(struct rte_mbuf *));
+}
static inline uint32_t
pdcp_reorder_get_sequential(struct pdcp_reorder *reorder, struct rte_mbuf **mbufs,
@@ -14,7 +14,15 @@
#define RTE_PDCP_DYNFIELD_NAME "rte_pdcp_dynfield"
-static int bitmap_mem_offset;
+struct entity_layout {
+ size_t bitmap_offset;
+ size_t bitmap_size;
+
+ size_t reorder_buf_offset;
+ size_t reorder_buf_size;
+
+ size_t total_size;
+};
int rte_pdcp_dynfield_offset = -1;
@@ -35,46 +43,54 @@ pdcp_dynfield_register(void)
}
static int
-pdcp_entity_size_get(const struct rte_pdcp_entity_conf *conf)
+pdcp_entity_layout_get(const struct rte_pdcp_entity_conf *conf, struct entity_layout *layout)
{
- int size;
+ size_t size;
+ const uint32_t window_size = pdcp_window_size_get(conf->pdcp_xfrm.sn_size);
size = sizeof(struct rte_pdcp_entity) + sizeof(struct entity_priv);
if (conf->pdcp_xfrm.pkt_dir == RTE_SECURITY_PDCP_DOWNLINK) {
size += sizeof(struct entity_priv_dl_part);
+ /* Bitmap require memory to be cache aligned */
size = RTE_CACHE_LINE_ROUNDUP(size);
- bitmap_mem_offset = size;
- size += pdcp_cnt_bitmap_get_memory_footprint(conf);
+ layout->bitmap_offset = size;
+ layout->bitmap_size = pdcp_cnt_bitmap_get_memory_footprint(conf);
+ size += layout->bitmap_size;
+ layout->reorder_buf_offset = size;
+ layout->reorder_buf_size = pdcp_reorder_memory_footprint_get(window_size);
+ size += layout->reorder_buf_size;
} else if (conf->pdcp_xfrm.pkt_dir == RTE_SECURITY_PDCP_UPLINK)
size += sizeof(struct entity_priv_ul_part);
else
return -EINVAL;
- return RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE);
+ layout->total_size = size;
+
+ return 0;
}
static int
-pdcp_dl_establish(struct rte_pdcp_entity *entity, const struct rte_pdcp_entity_conf *conf)
+pdcp_dl_establish(struct rte_pdcp_entity *entity, const struct rte_pdcp_entity_conf *conf,
+ const struct entity_layout *layout)
{
const uint32_t window_size = pdcp_window_size_get(conf->pdcp_xfrm.sn_size);
struct entity_priv_dl_part *dl = entity_dl_part_get(entity);
- void *bitmap_mem;
+ void *memory;
int ret;
entity->max_pkt_cache = RTE_MAX(entity->max_pkt_cache, window_size);
dl->t_reorder.handle = conf->t_reordering;
- ret = pdcp_reorder_create(&dl->reorder, window_size);
+ memory = RTE_PTR_ADD(entity, layout->reorder_buf_offset);
+ ret = pdcp_reorder_create(&dl->reorder, window_size, memory, layout->reorder_buf_size);
if (ret)
return ret;
- bitmap_mem = RTE_PTR_ADD(entity, bitmap_mem_offset);
- ret = pdcp_cnt_bitmap_create(dl, bitmap_mem, window_size);
- if (ret) {
- pdcp_reorder_destroy(&dl->reorder);
+ memory = RTE_PTR_ADD(entity, layout->bitmap_offset);
+ ret = pdcp_cnt_bitmap_create(dl, window_size, memory, layout->bitmap_size);
+ if (ret)
return ret;
- }
return 0;
}
@@ -82,10 +98,11 @@ pdcp_dl_establish(struct rte_pdcp_entity *entity, const struct rte_pdcp_entity_c
struct rte_pdcp_entity *
rte_pdcp_entity_establish(const struct rte_pdcp_entity_conf *conf)
{
+ struct entity_layout entity_layout = { 0 };
struct rte_pdcp_entity *entity = NULL;
struct entity_priv *en_priv;
- int ret, entity_size;
uint32_t count;
+ int ret;
if (pdcp_dynfield_register() < 0)
return NULL;
@@ -118,13 +135,14 @@ rte_pdcp_entity_establish(const struct rte_pdcp_entity_conf *conf)
return NULL;
}
- entity_size = pdcp_entity_size_get(conf);
- if (entity_size < 0) {
+ ret = pdcp_entity_layout_get(conf, &entity_layout);
+ if (ret < 0) {
rte_errno = EINVAL;
return NULL;
}
- entity = rte_zmalloc_socket("pdcp_entity", entity_size, RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
+ entity = rte_zmalloc_socket("pdcp_entity", entity_layout.total_size, RTE_CACHE_LINE_SIZE,
+ SOCKET_ID_ANY);
if (entity == NULL) {
rte_errno = ENOMEM;
return NULL;
@@ -149,7 +167,7 @@ rte_pdcp_entity_establish(const struct rte_pdcp_entity_conf *conf)
goto crypto_sess_destroy;
if (conf->pdcp_xfrm.pkt_dir == RTE_SECURITY_PDCP_DOWNLINK) {
- ret = pdcp_dl_establish(entity, conf);
+ ret = pdcp_dl_establish(entity, conf, &entity_layout);
if (ret)
goto crypto_sess_destroy;
}
@@ -174,8 +192,6 @@ pdcp_dl_release(struct rte_pdcp_entity *entity, struct rte_mbuf *out_mb[])
nb_out = pdcp_reorder_up_to_get(&dl->reorder, out_mb, entity->max_pkt_cache,
en_priv->state.rx_next);
- pdcp_reorder_destroy(&dl->reorder);
-
return nb_out;
}