DPDK 21.11.9
rte_mempool.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2016 6WIND S.A.
4 */
5
6#ifndef _RTE_MEMPOOL_H_
7#define _RTE_MEMPOOL_H_
8
36#include <stdio.h>
37#include <stdlib.h>
38#include <stdint.h>
39#include <errno.h>
40#include <inttypes.h>
41
42#include <rte_config.h>
43#include <rte_spinlock.h>
44#include <rte_log.h>
45#include <rte_debug.h>
46#include <rte_lcore.h>
47#include <rte_memory.h>
49#include <rte_ring.h>
50#include <rte_memcpy.h>
51#include <rte_common.h>
52
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59#define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL
60#define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL
61#define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL
63#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
70struct rte_mempool_debug_stats {
71 uint64_t put_bulk;
72 uint64_t put_objs;
73 uint64_t put_common_pool_bulk;
74 uint64_t put_common_pool_objs;
75 uint64_t get_common_pool_bulk;
76 uint64_t get_common_pool_objs;
77 uint64_t get_success_bulk;
78 uint64_t get_success_objs;
79 uint64_t get_fail_bulk;
80 uint64_t get_fail_objs;
81 uint64_t get_success_blks;
82 uint64_t get_fail_blks;
84#endif
85
90 uint32_t size;
91 uint32_t flushthresh;
92 uint32_t len;
93 /*
94 * Cache is allocated to this size to allow it to overflow in certain
95 * cases to avoid needless emptying of cache.
96 */
97 void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
99
104 uint32_t elt_size;
105 uint32_t header_size;
106 uint32_t trailer_size;
107 uint32_t total_size;
109};
110
112#define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
113 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
114#define RTE_MEMPOOL_MZ_PREFIX "MP_"
115
116/* "MP_<name>" */
117#define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
118
119#define MEMPOOL_PG_SHIFT_MAX \
120 RTE_DEPRECATED(MEMPOOL_PG_SHIFT_MAX) (sizeof(uintptr_t) * CHAR_BIT - 1)
121
123#define MEMPOOL_PG_NUM_DEFAULT RTE_DEPRECATED(MEMPOOL_PG_NUM_DEFAULT) 1
124
125#ifndef RTE_MEMPOOL_ALIGN
129#define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
130#endif
131
132#define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
133
145 struct rte_mempool *mp;
147#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
148 uint64_t cookie;
149#endif
150};
151
155RTE_STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
156
157#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
158
165struct rte_mempool_objtlr {
166 uint64_t cookie;
167};
168
169#endif
170
174RTE_STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
175
180 void *opaque);
181
190 struct rte_mempool *mp;
191 void *addr;
193 size_t len;
195 void *opaque;
196};
197
206 unsigned int contig_block_size;
208
213 char name[RTE_MEMPOOL_NAMESIZE];
215 union {
216 void *pool_data;
217 uint64_t pool_id;
218 };
220 const struct rte_memzone *mz;
221 unsigned int flags;
223 uint32_t size;
224 uint32_t cache_size;
227 uint32_t elt_size;
228 uint32_t header_size;
229 uint32_t trailer_size;
239 int32_t ops_index;
240
243 uint32_t populated_size;
244 struct rte_mempool_objhdr_list elt_list;
245 uint32_t nb_mem_chunks;
246 struct rte_mempool_memhdr_list mem_list;
248#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
250 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
251#endif
253
255#define RTE_MEMPOOL_F_NO_SPREAD 0x0001
260#define MEMPOOL_F_NO_SPREAD RTE_MEMPOOL_F_NO_SPREAD
262#define RTE_MEMPOOL_F_NO_CACHE_ALIGN 0x0002
267#define MEMPOOL_F_NO_CACHE_ALIGN RTE_MEMPOOL_F_NO_CACHE_ALIGN
269#define RTE_MEMPOOL_F_SP_PUT 0x0004
274#define MEMPOOL_F_SP_PUT RTE_MEMPOOL_F_SP_PUT
276#define RTE_MEMPOOL_F_SC_GET 0x0008
281#define MEMPOOL_F_SC_GET RTE_MEMPOOL_F_SC_GET
283#define RTE_MEMPOOL_F_POOL_CREATED 0x0010
285#define RTE_MEMPOOL_F_NO_IOVA_CONTIG 0x0020
290#define MEMPOOL_F_NO_IOVA_CONTIG RTE_MEMPOOL_F_NO_IOVA_CONTIG
292#define RTE_MEMPOOL_F_NON_IO 0x0040
293
297#define RTE_MEMPOOL_VALID_USER_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \
298 | RTE_MEMPOOL_F_NO_CACHE_ALIGN \
299 | RTE_MEMPOOL_F_SP_PUT \
300 | RTE_MEMPOOL_F_SC_GET \
301 | RTE_MEMPOOL_F_NO_IOVA_CONTIG \
302 )
313#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
314#define RTE_MEMPOOL_STAT_ADD(mp, name, n) do { \
315 unsigned __lcore_id = rte_lcore_id(); \
316 if (__lcore_id < RTE_MAX_LCORE) { \
317 mp->stats[__lcore_id].name += n; \
318 } \
319 } while (0)
320#else
321#define RTE_MEMPOOL_STAT_ADD(mp, name, n) do {} while (0)
322#endif
323
332#define RTE_MEMPOOL_HEADER_SIZE(mp, cs) \
333 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
334 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
335
337#define MEMPOOL_HEADER_SIZE(mp, cs) \
338 RTE_DEPRECATED(MEMPOOL_HEADER_SIZE) RTE_MEMPOOL_HEADER_SIZE(mp, cs)
339
340/* return the header of a mempool object (internal) */
341static inline struct rte_mempool_objhdr *
342rte_mempool_get_header(void *obj)
343{
344 return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
345 sizeof(struct rte_mempool_objhdr));
346}
347
357static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
358{
359 struct rte_mempool_objhdr *hdr = rte_mempool_get_header(obj);
360 return hdr->mp;
361}
362
363/* return the trailer of a mempool object (internal) */
364static inline struct rte_mempool_objtlr *rte_mempool_get_trailer(void *obj)
365{
366 struct rte_mempool *mp = rte_mempool_from_obj(obj);
367 return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
368}
369
384void rte_mempool_check_cookies(const struct rte_mempool *mp,
385 void * const *obj_table_const, unsigned n, int free);
386
387#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
388#define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) \
389 rte_mempool_check_cookies(mp, obj_table_const, n, free)
390#else
391#define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) do {} while (0)
392#endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
393
409void rte_mempool_contig_blocks_check_cookies(const struct rte_mempool *mp,
410 void * const *first_obj_table_const, unsigned int n, int free);
411
412#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
413#define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \
414 free) \
415 rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
416 free)
417#else
418#define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \
419 free) \
420 do {} while (0)
421#endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
422
423#define RTE_MEMPOOL_OPS_NAMESIZE 32
435typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
436
440typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
441
448typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
449 void * const *obj_table, unsigned int n);
450
457typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
458 void **obj_table, unsigned int n);
459
464 void **first_obj_table, unsigned int n);
465
469typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
470
494typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
495 uint32_t obj_num, uint32_t pg_shift,
496 size_t *min_chunk_size, size_t *align);
497
533ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
534 uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
535 size_t *min_chunk_size, size_t *align);
536
545 uint32_t obj_num, uint32_t pg_shift,
546 size_t *min_chunk_size, size_t *align);
547
561 void *opaque, void *vaddr, rte_iova_t iova);
562
591typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
592 unsigned int max_objs,
593 void *vaddr, rte_iova_t iova, size_t len,
594 rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
595
599#define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
600
633int rte_mempool_op_populate_helper(struct rte_mempool *mp,
634 unsigned int flags, unsigned int max_objs,
635 void *vaddr, rte_iova_t iova, size_t len,
636 rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
637
645 unsigned int max_objs,
646 void *vaddr, rte_iova_t iova, size_t len,
647 rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
648
652typedef int (*rte_mempool_get_info_t)(const struct rte_mempool *mp,
653 struct rte_mempool_info *info);
654
655
683
684#define RTE_MEMPOOL_MAX_OPS_IDX 16
697 uint32_t num_ops;
703
706
716static inline struct rte_mempool_ops *
717rte_mempool_get_ops(int ops_index)
718{
719 RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
720
721 return &rte_mempool_ops_table.ops[ops_index];
722}
723
733int
734rte_mempool_ops_alloc(struct rte_mempool *mp);
735
749static inline int
750rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
751 void **obj_table, unsigned n)
752{
753 struct rte_mempool_ops *ops;
754 int ret;
755
756 rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
757 ops = rte_mempool_get_ops(mp->ops_index);
758 ret = ops->dequeue(mp, obj_table, n);
759 if (ret == 0) {
760 RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_bulk, 1);
761 RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_objs, n);
762 }
763 return ret;
764}
765
779static inline int
780rte_mempool_ops_dequeue_contig_blocks(struct rte_mempool *mp,
781 void **first_obj_table, unsigned int n)
782{
783 struct rte_mempool_ops *ops;
784
785 ops = rte_mempool_get_ops(mp->ops_index);
786 RTE_ASSERT(ops->dequeue_contig_blocks != NULL);
787 rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
788 return ops->dequeue_contig_blocks(mp, first_obj_table, n);
789}
790
804static inline int
805rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
806 unsigned n)
807{
808 struct rte_mempool_ops *ops;
809
810 RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_bulk, 1);
811 RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_objs, n);
812 rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
813 ops = rte_mempool_get_ops(mp->ops_index);
814 return ops->enqueue(mp, obj_table, n);
815}
816
825unsigned
826rte_mempool_ops_get_count(const struct rte_mempool *mp);
827
847ssize_t rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
848 uint32_t obj_num, uint32_t pg_shift,
849 size_t *min_chunk_size, size_t *align);
850
874int rte_mempool_ops_populate(struct rte_mempool *mp, unsigned int max_objs,
875 void *vaddr, rte_iova_t iova, size_t len,
877 void *obj_cb_arg);
878
892 struct rte_mempool_info *info);
893
900void
901rte_mempool_ops_free(struct rte_mempool *mp);
902
920int
922 void *pool_config);
923
935
941#define RTE_MEMPOOL_REGISTER_OPS(ops) \
942 RTE_INIT(mp_hdlr_init_##ops) \
943 { \
944 rte_mempool_register_ops(&ops); \
945 }
946
948#define MEMPOOL_REGISTER_OPS(ops) \
949 RTE_DEPRECATED(MEMPOOL_REGISTER_OPS) RTE_MEMPOOL_REGISTER_OPS(ops)
950
956typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
957 void *opaque, void *obj, unsigned obj_idx);
958typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
959
965typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
966 void *opaque, struct rte_mempool_memhdr *memhdr,
967 unsigned mem_idx);
968
975typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
976
1055struct rte_mempool *
1056rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
1057 unsigned cache_size, unsigned private_data_size,
1058 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
1059 rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
1060 int socket_id, unsigned flags);
1061
1096struct rte_mempool *
1097rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
1098 unsigned cache_size, unsigned private_data_size,
1099 int socket_id, unsigned flags);
1110void
1112
1143int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
1144 rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
1145 void *opaque);
1146
1173int
1175 size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
1176 void *opaque);
1177
1192
1207
1224 rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1225
1242 rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1243
1252void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1253
1268struct rte_mempool_cache *
1269rte_mempool_cache_create(uint32_t size, int socket_id);
1270
1277void
1279
1292rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1293{
1294 if (mp->cache_size == 0)
1295 return NULL;
1296
1297 if (lcore_id >= RTE_MAX_LCORE)
1298 return NULL;
1299
1300 rte_mempool_trace_default_cache(mp, lcore_id,
1301 &mp->local_cache[lcore_id]);
1302 return &mp->local_cache[lcore_id];
1303}
1304
1313static __rte_always_inline void
1315 struct rte_mempool *mp)
1316{
1317 if (cache == NULL)
1319 if (cache == NULL || cache->len == 0)
1320 return;
1321 rte_mempool_trace_cache_flush(cache, mp);
1322 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1323 cache->len = 0;
1324}
1325
1338static __rte_always_inline void
1339rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
1340 unsigned int n, struct rte_mempool_cache *cache)
1341{
1342 void **cache_objs;
1343
1344 /* increment stat now, adding in mempool always success */
1345 RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
1346 RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
1347
1348 /* No cache provided or if put would overflow mem allocated for cache */
1349 if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1350 goto ring_enqueue;
1351
1352 cache_objs = &cache->objs[cache->len];
1353
1354 /*
1355 * The cache follows the following algorithm
1356 * 1. Add the objects to the cache
1357 * 2. Anything greater than the cache min value (if it crosses the
1358 * cache flush threshold) is flushed to the ring.
1359 */
1360
1361 /* Add elements back into the cache */
1362 rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1363
1364 cache->len += n;
1365
1366 if (cache->len >= cache->flushthresh) {
1367 rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1368 cache->len - cache->size);
1369 cache->len = cache->size;
1370 }
1371
1372 return;
1373
1374ring_enqueue:
1375
1376 /* push remaining objects in ring */
1377#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1378 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1379 rte_panic("cannot put objects in mempool\n");
1380#else
1381 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1382#endif
1383}
1384
1385
1398static __rte_always_inline void
1399rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1400 unsigned int n, struct rte_mempool_cache *cache)
1401{
1402 rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1403 RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 0);
1404 rte_mempool_do_generic_put(mp, obj_table, n, cache);
1405}
1406
1421static __rte_always_inline void
1422rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1423 unsigned int n)
1424{
1425 struct rte_mempool_cache *cache;
1427 rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1428 rte_mempool_generic_put(mp, obj_table, n, cache);
1429}
1430
1443static __rte_always_inline void
1444rte_mempool_put(struct rte_mempool *mp, void *obj)
1445{
1446 rte_mempool_put_bulk(mp, &obj, 1);
1447}
1448
1463static __rte_always_inline int
1464rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
1465 unsigned int n, struct rte_mempool_cache *cache)
1466{
1467 int ret;
1468 uint32_t index, len;
1469 void **cache_objs;
1470
1471 /* No cache provided or cannot be satisfied from cache */
1472 if (unlikely(cache == NULL || n >= cache->size))
1473 goto ring_dequeue;
1474
1475 cache_objs = cache->objs;
1476
1477 /* Can this be satisfied from the cache? */
1478 if (cache->len < n) {
1479 /* No. Backfill the cache first, and then fill from it */
1480 uint32_t req = n + (cache->size - cache->len);
1481
1482 /* How many do we require i.e. number to fill the cache + the request */
1483 ret = rte_mempool_ops_dequeue_bulk(mp,
1484 &cache->objs[cache->len], req);
1485 if (unlikely(ret < 0)) {
1486 /*
1487 * In the off chance that we are buffer constrained,
1488 * where we are not able to allocate cache + n, go to
1489 * the ring directly. If that fails, we are truly out of
1490 * buffers.
1491 */
1492 goto ring_dequeue;
1493 }
1494
1495 cache->len += req;
1496 }
1497
1498 /* Now fill in the response ... */
1499 for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1500 *obj_table = cache_objs[len];
1501
1502 cache->len -= n;
1503
1504 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1505 RTE_MEMPOOL_STAT_ADD(mp, get_success_objs, n);
1506
1507 return 0;
1508
1509ring_dequeue:
1510
1511 /* get remaining objects from ring */
1512 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1513
1514 if (ret < 0) {
1515 RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1516 RTE_MEMPOOL_STAT_ADD(mp, get_fail_objs, n);
1517 } else {
1518 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1519 RTE_MEMPOOL_STAT_ADD(mp, get_success_objs, n);
1520 }
1521
1522 return ret;
1523}
1524
1545static __rte_always_inline int
1546rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1547 unsigned int n, struct rte_mempool_cache *cache)
1548{
1549 int ret;
1550 ret = rte_mempool_do_generic_get(mp, obj_table, n, cache);
1551 if (ret == 0)
1552 RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 1);
1553 rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1554 return ret;
1555}
1556
1579static __rte_always_inline int
1580rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1581{
1582 struct rte_mempool_cache *cache;
1584 rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1585 return rte_mempool_generic_get(mp, obj_table, n, cache);
1586}
1587
1608static __rte_always_inline int
1609rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1610{
1611 return rte_mempool_get_bulk(mp, obj_p, 1);
1612}
1613
1635static __rte_always_inline int
1637 void **first_obj_table, unsigned int n)
1638{
1639 int ret;
1640
1641 ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1642 if (ret == 0) {
1643 RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1644 RTE_MEMPOOL_STAT_ADD(mp, get_success_blks, n);
1645 RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table, n,
1646 1);
1647 } else {
1648 RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1649 RTE_MEMPOOL_STAT_ADD(mp, get_fail_blks, n);
1650 }
1651
1652 rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1653 return ret;
1654}
1655
1668unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1669
1682unsigned int
1684
1698static inline int
1700{
1701 return rte_mempool_avail_count(mp) == mp->size;
1702}
1703
1717static inline int
1719{
1720 return rte_mempool_avail_count(mp) == 0;
1721}
1722
1733static inline rte_iova_t
1735{
1736 const struct rte_mempool_objhdr *hdr;
1737 hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1738 sizeof(*hdr));
1739 return hdr->iova;
1740}
1741
1753
1762static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1763{
1764 return (char *)mp +
1765 RTE_MEMPOOL_HEADER_SIZE(mp, mp->cache_size);
1766}
1767
1775
1789
1807uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1808 struct rte_mempool_objsz *sz);
1809
1818void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1819 void *arg);
1820
1825int
1826rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
1827
1837};
1838
1848typedef void (rte_mempool_event_callback)(
1849 enum rte_mempool_event event,
1850 struct rte_mempool *mp,
1851 void *user_data);
1852
1869__rte_internal
1870int
1871rte_mempool_event_callback_register(rte_mempool_event_callback *func,
1872 void *user_data);
1873
1887__rte_internal
1888int
1889rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
1890 void *user_data);
1891
1892#ifdef __cplusplus
1893}
1894#endif
1895
1896#endif /* _RTE_MEMPOOL_H_ */
#define unlikely(x)
#define __rte_cache_aligned
Definition: rte_common.h:420
#define RTE_PTR_SUB(ptr, x)
Definition: rte_common.h:273
uint64_t rte_iova_t
Definition: rte_common.h:438
#define RTE_PTR_ADD(ptr, x)
Definition: rte_common.h:268
#define RTE_STD_C11
Definition: rte_common.h:42
#define __rte_always_inline
Definition: rte_common.h:233
#define rte_panic(...)
Definition: rte_debug.h:43
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:76
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)
Definition: rte_mempool.h:179
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)
Definition: rte_mempool.h:1580
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)
Definition: rte_mempool.h:1292
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)
Definition: rte_mempool.h:956
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)
Definition: rte_mempool.h:448
static struct rte_mempool * rte_mempool_from_obj(void *obj)
Definition: rte_mempool.h:357
static rte_iova_t rte_mempool_virt2iova(const void *elt)
Definition: rte_mempool.h:1734
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:457
void rte_mempool_free(struct rte_mempool *mp)
rte_mempool_event
Definition: rte_mempool.h:1832
@ RTE_MEMPOOL_EVENT_DESTROY
Definition: rte_mempool.h:1836
@ RTE_MEMPOOL_EVENT_READY
Definition: rte_mempool.h:1834
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
Definition: rte_mempool.h:469
void() rte_mempool_populate_obj_cb_t(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
Definition: rte_mempool.h:560
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)
Definition: rte_mempool.h:1636
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
Definition: rte_mempool.h:463
void(* rte_mempool_free_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:440
static __rte_always_inline void rte_mempool_cache_flush(struct rte_mempool_cache *cache, struct rte_mempool *mp)
Definition: rte_mempool.h:1314
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:1422
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
Definition: rte_mempool.h:1609
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)
Definition: rte_mempool.h:1399
static int rte_mempool_full(const struct rte_mempool *mp)
Definition: rte_mempool.h:1699
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:435
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)
Definition: rte_mempool.h:1546
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
Definition: rte_mempool.h:423
void() rte_mempool_ctor_t(struct rte_mempool *, void *)
Definition: rte_mempool.h:975
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)
Definition: rte_mempool.h:965
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)
Definition: rte_mempool.h:494
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1444
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
Definition: rte_mempool.h:684
static int rte_mempool_empty(const struct rte_mempool *mp)
Definition: rte_mempool.h:1718
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)
Definition: rte_mempool.h:591
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1762
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)
Definition: rte_mempool.h:652
uint32_t flushthresh
Definition: rte_mempool.h:91
void * objs[RTE_MEMPOOL_CACHE_MAX_SIZE *3]
Definition: rte_mempool.h:97
unsigned int contig_block_size
Definition: rte_mempool.h:206
RTE_STAILQ_ENTRY(rte_mempool_memhdr) next
struct rte_mempool * mp
Definition: rte_mempool.h:190
rte_mempool_memchunk_free_cb_t * free_cb
Definition: rte_mempool.h:194
struct rte_mempool * mp
Definition: rte_mempool.h:145
RTE_STAILQ_ENTRY(rte_mempool_objhdr) next
uint32_t header_size
Definition: rte_mempool.h:105
uint32_t trailer_size
Definition: rte_mempool.h:106
uint32_t total_size
Definition: rte_mempool.h:107
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
Definition: rte_mempool.h:701
rte_spinlock_t sl
Definition: rte_mempool.h:696
char name[RTE_MEMPOOL_OPS_NAMESIZE]
Definition: rte_mempool.h:658
rte_mempool_alloc_t alloc
Definition: rte_mempool.h:659
rte_mempool_dequeue_t dequeue
Definition: rte_mempool.h:662
rte_mempool_get_info_t get_info
Definition: rte_mempool.h:677
rte_mempool_calc_mem_size_t calc_mem_size
Definition: rte_mempool.h:668
rte_mempool_get_count get_count
Definition: rte_mempool.h:663
rte_mempool_populate_t populate
Definition: rte_mempool.h:673
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
Definition: rte_mempool.h:681
rte_mempool_free_t free
Definition: rte_mempool.h:660
rte_mempool_enqueue_t enqueue
Definition: rte_mempool.h:661
uint32_t nb_mem_chunks
Definition: rte_mempool.h:245
const struct rte_memzone * mz
Definition: rte_mempool.h:220
struct rte_mempool_memhdr_list mem_list
Definition: rte_mempool.h:246
uint32_t populated_size
Definition: rte_mempool.h:243
uint32_t header_size
Definition: rte_mempool.h:228
uint64_t pool_id
Definition: rte_mempool.h:217
int32_t ops_index
Definition: rte_mempool.h:239
void * pool_config
Definition: rte_mempool.h:219
uint32_t trailer_size
Definition: rte_mempool.h:229
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:213
uint32_t size
Definition: rte_mempool.h:223
uint32_t cache_size
Definition: rte_mempool.h:224
unsigned int flags
Definition: rte_mempool.h:221
uint32_t elt_size
Definition: rte_mempool.h:227
unsigned private_data_size
Definition: rte_mempool.h:231
struct rte_mempool_cache * local_cache
Definition: rte_mempool.h:241
struct rte_mempool_objhdr_list elt_list
Definition: rte_mempool.h:244
void * pool_data
Definition: rte_mempool.h:216