7 #ifndef _RTE_MEMPOOL_H_ 8 #define _RTE_MEMPOOL_H_ 41 #include <rte_compat.h> 42 #include <rte_config.h> 57 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL 58 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL 59 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL 61 #ifdef RTE_LIBRTE_MEMPOOL_STATS 68 struct rte_mempool_debug_stats {
71 uint64_t put_common_pool_bulk;
72 uint64_t put_common_pool_objs;
73 uint64_t get_common_pool_bulk;
74 uint64_t get_common_pool_objs;
75 uint64_t get_success_bulk;
76 uint64_t get_success_objs;
77 uint64_t get_fail_bulk;
78 uint64_t get_fail_objs;
79 uint64_t get_success_blks;
80 uint64_t get_fail_blks;
91 #ifdef RTE_LIBRTE_MEMPOOL_STATS 100 uint64_t get_success_bulk;
101 uint64_t get_success_objs;
125 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \ 126 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1) 127 #define RTE_MEMPOOL_MZ_PREFIX "MP_" 130 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s" 132 #ifndef RTE_MEMPOOL_ALIGN 136 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE 139 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1) 154 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 164 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 172 struct rte_mempool_objtlr {
220 char name[RTE_MEMPOOL_NAMESIZE];
251 struct rte_mempool_objhdr_list elt_list;
253 struct rte_mempool_memhdr_list mem_list;
255 #ifdef RTE_LIBRTE_MEMPOOL_STATS 260 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE + 1];
265 #define RTE_MEMPOOL_F_NO_SPREAD 0x0001 270 #define MEMPOOL_F_NO_SPREAD RTE_MEMPOOL_F_NO_SPREAD 272 #define RTE_MEMPOOL_F_NO_CACHE_ALIGN 0x0002 277 #define MEMPOOL_F_NO_CACHE_ALIGN RTE_MEMPOOL_F_NO_CACHE_ALIGN 279 #define RTE_MEMPOOL_F_SP_PUT 0x0004 284 #define MEMPOOL_F_SP_PUT RTE_MEMPOOL_F_SP_PUT 286 #define RTE_MEMPOOL_F_SC_GET 0x0008 291 #define MEMPOOL_F_SC_GET RTE_MEMPOOL_F_SC_GET 293 #define RTE_MEMPOOL_F_POOL_CREATED 0x0010 295 #define RTE_MEMPOOL_F_NO_IOVA_CONTIG 0x0020 300 #define MEMPOOL_F_NO_IOVA_CONTIG RTE_MEMPOOL_F_NO_IOVA_CONTIG 302 #define RTE_MEMPOOL_F_NON_IO 0x0040 307 #define RTE_MEMPOOL_VALID_USER_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \ 308 | RTE_MEMPOOL_F_NO_CACHE_ALIGN \ 309 | RTE_MEMPOOL_F_SP_PUT \ 310 | RTE_MEMPOOL_F_SC_GET \ 311 | RTE_MEMPOOL_F_NO_IOVA_CONTIG \ 324 #ifdef RTE_LIBRTE_MEMPOOL_STATS 325 #define RTE_MEMPOOL_STAT_ADD(mp, name, n) do { \ 326 unsigned int __lcore_id = rte_lcore_id(); \ 327 if (likely(__lcore_id < RTE_MAX_LCORE)) \ 328 (mp)->stats[__lcore_id].name += (n); \ 330 __atomic_fetch_add(&((mp)->stats[RTE_MAX_LCORE].name), \ 331 (n), __ATOMIC_RELAXED); \ 334 #define RTE_MEMPOOL_STAT_ADD(mp, name, n) do {} while (0) 347 #ifdef RTE_LIBRTE_MEMPOOL_STATS 348 #define RTE_MEMPOOL_CACHE_STAT_ADD(cache, name, n) ((cache)->stats.name += (n)) 350 #define RTE_MEMPOOL_CACHE_STAT_ADD(cache, name, n) do {} while (0) 361 #define RTE_MEMPOOL_HEADER_SIZE(mp, cs) \ 362 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \ 363 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE))) 367 rte_mempool_get_header(
void *obj)
389 static inline struct rte_mempool_objtlr *rte_mempool_get_trailer(
void *obj)
409 void rte_mempool_check_cookies(
const struct rte_mempool *mp,
410 void *
const *obj_table_const,
unsigned n,
int free);
412 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 413 #define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) \ 414 rte_mempool_check_cookies(mp, obj_table_const, n, free) 416 #define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) do {} while (0) 434 void rte_mempool_contig_blocks_check_cookies(
const struct rte_mempool *mp,
435 void *
const *first_obj_table_const,
unsigned int n,
int free);
437 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 438 #define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \ 440 rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \ 443 #define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \ 448 #define RTE_MEMPOOL_OPS_NAMESIZE 32 460 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp); 474 void *
const *obj_table,
unsigned int n);
483 void **obj_table,
unsigned int n);
489 void **first_obj_table,
unsigned int n);
520 uint32_t obj_num, uint32_t pg_shift,
521 size_t *min_chunk_size,
size_t *align);
558 ssize_t rte_mempool_op_calc_mem_size_helper(
const struct rte_mempool *mp,
559 uint32_t obj_num, uint32_t pg_shift,
size_t chunk_reserve,
560 size_t *min_chunk_size,
size_t *align);
570 uint32_t obj_num, uint32_t pg_shift,
571 size_t *min_chunk_size,
size_t *align);
617 unsigned int max_objs,
624 #define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001 658 int rte_mempool_op_populate_helper(
struct rte_mempool *mp,
659 unsigned int flags,
unsigned int max_objs,
670 unsigned int max_objs,
709 #define RTE_MEMPOOL_MAX_OPS_IDX 16 720 struct rte_mempool_ops_table { 742 rte_mempool_get_ops(
int ops_index)
775 rte_mempool_ops_dequeue_bulk(
struct rte_mempool *mp,
776 void **obj_table,
unsigned n)
781 rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
782 ops = rte_mempool_get_ops(mp->
ops_index);
783 ret = ops->
dequeue(mp, obj_table, n);
785 RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_bulk, 1);
786 RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_objs, n);
805 rte_mempool_ops_dequeue_contig_blocks(
struct rte_mempool *mp,
806 void **first_obj_table,
unsigned int n)
810 ops = rte_mempool_get_ops(mp->
ops_index);
812 rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
830 rte_mempool_ops_enqueue_bulk(
struct rte_mempool *mp,
void *
const *obj_table,
836 RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_bulk, 1);
837 RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_objs, n);
838 rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
839 ops = rte_mempool_get_ops(mp->
ops_index);
840 ret = ops->
enqueue(mp, obj_table, n);
841 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 843 RTE_LOG(CRIT, MEMPOOL,
"cannot enqueue %u objects to mempool %s\n",
858 rte_mempool_ops_get_count(
const struct rte_mempool *mp);
879 ssize_t rte_mempool_ops_calc_mem_size(
const struct rte_mempool *mp,
880 uint32_t obj_num, uint32_t pg_shift,
881 size_t *min_chunk_size,
size_t *align);
906 int rte_mempool_ops_populate(
struct rte_mempool *mp,
unsigned int max_objs,
973 #define RTE_MEMPOOL_REGISTER_OPS(ops) \ 974 RTE_INIT(mp_hdlr_init_##ops) \ 976 rte_mempool_register_ops(&ops); \ 985 void *opaque,
void *obj,
unsigned obj_idx);
1326 if (lcore_id >= RTE_MAX_LCORE)
1329 rte_mempool_trace_default_cache(mp, lcore_id,
1348 if (cache == NULL || cache->
len == 0)
1350 rte_mempool_trace_cache_flush(cache, mp);
1351 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->
len);
1368 rte_mempool_do_generic_put(
struct rte_mempool *mp,
void *
const *obj_table,
1375 goto driver_enqueue;
1378 RTE_MEMPOOL_CACHE_STAT_ADD(cache, put_bulk, 1);
1379 RTE_MEMPOOL_CACHE_STAT_ADD(cache, put_objs, n);
1383 goto driver_enqueue_stats_incremented;
1393 cache_objs = &cache->objs[cache->
len];
1396 cache_objs = &cache->objs[0];
1397 rte_mempool_ops_enqueue_bulk(mp, cache_objs, cache->
len);
1402 rte_memcpy(cache_objs, obj_table,
sizeof(
void *) * n);
1409 RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
1410 RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
1412 driver_enqueue_stats_incremented:
1415 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1435 rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1436 RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 0);
1437 rte_mempool_do_generic_put(mp, obj_table, n, cache);
1460 rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1497 rte_mempool_do_generic_get(
struct rte_mempool *mp,
void **obj_table,
1501 unsigned int remaining = n;
1502 uint32_t index,
len;
1507 goto driver_dequeue;
1511 cache_objs = &cache->objs[cache->
len];
1514 for (index = 0; index <
len; index++)
1515 *obj_table++ = *--cache_objs;
1517 if (remaining == 0) {
1520 RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_bulk, 1);
1521 RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_objs, n);
1527 if (
unlikely(remaining > RTE_MEMPOOL_CACHE_MAX_SIZE))
1528 goto driver_dequeue;
1531 ret = rte_mempool_ops_dequeue_bulk(mp, cache->objs,
1532 cache->
size + remaining);
1540 goto driver_dequeue;
1544 cache_objs = &cache->objs[cache->
size + remaining];
1545 for (index = 0; index < remaining; index++)
1546 *obj_table++ = *--cache_objs;
1550 RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_bulk, 1);
1551 RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_objs, n);
1558 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, remaining);
1561 if (
likely(cache != NULL)) {
1562 cache->
len = n - remaining;
1570 RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1571 RTE_MEMPOOL_STAT_ADD(mp, get_fail_objs, n);
1573 if (
likely(cache != NULL)) {
1574 RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_bulk, 1);
1575 RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_objs, n);
1577 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1578 RTE_MEMPOOL_STAT_ADD(mp, get_success_objs, n);
1610 ret = rte_mempool_do_generic_get(mp, obj_table, n, cache);
1612 RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 1);
1613 rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1644 rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1697 void **first_obj_table,
unsigned int n)
1701 ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1703 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1704 RTE_MEMPOOL_STAT_ADD(mp, get_success_blks, n);
1705 RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table, n,
1708 RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1709 RTE_MEMPOOL_STAT_ADD(mp, get_fail_blks, n);
1712 rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1886 rte_mempool_get_page_size(
struct rte_mempool *mp,
size_t *pg_sz);
1908 typedef void (rte_mempool_event_callback)(
1931 rte_mempool_event_callback_register(rte_mempool_event_callback *func,
1949 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 *objs [RTE_MEMPOOL_CACHE_MAX_SIZE *2] __rte_cache_aligned
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)
#define RTE_LOG(l, t,...)
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)
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