35 #ifndef _RTE_MEMPOOL_H_
36 #define _RTE_MEMPOOL_H_
70 #include <sys/queue.h>
72 #include <rte_config.h>
87 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL
88 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL
89 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL
91 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
95 struct rte_mempool_debug_stats {
98 uint64_t get_success_bulk;
99 uint64_t get_success_objs;
100 uint64_t get_fail_bulk;
101 uint64_t get_fail_objs;
116 void *
objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
131 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
132 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
133 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
136 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
138 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
141 #define MEMPOOL_PG_NUM_DEFAULT 1
143 #ifndef RTE_MEMPOOL_ALIGN
144 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
147 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
166 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
176 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
184 struct rte_mempool_objtlr {
265 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
267 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
271 #define MEMPOOL_F_NO_SPREAD 0x0001
272 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002
273 #define MEMPOOL_F_SP_PUT 0x0004
274 #define MEMPOOL_F_SC_GET 0x0008
275 #define MEMPOOL_F_POOL_CREATED 0x0010
276 #define MEMPOOL_F_NO_PHYS_CONTIG 0x0020
282 #define MEMPOOL_F_CAPA_PHYS_CONTIG 0x0040
294 #define MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS 0x0080
306 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
307 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
308 unsigned __lcore_id = rte_lcore_id(); \
309 if (__lcore_id < RTE_MAX_LCORE) { \
310 mp->stats[__lcore_id].name##_objs += n; \
311 mp->stats[__lcore_id].name##_bulk += 1; \
315 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
326 #define MEMPOOL_HEADER_SIZE(mp, cs) \
327 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
328 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
353 static inline struct rte_mempool_objtlr *__mempool_get_trailer(
void *obj)
373 void rte_mempool_check_cookies(
const struct rte_mempool *mp,
374 void *
const *obj_table_const,
unsigned n,
int free);
376 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
377 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
378 rte_mempool_check_cookies(mp, obj_table_const, n, free)
380 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
383 #define RTE_MEMPOOL_OPS_NAMESIZE 32
395 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
406 void *
const *obj_table,
unsigned int n);
412 void **obj_table,
unsigned int n);
423 unsigned int *
flags);
449 #define RTE_MEMPOOL_MAX_OPS_IDX 16
460 struct rte_mempool_ops_table {
482 rte_mempool_get_ops(
int ops_index)
515 rte_mempool_ops_dequeue_bulk(
struct rte_mempool *mp,
516 void **obj_table,
unsigned n)
520 ops = rte_mempool_get_ops(mp->
ops_index);
521 return ops->
dequeue(mp, obj_table, n);
538 rte_mempool_ops_enqueue_bulk(
struct rte_mempool *mp,
void *
const *obj_table,
543 ops = rte_mempool_get_ops(mp->
ops_index);
544 return ops->
enqueue(mp, obj_table, n);
556 rte_mempool_ops_get_count(
const struct rte_mempool *mp);
572 rte_mempool_ops_get_capabilities(
const struct rte_mempool *mp,
573 unsigned int *flags);
592 rte_mempool_ops_register_memory_area(
const struct rte_mempool *mp,
642 #define MEMPOOL_REGISTER_OPS(ops) \
643 void mp_hdlr_init_##ops(void); \
644 void __attribute__((constructor, used)) mp_hdlr_init_##ops(void)\
646 rte_mempool_register_ops(&ops); \
655 void *opaque,
void *obj,
unsigned obj_idx);
825 const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift);
910 int rte_mempool_populate_phys(
struct rte_mempool *mp,
char *vaddr,
941 const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift,
945 int rte_mempool_populate_phys_tab(
struct rte_mempool *mp,
char *vaddr,
946 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
1092 rte_mempool_ops_enqueue_bulk(mp, cache->
objs, cache->
len);
1112 if (lcore_id >= RTE_MAX_LCORE)
1131 __mempool_generic_put(
struct rte_mempool *mp,
void *
const *obj_table,
1137 __MEMPOOL_STAT_ADD(mp, put, n);
1140 if (
unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1143 cache_objs = &cache->
objs[cache->
len];
1153 rte_memcpy(&cache_objs[0], obj_table,
sizeof(
void *) * n);
1158 rte_mempool_ops_enqueue_bulk(mp, &cache->
objs[cache->
size],
1168 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1169 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1170 rte_panic(
"cannot put objects in mempool\n");
1172 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1193 __mempool_check_cookies(mp, obj_table, n, 0);
1194 __mempool_generic_put(mp, obj_table, n, cache);
1253 __mempool_generic_get(
struct rte_mempool *mp,
void **obj_table,
1257 uint32_t index,
len;
1264 cache_objs = cache->
objs;
1267 if (cache->
len < n) {
1269 uint32_t req = n + (cache->
size - cache->
len);
1272 ret = rte_mempool_ops_dequeue_bulk(mp,
1273 &cache->
objs[cache->
len], req);
1288 for (index = 0, len = cache->
len - 1; index < n; ++index, len--, obj_table++)
1289 *obj_table = cache_objs[
len];
1293 __MEMPOOL_STAT_ADD(mp, get_success, n);
1300 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1303 __MEMPOOL_STAT_ADD(mp, get_fail, n);
1305 __MEMPOOL_STAT_ADD(mp, get_success, n);
1335 ret = __mempool_generic_get(mp, obj_table, n, cache);
1337 __mempool_check_cookies(mp, obj_table, n, 1);
1582 uint32_t pg_shift,
unsigned int flags);
1613 size_t total_elt_sz,
const rte_iova_t iova[], uint32_t pg_num,
1614 uint32_t pg_shift,
unsigned int flags);
#define __rte_always_inline
struct rte_mempool * rte_mempool_lookup(const char *name)
int(* rte_mempool_ops_register_memory_area_t)(const struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len)
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)
STAILQ_ENTRY(rte_mempool_objhdr) next
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)
rte_mempool_get_capabilities_t get_capabilities
void rte_mempool_list_dump(FILE *f)
rte_mempool_alloc_t alloc
void( rte_mempool_memchunk_free_cb_t)(struct rte_mempool_memhdr *memhdr, void *opaque)
void( rte_mempool_obj_cb_t)(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
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)
struct rte_mbuf __rte_cache_aligned
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)
#define MEMPOOL_HEADER_SIZE(mp, cs)
unsigned int rte_mempool_avail_count(const struct rte_mempool *mp)
ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t total_elt_sz, const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift, unsigned int flags)
struct rte_mempool_objhdr_list elt_list
#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_register_ops(const struct rte_mempool_ops *ops)
int rte_mempool_populate_iova_tab(struct rte_mempool *mp, char *vaddr, const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
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)
STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
rte_mempool_get_count get_count
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)
void( rte_mempool_mem_cb_t)(struct rte_mempool *mp, void *opaque, struct rte_mempool_memhdr *memhdr, unsigned mem_idx)
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)
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)
void * objs[RTE_MEMPOOL_CACHE_MAX_SIZE *3]
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)
void rte_mempool_audit(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)
unsigned private_data_size
void( rte_mempool_ctor_t)(struct rte_mempool *, void *)
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)
int rte_mempool_populate_anon(struct rte_mempool *mp)
struct rte_mempool_cache * local_cache
STAILQ_ENTRY(rte_mempool_memhdr) next
rte_mempool_dequeue_t dequeue
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
rte_mempool_ops_register_memory_area_t register_memory_area
int(* rte_mempool_get_capabilities_t)(const struct rte_mempool *mp, unsigned int *flags)
struct rte_mempool_memhdr_list mem_list
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)
size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift, unsigned int flags)
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)
char name[RTE_MEMZONE_NAMESIZE]
#define RTE_MEMPOOL_MAX_OPS_IDX
void(* rte_mempool_free_t)(struct rte_mempool *mp)
struct rte_mempool * rte_mempool_xmem_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 *vaddr, const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift)
rte_mempool_enqueue_t enqueue
#define RTE_MEMZONE_NAMESIZE