DPDK  20.08.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 
1270 static __rte_always_inline struct rte_mempool_cache *
1271 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1272 {
1273  if (mp->cache_size == 0)
1274  return NULL;
1275 
1276  if (lcore_id >= RTE_MAX_LCORE)
1277  return NULL;
1278 
1279  rte_mempool_trace_default_cache(mp, lcore_id,
1280  &mp->local_cache[lcore_id]);
1281  return &mp->local_cache[lcore_id];
1282 }
1283 
1292 static __rte_always_inline void
1294  struct rte_mempool *mp)
1295 {
1296  if (cache == NULL)
1297  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1298  if (cache == NULL || cache->len == 0)
1299  return;
1300  rte_mempool_trace_cache_flush(cache, mp);
1301  rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1302  cache->len = 0;
1303 }
1304 
1317 static __rte_always_inline void
1318 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1319  unsigned int n, struct rte_mempool_cache *cache)
1320 {
1321  void **cache_objs;
1322 
1323  /* increment stat now, adding in mempool always success */
1324  __MEMPOOL_STAT_ADD(mp, put, n);
1325 
1326  /* No cache provided or if put would overflow mem allocated for cache */
1327  if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1328  goto ring_enqueue;
1329 
1330  cache_objs = &cache->objs[cache->len];
1331 
1332  /*
1333  * The cache follows the following algorithm
1334  * 1. Add the objects to the cache
1335  * 2. Anything greater than the cache min value (if it crosses the
1336  * cache flush threshold) is flushed to the ring.
1337  */
1338 
1339  /* Add elements back into the cache */
1340  rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1341 
1342  cache->len += n;
1343 
1344  if (cache->len >= cache->flushthresh) {
1345  rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1346  cache->len - cache->size);
1347  cache->len = cache->size;
1348  }
1349 
1350  return;
1351 
1352 ring_enqueue:
1353 
1354  /* push remaining objects in ring */
1355 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1356  if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1357  rte_panic("cannot put objects in mempool\n");
1358 #else
1359  rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1360 #endif
1361 }
1362 
1363 
1376 static __rte_always_inline void
1377 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1378  unsigned int n, struct rte_mempool_cache *cache)
1379 {
1380  rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1381  __mempool_check_cookies(mp, obj_table, n, 0);
1382  __mempool_generic_put(mp, obj_table, n, cache);
1383 }
1384 
1399 static __rte_always_inline void
1400 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1401  unsigned int n)
1402 {
1403  struct rte_mempool_cache *cache;
1404  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1405  rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1406  rte_mempool_generic_put(mp, obj_table, n, cache);
1407 }
1408 
1421 static __rte_always_inline void
1422 rte_mempool_put(struct rte_mempool *mp, void *obj)
1423 {
1424  rte_mempool_put_bulk(mp, &obj, 1);
1425 }
1426 
1441 static __rte_always_inline int
1442 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1443  unsigned int n, struct rte_mempool_cache *cache)
1444 {
1445  int ret;
1446  uint32_t index, len;
1447  void **cache_objs;
1448 
1449  /* No cache provided or cannot be satisfied from cache */
1450  if (unlikely(cache == NULL || n >= cache->size))
1451  goto ring_dequeue;
1452 
1453  cache_objs = cache->objs;
1454 
1455  /* Can this be satisfied from the cache? */
1456  if (cache->len < n) {
1457  /* No. Backfill the cache first, and then fill from it */
1458  uint32_t req = n + (cache->size - cache->len);
1459 
1460  /* How many do we require i.e. number to fill the cache + the request */
1461  ret = rte_mempool_ops_dequeue_bulk(mp,
1462  &cache->objs[cache->len], req);
1463  if (unlikely(ret < 0)) {
1464  /*
1465  * In the off chance that we are buffer constrained,
1466  * where we are not able to allocate cache + n, go to
1467  * the ring directly. If that fails, we are truly out of
1468  * buffers.
1469  */
1470  goto ring_dequeue;
1471  }
1472 
1473  cache->len += req;
1474  }
1475 
1476  /* Now fill in the response ... */
1477  for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1478  *obj_table = cache_objs[len];
1479 
1480  cache->len -= n;
1481 
1482  __MEMPOOL_STAT_ADD(mp, get_success, n);
1483 
1484  return 0;
1485 
1486 ring_dequeue:
1487 
1488  /* get remaining objects from ring */
1489  ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1490 
1491  if (ret < 0)
1492  __MEMPOOL_STAT_ADD(mp, get_fail, n);
1493  else
1494  __MEMPOOL_STAT_ADD(mp, get_success, n);
1495 
1496  return ret;
1497 }
1498 
1519 static __rte_always_inline int
1520 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1521  unsigned int n, struct rte_mempool_cache *cache)
1522 {
1523  int ret;
1524  ret = __mempool_generic_get(mp, obj_table, n, cache);
1525  if (ret == 0)
1526  __mempool_check_cookies(mp, obj_table, n, 1);
1527  rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1528  return ret;
1529 }
1530 
1553 static __rte_always_inline int
1554 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1555 {
1556  struct rte_mempool_cache *cache;
1557  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1558  rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1559  return rte_mempool_generic_get(mp, obj_table, n, cache);
1560 }
1561 
1582 static __rte_always_inline int
1583 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1584 {
1585  return rte_mempool_get_bulk(mp, obj_p, 1);
1586 }
1587 
1612 static __rte_always_inline int
1613 __rte_experimental
1615  void **first_obj_table, unsigned int n)
1616 {
1617  int ret;
1618 
1619  ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1620  if (ret == 0) {
1621  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_success, n);
1622  __mempool_contig_blocks_check_cookies(mp, first_obj_table, n,
1623  1);
1624  } else {
1625  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_fail, n);
1626  }
1627 
1628  rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1629  return ret;
1630 }
1631 
1644 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1645 
1658 unsigned int
1659 rte_mempool_in_use_count(const struct rte_mempool *mp);
1660 
1674 static inline int
1676 {
1677  return rte_mempool_avail_count(mp) == mp->size;
1678 }
1679 
1693 static inline int
1695 {
1696  return rte_mempool_avail_count(mp) == 0;
1697 }
1698 
1709 static inline rte_iova_t
1710 rte_mempool_virt2iova(const void *elt)
1711 {
1712  const struct rte_mempool_objhdr *hdr;
1713  hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1714  sizeof(*hdr));
1715  return hdr->iova;
1716 }
1717 
1728 void rte_mempool_audit(struct rte_mempool *mp);
1729 
1738 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1739 {
1740  return (char *)mp +
1742 }
1743 
1750 void rte_mempool_list_dump(FILE *f);
1751 
1764 struct rte_mempool *rte_mempool_lookup(const char *name);
1765 
1783 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1784  struct rte_mempool_objsz *sz);
1785 
1794 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1795  void *arg);
1796 
1804 __rte_experimental
1805 int
1806 rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
1807 
1808 #ifdef __cplusplus
1809 }
1810 #endif
1811 
1812 #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:202
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:394
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:1400
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:1614
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:1377
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:1694
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:224
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:1520
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:1293
#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:1583
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:384
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:1675
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:75
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:1554
#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:1271
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
#define __rte_cache_aligned
Definition: rte_common.h:376
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)
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:229
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:1710
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1422
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:1738
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