DPDK  20.05.0
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 #include <sys/queue.h>
42 
43 #include <rte_config.h>
44 #include <rte_spinlock.h>
45 #include <rte_log.h>
46 #include <rte_debug.h>
47 #include <rte_lcore.h>
48 #include <rte_memory.h>
49 #include <rte_branch_prediction.h>
50 #include <rte_ring.h>
51 #include <rte_memcpy.h>
52 #include <rte_common.h>
53 
54 #include "rte_mempool_trace_fp.h"
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL
61 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL
62 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL
64 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
65 
68 struct rte_mempool_debug_stats {
69  uint64_t put_bulk;
70  uint64_t put_objs;
71  uint64_t get_success_bulk;
72  uint64_t get_success_objs;
73  uint64_t get_fail_bulk;
74  uint64_t get_fail_objs;
76  uint64_t get_success_blks;
78  uint64_t get_fail_blks;
80 #endif
81 
86  uint32_t size;
87  uint32_t flushthresh;
88  uint32_t len;
89  /*
90  * Cache is allocated to this size to allow it to overflow in certain
91  * cases to avoid needless emptying of cache.
92  */
93  void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
95 
100  uint32_t elt_size;
101  uint32_t header_size;
102  uint32_t trailer_size;
103  uint32_t total_size;
105 };
106 
108 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
109  sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
110 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
111 
112 /* "MP_<name>" */
113 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
114 
115 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
116 
118 #define MEMPOOL_PG_NUM_DEFAULT 1
119 
120 #ifndef RTE_MEMPOOL_ALIGN
121 
124 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
125 #endif
126 
127 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
128 
140  struct rte_mempool *mp;
142  union {
145  };
146 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
147  uint64_t cookie;
148 #endif
149 };
150 
154 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
155 
156 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
157 
164 struct rte_mempool_objtlr {
165  uint64_t cookie;
166 };
167 
168 #endif
169 
173 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
174 
179  void *opaque);
180 
189  struct rte_mempool *mp;
190  void *addr;
192  union {
195  };
196  size_t len;
198  void *opaque;
199 };
200 
212  unsigned int contig_block_size;
214 
218 struct rte_mempool {
219  /*
220  * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
221  * compatibility requirements, it could be changed to
222  * RTE_MEMPOOL_NAMESIZE next time the ABI changes
223  */
226  union {
227  void *pool_data;
228  uint64_t pool_id;
229  };
230  void *pool_config;
231  const struct rte_memzone *mz;
232  unsigned int flags;
233  int socket_id;
234  uint32_t size;
235  uint32_t cache_size;
238  uint32_t elt_size;
239  uint32_t header_size;
240  uint32_t trailer_size;
242  unsigned private_data_size;
250  int32_t ops_index;
251 
254  uint32_t populated_size;
255  struct rte_mempool_objhdr_list elt_list;
256  uint32_t nb_mem_chunks;
257  struct rte_mempool_memhdr_list mem_list;
259 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
260 
261  struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
262 #endif
264 
265 #define MEMPOOL_F_NO_SPREAD 0x0001
266 
267 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002
268 #define MEMPOOL_F_SP_PUT 0x0004
269 #define MEMPOOL_F_SC_GET 0x0008
270 #define MEMPOOL_F_POOL_CREATED 0x0010
271 #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020
272 #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
273 
284 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
285 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
286  unsigned __lcore_id = rte_lcore_id(); \
287  if (__lcore_id < RTE_MAX_LCORE) { \
288  mp->stats[__lcore_id].name##_objs += n; \
289  mp->stats[__lcore_id].name##_bulk += 1; \
290  } \
291  } while(0)
292 #define __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, name, n) do { \
293  unsigned int __lcore_id = rte_lcore_id(); \
294  if (__lcore_id < RTE_MAX_LCORE) { \
295  mp->stats[__lcore_id].name##_blks += n; \
296  mp->stats[__lcore_id].name##_bulk += 1; \
297  } \
298  } while (0)
299 #else
300 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
301 #define __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, name, n) do {} while (0)
302 #endif
303 
312 #define MEMPOOL_HEADER_SIZE(mp, cs) \
313  (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
314  (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
315 
316 /* return the header of a mempool object (internal) */
317 static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj)
318 {
319  return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
320  sizeof(struct rte_mempool_objhdr));
321 }
322 
332 static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
333 {
334  struct rte_mempool_objhdr *hdr = __mempool_get_header(obj);
335  return hdr->mp;
336 }
337 
338 /* return the trailer of a mempool object (internal) */
339 static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj)
340 {
341  struct rte_mempool *mp = rte_mempool_from_obj(obj);
342  return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
343 }
344 
359 void rte_mempool_check_cookies(const struct rte_mempool *mp,
360  void * const *obj_table_const, unsigned n, int free);
361 
362 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
363 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
364  rte_mempool_check_cookies(mp, obj_table_const, n, free)
365 #else
366 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
367 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
368 
388  void * const *first_obj_table_const, unsigned int n, int free);
389 
390 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
391 #define __mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
392  free) \
393  rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
394  free)
395 #else
396 #define __mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
397  free) \
398  do {} while (0)
399 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
400 
401 #define RTE_MEMPOOL_OPS_NAMESIZE 32
413 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
414 
418 typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
419 
423 typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
424  void * const *obj_table, unsigned int n);
425 
429 typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
430  void **obj_table, unsigned int n);
431 
439  void **first_obj_table, unsigned int n);
440 
444 typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
445 
469 typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
470  uint32_t obj_num, uint32_t pg_shift,
471  size_t *min_chunk_size, size_t *align);
472 
511 __rte_experimental
512 ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
513  uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
514  size_t *min_chunk_size, size_t *align);
515 
523 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
524  uint32_t obj_num, uint32_t pg_shift,
525  size_t *min_chunk_size, size_t *align);
526 
539 typedef void (rte_mempool_populate_obj_cb_t)(struct rte_mempool *mp,
540  void *opaque, void *vaddr, rte_iova_t iova);
541 
570 typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
571  unsigned int max_objs,
572  void *vaddr, rte_iova_t iova, size_t len,
573  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
574 
578 #define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
579 
615 __rte_experimental
617  unsigned int flags, unsigned int max_objs,
618  void *vaddr, rte_iova_t iova, size_t len,
619  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
620 
628  unsigned int max_objs,
629  void *vaddr, rte_iova_t iova, size_t len,
630  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
631 
638 typedef int (*rte_mempool_get_info_t)(const struct rte_mempool *mp,
639  struct rte_mempool_info *info);
640 
641 
669 
670 #define RTE_MEMPOOL_MAX_OPS_IDX 16
681 struct rte_mempool_ops_table {
683  uint32_t num_ops;
689 
692 
702 static inline struct rte_mempool_ops *
703 rte_mempool_get_ops(int ops_index)
704 {
705  RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
706 
707  return &rte_mempool_ops_table.ops[ops_index];
708 }
709 
719 int
720 rte_mempool_ops_alloc(struct rte_mempool *mp);
721 
735 static inline int
736 rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
737  void **obj_table, unsigned n)
738 {
739  struct rte_mempool_ops *ops;
740 
741  rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
742  ops = rte_mempool_get_ops(mp->ops_index);
743  return ops->dequeue(mp, obj_table, n);
744 }
745 
759 static inline int
760 rte_mempool_ops_dequeue_contig_blocks(struct rte_mempool *mp,
761  void **first_obj_table, unsigned int n)
762 {
763  struct rte_mempool_ops *ops;
764 
765  ops = rte_mempool_get_ops(mp->ops_index);
766  RTE_ASSERT(ops->dequeue_contig_blocks != NULL);
767  rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
768  return ops->dequeue_contig_blocks(mp, first_obj_table, n);
769 }
770 
784 static inline int
785 rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
786  unsigned n)
787 {
788  struct rte_mempool_ops *ops;
789 
790  rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
791  ops = rte_mempool_get_ops(mp->ops_index);
792  return ops->enqueue(mp, obj_table, n);
793 }
794 
803 unsigned
804 rte_mempool_ops_get_count(const struct rte_mempool *mp);
805 
825 ssize_t rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
826  uint32_t obj_num, uint32_t pg_shift,
827  size_t *min_chunk_size, size_t *align);
828 
852 int rte_mempool_ops_populate(struct rte_mempool *mp, unsigned int max_objs,
853  void *vaddr, rte_iova_t iova, size_t len,
855  void *obj_cb_arg);
856 
872 __rte_experimental
873 int rte_mempool_ops_get_info(const struct rte_mempool *mp,
874  struct rte_mempool_info *info);
875 
882 void
883 rte_mempool_ops_free(struct rte_mempool *mp);
884 
902 int
903 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
904  void *pool_config);
905 
916 int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
917 
923 #define MEMPOOL_REGISTER_OPS(ops) \
924  RTE_INIT(mp_hdlr_init_##ops) \
925  { \
926  rte_mempool_register_ops(&ops); \
927  }
928 
934 typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
935  void *opaque, void *obj, unsigned obj_idx);
936 typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
937 
943 typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
944  void *opaque, struct rte_mempool_memhdr *memhdr,
945  unsigned mem_idx);
946 
953 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
954 
1034 struct rte_mempool *
1035 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
1036  unsigned cache_size, unsigned private_data_size,
1037  rte_mempool_ctor_t *mp_init, void *mp_init_arg,
1038  rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
1039  int socket_id, unsigned flags);
1040 
1075 struct rte_mempool *
1076 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
1077  unsigned cache_size, unsigned private_data_size,
1078  int socket_id, unsigned flags);
1089 void
1090 rte_mempool_free(struct rte_mempool *mp);
1091 
1122 int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
1123  rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
1124  void *opaque);
1125 
1152 int
1153 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
1154  size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
1155  void *opaque);
1156 
1171 
1185 int rte_mempool_populate_anon(struct rte_mempool *mp);
1186 
1202 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1203  rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1204 
1220 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1221  rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1222 
1231 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1232 
1247 struct rte_mempool_cache *
1248 rte_mempool_cache_create(uint32_t size, int socket_id);
1249 
1256 void
1258 
1269 static __rte_always_inline struct rte_mempool_cache *
1270 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1271 {
1272  if (mp->cache_size == 0)
1273  return NULL;
1274 
1275  if (lcore_id >= RTE_MAX_LCORE)
1276  return NULL;
1277 
1278  rte_mempool_trace_default_cache(mp, lcore_id,
1279  &mp->local_cache[lcore_id]);
1280  return &mp->local_cache[lcore_id];
1281 }
1282 
1291 static __rte_always_inline void
1293  struct rte_mempool *mp)
1294 {
1295  if (cache == NULL)
1296  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1297  if (cache == NULL || cache->len == 0)
1298  return;
1299  rte_mempool_trace_cache_flush(cache, mp);
1300  rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1301  cache->len = 0;
1302 }
1303 
1316 static __rte_always_inline void
1317 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1318  unsigned int n, struct rte_mempool_cache *cache)
1319 {
1320  void **cache_objs;
1321 
1322  /* increment stat now, adding in mempool always success */
1323  __MEMPOOL_STAT_ADD(mp, put, n);
1324 
1325  /* No cache provided or if put would overflow mem allocated for cache */
1326  if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1327  goto ring_enqueue;
1328 
1329  cache_objs = &cache->objs[cache->len];
1330 
1331  /*
1332  * The cache follows the following algorithm
1333  * 1. Add the objects to the cache
1334  * 2. Anything greater than the cache min value (if it crosses the
1335  * cache flush threshold) is flushed to the ring.
1336  */
1337 
1338  /* Add elements back into the cache */
1339  rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1340 
1341  cache->len += n;
1342 
1343  if (cache->len >= cache->flushthresh) {
1344  rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1345  cache->len - cache->size);
1346  cache->len = cache->size;
1347  }
1348 
1349  return;
1350 
1351 ring_enqueue:
1352 
1353  /* push remaining objects in ring */
1354 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1355  if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1356  rte_panic("cannot put objects in mempool\n");
1357 #else
1358  rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1359 #endif
1360 }
1361 
1362 
1375 static __rte_always_inline void
1376 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1377  unsigned int n, struct rte_mempool_cache *cache)
1378 {
1379  rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1380  __mempool_check_cookies(mp, obj_table, n, 0);
1381  __mempool_generic_put(mp, obj_table, n, cache);
1382 }
1383 
1398 static __rte_always_inline void
1399 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1400  unsigned int n)
1401 {
1402  struct rte_mempool_cache *cache;
1403  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1404  rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1405  rte_mempool_generic_put(mp, obj_table, n, cache);
1406 }
1407 
1420 static __rte_always_inline void
1421 rte_mempool_put(struct rte_mempool *mp, void *obj)
1422 {
1423  rte_mempool_put_bulk(mp, &obj, 1);
1424 }
1425 
1440 static __rte_always_inline int
1441 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1442  unsigned int n, struct rte_mempool_cache *cache)
1443 {
1444  int ret;
1445  uint32_t index, len;
1446  void **cache_objs;
1447 
1448  /* No cache provided or cannot be satisfied from cache */
1449  if (unlikely(cache == NULL || n >= cache->size))
1450  goto ring_dequeue;
1451 
1452  cache_objs = cache->objs;
1453 
1454  /* Can this be satisfied from the cache? */
1455  if (cache->len < n) {
1456  /* No. Backfill the cache first, and then fill from it */
1457  uint32_t req = n + (cache->size - cache->len);
1458 
1459  /* How many do we require i.e. number to fill the cache + the request */
1460  ret = rte_mempool_ops_dequeue_bulk(mp,
1461  &cache->objs[cache->len], req);
1462  if (unlikely(ret < 0)) {
1463  /*
1464  * In the off chance that we are buffer constrained,
1465  * where we are not able to allocate cache + n, go to
1466  * the ring directly. If that fails, we are truly out of
1467  * buffers.
1468  */
1469  goto ring_dequeue;
1470  }
1471 
1472  cache->len += req;
1473  }
1474 
1475  /* Now fill in the response ... */
1476  for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1477  *obj_table = cache_objs[len];
1478 
1479  cache->len -= n;
1480 
1481  __MEMPOOL_STAT_ADD(mp, get_success, n);
1482 
1483  return 0;
1484 
1485 ring_dequeue:
1486 
1487  /* get remaining objects from ring */
1488  ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1489 
1490  if (ret < 0)
1491  __MEMPOOL_STAT_ADD(mp, get_fail, n);
1492  else
1493  __MEMPOOL_STAT_ADD(mp, get_success, n);
1494 
1495  return ret;
1496 }
1497 
1518 static __rte_always_inline int
1519 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1520  unsigned int n, struct rte_mempool_cache *cache)
1521 {
1522  int ret;
1523  ret = __mempool_generic_get(mp, obj_table, n, cache);
1524  if (ret == 0)
1525  __mempool_check_cookies(mp, obj_table, n, 1);
1526  rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1527  return ret;
1528 }
1529 
1552 static __rte_always_inline int
1553 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1554 {
1555  struct rte_mempool_cache *cache;
1556  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1557  rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1558  return rte_mempool_generic_get(mp, obj_table, n, cache);
1559 }
1560 
1581 static __rte_always_inline int
1582 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1583 {
1584  return rte_mempool_get_bulk(mp, obj_p, 1);
1585 }
1586 
1611 static __rte_always_inline int
1612 __rte_experimental
1614  void **first_obj_table, unsigned int n)
1615 {
1616  int ret;
1617 
1618  ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1619  if (ret == 0) {
1620  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_success, n);
1621  __mempool_contig_blocks_check_cookies(mp, first_obj_table, n,
1622  1);
1623  } else {
1624  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_fail, n);
1625  }
1626 
1627  rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1628  return ret;
1629 }
1630 
1643 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1644 
1657 unsigned int
1658 rte_mempool_in_use_count(const struct rte_mempool *mp);
1659 
1673 static inline int
1675 {
1676  return rte_mempool_avail_count(mp) == mp->size;
1677 }
1678 
1692 static inline int
1694 {
1695  return rte_mempool_avail_count(mp) == 0;
1696 }
1697 
1708 static inline rte_iova_t
1709 rte_mempool_virt2iova(const void *elt)
1710 {
1711  const struct rte_mempool_objhdr *hdr;
1712  hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1713  sizeof(*hdr));
1714  return hdr->iova;
1715 }
1716 
1727 void rte_mempool_audit(struct rte_mempool *mp);
1728 
1737 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1738 {
1739  return (char *)mp +
1741 }
1742 
1749 void rte_mempool_list_dump(FILE *f);
1750 
1763 struct rte_mempool *rte_mempool_lookup(const char *name);
1764 
1782 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1783  struct rte_mempool_objsz *sz);
1784 
1793 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1794  void *arg);
1795 
1803 __rte_experimental
1804 int
1805 rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
1806 
1807 #ifdef __cplusplus
1808 }
1809 #endif
1810 
1811 #endif /* _RTE_MEMPOOL_H_ */
__rte_experimental int rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags, 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)
uint64_t pool_id
Definition: rte_mempool.h:228
#define __rte_always_inline
Definition: rte_common.h:193
struct rte_mempool * rte_mempool_lookup(const char *name)
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)
uint32_t header_size
Definition: rte_mempool.h:239
STAILQ_ENTRY(rte_mempool_objhdr) next
const struct rte_memzone * mz
Definition: rte_mempool.h:231
uint64_t rte_iova_t
Definition: rte_common.h:385
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:1399
struct rte_mempool * mp
Definition: rte_mempool.h:189
void rte_mempool_list_dump(FILE *f)
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
Definition: rte_mempool.h:438
static __rte_always_inline int __rte_experimental rte_mempool_get_contig_blocks(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
Definition: rte_mempool.h:1613
rte_mempool_alloc_t alloc
Definition: rte_mempool.h:645
void( rte_mempool_memchunk_free_cb_t)(struct rte_mempool_memhdr *memhdr, void *opaque)
Definition: rte_mempool.h:178
unsigned int flags
Definition: rte_mempool.h:232
void( rte_mempool_obj_cb_t)(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
Definition: rte_mempool.h:934
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:1376
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:413
static int rte_mempool_empty(const struct rte_mempool *mp)
Definition: rte_mempool.h:1693
phys_addr_t physaddr
Definition: rte_mempool.h:144
phys_addr_t phys_addr
Definition: rte_mempool.h:194
rte_mempool_memchunk_free_cb_t * free_cb
Definition: rte_mempool.h:197
char name[RTE_MEMPOOL_OPS_NAMESIZE]
Definition: rte_mempool.h:644
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:429
#define MEMPOOL_HEADER_SIZE(mp, cs)
Definition: rte_mempool.h:312
rte_mempool_get_info_t get_info
Definition: rte_mempool.h:663
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
Definition: rte_mempool.h:667
uint32_t cache_size
Definition: rte_mempool.h:235
unsigned int rte_mempool_avail_count(const struct rte_mempool *mp)
uint32_t size
Definition: rte_mempool.h:234
struct rte_mempool_objhdr_list elt_list
Definition: rte_mempool.h:255
#define RTE_PTR_ADD(ptr, x)
Definition: rte_common.h:215
void rte_mempool_cache_free(struct rte_mempool_cache *cache)
uint32_t total_size
Definition: rte_mempool.h:103
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)
#define unlikely(x)
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:1519
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)
Definition: rte_mempool.h:1292
#define RTE_MEMPOOL_OPS_NAMESIZE
Definition: rte_mempool.h:401
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
Definition: rte_mempool.h:1582
STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
uint32_t nb_mem_chunks
Definition: rte_mempool.h:256
uint64_t phys_addr_t
Definition: rte_common.h:375
struct rte_mempool * mp
Definition: rte_mempool.h:140
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
Definition: rte_mempool.h:687
rte_mempool_get_count get_count
Definition: rte_mempool.h:649
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:469
static int rte_mempool_full(const struct rte_mempool *mp)
Definition: rte_mempool.h:1674
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:51
void * pool_config
Definition: rte_mempool.h:230
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)
Definition: rte_mempool.h:943
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1553
#define rte_panic(...)
Definition: rte_debug.h:50
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, void *pool_config)
__rte_experimental int rte_mempool_ops_get_info(const struct rte_mempool *mp, struct rte_mempool_info *info)
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)
rte_mempool_calc_mem_size_t calc_mem_size
Definition: rte_mempool.h:654
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
Definition: rte_mempool.h:444
uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, struct rte_mempool_objsz *sz)
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)
void * objs[RTE_MEMPOOL_CACHE_MAX_SIZE *3]
Definition: rte_mempool.h:93
void * pool_data
Definition: rte_mempool.h:227
unsigned int contig_block_size
Definition: rte_mempool.h:212
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)
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:570
uint32_t elt_size
Definition: rte_mempool.h:238
void rte_mempool_audit(struct rte_mempool *mp)
int(* rte_mempool_get_info_t)(const struct rte_mempool *mp, struct rte_mempool_info *info)
Definition: rte_mempool.h:638
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
Definition: rte_mempool.h:242
void( rte_mempool_ctor_t)(struct rte_mempool *, void *)
Definition: rte_mempool.h:953
__rte_experimental int rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz)
rte_spinlock_t sl
Definition: rte_mempool.h:682
static __rte_always_inline struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
Definition: rte_mempool.h:1270
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
Definition: rte_mempool.h:252
uint32_t trailer_size
Definition: rte_mempool.h:240
STAILQ_ENTRY(rte_mempool_memhdr) next
#define RTE_STD_C11
Definition: rte_common.h:40
rte_mempool_dequeue_t dequeue
Definition: rte_mempool.h:648
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:423
void rte_mempool_contig_blocks_check_cookies(const struct rte_mempool *mp, void *const *first_obj_table_const, unsigned int n, int free)
#define __rte_cache_aligned
Definition: rte_common.h:367
uint32_t flushthresh
Definition: rte_mempool.h:87
__rte_experimental ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp, uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve, size_t *min_chunk_size, size_t *align)
struct rte_mempool_memhdr_list mem_list
Definition: rte_mempool.h:257
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)
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)
Definition: rte_common.h:220
static struct rte_mempool * rte_mempool_from_obj(void *obj)
Definition: rte_mempool.h:332
uint32_t header_size
Definition: rte_mempool.h:101
int32_t ops_index
Definition: rte_mempool.h:250
static void * rte_memcpy(void *dst, const void *src, size_t n)
uint32_t populated_size
Definition: rte_mempool.h:254
static rte_iova_t rte_mempool_virt2iova(const void *elt)
Definition: rte_mempool.h:1709
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1421
rte_mempool_populate_t populate
Definition: rte_mempool.h:659
void( rte_mempool_populate_obj_cb_t)(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
Definition: rte_mempool.h:539
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)
Definition: rte_mempool.h:1737
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:224
uint32_t trailer_size
Definition: rte_mempool.h:102
#define RTE_MEMPOOL_MAX_OPS_IDX
Definition: rte_mempool.h:670
void(* rte_mempool_free_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:418
rte_mempool_free_t free
Definition: rte_mempool.h:646
rte_mempool_enqueue_t enqueue
Definition: rte_mempool.h:647
#define RTE_MEMZONE_NAMESIZE
Definition: rte_memzone.h:51