DPDK  20.11.9
rte_mempool.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright(c) 2016 6WIND S.A.
4  */
5 
6 #ifndef _RTE_MEMPOOL_H_
7 #define _RTE_MEMPOOL_H_
8 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 #include <errno.h>
40 #include <inttypes.h>
41 #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
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
125 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
126 #endif
127 
128 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
129 
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 
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  */
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
251  struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
252 #endif
254 
255 #define MEMPOOL_F_NO_SPREAD 0x0001
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 
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
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 
842  struct rte_mempool_info *info);
843 
850 void
851 rte_mempool_ops_free(struct rte_mempool *mp);
852 
870 int
872  void *pool_config);
873 
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 
1001 struct rte_mempool *
1002 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
1003  unsigned cache_size, unsigned private_data_size,
1004  rte_mempool_ctor_t *mp_init, void *mp_init_arg,
1005  rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
1006  int socket_id, unsigned flags);
1007 
1042 struct rte_mempool *
1043 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
1044  unsigned cache_size, unsigned private_data_size,
1045  int socket_id, unsigned flags);
1056 void
1058 
1089 int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
1090  rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
1091  void *opaque);
1092 
1119 int
1121  size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
1122  void *opaque);
1123 
1138 
1153 
1169 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1170  rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1171 
1187 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1188  rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1189 
1198 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1199 
1214 struct rte_mempool_cache *
1215 rte_mempool_cache_create(uint32_t size, int socket_id);
1216 
1223 void
1225 
1237 static __rte_always_inline struct rte_mempool_cache *
1238 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1239 {
1240  if (mp->cache_size == 0)
1241  return NULL;
1242 
1243  if (lcore_id >= RTE_MAX_LCORE)
1244  return NULL;
1245 
1246  rte_mempool_trace_default_cache(mp, lcore_id,
1247  &mp->local_cache[lcore_id]);
1248  return &mp->local_cache[lcore_id];
1249 }
1250 
1259 static __rte_always_inline void
1261  struct rte_mempool *mp)
1262 {
1263  if (cache == NULL)
1264  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1265  if (cache == NULL || cache->len == 0)
1266  return;
1267  rte_mempool_trace_cache_flush(cache, mp);
1268  rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1269  cache->len = 0;
1270 }
1271 
1284 static __rte_always_inline void
1285 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1286  unsigned int n, struct rte_mempool_cache *cache)
1287 {
1288  void **cache_objs;
1289 
1290  /* increment stat now, adding in mempool always success */
1291  __MEMPOOL_STAT_ADD(mp, put, n);
1292 
1293  /* No cache provided or if put would overflow mem allocated for cache */
1294  if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1295  goto ring_enqueue;
1296 
1297  cache_objs = &cache->objs[cache->len];
1298 
1299  /*
1300  * The cache follows the following algorithm
1301  * 1. Add the objects to the cache
1302  * 2. Anything greater than the cache min value (if it crosses the
1303  * cache flush threshold) is flushed to the ring.
1304  */
1305 
1306  /* Add elements back into the cache */
1307  rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1308 
1309  cache->len += n;
1310 
1311  if (cache->len >= cache->flushthresh) {
1312  rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1313  cache->len - cache->size);
1314  cache->len = cache->size;
1315  }
1316 
1317  return;
1318 
1319 ring_enqueue:
1320 
1321  /* push remaining objects in ring */
1322 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1323  if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1324  rte_panic("cannot put objects in mempool\n");
1325 #else
1326  rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1327 #endif
1328 }
1329 
1330 
1343 static __rte_always_inline void
1344 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1345  unsigned int n, struct rte_mempool_cache *cache)
1346 {
1347  rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1348  __mempool_check_cookies(mp, obj_table, n, 0);
1349  __mempool_generic_put(mp, obj_table, n, cache);
1350 }
1351 
1366 static __rte_always_inline void
1367 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1368  unsigned int n)
1369 {
1370  struct rte_mempool_cache *cache;
1371  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1372  rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1373  rte_mempool_generic_put(mp, obj_table, n, cache);
1374 }
1375 
1388 static __rte_always_inline void
1389 rte_mempool_put(struct rte_mempool *mp, void *obj)
1390 {
1391  rte_mempool_put_bulk(mp, &obj, 1);
1392 }
1393 
1408 static __rte_always_inline int
1409 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1410  unsigned int n, struct rte_mempool_cache *cache)
1411 {
1412  int ret;
1413  unsigned int remaining = n;
1414  uint32_t index, len;
1415  void **cache_objs;
1416 
1417  /* No cache provided */
1418  if (unlikely(cache == NULL))
1419  goto driver_dequeue;
1420 
1421  /* Use the cache as much as we have to return hot objects first */
1422  len = RTE_MIN(remaining, cache->len);
1423  cache_objs = &cache->objs[cache->len];
1424  cache->len -= len;
1425  remaining -= len;
1426  for (index = 0; index < len; index++)
1427  *obj_table++ = *--cache_objs;
1428 
1429  if (remaining == 0) {
1430  /* The entire request is satisfied from the cache. */
1431 
1432  __MEMPOOL_STAT_ADD(mp, get_success, n);
1433 
1434  return 0;
1435  }
1436 
1437  /* if dequeue below would overflow mem allocated for cache */
1438  if (unlikely(remaining > RTE_MEMPOOL_CACHE_MAX_SIZE))
1439  goto driver_dequeue;
1440 
1441  /* Fill the cache from the backend; fetch size + remaining objects. */
1442  ret = rte_mempool_ops_dequeue_bulk(mp, cache->objs,
1443  cache->size + remaining);
1444  if (unlikely(ret < 0)) {
1445  /*
1446  * We are buffer constrained, and not able to allocate
1447  * cache + remaining.
1448  * Do not fill the cache, just satisfy the remaining part of
1449  * the request directly from the backend.
1450  */
1451  goto driver_dequeue;
1452  }
1453 
1454  /* Satisfy the remaining part of the request from the filled cache. */
1455  cache_objs = &cache->objs[cache->size + remaining];
1456  for (index = 0; index < remaining; index++)
1457  *obj_table++ = *--cache_objs;
1458 
1459  cache->len = cache->size;
1460 
1461  __MEMPOOL_STAT_ADD(mp, get_success, n);
1462 
1463  return 0;
1464 
1465 driver_dequeue:
1466 
1467  /* Get remaining objects directly from the backend. */
1468  ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, remaining);
1469 
1470  if (ret < 0) {
1471  if (likely(cache != NULL)) {
1472  cache->len = n - remaining;
1473  /*
1474  * No further action is required to roll the first part
1475  * of the request back into the cache, as objects in
1476  * the cache are intact.
1477  */
1478  }
1479 
1480  __MEMPOOL_STAT_ADD(mp, get_fail, n);
1481  } else
1482  __MEMPOOL_STAT_ADD(mp, get_success, n);
1483 
1484  return ret;
1485 }
1486 
1507 static __rte_always_inline int
1508 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1509  unsigned int n, struct rte_mempool_cache *cache)
1510 {
1511  int ret;
1512  ret = __mempool_generic_get(mp, obj_table, n, cache);
1513  if (ret == 0)
1514  __mempool_check_cookies(mp, obj_table, n, 1);
1515  rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1516  return ret;
1517 }
1518 
1541 static __rte_always_inline int
1542 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1543 {
1544  struct rte_mempool_cache *cache;
1545  cache = rte_mempool_default_cache(mp, rte_lcore_id());
1546  rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1547  return rte_mempool_generic_get(mp, obj_table, n, cache);
1548 }
1549 
1570 static __rte_always_inline int
1571 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1572 {
1573  return rte_mempool_get_bulk(mp, obj_p, 1);
1574 }
1575 
1597 static __rte_always_inline int
1599  void **first_obj_table, unsigned int n)
1600 {
1601  int ret;
1602 
1603  ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1604  if (ret == 0) {
1605  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_success, n);
1606  __mempool_contig_blocks_check_cookies(mp, first_obj_table, n,
1607  1);
1608  } else {
1609  __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_fail, n);
1610  }
1611 
1612  rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1613  return ret;
1614 }
1615 
1628 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1629 
1642 unsigned int
1644 
1658 static inline int
1660 {
1661  return rte_mempool_avail_count(mp) == mp->size;
1662 }
1663 
1677 static inline int
1679 {
1680  return rte_mempool_avail_count(mp) == 0;
1681 }
1682 
1693 static inline rte_iova_t
1694 rte_mempool_virt2iova(const void *elt)
1695 {
1696  const struct rte_mempool_objhdr *hdr;
1697  hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1698  sizeof(*hdr));
1699  return hdr->iova;
1700 }
1701 
1713 
1722 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1723 {
1724  return (char *)mp +
1726 }
1727 
1735 
1748 struct rte_mempool *rte_mempool_lookup(const char *name);
1749 
1767 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1768  struct rte_mempool_objsz *sz);
1769 
1778 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1779  void *arg);
1780 
1785 int
1786 rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
1787 
1788 #ifdef __cplusplus
1789 }
1790 #endif
1791 
1792 #endif /* _RTE_MEMPOOL_H_ */
#define likely(x)
#define unlikely(x)
#define __rte_cache_aligned
Definition: rte_common.h:405
#define RTE_MIN(a, b)
Definition: rte_common.h:578
#define RTE_PTR_SUB(ptr, x)
Definition: rte_common.h:258
uint64_t rte_iova_t
Definition: rte_common.h:423
#define RTE_PTR_ADD(ptr, x)
Definition: rte_common.h:253
#define RTE_STD_C11
Definition: rte_common.h:40
#define __rte_always_inline
Definition: rte_common.h:231
#define rte_panic(...)
Definition: rte_debug.h:43
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:75
static void * rte_memcpy(void *dst, const void *src, size_t n)
void() rte_mempool_memchunk_free_cb_t(struct rte_mempool_memhdr *memhdr, void *opaque)
Definition: rte_mempool.h:175
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, void *pool_config)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1542
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)
uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, struct rte_mempool_objsz *sz)
void() rte_mempool_obj_cb_t(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx)
Definition: rte_mempool.h:902
int(* rte_mempool_enqueue_t)(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:409
static rte_iova_t rte_mempool_virt2iova(const void *elt)
Definition: rte_mempool.h:1694
int(* rte_mempool_dequeue_t)(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:415
void rte_mempool_free(struct rte_mempool *mp)
unsigned(* rte_mempool_get_count)(const struct rte_mempool *mp)
Definition: rte_mempool.h:427
struct rte_mempool * rte_mempool_lookup(const char *name)
void() rte_mempool_populate_obj_cb_t(struct rte_mempool *mp, void *opaque, void *vaddr, rte_iova_t iova)
Definition: rte_mempool.h:518
int rte_mempool_populate_default(struct rte_mempool *mp)
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)
unsigned int rte_mempool_avail_count(const struct rte_mempool *mp)
struct rte_mempool * rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, unsigned cache_size, unsigned private_data_size, int socket_id, unsigned flags)
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:1598
int(* rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp, void **first_obj_table, unsigned int n)
Definition: rte_mempool.h:421
void(* rte_mempool_free_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:404
static __rte_always_inline void rte_mempool_cache_flush(struct rte_mempool_cache *cache, struct rte_mempool *mp)
Definition: rte_mempool.h:1260
STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr)
static __rte_always_inline void rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
Definition: rte_mempool.h:1367
static __rte_always_inline int rte_mempool_get(struct rte_mempool *mp, void **obj_p)
Definition: rte_mempool.h:1571
int rte_mempool_register_ops(const struct rte_mempool_ops *ops)
int rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1722
ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp, uint32_t obj_num, uint32_t pg_shift, size_t *min_chunk_size, size_t *align)
int rte_mempool_populate_anon(struct rte_mempool *mp)
void rte_mempool_cache_free(struct rte_mempool_cache *cache)
static __rte_always_inline void rte_mempool_generic_put(struct rte_mempool *mp, void *const *obj_table, unsigned int n, struct rte_mempool_cache *cache)
Definition: rte_mempool.h:1344
static int rte_mempool_full(const struct rte_mempool *mp)
Definition: rte_mempool.h:1659
int(* rte_mempool_alloc_t)(struct rte_mempool *mp)
Definition: rte_mempool.h:399
void rte_mempool_dump(FILE *f, struct rte_mempool *mp)
static __rte_always_inline int rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned int n, struct rte_mempool_cache *cache)
Definition: rte_mempool.h:1508
static struct rte_mempool * rte_mempool_from_obj(void *obj)
Definition: rte_mempool.h:321
void rte_mempool_audit(struct rte_mempool *mp)
void rte_mempool_walk(void(*func)(struct rte_mempool *, void *arg), void *arg)
#define RTE_MEMPOOL_OPS_NAMESIZE
Definition: rte_mempool.h:387
void() rte_mempool_ctor_t(struct rte_mempool *, void *)
Definition: rte_mempool.h:921
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
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 __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1389
int rte_mempool_ops_get_info(const struct rte_mempool *mp, struct rte_mempool_info *info)
struct rte_mempool_cache * rte_mempool_cache_create(uint32_t size, int socket_id)
unsigned int rte_mempool_in_use_count(const struct rte_mempool *mp)
uint32_t rte_mempool_obj_iter(struct rte_mempool *mp, rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg)
#define MEMPOOL_HEADER_SIZE(mp, cs)
Definition: rte_mempool.h:301
int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque)
void rte_mempool_list_dump(FILE *f)
#define RTE_MEMPOOL_MAX_OPS_IDX
Definition: rte_mempool.h:642
static int rte_mempool_empty(const struct rte_mempool *mp)
Definition: rte_mempool.h:1678
uint32_t rte_mempool_mem_iter(struct rte_mempool *mp, rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg)
int(* rte_mempool_populate_t)(struct rte_mempool *mp, unsigned int max_objs, void *vaddr, rte_iova_t iova, size_t len, rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
Definition: rte_mempool.h:549
static __rte_always_inline struct rte_mempool_cache * rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
Definition: rte_mempool.h:1238
int(* rte_mempool_get_info_t)(const struct rte_mempool *mp, struct rte_mempool_info *info)
Definition: rte_mempool.h:610
#define RTE_MEMZONE_NAMESIZE
Definition: rte_memzone.h:51
uint32_t flushthresh
Definition: rte_mempool.h:87
void * objs[RTE_MEMPOOL_CACHE_MAX_SIZE *3]
Definition: rte_mempool.h:93
unsigned int contig_block_size
Definition: rte_mempool.h:202
STAILQ_ENTRY(rte_mempool_memhdr) next
struct rte_mempool * mp
Definition: rte_mempool.h:186
rte_mempool_memchunk_free_cb_t * free_cb
Definition: rte_mempool.h:190
STAILQ_ENTRY(rte_mempool_objhdr) next
struct rte_mempool * mp
Definition: rte_mempool.h:141
uint32_t header_size
Definition: rte_mempool.h:101
uint32_t trailer_size
Definition: rte_mempool.h:102
uint32_t total_size
Definition: rte_mempool.h:103
struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]
Definition: rte_mempool.h:659
rte_spinlock_t sl
Definition: rte_mempool.h:654
char name[RTE_MEMPOOL_OPS_NAMESIZE]
Definition: rte_mempool.h:616
rte_mempool_alloc_t alloc
Definition: rte_mempool.h:617
rte_mempool_dequeue_t dequeue
Definition: rte_mempool.h:620
rte_mempool_get_info_t get_info
Definition: rte_mempool.h:635
rte_mempool_calc_mem_size_t calc_mem_size
Definition: rte_mempool.h:626
rte_mempool_get_count get_count
Definition: rte_mempool.h:621
rte_mempool_populate_t populate
Definition: rte_mempool.h:631
rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks
Definition: rte_mempool.h:639
rte_mempool_free_t free
Definition: rte_mempool.h:618
rte_mempool_enqueue_t enqueue
Definition: rte_mempool.h:619
uint32_t nb_mem_chunks
Definition: rte_mempool.h:246
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:214
const struct rte_memzone * mz
Definition: rte_mempool.h:221
struct rte_mempool_memhdr_list mem_list
Definition: rte_mempool.h:247
uint32_t populated_size
Definition: rte_mempool.h:244
uint32_t header_size
Definition: rte_mempool.h:229
uint64_t pool_id
Definition: rte_mempool.h:218
int32_t ops_index
Definition: rte_mempool.h:240
void * pool_config
Definition: rte_mempool.h:220
uint32_t trailer_size
Definition: rte_mempool.h:230
uint32_t size
Definition: rte_mempool.h:224
uint32_t cache_size
Definition: rte_mempool.h:225
unsigned int flags
Definition: rte_mempool.h:222
uint32_t elt_size
Definition: rte_mempool.h:228
unsigned private_data_size
Definition: rte_mempool.h:232
struct rte_mempool_cache * local_cache
Definition: rte_mempool.h:242
struct rte_mempool_objhdr_list elt_list
Definition: rte_mempool.h:245
void * pool_data
Definition: rte_mempool.h:217