DPDK  19.11.10
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 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL
59 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL
60 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL
62 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
63 
66 struct rte_mempool_debug_stats {
67  uint64_t put_bulk;
68  uint64_t put_objs;
69  uint64_t get_success_bulk;
70  uint64_t get_success_objs;
71  uint64_t get_fail_bulk;
72  uint64_t get_fail_objs;
74  uint64_t get_success_blks;
76  uint64_t get_fail_blks;
78 #endif
79 
84  uint32_t size;
85  uint32_t flushthresh;
86  uint32_t len;
87  /*
88  * Cache is allocated to this size to allow it to overflow in certain
89  * cases to avoid needless emptying of cache.
90  */
91  void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
93 
98  uint32_t elt_size;
99  uint32_t header_size;
100  uint32_t trailer_size;
101  uint32_t total_size;
103 };
104 
106 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
107  sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
108 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
109 
110 /* "MP_<name>" */
111 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
112 
113 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
114 
116 #define MEMPOOL_PG_NUM_DEFAULT 1
117 
118 #ifndef RTE_MEMPOOL_ALIGN
119 
122 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
123 #endif
124 
125 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
126 
137  STAILQ_ENTRY(rte_mempool_objhdr) next;
138  struct rte_mempool *mp;
140  union {
143  };
144 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
145  uint64_t cookie;
146 #endif
147 };
148 
152 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
153 
154 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
155 
162 struct rte_mempool_objtlr {
163  uint64_t cookie;
164 };
165 
166 #endif
167 
171 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
172 
177  void *opaque);
178 
186  STAILQ_ENTRY(rte_mempool_memhdr) next;
187  struct rte_mempool *mp;
188  void *addr;
190  union {
193  };
194  size_t len;
196  void *opaque;
197 };
198 
210  unsigned int contig_block_size;
212 
216 struct rte_mempool {
217  /*
218  * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
219  * compatibility requirements, it could be changed to
220  * RTE_MEMPOOL_NAMESIZE next time the ABI changes
221  */
222  char name[RTE_MEMZONE_NAMESIZE];
224  union {
225  void *pool_data;
226  uint64_t pool_id;
227  };
228  void *pool_config;
229  const struct rte_memzone *mz;
230  unsigned int flags;
231  int socket_id;
232  uint32_t size;
233  uint32_t cache_size;
236  uint32_t elt_size;
237  uint32_t header_size;
238  uint32_t trailer_size;
240  unsigned private_data_size;
248  int32_t ops_index;
249 
252  uint32_t populated_size;
253  struct rte_mempool_objhdr_list elt_list;
254  uint32_t nb_mem_chunks;
255  struct rte_mempool_memhdr_list mem_list;
257 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
258 
259  struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
260 #endif
262 
263 #define MEMPOOL_F_NO_SPREAD 0x0001
264 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002
265 #define MEMPOOL_F_SP_PUT 0x0004
266 #define MEMPOOL_F_SC_GET 0x0008
267 #define MEMPOOL_F_POOL_CREATED 0x0010
268 #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020
269 #define MEMPOOL_F_NO_PHYS_CONTIG MEMPOOL_F_NO_IOVA_CONTIG /* deprecated */
270 
281 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
282 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
283  unsigned __lcore_id = rte_lcore_id(); \
284  if (__lcore_id < RTE_MAX_LCORE) { \
285  mp->stats[__lcore_id].name##_objs += n; \
286  mp->stats[__lcore_id].name##_bulk += 1; \
287  } \
288  } while(0)
289 #define __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, name, n) do { \
290  unsigned int __lcore_id = rte_lcore_id(); \
291  if (__lcore_id < RTE_MAX_LCORE) { \
292  mp->stats[__lcore_id].name##_blks += n; \
293  mp->stats[__lcore_id].name##_bulk += 1; \
294  } \
295  } while (0)
296 #else
297 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
298 #define __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, name, n) do {} while (0)
299 #endif
300 
309 #define MEMPOOL_HEADER_SIZE(mp, cs) \
310  (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
311  (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
312 
313 /* return the header of a mempool object (internal) */
314 static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj)
315 {
316  return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
317  sizeof(struct rte_mempool_objhdr));
318 }
319 
329 static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
330 {
331  struct rte_mempool_objhdr *hdr = __mempool_get_header(obj);
332  return hdr->mp;
333 }
334 
335 /* return the trailer of a mempool object (internal) */
336 static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj)
337 {
338  struct rte_mempool *mp = rte_mempool_from_obj(obj);
339  return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
340 }
341 
356 void rte_mempool_check_cookies(const struct rte_mempool *mp,
357  void * const *obj_table_const, unsigned n, int free);
358 
359 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
360 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
361  rte_mempool_check_cookies(mp, obj_table_const, n, free)
362 #else
363 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
364 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
365 
385  void * const *first_obj_table_const, unsigned int n, int free);
386 
387 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
388 #define __mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
389  free) \
390  rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
391  free)
392 #else
393 #define __mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
394  free) \
395  do {} while (0)
396 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
397 
398 #define RTE_MEMPOOL_OPS_NAMESIZE 32
410 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
411 
415 typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
416 
420 typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
421  void * const *obj_table, unsigned int n);
422 
426 typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
427  void **obj_table, unsigned int n);
428 
436  void **first_obj_table, unsigned int n);
437 
441 typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
442 
466 typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
467  uint32_t obj_num, uint32_t pg_shift,
468  size_t *min_chunk_size, size_t *align);
469 
508 __rte_experimental
509 ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
510  uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
511  size_t *min_chunk_size, size_t *align);
512 
520 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
521  uint32_t obj_num, uint32_t pg_shift,
522  size_t *min_chunk_size, size_t *align);
523 
536 typedef void (rte_mempool_populate_obj_cb_t)(struct rte_mempool *mp,
537  void *opaque, void *vaddr, rte_iova_t iova);
538 
567 typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
568  unsigned int max_objs,
569  void *vaddr, rte_iova_t iova, size_t len,
570  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
571 
575 #define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
576 
612 __rte_experimental
614  unsigned int flags, unsigned int max_objs,
615  void *vaddr, rte_iova_t iova, size_t len,
616  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
617 
625  unsigned int max_objs,
626  void *vaddr, rte_iova_t iova, size_t len,
627  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
628 
635 typedef int (*rte_mempool_get_info_t)(const struct rte_mempool *mp,
636  struct rte_mempool_info *info);
637 
638 
666 
667 #define RTE_MEMPOOL_MAX_OPS_IDX 16
678 struct rte_mempool_ops_table {
680  uint32_t num_ops;
686 
689 
699 static inline struct rte_mempool_ops *
700 rte_mempool_get_ops(int ops_index)
701 {
702  RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
703 
704  return &rte_mempool_ops_table.ops[ops_index];
705 }
706 
716 int
717 rte_mempool_ops_alloc(struct rte_mempool *mp);
718 
732 static inline int
733 rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
734  void **obj_table, unsigned n)
735 {
736  struct rte_mempool_ops *ops;
737 
738  ops = rte_mempool_get_ops(mp->ops_index);
739  return ops->dequeue(mp, obj_table, n);
740 }
741 
755 static inline int
756 rte_mempool_ops_dequeue_contig_blocks(struct rte_mempool *mp,
757  void **first_obj_table, unsigned int n)
758 {
759  struct rte_mempool_ops *ops;
760 
761  ops = rte_mempool_get_ops(mp->ops_index);
762  RTE_ASSERT(ops->dequeue_contig_blocks != NULL);
763  return ops->dequeue_contig_blocks(mp, first_obj_table, n);
764 }
765 
779 static inline int
780 rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
781  unsigned n)
782 {
783  struct rte_mempool_ops *ops;
784 
785  ops = rte_mempool_get_ops(mp->ops_index);
786  return ops->enqueue(mp, obj_table, n);
787 }
788 
797 unsigned
798 rte_mempool_ops_get_count(const struct rte_mempool *mp);
799 
819 ssize_t rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
820  uint32_t obj_num, uint32_t pg_shift,
821  size_t *min_chunk_size, size_t *align);
822 
846 int rte_mempool_ops_populate(struct rte_mempool *mp, unsigned int max_objs,
847  void *vaddr, rte_iova_t iova, size_t len,
849  void *obj_cb_arg);
850 
866 __rte_experimental
867 int rte_mempool_ops_get_info(const struct rte_mempool *mp,
868  struct rte_mempool_info *info);
869 
876 void
877 rte_mempool_ops_free(struct rte_mempool *mp);
878 
896 int
897 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
898  void *pool_config);
899 
910 int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
911 
917 #define MEMPOOL_REGISTER_OPS(ops) \
918  RTE_INIT(mp_hdlr_init_##ops) \
919  { \
920  rte_mempool_register_ops(&ops); \
921  }
922 
928 typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
929  void *opaque, void *obj, unsigned obj_idx);
930 typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
931 
937 typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
938  void *opaque, struct rte_mempool_memhdr *memhdr,
939  unsigned mem_idx);
940 
947 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
948 
1028 struct rte_mempool *
1029 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
1030  unsigned cache_size, unsigned private_data_size,
1031  rte_mempool_ctor_t *mp_init, void *mp_init_arg,
1032  rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
1033  int socket_id, unsigned flags);
1034 
1069 struct rte_mempool *
1070 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
1071  unsigned cache_size, unsigned private_data_size,
1072  int socket_id, unsigned flags);
1083 void
1084 rte_mempool_free(struct rte_mempool *mp);
1085 
1113 int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
1114  rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
1115  void *opaque);
1116 
1140 int
1141 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
1142  size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
1143  void *opaque);
1144 
1159 
1173 int rte_mempool_populate_anon(struct rte_mempool *mp);
1174 
1190 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1191  rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1192 
1208 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1209  rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1210 
1219 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1220 
1235 struct rte_mempool_cache *
1236 rte_mempool_cache_create(uint32_t size, int socket_id);
1237 
1244 void
1246 
1257 static __rte_always_inline struct rte_mempool_cache *
1258 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1259 {
1260  if (mp->cache_size == 0)
1261  return NULL;
1262 
1263  if (lcore_id >= RTE_MAX_LCORE)
1264  return NULL;
1265 
1266  return &mp->local_cache[lcore_id];
1267 }
1268 
1277 static __rte_always_inline void
1279  struct rte_mempool *mp)
1280 {
1281  if (cache == NULL)
1282  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1283  if (cache == NULL || cache->len == 0)
1284  return;
1285  rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1286  cache->len = 0;
1287 }
1288 
1301 static __rte_always_inline void
1302 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1303  unsigned int n, struct rte_mempool_cache *cache)
1304 {
1305  void **cache_objs;
1306 
1307  /* increment stat now, adding in mempool always success */
1308  __MEMPOOL_STAT_ADD(mp, put, n);
1309 
1310  /* No cache provided or if put would overflow mem allocated for cache */
1311  if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1312  goto ring_enqueue;
1313 
1314  cache_objs = &cache->objs[cache->len];
1315 
1316  /*
1317  * The cache follows the following algorithm
1318  * 1. Add the objects to the cache
1319  * 2. Anything greater than the cache min value (if it crosses the
1320  * cache flush threshold) is flushed to the ring.
1321  */
1322 
1323  /* Add elements back into the cache */
1324  rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1325 
1326  cache->len += n;
1327 
1328  if (cache->len >= cache->flushthresh) {
1329  rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1330  cache->len - cache->size);
1331  cache->len = cache->size;
1332  }
1333 
1334  return;
1335 
1336 ring_enqueue:
1337 
1338  /* push remaining objects in ring */
1339 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1340  if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1341  rte_panic("cannot put objects in mempool\n");
1342 #else
1343  rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1344 #endif
1345 }
1346 
1347 
1360 static __rte_always_inline void
1361 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1362  unsigned int n, struct rte_mempool_cache *cache)
1363 {
1364  __mempool_check_cookies(mp, obj_table, n, 0);
1365  __mempool_generic_put(mp, obj_table, n, cache);
1366 }
1367 
1382 static __rte_always_inline void
1383 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1384  unsigned int n)
1385 {
1386  struct rte_mempool_cache *cache;
1387  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1388  rte_mempool_generic_put(mp, obj_table, n, cache);
1389 }
1390 
1403 static __rte_always_inline void
1404 rte_mempool_put(struct rte_mempool *mp, void *obj)
1405 {
1406  rte_mempool_put_bulk(mp, &obj, 1);
1407 }
1408 
1423 static __rte_always_inline int
1424 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1425  unsigned int n, struct rte_mempool_cache *cache)
1426 {
1427  int ret;
1428  uint32_t index, len;
1429  void **cache_objs;
1430 
1431  /* No cache provided or cannot be satisfied from cache */
1432  if (unlikely(cache == NULL || n >= cache->size))
1433  goto ring_dequeue;
1434 
1435  cache_objs = cache->objs;
1436 
1437  /* Can this be satisfied from the cache? */
1438  if (cache->len < n) {
1439  /* No. Backfill the cache first, and then fill from it */
1440  uint32_t req = n + (cache->size - cache->len);
1441 
1442  /* How many do we require i.e. number to fill the cache + the request */
1443  ret = rte_mempool_ops_dequeue_bulk(mp,
1444  &cache->objs[cache->len], req);
1445  if (unlikely(ret < 0)) {
1446  /*
1447  * In the off chance that we are buffer constrained,
1448  * where we are not able to allocate cache + n, go to
1449  * the ring directly. If that fails, we are truly out of
1450  * buffers.
1451  */
1452  goto ring_dequeue;
1453  }
1454 
1455  cache->len += req;
1456  }
1457 
1458  /* Now fill in the response ... */
1459  for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1460  *obj_table = cache_objs[len];
1461 
1462  cache->len -= n;
1463 
1464  __MEMPOOL_STAT_ADD(mp, get_success, n);
1465 
1466  return 0;
1467 
1468 ring_dequeue:
1469 
1470  /* get remaining objects from ring */
1471  ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1472 
1473  if (ret < 0)
1474  __MEMPOOL_STAT_ADD(mp, get_fail, n);
1475  else
1476  __MEMPOOL_STAT_ADD(mp, get_success, n);
1477 
1478  return ret;
1479 }
1480 
1501 static __rte_always_inline int
1502 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1503  unsigned int n, struct rte_mempool_cache *cache)
1504 {
1505  int ret;
1506  ret = __mempool_generic_get(mp, obj_table, n, cache);
1507  if (ret == 0)
1508  __mempool_check_cookies(mp, obj_table, n, 1);
1509  return ret;
1510 }
1511 
1534 static __rte_always_inline int
1535 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1536 {
1537  struct rte_mempool_cache *cache;
1538  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1539  return rte_mempool_generic_get(mp, obj_table, n, cache);
1540 }
1541 
1562 static __rte_always_inline int
1563 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1564 {
1565  return rte_mempool_get_bulk(mp, obj_p, 1);
1566 }
1567 
1592 static __rte_always_inline int
1593 __rte_experimental
1595  void **first_obj_table, unsigned int n)
1596 {
1597  int ret;
1598 
1599  ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1600  if (ret == 0) {
1601  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_success, n);
1602  __mempool_contig_blocks_check_cookies(mp, first_obj_table, n,
1603  1);
1604  } else {
1605  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_fail, n);
1606  }
1607 
1608  return ret;
1609 }
1610 
1623 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1624 
1637 unsigned int
1638 rte_mempool_in_use_count(const struct rte_mempool *mp);
1639 
1653 static inline int
1655 {
1656  return rte_mempool_avail_count(mp) == mp->size;
1657 }
1658 
1672 static inline int
1674 {
1675  return rte_mempool_avail_count(mp) == 0;
1676 }
1677 
1688 static inline rte_iova_t
1689 rte_mempool_virt2iova(const void *elt)
1690 {
1691  const struct rte_mempool_objhdr *hdr;
1692  hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1693  sizeof(*hdr));
1694  return hdr->iova;
1695 }
1696 
1707 void rte_mempool_audit(struct rte_mempool *mp);
1708 
1717 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1718 {
1719  return (char *)mp +
1721 }
1722 
1729 void rte_mempool_list_dump(FILE *f);
1730 
1743 struct rte_mempool *rte_mempool_lookup(const char *name);
1744 
1762 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1763  struct rte_mempool_objsz *sz);
1764 
1773 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1774  void *arg);
1775 
1783 __rte_experimental
1784 int
1785 rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
1786 
1787 #ifdef __cplusplus
1788 }
1789 #endif
1790 
1791 #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:226
#define __rte_always_inline
Definition: rte_common.h:153
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:237
const struct rte_memzone * mz
Definition: rte_mempool.h:229
uint64_t rte_iova_t
Definition: rte_common.h:335
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:1383
struct rte_mempool * mp
Definition: rte_mempool.h:187
void rte_mempool_list_dump(FILE *f)
void() rte_mempool_memchunk_free_cb_t(struct rte_mempool_memhdr *memhdr, void *opaque)
Definition: rte_mempool.h:176
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
Definition: rte_mempool.h:435
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:1594
rte_mempool_alloc_t alloc
Definition: rte_mempool.h:642
void() rte_mempool_populate_obj_cb_t(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
Definition: rte_mempool.h:536
unsigned int flags
Definition: rte_mempool.h:230
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:1361
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:410
static int rte_mempool_empty(const struct rte_mempool *mp)
Definition: rte_mempool.h:1673
phys_addr_t physaddr
Definition: rte_mempool.h:142
phys_addr_t phys_addr
Definition: rte_mempool.h:192
rte_mempool_memchunk_free_cb_t * free_cb
Definition: rte_mempool.h:195
char name[RTE_MEMPOOL_OPS_NAMESIZE]
Definition: rte_mempool.h:641
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:426
#define MEMPOOL_HEADER_SIZE(mp, cs)
Definition: rte_mempool.h:309
rte_mempool_get_info_t get_info
Definition: rte_mempool.h:660
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
Definition: rte_mempool.h:664
uint32_t cache_size
Definition: rte_mempool.h:233
unsigned int rte_mempool_avail_count(const struct rte_mempool *mp)
uint32_t size
Definition: rte_mempool.h:232
#define RTE_PTR_ADD(ptr, x)
Definition: rte_common.h:165
void rte_mempool_cache_free(struct rte_mempool_cache *cache)
uint32_t total_size
Definition: rte_mempool.h:101
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:1502
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:1278
#define RTE_MEMPOOL_OPS_NAMESIZE
Definition: rte_mempool.h:398
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
Definition: rte_mempool.h:1563
STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
uint32_t nb_mem_chunks
Definition: rte_mempool.h:254
uint64_t phys_addr_t
Definition: rte_common.h:325
struct rte_mempool * mp
Definition: rte_mempool.h:138
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
Definition: rte_mempool.h:684
rte_mempool_get_count get_count
Definition: rte_mempool.h:646
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:466
static int rte_mempool_full(const struct rte_mempool *mp)
Definition: rte_mempool.h:1654
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:51
void * pool_config
Definition: rte_mempool.h:228
unsigned int rte_mempool_in_use_count(const struct rte_mempool *mp)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1535
#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:651
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
Definition: rte_mempool.h:441
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:91
void * pool_data
Definition: rte_mempool.h:225
unsigned int contig_block_size
Definition: rte_mempool.h:210
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:567
uint32_t elt_size
Definition: rte_mempool.h:236
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:635
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:240
__rte_experimental int rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz)
rte_spinlock_t sl
Definition: rte_mempool.h:679
static __rte_always_inline struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
Definition: rte_mempool.h:1258
void rte_mempool_dump(FILE *f, struct rte_mempool *mp)
void() rte_mempool_ctor_t(struct rte_mempool *, void *)
Definition: rte_mempool.h:947
int rte_mempool_populate_anon(struct rte_mempool *mp)
struct rte_mempool_cache * local_cache
Definition: rte_mempool.h:250
uint32_t trailer_size
Definition: rte_mempool.h:238
#define RTE_STD_C11
Definition: rte_common.h:40
rte_mempool_dequeue_t dequeue
Definition: rte_mempool.h:645
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:420
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:317
uint32_t flushthresh
Definition: rte_mempool.h:85
void() rte_mempool_obj_cb_t(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
Definition: rte_mempool.h:928
void() rte_mempool_mem_cb_t(struct rte_mempool *mp, void *opaque, struct rte_mempool_memhdr *memhdr, unsigned mem_idx)
Definition: rte_mempool.h:937
__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)
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:170
uint32_t elt_size
Definition: rte_mempool.h:98
static struct rte_mempool * rte_mempool_from_obj(void *obj)
Definition: rte_mempool.h:329
uint32_t header_size
Definition: rte_mempool.h:99
int32_t ops_index
Definition: rte_mempool.h:248
static void * rte_memcpy(void *dst, const void *src, size_t n)
uint32_t populated_size
Definition: rte_mempool.h:252
static rte_iova_t rte_mempool_virt2iova(const void *elt)
Definition: rte_mempool.h:1689
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1404
rte_mempool_populate_t populate
Definition: rte_mempool.h:656
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:1717
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:222
uint32_t trailer_size
Definition: rte_mempool.h:100
#define RTE_MEMPOOL_MAX_OPS_IDX
Definition: rte_mempool.h:667
void(* rte_mempool_free_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:415
rte_mempool_free_t free
Definition: rte_mempool.h:643
rte_mempool_enqueue_t enqueue
Definition: rte_mempool.h:644
#define RTE_MEMZONE_NAMESIZE
Definition: rte_memzone.h:51