35 #ifndef _RTE_MEMPOOL_H_
36 #define _RTE_MEMPOOL_H_
68 #include <sys/queue.h>
83 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL
84 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL
85 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL
87 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
91 struct rte_mempool_debug_stats {
94 uint64_t get_success_bulk;
95 uint64_t get_success_objs;
96 uint64_t get_fail_bulk;
97 uint64_t get_fail_objs;
112 void *
objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
127 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
128 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
129 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
132 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
134 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
137 #define MEMPOOL_PG_NUM_DEFAULT 1
139 #ifndef RTE_MEMPOOL_ALIGN
140 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
143 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
158 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
168 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
176 struct rte_mempool_objtlr {
252 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
254 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
258 #define MEMPOOL_F_NO_SPREAD 0x0001
259 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002
260 #define MEMPOOL_F_SP_PUT 0x0004
261 #define MEMPOOL_F_SC_GET 0x0008
262 #define MEMPOOL_F_POOL_CREATED 0x0010
263 #define MEMPOOL_F_NO_PHYS_CONTIG 0x0020
275 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
276 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
277 unsigned __lcore_id = rte_lcore_id(); \
278 if (__lcore_id < RTE_MAX_LCORE) { \
279 mp->stats[__lcore_id].name##_objs += n; \
280 mp->stats[__lcore_id].name##_bulk += 1; \
284 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
295 #define MEMPOOL_HEADER_SIZE(mp, cs) \
296 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
297 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
322 static inline struct rte_mempool_objtlr *__mempool_get_trailer(
void *obj)
342 void rte_mempool_check_cookies(
const struct rte_mempool *mp,
343 void *
const *obj_table_const,
unsigned n,
int free);
345 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
346 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
347 rte_mempool_check_cookies(mp, obj_table_const, n, free)
349 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
352 #define RTE_MEMPOOL_OPS_NAMESIZE 32
364 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
375 void *
const *obj_table,
unsigned int n);
381 void **obj_table,
unsigned int n);
398 #define RTE_MEMPOOL_MAX_OPS_IDX 16
409 struct rte_mempool_ops_table {
431 rte_mempool_get_ops(
int ops_index)
465 void **obj_table,
unsigned n)
469 ops = rte_mempool_get_ops(mp->
ops_index);
470 return ops->
dequeue(mp, obj_table, n);
487 rte_mempool_ops_enqueue_bulk(
struct rte_mempool *mp,
void *
const *obj_table,
492 ops = rte_mempool_get_ops(mp->
ops_index);
493 return ops->
enqueue(mp, obj_table, n);
505 rte_mempool_ops_get_count(
const struct rte_mempool *mp);
554 #define MEMPOOL_REGISTER_OPS(ops) \
555 void mp_hdlr_init_##ops(void); \
556 void __attribute__((constructor, used)) mp_hdlr_init_##ops(void)\
558 rte_mempool_register_ops(&ops); \
567 void *opaque,
void *obj,
unsigned obj_idx);
742 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift);
850 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
992 static inline void __attribute__((always_inline))
996 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1013 if (mp->cache_size == 0)
1016 if (lcore_id >= RTE_MAX_LCORE)
1019 return &mp->local_cache[lcore_id];
1037 static inline void __attribute__((always_inline))
1038 __mempool_generic_put(struct
rte_mempool *mp,
void * const *obj_table,
1044 __MEMPOOL_STAT_ADD(mp, put, n);
1051 if (
unlikely(n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1054 cache_objs = &cache->objs[cache->len];
1064 rte_memcpy(&cache_objs[0], obj_table,
sizeof(
void *) * n);
1068 if (cache->len >= cache->flushthresh) {
1069 rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1070 cache->len - cache->size);
1071 cache->len = cache->size;
1079 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1080 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1081 rte_panic(
"cannot put objects in mempool\n");
1083 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1103 static inline void __attribute__((always_inline))
1107 __mempool_check_cookies(mp, obj_table, n, 0);
1108 __mempool_generic_put(mp, obj_table, n, cache, flags);
1123 static inline void __attribute__((always_inline))
1144 static inline void __attribute__((always_inline))
1165 static inline void __attribute__((always_inline))
1184 static inline void __attribute__((always_inline))
1202 static inline void __attribute__((always_inline))
1220 static inline void __attribute__((always_inline))
1243 static inline int __attribute__((always_inline))
1244 __mempool_generic_get(struct
rte_mempool *mp,
void **obj_table,
1248 uint32_t index,
len;
1256 cache_objs = cache->objs;
1259 if (cache->len < n) {
1261 uint32_t req = n + (cache->size - cache->len);
1264 ret = rte_mempool_ops_dequeue_bulk(mp,
1265 &cache->objs[cache->len], req);
1280 for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1281 *obj_table = cache_objs[
len];
1285 __MEMPOOL_STAT_ADD(mp, get_success, n);
1292 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1295 __MEMPOOL_STAT_ADD(mp, get_fail, n);
1297 __MEMPOOL_STAT_ADD(mp, get_success, n);
1325 static inline int __attribute__((always_inline))
1330 ret = __mempool_generic_get(mp, obj_table, n, cache, flags);
1332 __mempool_check_cookies(mp, obj_table, n, 1);
1356 static inline int __attribute__((always_inline))
1385 static inline int __attribute__((always_inline))
1414 static inline int __attribute__((always_inline))
1440 static inline int __attribute__((always_inline))
1466 static inline int __attribute__((always_inline))
1492 static inline int __attribute__((always_inline))
1562 static inline unsigned
1747 size_t total_elt_sz,
const phys_addr_t paddr[], uint32_t pg_num,