35 #ifndef _RTE_MEMPOOL_H_ 36 #define _RTE_MEMPOOL_H_ 68 #include <sys/queue.h> 84 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL 85 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL 86 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL 88 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 92 struct rte_mempool_debug_stats {
95 uint64_t get_success_bulk;
96 uint64_t get_success_objs;
97 uint64_t get_fail_bulk;
98 uint64_t get_fail_objs;
113 void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
128 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \ 129 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1) 130 #define RTE_MEMPOOL_MZ_PREFIX "MP_" 133 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s" 135 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1) 138 #define MEMPOOL_PG_NUM_DEFAULT 1 140 #ifndef RTE_MEMPOOL_ALIGN 141 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE 144 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1) 159 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 169 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 177 struct rte_mempool_objtlr {
250 struct rte_mempool_objhdr_list elt_list;
252 struct rte_mempool_memhdr_list mem_list;
254 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 256 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
260 #define MEMPOOL_F_NO_SPREAD 0x0001 261 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002 262 #define MEMPOOL_F_SP_PUT 0x0004 263 #define MEMPOOL_F_SC_GET 0x0008 264 #define MEMPOOL_F_POOL_CREATED 0x0010 265 #define MEMPOOL_F_NO_PHYS_CONTIG 0x0020 277 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 278 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \ 279 unsigned __lcore_id = rte_lcore_id(); \ 280 if (__lcore_id < RTE_MAX_LCORE) { \ 281 mp->stats[__lcore_id].name##_objs += n; \ 282 mp->stats[__lcore_id].name##_bulk += 1; \ 286 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0) 297 #define MEMPOOL_HEADER_SIZE(mp, cs) \ 298 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \ 299 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE))) 324 static inline struct rte_mempool_objtlr *__mempool_get_trailer(
void *obj)
345 void *
const *obj_table_const,
unsigned n,
int free);
347 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 348 #define __mempool_check_cookies(mp, obj_table_const, n, free) \ 349 rte_mempool_check_cookies(mp, obj_table_const, n, free) 351 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0) 354 #define RTE_MEMPOOL_OPS_NAMESIZE 32 366 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp); 377 void *
const *obj_table,
unsigned int n);
383 void **obj_table,
unsigned int n);
400 #define RTE_MEMPOOL_MAX_OPS_IDX 16 411 struct rte_mempool_ops_table { 433 rte_mempool_get_ops(
int ops_index)
467 void **obj_table,
unsigned n)
471 ops = rte_mempool_get_ops(mp->
ops_index);
472 return ops->
dequeue(mp, obj_table, n);
489 rte_mempool_ops_enqueue_bulk(
struct rte_mempool *mp,
void *
const *obj_table,
494 ops = rte_mempool_get_ops(mp->
ops_index);
495 return ops->
enqueue(mp, obj_table, n);
507 rte_mempool_ops_get_count(
const struct rte_mempool *mp);
556 #define MEMPOOL_REGISTER_OPS(ops) \ 557 void mp_hdlr_init_##ops(void); \ 558 void __attribute__((constructor, used)) mp_hdlr_init_##ops(void)\ 560 rte_mempool_register_ops(&ops); \ 569 void *opaque,
void *obj,
unsigned obj_idx);
742 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift);
854 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
996 static inline void __attribute__((always_inline))
1000 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1017 if (mp->cache_size == 0)
1020 if (lcore_id >= RTE_MAX_LCORE)
1023 return &mp->local_cache[lcore_id];
1041 static inline void __attribute__((always_inline))
1042 __mempool_generic_put(
struct rte_mempool *mp,
void *
const *obj_table,
1048 __MEMPOOL_STAT_ADD(mp, put, n);
1055 if (
unlikely(n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1058 cache_objs = &cache->
objs[cache->
len];
1068 rte_memcpy(&cache_objs[0], obj_table,
sizeof(
void *) * n);
1073 rte_mempool_ops_enqueue_bulk(mp, &cache->
objs[cache->
size],
1083 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG 1084 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1085 rte_panic(
"cannot put objects in mempool\n");
1087 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1107 static inline void __attribute__((always_inline))
1111 __mempool_check_cookies(mp, obj_table, n, 0);
1112 __mempool_generic_put(mp, obj_table, n, cache, flags);
1127 static inline void __attribute__((always_inline))
1148 static inline void __attribute__((always_inline))
1169 static inline void __attribute__((always_inline))
1188 static inline void __attribute__((always_inline))
1206 static inline void __attribute__((always_inline))
1224 static inline void __attribute__((always_inline))
1247 static inline int __attribute__((always_inline))
1248 __mempool_generic_get(
struct rte_mempool *
mp,
void **obj_table,
1252 uint32_t index,
len;
1260 cache_objs = cache->
objs;
1263 if (cache->
len < n) {
1265 uint32_t req = n + (cache->
size - cache->
len);
1268 ret = rte_mempool_ops_dequeue_bulk(mp,
1269 &cache->
objs[cache->
len], req);
1284 for (index = 0, len = cache->
len - 1; index < n; ++index, len--, obj_table++)
1285 *obj_table = cache_objs[
len];
1289 __MEMPOOL_STAT_ADD(mp, get_success, n);
1296 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1299 __MEMPOOL_STAT_ADD(mp, get_fail, n);
1301 __MEMPOOL_STAT_ADD(mp, get_success, n);
1329 static inline int __attribute__((always_inline))
1334 ret = __mempool_generic_get(mp, obj_table, n, cache, flags);
1336 __mempool_check_cookies(mp, obj_table, n, 1);
1360 static inline int __attribute__((always_inline))
1389 static inline int __attribute__((always_inline))
1418 static inline int __attribute__((always_inline))
1444 static inline int __attribute__((always_inline))
1470 static inline int __attribute__((always_inline))
1496 static inline int __attribute__((always_inline))
1566 static inline unsigned 1751 size_t total_elt_sz,
const phys_addr_t paddr[], uint32_t pg_num,
__rte_deprecated unsigned rte_mempool_count(const struct rte_mempool *mp)
static int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
struct rte_mempool * rte_mempool_lookup(const char *name)
struct rte_mempool_cache * rte_mempool_cache_create(uint32_t size, int socket_id)
static __rte_deprecated int rte_mempool_mc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
static __rte_deprecated unsigned rte_mempool_free_count(const struct rte_mempool *mp)
static struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_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 phys_addr_t rte_mempool_virt2phy(__rte_unused const struct rte_mempool *mp, const void *elt)
static __rte_deprecated int rte_mempool_mc_get(struct rte_mempool *mp, void **obj_p)
void rte_mempool_list_dump(FILE *f)
void() rte_mempool_memchunk_free_cb_t(struct rte_mempool_memhdr *memhdr, void *opaque)
rte_mempool_alloc_t alloc
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 phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
static int rte_mempool_empty(const struct rte_mempool *mp)
static __rte_deprecated void rte_mempool_mp_put(struct rte_mempool *mp, void *obj)
static __rte_deprecated int rte_mempool_sc_get(struct rte_mempool *mp, void **obj_p)
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)
static int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
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_register_ops(const struct rte_mempool_ops *ops)
int rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr, const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
int rte_mempool_populate_default(struct rte_mempool *mp)
static void rte_mempool_cache_flush(struct rte_mempool_cache *cache, struct rte_mempool *mp)
#define RTE_MEMPOOL_OPS_NAMESIZE
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)
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, void *pool_config)
static __rte_deprecated int rte_mempool_sc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
static void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned n)
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]
static __rte_deprecated void rte_mempool_mp_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned n)
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_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
static int rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned n, struct rte_mempool_cache *cache, int flags)
rte_mempool_dequeue_t dequeue
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t total_elt_sz, const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
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)
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)
#define __rte_cache_aligned
size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift)
static struct rte_mempool * rte_mempool_from_obj(void *obj)
static __rte_deprecated void rte_mempool_sp_put(struct rte_mempool *mp, void *obj)
static void * rte_memcpy(void *dst, const void *src, size_t n)
static __rte_deprecated void rte_mempool_sp_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned n)
static void rte_mempool_generic_put(struct rte_mempool *mp, void *const *obj_table, unsigned n, struct rte_mempool_cache *cache, 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]
static void rte_mempool_put(struct rte_mempool *mp, void *obj)
int rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, phys_addr_t paddr, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
#define RTE_MEMPOOL_MAX_OPS_IDX
void(* rte_mempool_free_t)(struct rte_mempool *mp)
rte_mempool_enqueue_t enqueue
#define RTE_MEMZONE_NAMESIZE