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
68struct 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
172struct rte_mempool_objtlr {
220 char name[RTE_MEMPOOL_NAMESIZE];
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)))
367rte_mempool_get_header(
void *obj)
389static inline struct rte_mempool_objtlr *rte_mempool_get_trailer(
void *obj)
409void 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)
434void 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
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);
558ssize_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
658int 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
742rte_mempool_get_ops(
int ops_index)
775rte_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);
805rte_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);
830rte_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",
858rte_mempool_ops_get_count(
const struct rte_mempool *mp);
879ssize_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);
906int 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);
1368rte_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);
1412driver_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);
1497rte_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);
1886rte_mempool_get_page_size(
struct rte_mempool *mp,
size_t *pg_sz);
1908typedef void (rte_mempool_event_callback)(
1931rte_mempool_event_callback_register(rte_mempool_event_callback *func,
1949rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
#define __rte_cache_aligned
#define RTE_PTR_SUB(ptr, x)
#define RTE_PTR_ADD(ptr, x)
#define __rte_always_inline
static unsigned rte_lcore_id(void)
#define RTE_LOG(l, t,...)
static void * rte_memcpy(void *dst, const void *src, size_t n)
void() rte_mempool_memchunk_free_cb_t(struct rte_mempool_memhdr *memhdr, void *opaque)
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, void *pool_config)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
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)
static __rte_always_inline struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, struct rte_mempool_objsz *sz)
void() rte_mempool_obj_cb_t(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
struct rte_mempool * rte_mempool_lookup(const char *name)
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
static struct rte_mempool * rte_mempool_from_obj(void *obj)
static rte_iova_t rte_mempool_virt2iova(const void *elt)
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
void rte_mempool_free(struct rte_mempool *mp)
@ RTE_MEMPOOL_EVENT_DESTROY
@ RTE_MEMPOOL_EVENT_READY
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
void() rte_mempool_populate_obj_cb_t(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
int rte_mempool_populate_default(struct rte_mempool *mp)
unsigned int rte_mempool_avail_count(const 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)
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
void(* rte_mempool_free_t)(struct rte_mempool *mp)
static __rte_always_inline void rte_mempool_cache_flush(struct rte_mempool_cache *cache, struct rte_mempool *mp)
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
int rte_mempool_register_ops(const struct rte_mempool_ops *ops)
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)
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)
int rte_mempool_populate_anon(struct rte_mempool *mp)
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)
void rte_mempool_cache_free(struct rte_mempool_cache *cache)
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)
static int rte_mempool_full(const struct rte_mempool *mp)
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
void rte_mempool_dump(FILE *f, struct rte_mempool *mp)
static __rte_always_inline int rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned int n, struct rte_mempool_cache *cache)
struct rte_mempool_cache * rte_mempool_cache_create(uint32_t size, int socket_id)
void rte_mempool_audit(struct rte_mempool *mp)
void rte_mempool_walk(void(*func)(struct rte_mempool *, void *arg), void *arg)
#define RTE_MEMPOOL_OPS_NAMESIZE
void() rte_mempool_ctor_t(struct rte_mempool *, void *)
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)
void() rte_mempool_mem_cb_t(struct rte_mempool *mp, void *opaque, struct rte_mempool_memhdr *memhdr, unsigned mem_idx)
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 __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
int rte_mempool_ops_get_info(const struct rte_mempool *mp, struct rte_mempool_info *info)
unsigned int rte_mempool_in_use_count(const struct rte_mempool *mp)
uint32_t rte_mempool_obj_iter(struct rte_mempool *mp, rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg)
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)
void rte_mempool_list_dump(FILE *f)
#define RTE_MEMPOOL_MAX_OPS_IDX
static int rte_mempool_empty(const struct rte_mempool *mp)
uint32_t rte_mempool_mem_iter(struct rte_mempool *mp, rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg)
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)
static void * rte_mempool_get_priv(struct rte_mempool *mp)
RTE_STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
int(* rte_mempool_get_info_t)(const struct rte_mempool *mp, struct rte_mempool_info *info)
void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE *2] __rte_cache_aligned
unsigned int contig_block_size
RTE_STAILQ_ENTRY(rte_mempool_memhdr) next
rte_mempool_memchunk_free_cb_t * free_cb
RTE_STAILQ_ENTRY(rte_mempool_objhdr) next
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
char name[RTE_MEMPOOL_OPS_NAMESIZE]
rte_mempool_alloc_t alloc
rte_mempool_dequeue_t dequeue
rte_mempool_get_info_t get_info
rte_mempool_calc_mem_size_t calc_mem_size
rte_mempool_get_count get_count
rte_mempool_populate_t populate
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
rte_mempool_enqueue_t enqueue
const struct rte_memzone * mz
struct rte_mempool_memhdr_list mem_list
char name[RTE_MEMPOOL_NAMESIZE]
unsigned private_data_size
struct rte_mempool_cache * local_cache
struct rte_mempool_objhdr_list elt_list