DPDK  20.11.6
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 \
116  RTE_DEPRECATED(MEMPOOL_PG_SHIFT_MAX) (sizeof(uintptr_t) * CHAR_BIT - 1)
117 
119 #define MEMPOOL_PG_NUM_DEFAULT RTE_DEPRECATED(MEMPOOL_PG_NUM_DEFAULT) 1
120 
121 #ifndef RTE_MEMPOOL_ALIGN
122 
125 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
126 #endif
127 
128 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
129 
140  STAILQ_ENTRY(rte_mempool_objhdr) next;
141  struct rte_mempool *mp;
143 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
144  uint64_t cookie;
145 #endif
146 };
147 
151 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
152 
153 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
154 
161 struct rte_mempool_objtlr {
162  uint64_t cookie;
163 };
164 
165 #endif
166 
170 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
171 
176  void *opaque);
177 
185  STAILQ_ENTRY(rte_mempool_memhdr) next;
186  struct rte_mempool *mp;
187  void *addr;
189  size_t len;
191  void *opaque;
192 };
193 
202  unsigned int contig_block_size;
204 
208 struct rte_mempool {
209  /*
210  * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
211  * compatibility requirements, it could be changed to
212  * RTE_MEMPOOL_NAMESIZE next time the ABI changes
213  */
214  char name[RTE_MEMZONE_NAMESIZE];
216  union {
217  void *pool_data;
218  uint64_t pool_id;
219  };
220  void *pool_config;
221  const struct rte_memzone *mz;
222  unsigned int flags;
223  int socket_id;
224  uint32_t size;
225  uint32_t cache_size;
228  uint32_t elt_size;
229  uint32_t header_size;
230  uint32_t trailer_size;
232  unsigned private_data_size;
240  int32_t ops_index;
241 
244  uint32_t populated_size;
245  struct rte_mempool_objhdr_list elt_list;
246  uint32_t nb_mem_chunks;
247  struct rte_mempool_memhdr_list mem_list;
249 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
250 
251  struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
252 #endif
254 
255 #define MEMPOOL_F_NO_SPREAD 0x0001
256 
257 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002
258 #define MEMPOOL_F_SP_PUT 0x0004
259 #define MEMPOOL_F_SC_GET 0x0008
260 #define MEMPOOL_F_POOL_CREATED 0x0010
261 #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020
273 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
274 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
275  unsigned __lcore_id = rte_lcore_id(); \
276  if (__lcore_id < RTE_MAX_LCORE) { \
277  mp->stats[__lcore_id].name##_objs += n; \
278  mp->stats[__lcore_id].name##_bulk += 1; \
279  } \
280  } while(0)
281 #define __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, name, n) do { \
282  unsigned int __lcore_id = rte_lcore_id(); \
283  if (__lcore_id < RTE_MAX_LCORE) { \
284  mp->stats[__lcore_id].name##_blks += n; \
285  mp->stats[__lcore_id].name##_bulk += 1; \
286  } \
287  } while (0)
288 #else
289 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
290 #define __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, name, n) do {} while (0)
291 #endif
292 
301 #define MEMPOOL_HEADER_SIZE(mp, cs) \
302  (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
303  (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
304 
305 /* return the header of a mempool object (internal) */
306 static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj)
307 {
308  return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
309  sizeof(struct rte_mempool_objhdr));
310 }
311 
321 static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
322 {
323  struct rte_mempool_objhdr *hdr = __mempool_get_header(obj);
324  return hdr->mp;
325 }
326 
327 /* return the trailer of a mempool object (internal) */
328 static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj)
329 {
330  struct rte_mempool *mp = rte_mempool_from_obj(obj);
331  return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
332 }
333 
348 void rte_mempool_check_cookies(const struct rte_mempool *mp,
349  void * const *obj_table_const, unsigned n, int free);
350 
351 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
352 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
353  rte_mempool_check_cookies(mp, obj_table_const, n, free)
354 #else
355 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
356 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
357 
373 void rte_mempool_contig_blocks_check_cookies(const struct rte_mempool *mp,
374  void * const *first_obj_table_const, unsigned int n, int free);
375 
376 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
377 #define __mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
378  free) \
379  rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
380  free)
381 #else
382 #define __mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
383  free) \
384  do {} while (0)
385 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
386 
387 #define RTE_MEMPOOL_OPS_NAMESIZE 32
399 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
400 
404 typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
405 
409 typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
410  void * const *obj_table, unsigned int n);
411 
415 typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
416  void **obj_table, unsigned int n);
417 
422  void **first_obj_table, unsigned int n);
423 
427 typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
428 
452 typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
453  uint32_t obj_num, uint32_t pg_shift,
454  size_t *min_chunk_size, size_t *align);
455 
491 ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
492  uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
493  size_t *min_chunk_size, size_t *align);
494 
502 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
503  uint32_t obj_num, uint32_t pg_shift,
504  size_t *min_chunk_size, size_t *align);
505 
518 typedef void (rte_mempool_populate_obj_cb_t)(struct rte_mempool *mp,
519  void *opaque, void *vaddr, rte_iova_t iova);
520 
549 typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
550  unsigned int max_objs,
551  void *vaddr, rte_iova_t iova, size_t len,
552  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
553 
557 #define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
558 
591 int rte_mempool_op_populate_helper(struct rte_mempool *mp,
592  unsigned int flags, 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 
603  unsigned int max_objs,
604  void *vaddr, rte_iova_t iova, size_t len,
605  rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
606 
610 typedef int (*rte_mempool_get_info_t)(const struct rte_mempool *mp,
611  struct rte_mempool_info *info);
612 
613 
641 
642 #define RTE_MEMPOOL_MAX_OPS_IDX 16
653 struct rte_mempool_ops_table {
655  uint32_t num_ops;
661 
664 
674 static inline struct rte_mempool_ops *
675 rte_mempool_get_ops(int ops_index)
676 {
677  RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
678 
679  return &rte_mempool_ops_table.ops[ops_index];
680 }
681 
691 int
692 rte_mempool_ops_alloc(struct rte_mempool *mp);
693 
707 static inline int
708 rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
709  void **obj_table, unsigned n)
710 {
711  struct rte_mempool_ops *ops;
712 
713  rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
714  ops = rte_mempool_get_ops(mp->ops_index);
715  return ops->dequeue(mp, obj_table, n);
716 }
717 
731 static inline int
732 rte_mempool_ops_dequeue_contig_blocks(struct rte_mempool *mp,
733  void **first_obj_table, unsigned int n)
734 {
735  struct rte_mempool_ops *ops;
736 
737  ops = rte_mempool_get_ops(mp->ops_index);
738  RTE_ASSERT(ops->dequeue_contig_blocks != NULL);
739  rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
740  return ops->dequeue_contig_blocks(mp, first_obj_table, n);
741 }
742 
756 static inline int
757 rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
758  unsigned n)
759 {
760  struct rte_mempool_ops *ops;
761 
762  rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
763  ops = rte_mempool_get_ops(mp->ops_index);
764  return ops->enqueue(mp, obj_table, n);
765 }
766 
775 unsigned
776 rte_mempool_ops_get_count(const struct rte_mempool *mp);
777 
797 ssize_t rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
798  uint32_t obj_num, uint32_t pg_shift,
799  size_t *min_chunk_size, size_t *align);
800 
824 int rte_mempool_ops_populate(struct rte_mempool *mp, unsigned int max_objs,
825  void *vaddr, rte_iova_t iova, size_t len,
827  void *obj_cb_arg);
828 
841 int rte_mempool_ops_get_info(const struct rte_mempool *mp,
842  struct rte_mempool_info *info);
843 
850 void
851 rte_mempool_ops_free(struct rte_mempool *mp);
852 
870 int
871 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
872  void *pool_config);
873 
884 int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
885 
891 #define MEMPOOL_REGISTER_OPS(ops) \
892  RTE_INIT(mp_hdlr_init_##ops) \
893  { \
894  rte_mempool_register_ops(&ops); \
895  }
896 
902 typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
903  void *opaque, void *obj, unsigned obj_idx);
904 typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
905 
911 typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
912  void *opaque, struct rte_mempool_memhdr *memhdr,
913  unsigned mem_idx);
914 
921 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
922 
1002 struct rte_mempool *
1003 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
1004  unsigned cache_size, unsigned private_data_size,
1005  rte_mempool_ctor_t *mp_init, void *mp_init_arg,
1006  rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
1007  int socket_id, unsigned flags);
1008 
1043 struct rte_mempool *
1044 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
1045  unsigned cache_size, unsigned private_data_size,
1046  int socket_id, unsigned flags);
1057 void
1058 rte_mempool_free(struct rte_mempool *mp);
1059 
1090 int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
1091  rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
1092  void *opaque);
1093 
1120 int
1121 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
1122  size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
1123  void *opaque);
1124 
1139 
1153 int rte_mempool_populate_anon(struct rte_mempool *mp);
1154 
1170 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1171  rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1172 
1188 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1189  rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1190 
1199 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1200 
1215 struct rte_mempool_cache *
1216 rte_mempool_cache_create(uint32_t size, int socket_id);
1217 
1224 void
1226 
1238 static __rte_always_inline struct rte_mempool_cache *
1239 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1240 {
1241  if (mp->cache_size == 0)
1242  return NULL;
1243 
1244  if (lcore_id >= RTE_MAX_LCORE)
1245  return NULL;
1246 
1247  rte_mempool_trace_default_cache(mp, lcore_id,
1248  &mp->local_cache[lcore_id]);
1249  return &mp->local_cache[lcore_id];
1250 }
1251 
1260 static __rte_always_inline void
1262  struct rte_mempool *mp)
1263 {
1264  if (cache == NULL)
1265  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1266  if (cache == NULL || cache->len == 0)
1267  return;
1268  rte_mempool_trace_cache_flush(cache, mp);
1269  rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1270  cache->len = 0;
1271 }
1272 
1285 static __rte_always_inline void
1286 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1287  unsigned int n, struct rte_mempool_cache *cache)
1288 {
1289  void **cache_objs;
1290 
1291  /* increment stat now, adding in mempool always success */
1292  __MEMPOOL_STAT_ADD(mp, put, n);
1293 
1294  /* No cache provided or if put would overflow mem allocated for cache */
1295  if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1296  goto ring_enqueue;
1297 
1298  cache_objs = &cache->objs[cache->len];
1299 
1300  /*
1301  * The cache follows the following algorithm
1302  * 1. Add the objects to the cache
1303  * 2. Anything greater than the cache min value (if it crosses the
1304  * cache flush threshold) is flushed to the ring.
1305  */
1306 
1307  /* Add elements back into the cache */
1308  rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1309 
1310  cache->len += n;
1311 
1312  if (cache->len >= cache->flushthresh) {
1313  rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1314  cache->len - cache->size);
1315  cache->len = cache->size;
1316  }
1317 
1318  return;
1319 
1320 ring_enqueue:
1321 
1322  /* push remaining objects in ring */
1323 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1324  if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1325  rte_panic("cannot put objects in mempool\n");
1326 #else
1327  rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1328 #endif
1329 }
1330 
1331 
1344 static __rte_always_inline void
1345 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1346  unsigned int n, struct rte_mempool_cache *cache)
1347 {
1348  rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1349  __mempool_check_cookies(mp, obj_table, n, 0);
1350  __mempool_generic_put(mp, obj_table, n, cache);
1351 }
1352 
1367 static __rte_always_inline void
1368 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1369  unsigned int n)
1370 {
1371  struct rte_mempool_cache *cache;
1372  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1373  rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1374  rte_mempool_generic_put(mp, obj_table, n, cache);
1375 }
1376 
1389 static __rte_always_inline void
1390 rte_mempool_put(struct rte_mempool *mp, void *obj)
1391 {
1392  rte_mempool_put_bulk(mp, &obj, 1);
1393 }
1394 
1409 static __rte_always_inline int
1410 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1411  unsigned int n, struct rte_mempool_cache *cache)
1412 {
1413  int ret;
1414  uint32_t index, len;
1415  void **cache_objs;
1416 
1417  /* No cache provided or cannot be satisfied from cache */
1418  if (unlikely(cache == NULL || n >= cache->size))
1419  goto ring_dequeue;
1420 
1421  cache_objs = cache->objs;
1422 
1423  /* Can this be satisfied from the cache? */
1424  if (cache->len < n) {
1425  /* No. Backfill the cache first, and then fill from it */
1426  uint32_t req = n + (cache->size - cache->len);
1427 
1428  /* How many do we require i.e. number to fill the cache + the request */
1429  ret = rte_mempool_ops_dequeue_bulk(mp,
1430  &cache->objs[cache->len], req);
1431  if (unlikely(ret < 0)) {
1432  /*
1433  * In the off chance that we are buffer constrained,
1434  * where we are not able to allocate cache + n, go to
1435  * the ring directly. If that fails, we are truly out of
1436  * buffers.
1437  */
1438  goto ring_dequeue;
1439  }
1440 
1441  cache->len += req;
1442  }
1443 
1444  /* Now fill in the response ... */
1445  for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1446  *obj_table = cache_objs[len];
1447 
1448  cache->len -= n;
1449 
1450  __MEMPOOL_STAT_ADD(mp, get_success, n);
1451 
1452  return 0;
1453 
1454 ring_dequeue:
1455 
1456  /* get remaining objects from ring */
1457  ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1458 
1459  if (ret < 0)
1460  __MEMPOOL_STAT_ADD(mp, get_fail, n);
1461  else
1462  __MEMPOOL_STAT_ADD(mp, get_success, n);
1463 
1464  return ret;
1465 }
1466 
1487 static __rte_always_inline int
1488 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1489  unsigned int n, struct rte_mempool_cache *cache)
1490 {
1491  int ret;
1492  ret = __mempool_generic_get(mp, obj_table, n, cache);
1493  if (ret == 0)
1494  __mempool_check_cookies(mp, obj_table, n, 1);
1495  rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1496  return ret;
1497 }
1498 
1521 static __rte_always_inline int
1522 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1523 {
1524  struct rte_mempool_cache *cache;
1525  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1526  rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1527  return rte_mempool_generic_get(mp, obj_table, n, cache);
1528 }
1529 
1550 static __rte_always_inline int
1551 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1552 {
1553  return rte_mempool_get_bulk(mp, obj_p, 1);
1554 }
1555 
1577 static __rte_always_inline int
1579  void **first_obj_table, unsigned int n)
1580 {
1581  int ret;
1582 
1583  ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1584  if (ret == 0) {
1585  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_success, n);
1586  __mempool_contig_blocks_check_cookies(mp, first_obj_table, n,
1587  1);
1588  } else {
1589  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_fail, n);
1590  }
1591 
1592  rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1593  return ret;
1594 }
1595 
1608 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1609 
1622 unsigned int
1623 rte_mempool_in_use_count(const struct rte_mempool *mp);
1624 
1638 static inline int
1640 {
1641  return rte_mempool_avail_count(mp) == mp->size;
1642 }
1643 
1657 static inline int
1659 {
1660  return rte_mempool_avail_count(mp) == 0;
1661 }
1662 
1673 static inline rte_iova_t
1674 rte_mempool_virt2iova(const void *elt)
1675 {
1676  const struct rte_mempool_objhdr *hdr;
1677  hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1678  sizeof(*hdr));
1679  return hdr->iova;
1680 }
1681 
1692 void rte_mempool_audit(struct rte_mempool *mp);
1693 
1702 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1703 {
1704  return (char *)mp +
1706 }
1707 
1714 void rte_mempool_list_dump(FILE *f);
1715 
1728 struct rte_mempool *rte_mempool_lookup(const char *name);
1729 
1747 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1748  struct rte_mempool_objsz *sz);
1749 
1758 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1759  void *arg);
1760 
1765 int
1766 rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
1767 
1768 #ifdef __cplusplus
1769 }
1770 #endif
1771 
1772 #endif /* _RTE_MEMPOOL_H_ */
uint64_t pool_id
Definition: rte_mempool.h:218
#define __rte_always_inline
Definition: rte_common.h:231
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:229
const struct rte_memzone * mz
Definition: rte_mempool.h:221
uint64_t rte_iova_t
Definition: rte_common.h:423
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:1368
struct rte_mempool * mp
Definition: rte_mempool.h:186
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:175
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
Definition: rte_mempool.h:421
rte_mempool_alloc_t alloc
Definition: rte_mempool.h:617
void() rte_mempool_populate_obj_cb_t(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
Definition: rte_mempool.h:518
unsigned int flags
Definition: rte_mempool.h:222
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:1345
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:399
static int rte_mempool_empty(const struct rte_mempool *mp)
Definition: rte_mempool.h:1658
rte_mempool_memchunk_free_cb_t * free_cb
Definition: rte_mempool.h:190
char name[RTE_MEMPOOL_OPS_NAMESIZE]
Definition: rte_mempool.h:616
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:415
#define MEMPOOL_HEADER_SIZE(mp, cs)
Definition: rte_mempool.h:301
rte_mempool_get_info_t get_info
Definition: rte_mempool.h:635
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
Definition: rte_mempool.h:639
uint32_t cache_size
Definition: rte_mempool.h:225
unsigned int rte_mempool_avail_count(const struct rte_mempool *mp)
uint32_t size
Definition: rte_mempool.h:224
#define RTE_PTR_ADD(ptr, x)
Definition: rte_common.h:253
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_ops_get_info(const struct rte_mempool *mp, struct rte_mempool_info *info)
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:1488
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:1261
#define RTE_MEMPOOL_OPS_NAMESIZE
Definition: rte_mempool.h:387
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
Definition: rte_mempool.h:1551
STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
uint32_t nb_mem_chunks
Definition: rte_mempool.h:246
struct rte_mempool * mp
Definition: rte_mempool.h:141
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
Definition: rte_mempool.h:659
rte_mempool_get_count get_count
Definition: rte_mempool.h:621
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:452
static int rte_mempool_full(const struct rte_mempool *mp)
Definition: rte_mempool.h:1639
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:75
void * pool_config
Definition: rte_mempool.h:220
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:1522
#define rte_panic(...)
Definition: rte_debug.h:43
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, void *pool_config)
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:626
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
Definition: rte_mempool.h:427
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:217
unsigned int contig_block_size
Definition: rte_mempool.h:202
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:549
uint32_t elt_size
Definition: rte_mempool.h:228
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:610
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:232
rte_spinlock_t sl
Definition: rte_mempool.h:654
static __rte_always_inline struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
Definition: rte_mempool.h:1239
void rte_mempool_dump(FILE *f, struct rte_mempool *mp)
void() rte_mempool_ctor_t(struct rte_mempool *, void *)
Definition: rte_mempool.h:921
int rte_mempool_populate_anon(struct rte_mempool *mp)
struct rte_mempool_cache * local_cache
Definition: rte_mempool.h:242
#define __rte_cache_aligned
Definition: rte_common.h:405
uint32_t trailer_size
Definition: rte_mempool.h:230
#define RTE_STD_C11
Definition: rte_common.h:40
rte_mempool_dequeue_t dequeue
Definition: rte_mempool.h:620
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:409
uint32_t flushthresh
Definition: rte_mempool.h:87
void() rte_mempool_obj_cb_t(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
Definition: rte_mempool.h:902
void() rte_mempool_mem_cb_t(struct rte_mempool *mp, void *opaque, struct rte_mempool_memhdr *memhdr, unsigned mem_idx)
Definition: rte_mempool.h:911
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:258
static struct rte_mempool * rte_mempool_from_obj(void *obj)
Definition: rte_mempool.h:321
uint32_t header_size
Definition: rte_mempool.h:101
int32_t ops_index
Definition: rte_mempool.h:240
static void * rte_memcpy(void *dst, const void *src, size_t n)
uint32_t populated_size
Definition: rte_mempool.h:244
static rte_iova_t rte_mempool_virt2iova(const void *elt)
Definition: rte_mempool.h:1674
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1390
rte_mempool_populate_t populate
Definition: rte_mempool.h:631
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:1702
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:214
uint32_t trailer_size
Definition: rte_mempool.h:102
#define RTE_MEMPOOL_MAX_OPS_IDX
Definition: rte_mempool.h:642
void(* rte_mempool_free_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:404
rte_mempool_free_t free
Definition: rte_mempool.h:618
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:1578
rte_mempool_enqueue_t enqueue
Definition: rte_mempool.h:619
#define RTE_MEMZONE_NAMESIZE
Definition: rte_memzone.h:51