6 #ifndef _RTE_MEMPOOL_H_ 7 #define _RTE_MEMPOOL_H_ 40 #include <rte_config.h> 55 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL 56 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL 57 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL 59 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 66 struct rte_mempool_debug_stats {
69 uint64_t put_common_pool_bulk;
70 uint64_t put_common_pool_objs;
71 uint64_t get_common_pool_bulk;
72 uint64_t get_common_pool_objs;
73 uint64_t get_success_bulk;
74 uint64_t get_success_objs;
75 uint64_t get_fail_bulk;
76 uint64_t get_fail_objs;
77 uint64_t get_success_blks;
78 uint64_t get_fail_blks;
93 void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
108 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \ 109 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1) 110 #define RTE_MEMPOOL_MZ_PREFIX "MP_" 113 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s" 115 #define MEMPOOL_PG_SHIFT_MAX \ 116 RTE_DEPRECATED(MEMPOOL_PG_SHIFT_MAX) (sizeof(uintptr_t) * CHAR_BIT - 1) 119 #define MEMPOOL_PG_NUM_DEFAULT RTE_DEPRECATED(MEMPOOL_PG_NUM_DEFAULT) 1 121 #ifndef RTE_MEMPOOL_ALIGN 125 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE 128 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1) 143 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 153 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 161 struct rte_mempool_objtlr {
209 char name[RTE_MEMPOOL_NAMESIZE];
240 struct rte_mempool_objhdr_list elt_list;
242 struct rte_mempool_memhdr_list mem_list;
244 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 246 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
251 #define RTE_MEMPOOL_F_NO_SPREAD 0x0001 256 #define MEMPOOL_F_NO_SPREAD RTE_MEMPOOL_F_NO_SPREAD 258 #define RTE_MEMPOOL_F_NO_CACHE_ALIGN 0x0002 263 #define MEMPOOL_F_NO_CACHE_ALIGN RTE_MEMPOOL_F_NO_CACHE_ALIGN 265 #define RTE_MEMPOOL_F_SP_PUT 0x0004 270 #define MEMPOOL_F_SP_PUT RTE_MEMPOOL_F_SP_PUT 272 #define RTE_MEMPOOL_F_SC_GET 0x0008 277 #define MEMPOOL_F_SC_GET RTE_MEMPOOL_F_SC_GET 279 #define RTE_MEMPOOL_F_POOL_CREATED 0x0010 281 #define RTE_MEMPOOL_F_NO_IOVA_CONTIG 0x0020 286 #define MEMPOOL_F_NO_IOVA_CONTIG RTE_MEMPOOL_F_NO_IOVA_CONTIG 288 #define RTE_MEMPOOL_F_NON_IO 0x0040 293 #define RTE_MEMPOOL_VALID_USER_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \ 294 | RTE_MEMPOOL_F_NO_CACHE_ALIGN \ 295 | RTE_MEMPOOL_F_SP_PUT \ 296 | RTE_MEMPOOL_F_SC_GET \ 297 | RTE_MEMPOOL_F_NO_IOVA_CONTIG \ 309 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 310 #define RTE_MEMPOOL_STAT_ADD(mp, name, n) do { \ 311 unsigned __lcore_id = rte_lcore_id(); \ 312 if (__lcore_id < RTE_MAX_LCORE) { \ 313 mp->stats[__lcore_id].name += n; \ 317 #define RTE_MEMPOOL_STAT_ADD(mp, name, n) do {} while (0) 328 #define RTE_MEMPOOL_HEADER_SIZE(mp, cs) \ 329 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \ 330 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE))) 333 #define MEMPOOL_HEADER_SIZE(mp, cs) \ 334 RTE_DEPRECATED(MEMPOOL_HEADER_SIZE) RTE_MEMPOOL_HEADER_SIZE(mp, cs) 338 rte_mempool_get_header(
void *obj)
360 static inline struct rte_mempool_objtlr *rte_mempool_get_trailer(
void *obj)
380 void rte_mempool_check_cookies(
const struct rte_mempool *mp,
381 void *
const *obj_table_const,
unsigned n,
int free);
383 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 384 #define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) \ 385 rte_mempool_check_cookies(mp, obj_table_const, n, free) 387 #define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) do {} while (0) 405 void rte_mempool_contig_blocks_check_cookies(
const struct rte_mempool *mp,
406 void *
const *first_obj_table_const,
unsigned int n,
int free);
408 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 409 #define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \ 411 rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \ 414 #define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \ 419 #define RTE_MEMPOOL_OPS_NAMESIZE 32 431 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp); 442 void *
const *obj_table,
unsigned int n);
448 void **obj_table,
unsigned int n);
454 void **first_obj_table,
unsigned int n);
485 uint32_t obj_num, uint32_t pg_shift,
486 size_t *min_chunk_size,
size_t *align);
523 ssize_t rte_mempool_op_calc_mem_size_helper(
const struct rte_mempool *mp,
524 uint32_t obj_num, uint32_t pg_shift,
size_t chunk_reserve,
525 size_t *min_chunk_size,
size_t *align);
535 uint32_t obj_num, uint32_t pg_shift,
536 size_t *min_chunk_size,
size_t *align);
582 unsigned int max_objs,
589 #define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001 623 int rte_mempool_op_populate_helper(
struct rte_mempool *mp,
624 unsigned int flags,
unsigned int max_objs,
635 unsigned int max_objs,
674 #define RTE_MEMPOOL_MAX_OPS_IDX 16 685 struct rte_mempool_ops_table { 707 rte_mempool_get_ops(
int ops_index)
740 rte_mempool_ops_dequeue_bulk(
struct rte_mempool *mp,
741 void **obj_table,
unsigned n)
746 rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
747 ops = rte_mempool_get_ops(mp->
ops_index);
748 ret = ops->
dequeue(mp, obj_table, n);
750 RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_bulk, 1);
751 RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_objs, n);
770 rte_mempool_ops_dequeue_contig_blocks(
struct rte_mempool *mp,
771 void **first_obj_table,
unsigned int n)
775 ops = rte_mempool_get_ops(mp->
ops_index);
777 rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
795 rte_mempool_ops_enqueue_bulk(
struct rte_mempool *mp,
void *
const *obj_table,
800 RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_bulk, 1);
801 RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_objs, n);
802 rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
803 ops = rte_mempool_get_ops(mp->
ops_index);
804 return ops->
enqueue(mp, obj_table, n);
816 rte_mempool_ops_get_count(
const struct rte_mempool *mp);
837 ssize_t rte_mempool_ops_calc_mem_size(
const struct rte_mempool *mp,
838 uint32_t obj_num, uint32_t pg_shift,
839 size_t *min_chunk_size,
size_t *align);
864 int rte_mempool_ops_populate(
struct rte_mempool *mp,
unsigned int max_objs,
931 #define RTE_MEMPOOL_REGISTER_OPS(ops) \ 932 RTE_INIT(mp_hdlr_init_##ops) \ 934 rte_mempool_register_ops(&ops); \ 938 #define MEMPOOL_REGISTER_OPS(ops) \ 939 RTE_DEPRECATED(MEMPOOL_REGISTER_OPS) RTE_MEMPOOL_REGISTER_OPS(ops) 947 void *opaque,
void *obj,
unsigned obj_idx);
1289 if (lcore_id >= RTE_MAX_LCORE)
1292 rte_mempool_trace_default_cache(mp, lcore_id,
1311 if (cache == NULL || cache->
len == 0)
1313 rte_mempool_trace_cache_flush(cache, mp);
1314 rte_mempool_ops_enqueue_bulk(mp, cache->
objs, cache->
len);
1331 rte_mempool_do_generic_put(
struct rte_mempool *mp,
void *
const *obj_table,
1337 RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
1338 RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
1341 if (
unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1344 cache_objs = &cache->
objs[cache->
len];
1354 rte_memcpy(&cache_objs[0], obj_table,
sizeof(
void *) * n);
1359 rte_mempool_ops_enqueue_bulk(mp, &cache->
objs[cache->
size],
1369 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 1370 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1371 rte_panic(
"cannot put objects in mempool\n");
1373 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1394 rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1395 RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 0);
1396 rte_mempool_do_generic_put(mp, obj_table, n, cache);
1419 rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1456 rte_mempool_do_generic_get(
struct rte_mempool *mp,
void **obj_table,
1460 uint32_t index,
len;
1467 cache_objs = cache->
objs;
1470 if (cache->
len < n) {
1472 uint32_t req = n + (cache->
size - cache->
len);
1475 ret = rte_mempool_ops_dequeue_bulk(mp,
1476 &cache->
objs[cache->
len], req);
1491 for (index = 0, len = cache->
len - 1; index < n; ++index, len--, obj_table++)
1492 *obj_table = cache_objs[
len];
1496 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1497 RTE_MEMPOOL_STAT_ADD(mp, get_success_objs, n);
1504 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1507 RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1508 RTE_MEMPOOL_STAT_ADD(mp, get_fail_objs, n);
1510 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1511 RTE_MEMPOOL_STAT_ADD(mp, get_success_objs, n);
1542 ret = rte_mempool_do_generic_get(mp, obj_table, n, cache);
1544 RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 1);
1545 rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1576 rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1629 void **first_obj_table,
unsigned int n)
1633 ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1635 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1636 RTE_MEMPOOL_STAT_ADD(mp, get_success_blks, n);
1637 RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table, n,
1640 RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1641 RTE_MEMPOOL_STAT_ADD(mp, get_fail_blks, n);
1644 rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1818 rte_mempool_get_page_size(
struct rte_mempool *mp,
size_t *pg_sz);
1840 typedef void (rte_mempool_event_callback)(
1861 rte_mempool_event_callback_register(rte_mempool_event_callback *func,
1879 rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
#define __rte_always_inline
struct rte_mempool * rte_mempool_lookup(const char *name)
struct rte_mempool_cache * rte_mempool_cache_create(uint32_t size, int socket_id)
uint32_t rte_mempool_mem_iter(struct rte_mempool *mp, rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg)
const struct rte_memzone * mz
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
void rte_mempool_list_dump(FILE *f)
void() rte_mempool_memchunk_free_cb_t(struct rte_mempool_memhdr *memhdr, void *opaque)
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
rte_mempool_alloc_t alloc
void() rte_mempool_populate_obj_cb_t(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
static __rte_always_inline void rte_mempool_generic_put(struct rte_mempool *mp, void *const *obj_table, unsigned int n, struct rte_mempool_cache *cache)
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
static int rte_mempool_empty(const struct rte_mempool *mp)
RTE_STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
rte_mempool_memchunk_free_cb_t * free_cb
char name[RTE_MEMPOOL_OPS_NAMESIZE]
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
rte_mempool_get_info_t get_info
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
char name[RTE_MEMPOOL_NAMESIZE]
unsigned int rte_mempool_avail_count(const struct rte_mempool *mp)
#define RTE_PTR_ADD(ptr, x)
void rte_mempool_cache_free(struct rte_mempool_cache *cache)
uint32_t rte_mempool_obj_iter(struct rte_mempool *mp, rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg)
int rte_mempool_ops_get_info(const struct rte_mempool *mp, struct rte_mempool_info *info)
int rte_mempool_register_ops(const struct rte_mempool_ops *ops)
static __rte_always_inline int rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned int n, struct rte_mempool_cache *cache)
int rte_mempool_populate_default(struct rte_mempool *mp)
static __rte_always_inline void rte_mempool_cache_flush(struct rte_mempool_cache *cache, struct rte_mempool *mp)
#define RTE_MEMPOOL_OPS_NAMESIZE
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
rte_mempool_get_count get_count
ssize_t(* rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp, uint32_t obj_num, uint32_t pg_shift, size_t *min_chunk_size, size_t *align)
static int rte_mempool_full(const struct rte_mempool *mp)
static unsigned rte_lcore_id(void)
unsigned int rte_mempool_in_use_count(const struct rte_mempool *mp)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, void *pool_config)
int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
rte_mempool_calc_mem_size_t calc_mem_size
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, struct rte_mempool_objsz *sz)
ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp, uint32_t obj_num, uint32_t pg_shift, size_t *min_chunk_size, size_t *align)
void * objs[RTE_MEMPOOL_CACHE_MAX_SIZE *3]
unsigned int contig_block_size
int rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
int(* rte_mempool_populate_t)(struct rte_mempool *mp, unsigned int max_objs, void *vaddr, rte_iova_t iova, size_t len, rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
void rte_mempool_audit(struct rte_mempool *mp)
int(* rte_mempool_get_info_t)(const struct rte_mempool *mp, struct rte_mempool_info *info)
struct rte_mempool * rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, unsigned cache_size, unsigned private_data_size, int socket_id, unsigned flags)
unsigned private_data_size
static __rte_always_inline struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
void rte_mempool_dump(FILE *f, struct rte_mempool *mp)
void() rte_mempool_ctor_t(struct rte_mempool *, void *)
int rte_mempool_populate_anon(struct rte_mempool *mp)
struct rte_mempool_cache * local_cache
#define __rte_cache_aligned
rte_mempool_dequeue_t dequeue
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
void() rte_mempool_obj_cb_t(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
void() rte_mempool_mem_cb_t(struct rte_mempool *mp, void *opaque, struct rte_mempool_memhdr *memhdr, unsigned mem_idx)
int rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs, void *vaddr, rte_iova_t iova, size_t len, rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
struct rte_mempool * rte_mempool_create(const char *name, unsigned n, unsigned elt_size, unsigned cache_size, unsigned private_data_size, rte_mempool_ctor_t *mp_init, void *mp_init_arg, rte_mempool_obj_cb_t *obj_init, void *obj_init_arg, int socket_id, unsigned flags)
#define RTE_PTR_SUB(ptr, x)
static struct rte_mempool * rte_mempool_from_obj(void *obj)
static void * rte_memcpy(void *dst, const void *src, size_t n)
static rte_iova_t rte_mempool_virt2iova(const void *elt)
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
rte_mempool_populate_t populate
void rte_mempool_free(struct rte_mempool *mp)
void rte_mempool_walk(void(*func)(struct rte_mempool *, void *arg), void *arg)
static void * rte_mempool_get_priv(struct rte_mempool *mp)
#define RTE_MEMPOOL_MAX_OPS_IDX
void(* rte_mempool_free_t)(struct rte_mempool *mp)
static __rte_always_inline int rte_mempool_get_contig_blocks(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
rte_mempool_enqueue_t enqueue