Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation.
3 : : * Copyright(c) 2016 6WIND S.A.
4 : : * Copyright(c) 2022 SmartShare Systems
5 : : */
6 : :
7 : : #ifndef _RTE_MEMPOOL_H_
8 : : #define _RTE_MEMPOOL_H_
9 : :
10 : : /**
11 : : * @file
12 : : * RTE Mempool.
13 : : *
14 : : * A memory pool is an allocator of fixed-size object. It is
15 : : * identified by its name, and uses a ring to store free objects. It
16 : : * provides some other optional services, like a per-core object
17 : : * cache, and an alignment helper to ensure that objects are padded
18 : : * to spread them equally on all RAM channels, ranks, and so on.
19 : : *
20 : : * Objects owned by a mempool should never be added in another
21 : : * mempool. When an object is freed using rte_mempool_put() or
22 : : * equivalent, the object data is not modified; the user can save some
23 : : * meta-data in the object data and retrieve them when allocating a
24 : : * new object.
25 : : *
26 : : * Note: the mempool implementation is not preemptible. An lcore must not be
27 : : * interrupted by another task that uses the same mempool (because it uses a
28 : : * ring which is not preemptible). Also, usual mempool functions like
29 : : * rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL
30 : : * thread due to the internal per-lcore cache. Due to the lack of caching,
31 : : * rte_mempool_get() or rte_mempool_put() performance will suffer when called
32 : : * by unregistered non-EAL threads. Instead, unregistered non-EAL threads
33 : : * should call rte_mempool_generic_get() or rte_mempool_generic_put() with a
34 : : * user cache created with rte_mempool_cache_create().
35 : : */
36 : :
37 : : #include <stdalign.h>
38 : : #include <stdio.h>
39 : : #include <stdint.h>
40 : : #include <inttypes.h>
41 : :
42 : : #include <rte_compat.h>
43 : : #include <rte_config.h>
44 : : #include <rte_spinlock.h>
45 : : #include <rte_debug.h>
46 : : #include <rte_lcore.h>
47 : : #include <rte_log.h>
48 : : #include <rte_branch_prediction.h>
49 : : #include <rte_ring.h>
50 : : #include <rte_memcpy.h>
51 : : #include <rte_common.h>
52 : :
53 : : #include "rte_mempool_trace_fp.h"
54 : :
55 : : #ifdef __cplusplus
56 : : extern "C" {
57 : : #endif
58 : :
59 : : #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL /**< Header cookie. */
60 : : #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL /**< Header cookie. */
61 : : #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL /**< Trailer cookie.*/
62 : :
63 : : #ifdef RTE_LIBRTE_MEMPOOL_STATS
64 : : /**
65 : : * A structure that stores the mempool statistics (per-lcore).
66 : : * Note: Cache stats (put_cache_bulk/objs, get_cache_bulk/objs) are not
67 : : * captured since they can be calculated from other stats.
68 : : * For example: put_cache_objs = put_objs - put_common_pool_objs.
69 : : */
70 : : struct __rte_cache_aligned rte_mempool_debug_stats {
71 : : uint64_t put_bulk; /**< Number of puts. */
72 : : uint64_t put_objs; /**< Number of objects successfully put. */
73 : : uint64_t put_common_pool_bulk; /**< Number of bulks enqueued in common pool. */
74 : : uint64_t put_common_pool_objs; /**< Number of objects enqueued in common pool. */
75 : : uint64_t get_common_pool_bulk; /**< Number of bulks dequeued from common pool. */
76 : : uint64_t get_common_pool_objs; /**< Number of objects dequeued from common pool. */
77 : : uint64_t get_success_bulk; /**< Successful allocation number. */
78 : : uint64_t get_success_objs; /**< Objects successfully allocated. */
79 : : uint64_t get_fail_bulk; /**< Failed allocation number. */
80 : : uint64_t get_fail_objs; /**< Objects that failed to be allocated. */
81 : : uint64_t get_success_blks; /**< Successful allocation number of contiguous blocks. */
82 : : uint64_t get_fail_blks; /**< Failed allocation number of contiguous blocks. */
83 : : RTE_CACHE_GUARD;
84 : : };
85 : : #endif
86 : :
87 : : /**
88 : : * A structure that stores a per-core object cache.
89 : : */
90 : : struct __rte_cache_aligned rte_mempool_cache {
91 : : uint32_t size; /**< Size of the cache */
92 : : uint32_t len; /**< Current cache count */
93 : : #ifdef RTE_LIBRTE_MEMPOOL_STATS
94 : : /*
95 : : * Alternative location for the most frequently updated mempool statistics (per-lcore),
96 : : * providing faster update access when using a mempool cache.
97 : : * Note: 16-byte aligned for optimal SIMD access, when updating pairs of counters.
98 : : */
99 : : alignas(16)
100 : : struct {
101 : : uint64_t put_bulk; /**< Number of puts. */
102 : : uint64_t put_objs; /**< Number of objects successfully put. */
103 : : uint64_t get_success_bulk; /**< Successful allocation number. */
104 : : uint64_t get_success_objs; /**< Objects successfully allocated. */
105 : : } stats; /**< Statistics */
106 : : #endif
107 : : /** Cache objects */
108 : : alignas(RTE_CACHE_LINE_SIZE) void *objs[];
109 : : };
110 : :
111 : : /**
112 : : * A structure that stores the size of mempool elements.
113 : : */
114 : : struct rte_mempool_objsz {
115 : : uint32_t elt_size; /**< Size of an element. */
116 : : uint32_t header_size; /**< Size of header (before elt). */
117 : : uint32_t trailer_size; /**< Size of trailer (after elt). */
118 : : uint32_t total_size;
119 : : /**< Total size of an object (header + elt + trailer). */
120 : : };
121 : :
122 : : /**
123 : : * Maximum length of a memory pool's name.
124 : : *
125 : : * Note:
126 : : * Needs room for memzone prefix indicating "mempool" type:
127 : : * "MP_<name>"
128 : : * Furthermore, the mempool driver needs additional room for its own memzone prefix, e.g.:
129 : : * "RG_MP_<name>" (ring driver) or "STK_MP_<name>" (stack driver).
130 : : * In order to fail early on too long names, the length of the memzone name reserved
131 : : * by the default mempool driver (ring) is considered when creating the mempool.
132 : : * The length of the memzone name reserved by various other mempool drivers is
133 : : * not considered when creating the mempool.
134 : : * If the name eventually turns out to be too long for the chosen mempool driver,
135 : : * populating the mempool will fail.
136 : : */
137 : : #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
138 : : sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
139 : : #define RTE_MEMPOOL_MZ_PREFIX "MP_"
140 : :
141 : : /* "MP_<name>" */
142 : : #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
143 : :
144 : : #ifndef RTE_MEMPOOL_ALIGN
145 : : /**
146 : : * Alignment of elements inside mempool.
147 : : */
148 : : #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
149 : : #endif
150 : :
151 : : #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
152 : :
153 : : /**
154 : : * Mempool object header structure
155 : : *
156 : : * Each object stored in mempools are prefixed by this header structure,
157 : : * it allows retrieving the mempool pointer from the object and
158 : : * iterate on all objects attached to a mempool. When debug is enabled,
159 : : * a cookie is also added in this structure preventing corruptions and
160 : : * double-frees.
161 : : */
162 : : struct rte_mempool_objhdr {
163 : : RTE_STAILQ_ENTRY(rte_mempool_objhdr) next; /**< Next in list. */
164 : : struct rte_mempool *mp; /**< The mempool owning the object. */
165 : : rte_iova_t iova; /**< IO address of the object. */
166 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
167 : : uint64_t cookie; /**< Debug cookie. */
168 : : #endif
169 : : };
170 : :
171 : : /**
172 : : * A list of object headers type
173 : : */
174 : : RTE_STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
175 : :
176 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
177 : :
178 : : /**
179 : : * Mempool object trailer structure
180 : : *
181 : : * In debug mode, each object stored in mempools are suffixed by this
182 : : * trailer structure containing a cookie preventing memory corruptions.
183 : : */
184 : : struct rte_mempool_objtlr {
185 : : uint64_t cookie; /**< Debug cookie. */
186 : : };
187 : :
188 : : #endif
189 : :
190 : : /**
191 : : * @internal Logtype used for mempool related messages.
192 : : */
193 : : extern int rte_mempool_logtype;
194 : : #define RTE_LOGTYPE_MEMPOOL rte_mempool_logtype
195 : : #define RTE_MEMPOOL_LOG(level, ...) \
196 : : RTE_LOG_LINE(level, MEMPOOL, "" __VA_ARGS__)
197 : :
198 : : /**
199 : : * A list of memory where objects are stored
200 : : */
201 : : RTE_STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
202 : :
203 : : /**
204 : : * Callback used to free a memory chunk
205 : : */
206 : : typedef void (rte_mempool_memchunk_free_cb_t)(struct rte_mempool_memhdr *memhdr,
207 : : void *opaque);
208 : :
209 : : /**
210 : : * Mempool objects memory header structure
211 : : *
212 : : * The memory chunks where objects are stored. Each chunk is virtually
213 : : * and physically contiguous.
214 : : */
215 : : struct rte_mempool_memhdr {
216 : : RTE_STAILQ_ENTRY(rte_mempool_memhdr) next; /**< Next in list. */
217 : : struct rte_mempool *mp; /**< The mempool owning the chunk */
218 : : void *addr; /**< Virtual address of the chunk */
219 : : rte_iova_t iova; /**< IO address of the chunk */
220 : : size_t len; /**< length of the chunk */
221 : : rte_mempool_memchunk_free_cb_t *free_cb; /**< Free callback */
222 : : void *opaque; /**< Argument passed to the free callback */
223 : : };
224 : :
225 : : /**
226 : : * Additional information about the mempool
227 : : *
228 : : * The structure is cache-line aligned to avoid ABI breakages in
229 : : * a number of cases when something small is added.
230 : : */
231 : : struct __rte_cache_aligned rte_mempool_info {
232 : : /** Number of objects in the contiguous block */
233 : : unsigned int contig_block_size;
234 : : };
235 : :
236 : : /**
237 : : * The RTE mempool structure.
238 : : */
239 : : struct __rte_cache_aligned rte_mempool {
240 : : char name[RTE_MEMPOOL_NAMESIZE]; /**< Name of mempool. */
241 : : union {
242 : : void *pool_data; /**< Ring or pool to store objects. */
243 : : uint64_t pool_id; /**< External mempool identifier. */
244 : : };
245 : : void *pool_config; /**< optional args for ops alloc. */
246 : : const struct rte_memzone *mz; /**< Memzone where pool is alloc'd. */
247 : : unsigned int flags; /**< Flags of the mempool. */
248 : : int socket_id; /**< Socket id passed at create. */
249 : : uint32_t size; /**< Max size of the mempool. */
250 : : uint32_t cache_size; /**< Size of per-lcore default local cache. */
251 : :
252 : : uint32_t elt_size; /**< Size of an element. */
253 : : uint32_t header_size; /**< Size of header (before elt). */
254 : : uint32_t trailer_size; /**< Size of trailer (after elt). */
255 : :
256 : : unsigned private_data_size; /**< Size of private data. */
257 : : /**
258 : : * Index into rte_mempool_ops_table array of mempool ops
259 : : * structs, which contain callback function pointers.
260 : : * We're using an index here rather than pointers to the callbacks
261 : : * to facilitate any secondary processes that may want to use
262 : : * this mempool.
263 : : */
264 : : int32_t ops_index;
265 : :
266 : : struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
267 : : uint32_t sizeof_cache_per_lcore; /**< Multiplier for indexing into the local cache. */
268 : :
269 : : uint32_t populated_size; /**< Number of populated objects. */
270 : : struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
271 : : uint32_t nb_mem_chunks; /**< Number of memory chunks */
272 : : struct rte_mempool_memhdr_list mem_list; /**< List of memory chunks */
273 : :
274 : : #ifdef RTE_LIBRTE_MEMPOOL_STATS
275 : : /** Per-lcore statistics.
276 : : *
277 : : * Plus one, for unregistered non-EAL threads.
278 : : */
279 : : struct rte_mempool_debug_stats stats[RTE_MAX_LCORE + 1];
280 : : #endif
281 : :
282 : : /*
283 : : * Private data, if any, is located after the mempool header.
284 : : * Per-lcore local cache, if any, is located after the private data.
285 : : */
286 : : };
287 : :
288 : : /** Spreading among memory channels not required. */
289 : : #define RTE_MEMPOOL_F_NO_SPREAD 0x0001
290 : : /**
291 : : * Backward compatibility synonym for RTE_MEMPOOL_F_NO_SPREAD.
292 : : * To be deprecated.
293 : : */
294 : : #define MEMPOOL_F_NO_SPREAD RTE_MEMPOOL_F_NO_SPREAD
295 : : /** Do not align objects on cache lines. */
296 : : #define RTE_MEMPOOL_F_NO_CACHE_ALIGN 0x0002
297 : : /**
298 : : * Backward compatibility synonym for RTE_MEMPOOL_F_NO_CACHE_ALIGN.
299 : : * To be deprecated.
300 : : */
301 : : #define MEMPOOL_F_NO_CACHE_ALIGN RTE_MEMPOOL_F_NO_CACHE_ALIGN
302 : : /** Default put is "single-producer". */
303 : : #define RTE_MEMPOOL_F_SP_PUT 0x0004
304 : : /**
305 : : * Backward compatibility synonym for RTE_MEMPOOL_F_SP_PUT.
306 : : * To be deprecated.
307 : : */
308 : : #define MEMPOOL_F_SP_PUT RTE_MEMPOOL_F_SP_PUT
309 : : /** Default get is "single-consumer". */
310 : : #define RTE_MEMPOOL_F_SC_GET 0x0008
311 : : /**
312 : : * Backward compatibility synonym for RTE_MEMPOOL_F_SC_GET.
313 : : * To be deprecated.
314 : : */
315 : : #define MEMPOOL_F_SC_GET RTE_MEMPOOL_F_SC_GET
316 : : /** Internal: pool is created. */
317 : : #define RTE_MEMPOOL_F_POOL_CREATED 0x0010
318 : : /** Don't need IOVA contiguous objects. */
319 : : #define RTE_MEMPOOL_F_NO_IOVA_CONTIG 0x0020
320 : : /**
321 : : * Backward compatibility synonym for RTE_MEMPOOL_F_NO_IOVA_CONTIG.
322 : : * To be deprecated.
323 : : */
324 : : #define MEMPOOL_F_NO_IOVA_CONTIG RTE_MEMPOOL_F_NO_IOVA_CONTIG
325 : : /** Internal: no object from the pool can be used for device IO (DMA). */
326 : : #define RTE_MEMPOOL_F_NON_IO 0x0040
327 : :
328 : : /**
329 : : * This macro lists all the mempool flags an application may request.
330 : : */
331 : : #define RTE_MEMPOOL_VALID_USER_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \
332 : : | RTE_MEMPOOL_F_NO_CACHE_ALIGN \
333 : : | RTE_MEMPOOL_F_SP_PUT \
334 : : | RTE_MEMPOOL_F_SC_GET \
335 : : | RTE_MEMPOOL_F_NO_IOVA_CONTIG \
336 : : )
337 : :
338 : : /**
339 : : * @internal When stats is enabled, store some statistics.
340 : : *
341 : : * @param mp
342 : : * Pointer to the memory pool.
343 : : * @param name
344 : : * Name of the statistics field to increment in the memory pool.
345 : : * @param n
346 : : * Number to add to the statistics.
347 : : */
348 : : #ifdef RTE_LIBRTE_MEMPOOL_STATS
349 : : #define RTE_MEMPOOL_STAT_ADD(mp, name, n) do { \
350 : : unsigned int __lcore_id = rte_lcore_id(); \
351 : : if (likely(__lcore_id != LCORE_ID_ANY)) \
352 : : (mp)->stats[__lcore_id].name += (n); \
353 : : else \
354 : : rte_atomic_fetch_add_explicit(&((mp)->stats[RTE_MAX_LCORE].name), \
355 : : (n), rte_memory_order_relaxed); \
356 : : } while (0)
357 : : #else
358 : : #define RTE_MEMPOOL_STAT_ADD(mp, name, n) do {} while (0)
359 : : #endif
360 : :
361 : : /**
362 : : * @internal When stats is enabled, store some statistics.
363 : : *
364 : : * @param cache
365 : : * Pointer to the memory pool cache.
366 : : * @param name
367 : : * Name of the statistics field to increment in the memory pool cache.
368 : : * @param n
369 : : * Number to add to the statistics.
370 : : */
371 : : #ifdef RTE_LIBRTE_MEMPOOL_STATS
372 : : #define RTE_MEMPOOL_CACHE_STAT_ADD(cache, name, n) ((cache)->stats.name += (n))
373 : : #else
374 : : #define RTE_MEMPOOL_CACHE_STAT_ADD(cache, name, n) do {} while (0)
375 : : #endif
376 : :
377 : : /* return the header of a mempool object (internal) */
378 : : static inline struct rte_mempool_objhdr *
379 : : rte_mempool_get_header(void *obj)
380 : : {
381 : : RTE_ASSERT(obj != NULL);
382 [ - + # # ]: 249663 : __rte_assume(obj != NULL);
383 : : return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
384 : : sizeof(struct rte_mempool_objhdr));
385 : : }
386 : :
387 : : /**
388 : : * Return a pointer to the mempool owning this object.
389 : : *
390 : : * @param obj
391 : : * An object that is owned by a pool. If this is not the case,
392 : : * the behavior is undefined.
393 : : * @return
394 : : * A pointer to the mempool structure.
395 : : */
396 : 0 : static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
397 : : {
398 : : struct rte_mempool_objhdr *hdr = rte_mempool_get_header(obj);
399 [ - + + - ]: 250040 : return hdr->mp;
400 : : }
401 : :
402 : : /* return the trailer of a mempool object (internal) */
403 : : static inline struct rte_mempool_objtlr *rte_mempool_get_trailer(void *obj)
404 : : {
405 : : struct rte_mempool *mp = rte_mempool_from_obj(obj);
406 : : RTE_ASSERT(mp != NULL);
407 : : return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
408 : : }
409 : :
410 : : /**
411 : : * @internal Check and update cookies or panic.
412 : : *
413 : : * @param mp
414 : : * Pointer to the memory pool.
415 : : * @param obj_table_const
416 : : * Pointer to a table of void * pointers (objects).
417 : : * @param n
418 : : * Index of object in object table.
419 : : * @param free
420 : : * - 0: object is supposed to be allocated, mark it as free
421 : : * - 1: object is supposed to be free, mark it as allocated
422 : : * - 2: just check that cookie is valid (free or allocated)
423 : : */
424 : : void rte_mempool_check_cookies(const struct rte_mempool *mp,
425 : : void * const *obj_table_const, unsigned n, int free);
426 : :
427 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
428 : : #define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) \
429 : : rte_mempool_check_cookies(mp, obj_table_const, n, free)
430 : : #else
431 : : #define RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table_const, n, free) do {} while (0)
432 : : #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
433 : :
434 : : /**
435 : : * @internal Check contiguous object blocks and update cookies or panic.
436 : : *
437 : : * @param mp
438 : : * Pointer to the memory pool.
439 : : * @param first_obj_table_const
440 : : * Pointer to a table of void * pointers (first object of the contiguous
441 : : * object blocks).
442 : : * @param n
443 : : * Number of contiguous object blocks.
444 : : * @param free
445 : : * - 0: object is supposed to be allocated, mark it as free
446 : : * - 1: object is supposed to be free, mark it as allocated
447 : : * - 2: just check that cookie is valid (free or allocated)
448 : : */
449 : : void rte_mempool_contig_blocks_check_cookies(const struct rte_mempool *mp,
450 : : void * const *first_obj_table_const, unsigned int n, int free);
451 : :
452 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
453 : : #define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \
454 : : free) \
455 : : rte_mempool_contig_blocks_check_cookies(mp, first_obj_table_const, n, \
456 : : free)
457 : : #else
458 : : #define RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table_const, n, \
459 : : free) \
460 : : do {} while (0)
461 : : #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
462 : :
463 : : #define RTE_MEMPOOL_OPS_NAMESIZE 32 /**< Max length of ops struct name. */
464 : :
465 : : /**
466 : : * Prototype for implementation specific data provisioning function.
467 : : *
468 : : * The function should provide the implementation specific memory for
469 : : * use by the other mempool ops functions in a given mempool ops struct.
470 : : * E.g. the default ops provides an instance of the rte_ring for this purpose.
471 : : * it will most likely point to a different type of data structure, and
472 : : * will be transparent to the application programmer.
473 : : * This function should set mp->pool_data.
474 : : */
475 : : typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
476 : :
477 : : /**
478 : : * Free the opaque private data pointed to by mp->pool_data pointer.
479 : : */
480 : : typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
481 : :
482 : : /**
483 : : * Enqueue 'n' objects into the external pool.
484 : : * @return
485 : : * - 0: Success
486 : : * - <0: Error
487 : : */
488 : : typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
489 : : void * const *obj_table, unsigned int n);
490 : :
491 : : /**
492 : : * Dequeue 'n' objects from the external pool.
493 : : * @return
494 : : * - 0: Success
495 : : * - <0: Error
496 : : */
497 : : typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
498 : : void **obj_table, unsigned int n);
499 : :
500 : : /**
501 : : * Dequeue a number of contiguous object blocks from the external pool.
502 : : */
503 : : typedef int (*rte_mempool_dequeue_contig_blocks_t)(struct rte_mempool *mp,
504 : : void **first_obj_table, unsigned int n);
505 : :
506 : : /**
507 : : * Return the number of available objects in the external pool.
508 : : */
509 : : typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
510 : :
511 : : /**
512 : : * Calculate memory size required to store given number of objects.
513 : : *
514 : : * If mempool objects are not required to be IOVA-contiguous
515 : : * (the flag RTE_MEMPOOL_F_NO_IOVA_CONTIG is set), min_chunk_size defines
516 : : * virtually contiguous chunk size. Otherwise, if mempool objects must
517 : : * be IOVA-contiguous (the flag RTE_MEMPOOL_F_NO_IOVA_CONTIG is clear),
518 : : * min_chunk_size defines IOVA-contiguous chunk size.
519 : : *
520 : : * @param[in] mp
521 : : * Pointer to the memory pool.
522 : : * @param[in] obj_num
523 : : * Number of objects.
524 : : * @param[in] pg_shift
525 : : * LOG2 of the physical pages size. If set to 0, ignore page boundaries.
526 : : * @param[out] min_chunk_size
527 : : * Location for minimum size of the memory chunk which may be used to
528 : : * store memory pool objects.
529 : : * @param[out] align
530 : : * Location for required memory chunk alignment.
531 : : * @return
532 : : * Required memory size.
533 : : */
534 : : typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
535 : : uint32_t obj_num, uint32_t pg_shift,
536 : : size_t *min_chunk_size, size_t *align);
537 : :
538 : : /**
539 : : * @internal Helper to calculate memory size required to store given
540 : : * number of objects.
541 : : *
542 : : * This function is internal to mempool library and mempool drivers.
543 : : *
544 : : * If page boundaries may be ignored, it is just a product of total
545 : : * object size including header and trailer and number of objects.
546 : : * Otherwise, it is a number of pages required to store given number of
547 : : * objects without crossing page boundary.
548 : : *
549 : : * Note that if object size is bigger than page size, then it assumes
550 : : * that pages are grouped in subsets of physically continuous pages big
551 : : * enough to store at least one object.
552 : : *
553 : : * Minimum size of memory chunk is the total element size.
554 : : * Required memory chunk alignment is the cache line size.
555 : : *
556 : : * @param[in] mp
557 : : * A pointer to the mempool structure.
558 : : * @param[in] obj_num
559 : : * Number of objects to be added in mempool.
560 : : * @param[in] pg_shift
561 : : * LOG2 of the physical pages size. If set to 0, ignore page boundaries.
562 : : * @param[in] chunk_reserve
563 : : * Amount of memory that must be reserved at the beginning of each page,
564 : : * or at the beginning of the memory area if pg_shift is 0.
565 : : * @param[out] min_chunk_size
566 : : * Location for minimum size of the memory chunk which may be used to
567 : : * store memory pool objects.
568 : : * @param[out] align
569 : : * Location for required memory chunk alignment.
570 : : * @return
571 : : * Required memory size.
572 : : */
573 : : ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
574 : : uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
575 : : size_t *min_chunk_size, size_t *align);
576 : :
577 : : /**
578 : : * Default way to calculate memory size required to store given number of
579 : : * objects.
580 : : *
581 : : * Equivalent to rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
582 : : * 0, min_chunk_size, align).
583 : : */
584 : : ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
585 : : uint32_t obj_num, uint32_t pg_shift,
586 : : size_t *min_chunk_size, size_t *align);
587 : :
588 : : /**
589 : : * Function to be called for each populated object.
590 : : *
591 : : * @param[in] mp
592 : : * A pointer to the mempool structure.
593 : : * @param[in] opaque
594 : : * An opaque pointer passed to iterator.
595 : : * @param[in] vaddr
596 : : * Object virtual address.
597 : : * @param[in] iova
598 : : * Input/output virtual address of the object or RTE_BAD_IOVA.
599 : : */
600 : : typedef void (rte_mempool_populate_obj_cb_t)(struct rte_mempool *mp,
601 : : void *opaque, void *vaddr, rte_iova_t iova);
602 : :
603 : : /**
604 : : * Populate memory pool objects using provided memory chunk.
605 : : *
606 : : * Populated objects should be enqueued to the pool, e.g. using
607 : : * rte_mempool_ops_enqueue_bulk().
608 : : *
609 : : * If the given IO address is unknown (iova = RTE_BAD_IOVA),
610 : : * the chunk doesn't need to be physically contiguous (only virtually),
611 : : * and allocated objects may span two pages.
612 : : *
613 : : * @param[in] mp
614 : : * A pointer to the mempool structure.
615 : : * @param[in] max_objs
616 : : * Maximum number of objects to be populated.
617 : : * @param[in] vaddr
618 : : * The virtual address of memory that should be used to store objects.
619 : : * @param[in] iova
620 : : * The IO address
621 : : * @param[in] len
622 : : * The length of memory in bytes.
623 : : * @param[in] obj_cb
624 : : * Callback function to be executed for each populated object.
625 : : * @param[in] obj_cb_arg
626 : : * An opaque pointer passed to the callback function.
627 : : * @return
628 : : * The number of objects added on success.
629 : : * On error, no objects are populated and a negative errno is returned.
630 : : */
631 : : typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
632 : : unsigned int max_objs,
633 : : void *vaddr, rte_iova_t iova, size_t len,
634 : : rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
635 : :
636 : : /**
637 : : * Align objects on addresses multiple of total_elt_sz.
638 : : */
639 : : #define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
640 : :
641 : : /**
642 : : * @internal Helper to populate memory pool object using provided memory
643 : : * chunk: just slice objects one by one, taking care of not
644 : : * crossing page boundaries.
645 : : *
646 : : * If RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is set in flags, the addresses
647 : : * of object headers will be aligned on a multiple of total_elt_sz.
648 : : * This feature is used by octeontx hardware.
649 : : *
650 : : * This function is internal to mempool library and mempool drivers.
651 : : *
652 : : * @param[in] mp
653 : : * A pointer to the mempool structure.
654 : : * @param[in] flags
655 : : * Logical OR of following flags:
656 : : * - RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ: align objects on addresses
657 : : * multiple of total_elt_sz.
658 : : * @param[in] max_objs
659 : : * Maximum number of objects to be added in mempool.
660 : : * @param[in] vaddr
661 : : * The virtual address of memory that should be used to store objects.
662 : : * @param[in] iova
663 : : * The IO address corresponding to vaddr, or RTE_BAD_IOVA.
664 : : * @param[in] len
665 : : * The length of memory in bytes.
666 : : * @param[in] obj_cb
667 : : * Callback function to be executed for each populated object.
668 : : * @param[in] obj_cb_arg
669 : : * An opaque pointer passed to the callback function.
670 : : * @return
671 : : * The number of objects added in mempool.
672 : : */
673 : : int rte_mempool_op_populate_helper(struct rte_mempool *mp,
674 : : unsigned int flags, unsigned int max_objs,
675 : : void *vaddr, rte_iova_t iova, size_t len,
676 : : rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
677 : :
678 : : /**
679 : : * Default way to populate memory pool object using provided memory chunk.
680 : : *
681 : : * Equivalent to rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, iova,
682 : : * len, obj_cb, obj_cb_arg).
683 : : */
684 : : int rte_mempool_op_populate_default(struct rte_mempool *mp,
685 : : unsigned int max_objs,
686 : : void *vaddr, rte_iova_t iova, size_t len,
687 : : rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
688 : :
689 : : /**
690 : : * Get some additional information about a mempool.
691 : : */
692 : : typedef int (*rte_mempool_get_info_t)(const struct rte_mempool *mp,
693 : : struct rte_mempool_info *info);
694 : :
695 : :
696 : : /** Structure defining mempool operations structure */
697 : : struct __rte_cache_aligned rte_mempool_ops {
698 : : char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
699 : : rte_mempool_alloc_t alloc; /**< Allocate private data. */
700 : : rte_mempool_free_t free; /**< Free the external pool. */
701 : : rte_mempool_enqueue_t enqueue; /**< Enqueue an object. */
702 : : rte_mempool_dequeue_t dequeue; /**< Dequeue an object. */
703 : : rte_mempool_get_count get_count; /**< Get qty of available objs. */
704 : : /**
705 : : * Optional callback to calculate memory size required to
706 : : * store specified number of objects.
707 : : */
708 : : rte_mempool_calc_mem_size_t calc_mem_size;
709 : : /**
710 : : * Optional callback to populate mempool objects using
711 : : * provided memory chunk.
712 : : */
713 : : rte_mempool_populate_t populate;
714 : : /**
715 : : * Get mempool info
716 : : */
717 : : rte_mempool_get_info_t get_info;
718 : : /**
719 : : * Dequeue a number of contiguous object blocks.
720 : : */
721 : : rte_mempool_dequeue_contig_blocks_t dequeue_contig_blocks;
722 : : };
723 : :
724 : : #define RTE_MEMPOOL_MAX_OPS_IDX 32 /**< Max registered ops structs */
725 : :
726 : : /**
727 : : * Structure storing the table of registered ops structs, each of which contain
728 : : * the function pointers for the mempool ops functions.
729 : : * Each process has its own storage for this ops struct array so that
730 : : * the mempools can be shared across primary and secondary processes.
731 : : * The indices used to access the array are valid across processes, whereas
732 : : * any function pointers stored directly in the mempool struct would not be.
733 : : * This results in us simply having "ops_index" in the mempool struct.
734 : : */
735 : : struct __rte_cache_aligned rte_mempool_ops_table {
736 : : rte_spinlock_t sl; /**< Spinlock for add/delete. */
737 : : uint32_t num_ops; /**< Number of used ops structs in the table. */
738 : : /**
739 : : * Storage for all possible ops structs.
740 : : */
741 : : struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX];
742 : : };
743 : :
744 : : /** Array of registered ops structs. */
745 : : extern struct rte_mempool_ops_table rte_mempool_ops_table;
746 : :
747 : : /**
748 : : * @internal Get the mempool ops struct from its index.
749 : : *
750 : : * @param ops_index
751 : : * The index of the ops struct in the ops struct table. It must be a valid
752 : : * index: (0 <= idx < num_ops).
753 : : * @return
754 : : * The pointer to the ops struct in the table.
755 : : */
756 : : static inline struct rte_mempool_ops *
757 : 0 : rte_mempool_get_ops(int ops_index)
758 : : {
759 : 0 : RTE_ASSERT((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
760 : :
761 : 0 : return &rte_mempool_ops_table.ops[ops_index];
762 : : }
763 : :
764 : : /**
765 : : * @internal Wrapper for mempool_ops alloc callback.
766 : : *
767 : : * @param mp
768 : : * Pointer to the memory pool.
769 : : * @return
770 : : * - 0: Success; successfully allocated mempool pool_data.
771 : : * - <0: Error; code of alloc function.
772 : : */
773 : : int
774 : : rte_mempool_ops_alloc(struct rte_mempool *mp);
775 : :
776 : : /**
777 : : * @internal Wrapper for mempool_ops dequeue callback.
778 : : *
779 : : * @param mp
780 : : * Pointer to the memory pool.
781 : : * @param obj_table
782 : : * Pointer to a table of void * pointers (objects).
783 : : * @param n
784 : : * Number of objects to get.
785 : : * @return
786 : : * - 0: Success; got n objects.
787 : : * - <0: Error; code of dequeue function.
788 : : */
789 : : static inline int
790 : 13531 : rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
791 : : void **obj_table, unsigned n)
792 : : {
793 : 0 : struct rte_mempool_ops *ops;
794 : 0 : int ret;
795 : :
796 : 0 : rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
797 : 45373422 : ops = rte_mempool_get_ops(mp->ops_index);
798 : 45373393 : ret = ops->dequeue(mp, obj_table, n);
799 : 0 : RTE_ASSERT(ret <= 0);
800 : 0 : if (likely(ret == 0)) {
801 : 0 : RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_bulk, 1);
802 : 0 : RTE_MEMPOOL_STAT_ADD(mp, get_common_pool_objs, n);
803 : : }
804 : 13531 : return ret;
805 : : }
806 : :
807 : : /**
808 : : * @internal Wrapper for mempool_ops dequeue_contig_blocks callback.
809 : : *
810 : : * @param[in] mp
811 : : * Pointer to the memory pool.
812 : : * @param[out] first_obj_table
813 : : * Pointer to a table of void * pointers (first objects).
814 : : * @param[in] n
815 : : * Number of blocks to get.
816 : : * @return
817 : : * - 0: Success; got n objects.
818 : : * - <0: Error; code of dequeue function.
819 : : */
820 : : static inline int
821 : : rte_mempool_ops_dequeue_contig_blocks(struct rte_mempool *mp,
822 : : void **first_obj_table, unsigned int n)
823 : : {
824 : : struct rte_mempool_ops *ops;
825 : : int ret;
826 : :
827 : 0 : ops = rte_mempool_get_ops(mp->ops_index);
828 : : RTE_ASSERT(ops->dequeue_contig_blocks != NULL);
829 : : rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
830 : 0 : ret = ops->dequeue_contig_blocks(mp, first_obj_table, n);
831 : : RTE_ASSERT(ret <= 0);
832 : : return ret;
833 : : }
834 : :
835 : : /**
836 : : * @internal wrapper for mempool_ops enqueue callback.
837 : : *
838 : : * @param mp
839 : : * Pointer to the memory pool.
840 : : * @param obj_table
841 : : * Pointer to a table of void * pointers (objects).
842 : : * @param n
843 : : * Number of objects to put.
844 : : * @return
845 : : * - 0: Success; n objects supplied.
846 : : * - <0: Error; code of enqueue function.
847 : : */
848 : : static inline int
849 : 0 : rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
850 : : unsigned n)
851 : : {
852 : 0 : struct rte_mempool_ops *ops;
853 : 0 : int ret;
854 : :
855 : 0 : RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_bulk, 1);
856 : 0 : RTE_MEMPOOL_STAT_ADD(mp, put_common_pool_objs, n);
857 : 0 : rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
858 : 45443105 : ops = rte_mempool_get_ops(mp->ops_index);
859 : 45443105 : ret = ops->enqueue(mp, obj_table, n);
860 : 0 : RTE_ASSERT(ret <= 0);
861 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
862 : : if (unlikely(ret < 0))
863 : : RTE_MEMPOOL_LOG(CRIT, "cannot enqueue %u objects to mempool %s",
864 : : n, mp->name);
865 : : #endif
866 : 262754 : return ret;
867 : : }
868 : :
869 : : /**
870 : : * @internal wrapper for mempool_ops get_count callback.
871 : : *
872 : : * @param mp
873 : : * Pointer to the memory pool.
874 : : * @return
875 : : * The number of available objects in the external pool.
876 : : */
877 : : unsigned
878 : : rte_mempool_ops_get_count(const struct rte_mempool *mp);
879 : :
880 : : /**
881 : : * @internal wrapper for mempool_ops calc_mem_size callback.
882 : : * API to calculate size of memory required to store specified number of
883 : : * object.
884 : : *
885 : : * @param[in] mp
886 : : * Pointer to the memory pool.
887 : : * @param[in] obj_num
888 : : * Number of objects.
889 : : * @param[in] pg_shift
890 : : * LOG2 of the physical pages size. If set to 0, ignore page boundaries.
891 : : * @param[out] min_chunk_size
892 : : * Location for minimum size of the memory chunk which may be used to
893 : : * store memory pool objects.
894 : : * @param[out] align
895 : : * Location for required memory chunk alignment.
896 : : * @return
897 : : * Required memory size aligned at page boundary.
898 : : */
899 : : ssize_t rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
900 : : uint32_t obj_num, uint32_t pg_shift,
901 : : size_t *min_chunk_size, size_t *align);
902 : :
903 : : /**
904 : : * @internal wrapper for mempool_ops populate callback.
905 : : *
906 : : * Populate memory pool objects using provided memory chunk.
907 : : *
908 : : * @param[in] mp
909 : : * A pointer to the mempool structure.
910 : : * @param[in] max_objs
911 : : * Maximum number of objects to be populated.
912 : : * @param[in] vaddr
913 : : * The virtual address of memory that should be used to store objects.
914 : : * @param[in] iova
915 : : * The IO address
916 : : * @param[in] len
917 : : * The length of memory in bytes.
918 : : * @param[in] obj_cb
919 : : * Callback function to be executed for each populated object.
920 : : * @param[in] obj_cb_arg
921 : : * An opaque pointer passed to the callback function.
922 : : * @return
923 : : * The number of objects added on success.
924 : : * On error, no objects are populated and a negative errno is returned.
925 : : */
926 : : int rte_mempool_ops_populate(struct rte_mempool *mp, unsigned int max_objs,
927 : : void *vaddr, rte_iova_t iova, size_t len,
928 : : rte_mempool_populate_obj_cb_t *obj_cb,
929 : : void *obj_cb_arg);
930 : :
931 : : /**
932 : : * Wrapper for mempool_ops get_info callback.
933 : : *
934 : : * @param[in] mp
935 : : * Pointer to the memory pool.
936 : : * @param[out] info
937 : : * Pointer to the rte_mempool_info structure
938 : : * @return
939 : : * - 0: Success; The mempool driver supports retrieving supplementary
940 : : * mempool information
941 : : * - -ENOTSUP - doesn't support get_info ops (valid case).
942 : : */
943 : : int rte_mempool_ops_get_info(const struct rte_mempool *mp,
944 : : struct rte_mempool_info *info);
945 : :
946 : : /**
947 : : * @internal wrapper for mempool_ops free callback.
948 : : *
949 : : * @param mp
950 : : * Pointer to the memory pool.
951 : : */
952 : : void
953 : : rte_mempool_ops_free(struct rte_mempool *mp);
954 : :
955 : : /**
956 : : * Set the ops of a mempool.
957 : : *
958 : : * This can only be done on a mempool that is not populated, i.e. just after
959 : : * a call to rte_mempool_create_empty().
960 : : *
961 : : * @param mp
962 : : * Pointer to the memory pool.
963 : : * @param name
964 : : * Name of the ops structure to use for this mempool.
965 : : * @param pool_config
966 : : * Opaque data that can be passed by the application to the ops functions.
967 : : * @return
968 : : * - 0: Success; the mempool is now using the requested ops functions.
969 : : * - -EINVAL - Invalid ops struct name provided.
970 : : * - -EEXIST - mempool already has an ops struct assigned.
971 : : */
972 : : int
973 : : rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
974 : : void *pool_config);
975 : :
976 : : /**
977 : : * Register mempool operations.
978 : : *
979 : : * @param ops
980 : : * Pointer to an ops structure to register.
981 : : * @return
982 : : * - >=0: Success; return the index of the ops struct in the table.
983 : : * - -EINVAL - some missing callbacks while registering ops struct.
984 : : * - -ENOSPC - the maximum number of ops structs has been reached.
985 : : * - -ENAMETOOLONG - the name of the ops is too long.
986 : : * - -EEXIST - the name of the ops is already registered.
987 : : */
988 : : int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
989 : :
990 : : /**
991 : : * Macro to statically register the ops of a mempool handler.
992 : : * Note that the rte_mempool_register_ops fails silently here when
993 : : * more than RTE_MEMPOOL_MAX_OPS_IDX is registered.
994 : : */
995 : : #define RTE_MEMPOOL_REGISTER_OPS(ops) \
996 : : RTE_INIT(mp_hdlr_init_##ops) \
997 : : { \
998 : : rte_mempool_register_ops(&ops); \
999 : : }
1000 : :
1001 : : /**
1002 : : * An object callback function for mempool.
1003 : : *
1004 : : * Used by rte_mempool_create() and rte_mempool_obj_iter().
1005 : : */
1006 : : typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
1007 : : void *opaque, void *obj, unsigned obj_idx);
1008 : : typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
1009 : :
1010 : : /**
1011 : : * A memory callback function for mempool.
1012 : : *
1013 : : * Used by rte_mempool_mem_iter().
1014 : : */
1015 : : typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
1016 : : void *opaque, struct rte_mempool_memhdr *memhdr,
1017 : : unsigned mem_idx);
1018 : :
1019 : : /**
1020 : : * A mempool constructor callback function.
1021 : : *
1022 : : * Arguments are the mempool and the opaque pointer given by the user in
1023 : : * rte_mempool_create().
1024 : : */
1025 : : typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
1026 : :
1027 : : /**
1028 : : * Free a mempool
1029 : : *
1030 : : * Unlink the mempool from global list, free the memory chunks, and all
1031 : : * memory referenced by the mempool. The objects must not be used by
1032 : : * other cores as they will be freed.
1033 : : *
1034 : : * @param mp
1035 : : * A pointer to the mempool structure.
1036 : : * If NULL then, the function does nothing.
1037 : : */
1038 : : void
1039 : : rte_mempool_free(struct rte_mempool *mp);
1040 : :
1041 : : /**
1042 : : * Create a new mempool named *name* in memory.
1043 : : *
1044 : : * This function uses ``rte_memzone_reserve()`` to allocate memory. The
1045 : : * pool contains n elements of elt_size. Its size is set to n.
1046 : : *
1047 : : * @param name
1048 : : * The name of the mempool.
1049 : : * @param n
1050 : : * The number of elements in the mempool.
1051 : : * @param elt_size
1052 : : * The size of each element.
1053 : : * @param cache_size
1054 : : * If cache_size is non-zero, the rte_mempool library will try to
1055 : : * limit the accesses to the common lockless pool, by maintaining a
1056 : : * per-lcore object cache. This argument must be lower or equal to n.
1057 : : * The access to the per-lcore table is of course
1058 : : * faster than the multi-producer/consumer pool. The cache can be
1059 : : * disabled if the cache_size argument is set to 0; it can be useful to
1060 : : * avoid losing objects in cache.
1061 : : * Note:
1062 : : * Mempool put/get requests of more than cache_size / 2 objects may be
1063 : : * partially or fully served directly by the multi-producer/consumer
1064 : : * pool, to avoid the overhead of copying the objects twice (instead of
1065 : : * once) when using the cache as a bounce buffer.
1066 : : * @param private_data_size
1067 : : * The size of the private data appended after the mempool
1068 : : * structure. This is useful for storing some private data after the
1069 : : * mempool structure, as is done for rte_mbuf_pool for example.
1070 : : * @param mp_init
1071 : : * A function pointer that is called for initialization of the pool,
1072 : : * before object initialization. The user can initialize the private
1073 : : * data in this function if needed. This parameter can be NULL if
1074 : : * not needed.
1075 : : * @param mp_init_arg
1076 : : * An opaque pointer to data that can be used in the mempool
1077 : : * constructor function.
1078 : : * @param obj_init
1079 : : * A function pointer that is called for each object at
1080 : : * initialization of the pool. The user can set some meta data in
1081 : : * objects if needed. This parameter can be NULL if not needed.
1082 : : * The obj_init() function takes the mempool pointer, the init_arg,
1083 : : * the object pointer and the object number as parameters.
1084 : : * @param obj_init_arg
1085 : : * An opaque pointer to data that can be used as an argument for
1086 : : * each call to the object constructor function.
1087 : : * @param socket_id
1088 : : * The *socket_id* argument is the socket identifier in the case of
1089 : : * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1090 : : * constraint for the reserved zone.
1091 : : * @param flags
1092 : : * The *flags* arguments is an OR of following flags:
1093 : : * - RTE_MEMPOOL_F_NO_SPREAD: By default, objects addresses are spread
1094 : : * between channels in RAM: the pool allocator will add padding
1095 : : * between objects depending on the hardware configuration. See
1096 : : * Memory alignment constraints for details. If this flag is set,
1097 : : * the allocator will just align them to a cache line.
1098 : : * - RTE_MEMPOOL_F_NO_CACHE_ALIGN: By default, the returned objects are
1099 : : * cache-aligned. This flag removes this constraint, and no
1100 : : * padding will be present between objects. This flag implies
1101 : : * RTE_MEMPOOL_F_NO_SPREAD.
1102 : : * - RTE_MEMPOOL_F_SP_PUT: If this flag is set, the default behavior
1103 : : * when using rte_mempool_put() or rte_mempool_put_bulk() is
1104 : : * "single-producer". Otherwise, it is "multi-producers".
1105 : : * - RTE_MEMPOOL_F_SC_GET: If this flag is set, the default behavior
1106 : : * when using rte_mempool_get() or rte_mempool_get_bulk() is
1107 : : * "single-consumer". Otherwise, it is "multi-consumers".
1108 : : * - RTE_MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't
1109 : : * necessarily be contiguous in IO memory.
1110 : : * @return
1111 : : * The pointer to the new allocated mempool, on success. NULL on error
1112 : : * with rte_errno set appropriately. Possible rte_errno values include:
1113 : : * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
1114 : : * - EINVAL - cache size provided is too large or an unknown flag was passed
1115 : : * - ENOSPC - the maximum number of memzones has already been allocated
1116 : : * - EEXIST - a memzone with the same name already exists
1117 : : * - ENOMEM - no appropriate memory area found in which to create memzone
1118 : : */
1119 : : struct rte_mempool *
1120 : : rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
1121 : : unsigned cache_size, unsigned private_data_size,
1122 : : rte_mempool_ctor_t *mp_init, void *mp_init_arg,
1123 : : rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
1124 : : int socket_id, unsigned int flags)
1125 : : __rte_malloc __rte_dealloc(rte_mempool_free, 1);
1126 : :
1127 : : /**
1128 : : * Create an empty mempool
1129 : : *
1130 : : * The mempool is allocated and initialized, but it is not populated: no
1131 : : * memory is allocated for the mempool elements. The user has to call
1132 : : * rte_mempool_populate_*() to add memory chunks to the pool. Once
1133 : : * populated, the user may also want to initialize each object with
1134 : : * rte_mempool_obj_iter().
1135 : : *
1136 : : * @param name
1137 : : * The name of the mempool.
1138 : : * @param n
1139 : : * The maximum number of elements that can be added in the mempool.
1140 : : * @param elt_size
1141 : : * The size of each element.
1142 : : * @param cache_size
1143 : : * Size of the cache. See rte_mempool_create() for details.
1144 : : * @param private_data_size
1145 : : * The size of the private data appended after the mempool
1146 : : * structure. This is useful for storing some private data after the
1147 : : * mempool structure, as is done for rte_mbuf_pool for example.
1148 : : * @param socket_id
1149 : : * The *socket_id* argument is the socket identifier in the case of
1150 : : * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1151 : : * constraint for the reserved zone.
1152 : : * @param flags
1153 : : * Flags controlling the behavior of the mempool. See
1154 : : * rte_mempool_create() for details.
1155 : : * @return
1156 : : * The pointer to the new allocated mempool, on success. NULL on error
1157 : : * with rte_errno set appropriately. See rte_mempool_create() for details.
1158 : : */
1159 : : struct rte_mempool *
1160 : : rte_mempool_create_empty(const char *name, unsigned int n, unsigned int elt_size,
1161 : : unsigned int cache_size, unsigned int private_data_size,
1162 : : int socket_id, unsigned int flags)
1163 : : __rte_malloc __rte_dealloc(rte_mempool_free, 1);
1164 : :
1165 : : /**
1166 : : * Add physically contiguous memory for objects in the pool at init
1167 : : *
1168 : : * Add a virtually and physically contiguous memory chunk in the pool
1169 : : * where objects can be instantiated.
1170 : : *
1171 : : * If the given IO address is unknown (iova = RTE_BAD_IOVA),
1172 : : * the chunk doesn't need to be physically contiguous (only virtually),
1173 : : * and allocated objects may span two pages.
1174 : : *
1175 : : * @param mp
1176 : : * A pointer to the mempool structure.
1177 : : * @param vaddr
1178 : : * The virtual address of memory that should be used to store objects.
1179 : : * @param iova
1180 : : * The IO address
1181 : : * @param len
1182 : : * The length of memory in bytes.
1183 : : * @param free_cb
1184 : : * The callback used to free this chunk when destroying the mempool.
1185 : : * @param opaque
1186 : : * An opaque argument passed to free_cb.
1187 : : * @return
1188 : : * The number of objects added on success (strictly positive).
1189 : : * On error, the chunk is not added in the memory list of the
1190 : : * mempool the following code is returned:
1191 : : * (0): not enough room in chunk for one object.
1192 : : * (-ENOSPC): mempool is already populated.
1193 : : * (-ENOMEM): allocation failure.
1194 : : */
1195 : : int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
1196 : : rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
1197 : : void *opaque);
1198 : :
1199 : : /**
1200 : : * Add virtually contiguous memory for objects in the pool at init
1201 : : *
1202 : : * Add a virtually contiguous memory chunk in the pool where objects can
1203 : : * be instantiated.
1204 : : *
1205 : : * @param mp
1206 : : * A pointer to the mempool structure.
1207 : : * @param addr
1208 : : * The virtual address of memory that should be used to store objects.
1209 : : * @param len
1210 : : * The length of memory in bytes.
1211 : : * @param pg_sz
1212 : : * The size of memory pages in this virtual area.
1213 : : * @param free_cb
1214 : : * The callback used to free this chunk when destroying the mempool.
1215 : : * @param opaque
1216 : : * An opaque argument passed to free_cb.
1217 : : * @return
1218 : : * The number of objects added on success (strictly positive).
1219 : : * On error, the chunk is not added in the memory list of the
1220 : : * mempool the following code is returned:
1221 : : * (0): not enough room in chunk for one object.
1222 : : * (-ENOSPC): mempool is already populated.
1223 : : * (-ENOMEM): allocation failure.
1224 : : */
1225 : : int
1226 : : rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
1227 : : size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
1228 : : void *opaque);
1229 : :
1230 : : /**
1231 : : * Add memory for objects in the pool at init
1232 : : *
1233 : : * This is the default function used by rte_mempool_create() to populate
1234 : : * the mempool. It adds memory allocated using rte_memzone_reserve().
1235 : : *
1236 : : * @param mp
1237 : : * A pointer to the mempool structure.
1238 : : * @return
1239 : : * The number of objects added on success.
1240 : : * On error, the chunk is not added in the memory list of the
1241 : : * mempool and a negative errno is returned.
1242 : : */
1243 : : int rte_mempool_populate_default(struct rte_mempool *mp);
1244 : :
1245 : : /**
1246 : : * Add memory from anonymous mapping for objects in the pool at init
1247 : : *
1248 : : * This function mmap an anonymous memory zone that is locked in
1249 : : * memory to store the objects of the mempool.
1250 : : *
1251 : : * @param mp
1252 : : * A pointer to the mempool structure.
1253 : : * @return
1254 : : * The number of objects added on success.
1255 : : * On error, 0 is returned, rte_errno is set, and the chunk is not added in
1256 : : * the memory list of the mempool.
1257 : : */
1258 : : int rte_mempool_populate_anon(struct rte_mempool *mp);
1259 : :
1260 : : /**
1261 : : * Call a function for each mempool element
1262 : : *
1263 : : * Iterate across all objects attached to a rte_mempool and call the
1264 : : * callback function on it.
1265 : : *
1266 : : * @param mp
1267 : : * A pointer to an initialized mempool.
1268 : : * @param obj_cb
1269 : : * A function pointer that is called for each object.
1270 : : * @param obj_cb_arg
1271 : : * An opaque pointer passed to the callback function.
1272 : : * @return
1273 : : * Number of objects iterated.
1274 : : */
1275 : : uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1276 : : rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1277 : :
1278 : : /**
1279 : : * Call a function for each mempool memory chunk
1280 : : *
1281 : : * Iterate across all memory chunks attached to a rte_mempool and call
1282 : : * the callback function on it.
1283 : : *
1284 : : * @param mp
1285 : : * A pointer to an initialized mempool.
1286 : : * @param mem_cb
1287 : : * A function pointer that is called for each memory chunk.
1288 : : * @param mem_cb_arg
1289 : : * An opaque pointer passed to the callback function.
1290 : : * @return
1291 : : * Number of memory chunks iterated.
1292 : : */
1293 : : uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1294 : : rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1295 : :
1296 : : /**
1297 : : * @warning
1298 : : * @b EXPERIMENTAL: This API may change, or be removed, without prior notice.
1299 : : *
1300 : : * Reset the statistics of a mempool.
1301 : : *
1302 : : * This function is intended for use when analyzing mempool statistics
1303 : : * without counting any mempool operations performed during application
1304 : : * initialization.
1305 : : * For example, populating the mempool counts as put operations into the
1306 : : * common pool, and setting up ethdev Rx queues counts as get operations.
1307 : : *
1308 : : * This function should only be called after application initialization,
1309 : : * before the data path is started; otherwise, the mempool statistics may
1310 : : * become inconsistent.
1311 : : *
1312 : : * For a perfectly clean slate, the local caches of the mempools used
1313 : : * during application initialization should be flushed before resetting
1314 : : * the mempool statistics.
1315 : : * For example, mbuf pools used by ethdev Rx queues.
1316 : : *
1317 : : * @see rte_mempool_cache_flush()
1318 : : *
1319 : : * @param mp
1320 : : * A pointer to the mempool structure.
1321 : : */
1322 : : __rte_experimental
1323 : : void rte_mempool_stats_reset(struct rte_mempool *mp);
1324 : :
1325 : : /**
1326 : : * Dump the status of the mempool to a file.
1327 : : *
1328 : : * @param f
1329 : : * A pointer to a file for output
1330 : : * @param mp
1331 : : * A pointer to the mempool structure.
1332 : : */
1333 : : void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1334 : :
1335 : : /**
1336 : : * Free a user-owned mempool cache.
1337 : : *
1338 : : * @param cache
1339 : : * A pointer to the mempool cache.
1340 : : */
1341 : : void
1342 : : rte_mempool_cache_free(struct rte_mempool_cache *cache);
1343 : :
1344 : : /**
1345 : : * Create a user-owned mempool cache.
1346 : : *
1347 : : * This can be used by unregistered non-EAL threads to enable caching when they
1348 : : * interact with a mempool.
1349 : : *
1350 : : * @param size
1351 : : * The size of the mempool cache. See rte_mempool_create()'s cache_size
1352 : : * parameter description for more information. The same limits and
1353 : : * considerations apply here too.
1354 : : * @param socket_id
1355 : : * The socket identifier in the case of NUMA. The value can be
1356 : : * SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone.
1357 : : */
1358 : : struct rte_mempool_cache *
1359 : : rte_mempool_cache_create(uint32_t size, int socket_id)
1360 : : __rte_malloc __rte_dealloc(rte_mempool_cache_free, 1);
1361 : :
1362 : : /**
1363 : : * Get a pointer to the per-lcore default mempool cache.
1364 : : *
1365 : : * @param mp
1366 : : * A pointer to the mempool structure.
1367 : : * @param lcore_id
1368 : : * The logical core id.
1369 : : * @return
1370 : : * A pointer to the mempool cache or NULL if disabled or unregistered non-EAL
1371 : : * thread.
1372 : : */
1373 : : static __rte_always_inline struct rte_mempool_cache *
1374 : 0 : rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1375 : : {
1376 [ + + + + : 2699337 : if (unlikely(mp->local_cache == NULL))
+ + + + +
+ + + + +
- - - - -
- - - + -
+ - - - -
- - - + -
+ - - - -
- + - + -
- - # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1377 : : return NULL;
1378 : :
1379 [ + + + - : 2173213 : if (unlikely(lcore_id == LCORE_ID_ANY))
+ + + - +
- + - + -
- - - - -
- - - + -
+ - - - -
- - - + -
+ - - - -
- + - + -
- - # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1380 : : return NULL;
1381 : :
1382 : 2173202 : struct rte_mempool_cache *cache = (struct rte_mempool_cache *)RTE_PTR_ADD(mp->local_cache,
1383 : : lcore_id * (size_t)mp->sizeof_cache_per_lcore);
1384 : 0 : rte_mempool_trace_default_cache(mp, lcore_id, cache);
1385 [ - + - + : 2173202 : __rte_assume(cache != NULL);
- + - + -
+ - + - +
- - - - -
- - - - +
- + - - -
- - - - +
- + - - -
- - + - +
- - # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1386 : : return cache;
1387 : : }
1388 : :
1389 : : /**
1390 : : * Flush a user-owned mempool cache to the specified mempool.
1391 : : *
1392 : : * @param cache
1393 : : * A pointer to the mempool cache.
1394 : : * @param mp
1395 : : * A pointer to the mempool.
1396 : : */
1397 : : static __rte_always_inline void
1398 : : rte_mempool_cache_flush(struct rte_mempool_cache *cache,
1399 : : struct rte_mempool *mp)
1400 : : {
1401 [ - + ]: 3 : if (cache == NULL)
1402 [ # # ]: 0 : cache = rte_mempool_default_cache(mp, rte_lcore_id());
1403 [ + - ]: 3 : if (cache == NULL || cache->len == 0)
1404 : : return;
1405 : : rte_mempool_trace_cache_flush(cache, mp);
1406 : 3 : rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1407 : 3 : cache->len = 0;
1408 : : }
1409 : :
1410 : : /**
1411 : : * @internal Put several objects back in the mempool; used internally.
1412 : : * @param mp
1413 : : * A pointer to the mempool structure.
1414 : : * @param obj_table
1415 : : * A pointer to a table of void * pointers (objects).
1416 : : * @param n
1417 : : * The number of objects to store back in the mempool, must be strictly
1418 : : * positive.
1419 : : * @param cache
1420 : : * A pointer to a mempool cache structure. May be NULL if not needed.
1421 : : */
1422 : : static __rte_always_inline void
1423 : 0 : rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
1424 : : unsigned int n, struct rte_mempool_cache *cache)
1425 : : {
1426 : 0 : void **cache_objs;
1427 : :
1428 : : /* No cache provided? */
1429 [ + + + + : 2369444 : if (unlikely(cache == NULL))
+ + - + +
+ + + + +
- - - - -
+ - - - -
- + - + -
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1430 : 262748 : goto driver_enqueue;
1431 : :
1432 : : /* Increment stats now, adding in mempool always succeeds. */
1433 : 0 : RTE_MEMPOOL_CACHE_STAT_ADD(cache, put_bulk, 1);
1434 : 0 : RTE_MEMPOOL_CACHE_STAT_ADD(cache, put_objs, n);
1435 : :
1436 [ - + - + : 2106696 : __rte_assume(cache->size <= RTE_MEMPOOL_CACHE_MAX_SIZE);
- + - + -
+ - + - +
- - - - -
+ - - - -
- + - + -
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1437 : 0 : __rte_assume(cache->size / 2 <= RTE_MEMPOOL_CACHE_MAX_SIZE / 2);
1438 [ - + - + : 2106696 : __rte_assume(cache->len <= RTE_MEMPOOL_CACHE_MAX_SIZE);
- + - + -
+ - + - +
- - - - -
+ - - - -
- + - + -
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1439 [ - + - + : 2106696 : __rte_assume(cache->len <= cache->size);
- + - + -
+ - + - +
- - - - -
+ - - - -
- + - + -
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1440 [ + + + + : 2106694 : if (likely(cache->len + n <= cache->size)) {
+ + + - +
- + - + +
- - - - +
- + + - -
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1441 : : /* Sufficient room in the cache for the objects. */
1442 : 1975439 : cache_objs = &cache->objs[cache->len];
1443 [ # # # # ]: 1975439 : cache->len += n;
1444 [ + - + + : 131255 : } else if (n <= cache->size / 2) {
- + - - -
- - - + -
- - - - -
- + - - -
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1445 : : /*
1446 : : * The number of objects is within the cache bounce buffer limit,
1447 : : * but - as detected by the comparison above - the cache has
1448 : : * insufficient room for them.
1449 : : * Flush the cache to the backend to make room for the objects;
1450 : : * flush (size / 2) objects from the bottom of the cache, where
1451 : : * objects are less hot, and move down the remaining objects, which
1452 : : * are more hot, from the upper half of the cache.
1453 : : */
1454 [ - + - + : 131249 : __rte_assume(cache->len > cache->size / 2);
- - - - -
- - - - +
- - - - -
- - + - -
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1455 : 131249 : rte_mempool_ops_enqueue_bulk(mp, &cache->objs[0], cache->size / 2);
1456 : 131249 : rte_memcpy(&cache->objs[0], &cache->objs[cache->size / 2],
1457 [ - + - + : 131249 : sizeof(void *) * (cache->len - cache->size / 2));
- - - - -
- - - - +
- - - - -
- - + - -
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1458 : 131249 : cache_objs = &cache->objs[cache->len - cache->size / 2];
1459 : 131249 : cache->len = cache->len - cache->size / 2 + n;
1460 : : } else {
1461 : : /* The request itself is too big for the cache. */
1462 : 8 : goto driver_enqueue_stats_incremented;
1463 : : }
1464 : :
1465 : : /* Add the objects to the cache. */
1466 [ + + - - : 68 : rte_memcpy(cache_objs, obj_table, sizeof(void *) * n);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1467 : :
1468 : : return;
1469 : :
1470 : 0 : driver_enqueue:
1471 : :
1472 : : /* increment stat now, adding in mempool always success */
1473 : 0 : RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
1474 : 0 : RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
1475 : :
1476 : 262756 : driver_enqueue_stats_incremented:
1477 : :
1478 : : /* push objects to the backend */
1479 [ # # # # ]: 0 : rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1480 : : }
1481 : :
1482 : :
1483 : : /**
1484 : : * Put several objects back in the mempool.
1485 : : *
1486 : : * @param mp
1487 : : * A pointer to the mempool structure.
1488 : : * @param obj_table
1489 : : * A pointer to a table of void * pointers (objects).
1490 : : * @param n
1491 : : * The number of objects to add in the mempool from the obj_table.
1492 : : * @param cache
1493 : : * A pointer to a mempool cache structure. May be NULL if not needed.
1494 : : */
1495 : : static __rte_always_inline void
1496 : 0 : rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1497 : : unsigned int n, struct rte_mempool_cache *cache)
1498 : : {
1499 : 0 : rte_mempool_trace_generic_put(mp, obj_table, n, cache);
1500 : 0 : RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 0);
1501 : 0 : rte_mempool_do_generic_put(mp, obj_table, n, cache);
1502 : : }
1503 : :
1504 : : /**
1505 : : * Put several objects back in the mempool.
1506 : : *
1507 : : * This function calls the multi-producer or the single-producer
1508 : : * version depending on the default behavior that was specified at
1509 : : * mempool creation time (see flags).
1510 : : *
1511 : : * @param mp
1512 : : * A pointer to the mempool structure.
1513 : : * @param obj_table
1514 : : * A pointer to a table of void * pointers (objects).
1515 : : * @param n
1516 : : * The number of objects to add in the mempool from obj_table.
1517 : : */
1518 : : static __rte_always_inline void
1519 : 0 : rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1520 : : unsigned int n)
1521 : : {
1522 : 0 : struct rte_mempool_cache *cache;
1523 [ # # # # : 0 : cache = rte_mempool_default_cache(mp, rte_lcore_id());
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1524 : 0 : rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
1525 [ # # # # : 0 : rte_mempool_generic_put(mp, obj_table, n, cache);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
1526 : : }
1527 : :
1528 : : /**
1529 : : * Put one object back in the mempool.
1530 : : *
1531 : : * This function calls the multi-producer or the single-producer
1532 : : * version depending on the default behavior that was specified at
1533 : : * mempool creation time (see flags).
1534 : : *
1535 : : * @param mp
1536 : : * A pointer to the mempool structure.
1537 : : * @param obj
1538 : : * A pointer to the object to be added.
1539 : : */
1540 : : static __rte_always_inline void
1541 : 0 : rte_mempool_put(struct rte_mempool *mp, void *obj)
1542 : : {
1543 [ # # # # : 0 : rte_mempool_put_bulk(mp, &obj, 1);
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1544 : : }
1545 : :
1546 : : /**
1547 : : * @internal Get several objects from the mempool; used internally.
1548 : : * @param mp
1549 : : * A pointer to the mempool structure.
1550 : : * @param obj_table
1551 : : * A pointer to a table of void * pointers (objects).
1552 : : * @param n
1553 : : * The number of objects to get, must be strictly positive.
1554 : : * @param cache
1555 : : * A pointer to a mempool cache structure. May be NULL if not needed.
1556 : : * @return
1557 : : * - 0: Success.
1558 : : * - <0: Error; code of driver dequeue function.
1559 : : */
1560 : : static __rte_always_inline int
1561 : 0 : rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
1562 : : unsigned int n, struct rte_mempool_cache *cache)
1563 : : {
1564 : 0 : int ret;
1565 : 0 : unsigned int remaining;
1566 : 0 : uint32_t index, len;
1567 : 0 : void **cache_objs;
1568 : :
1569 : : /* No cache provided? */
1570 [ + + + + : 340471 : if (unlikely(cache == NULL)) {
+ - + + +
+ + + + +
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1571 : 0 : remaining = n;
1572 : 265502 : goto driver_dequeue;
1573 : : }
1574 : :
1575 : : /* The cache is a stack, so copy will be in reverse order. */
1576 : 74969 : cache_objs = &cache->objs[cache->len];
1577 : :
1578 [ - + - + : 74969 : __rte_assume(cache->len <= RTE_MEMPOOL_CACHE_MAX_SIZE);
- - - + -
+ - + - +
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1579 [ + + + + : 74967 : if (likely(n <= cache->len)) {
- - - + +
- + + + +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1580 : : /* The entire request can be satisfied from the cache. */
1581 : 0 : RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_bulk, 1);
1582 : 0 : RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_objs, n);
1583 : :
1584 : : /*
1585 : : * If the request size is known at build time,
1586 : : * the compiler unrolls the fixed length copy loop.
1587 : : */
1588 : 9069 : cache->len -= n;
1589 [ + + + + : 18549 : for (index = 0; index < n; index++)
- - - - +
+ + + + +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1590 : 9480 : *obj_table++ = *--cache_objs;
1591 : :
1592 : : return 0;
1593 : : }
1594 : :
1595 : : /* Use the cache as much as we have to return hot objects first. */
1596 : 0 : len = cache->len;
1597 : 65900 : remaining = n - len;
1598 : 65900 : cache->len = 0;
1599 [ + + - + : 66528 : for (index = 0; index < len; index++)
- - - + -
- + + + +
+ + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1600 : 628 : *obj_table++ = *--cache_objs;
1601 : :
1602 : : /* Dequeue below would exceed the cache bounce buffer limit? */
1603 [ - + - + : 65900 : __rte_assume(cache->size / 2 <= RTE_MEMPOOL_CACHE_MAX_SIZE / 2);
- - - + -
- - + - +
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1604 [ + + - + : 65898 : if (unlikely(remaining > cache->size / 2))
- - - + -
- + + + +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1605 : 65558 : goto driver_dequeue;
1606 : :
1607 : : /* Fill the cache from the backend; fetch (size / 2) objects. */
1608 : 342 : ret = rte_mempool_ops_dequeue_bulk(mp, cache->objs, cache->size / 2);
1609 [ + + + + : 342 : if (unlikely(ret < 0)) {
- - - + -
- - + + +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1610 : : /*
1611 : : * We are buffer constrained, and not able to fetch all that.
1612 : : * Do not fill the cache, just satisfy the remaining part of
1613 : : * the request directly from the backend.
1614 : : */
1615 : 132 : goto driver_dequeue;
1616 : : }
1617 : :
1618 : : /* Satisfy the remaining part of the request from the filled cache. */
1619 : 0 : RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_bulk, 1);
1620 : 0 : RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_objs, n);
1621 : :
1622 [ - + - + : 210 : __rte_assume(cache->size / 2 <= RTE_MEMPOOL_CACHE_MAX_SIZE / 2);
- - - + -
- - + - +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1623 [ - + - + : 210 : __rte_assume(remaining <= RTE_MEMPOOL_CACHE_MAX_SIZE / 2);
- - - + -
- - + - +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1624 [ - + - + : 210 : __rte_assume(remaining <= cache->size / 2);
- - - + -
- - + - +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1625 : 210 : cache_objs = &cache->objs[cache->size / 2];
1626 : 210 : cache->len = cache->size / 2 - remaining;
1627 [ + + + + : 513 : for (index = 0; index < remaining; index++)
- - + + -
- + + + +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1628 : 303 : *obj_table++ = *--cache_objs;
1629 : :
1630 : : return 0;
1631 : :
1632 : 326824 : driver_dequeue:
1633 : :
1634 : : /* Get remaining objects directly from the backend. */
1635 : 13341 : ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, remaining);
1636 : :
1637 [ + + + + : 331192 : if (unlikely(ret < 0)) {
- + - + -
+ - + - +
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1638 [ + + + + : 18 : if (likely(cache != NULL)) {
- - - - -
- - - - -
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1639 : 16 : cache->len = n - remaining;
1640 : : /*
1641 : : * No further action is required to roll the first part
1642 : : * of the request back into the cache, as objects in
1643 : : * the cache are intact.
1644 : : */
1645 : : }
1646 : :
1647 : : RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1648 : : RTE_MEMPOOL_STAT_ADD(mp, get_fail_objs, n);
1649 : : } else {
1650 : 0 : if (likely(cache != NULL)) {
1651 : : RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_bulk, 1);
1652 : : RTE_MEMPOOL_CACHE_STAT_ADD(cache, get_success_objs, n);
1653 : : } else {
1654 : 0 : RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1655 : 0 : RTE_MEMPOOL_STAT_ADD(mp, get_success_objs, n);
1656 : : }
1657 [ - + - + : 331174 : __rte_assume(ret == 0);
- + - + -
+ + + + +
+ - # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1658 : : }
1659 : :
1660 : : return ret;
1661 : : }
1662 : :
1663 : : /**
1664 : : * Get several objects from the mempool.
1665 : : *
1666 : : * If cache is enabled, objects will be retrieved first from cache,
1667 : : * subsequently from the common pool. Note that it can return -ENOENT when
1668 : : * the local cache and common pool are empty, even if cache from other
1669 : : * lcores are full.
1670 : : *
1671 : : * @param mp
1672 : : * A pointer to the mempool structure.
1673 : : * @param obj_table
1674 : : * A pointer to a table of void * pointers (objects) that will be filled.
1675 : : * @param n
1676 : : * The number of objects to get from mempool to obj_table.
1677 : : * @param cache
1678 : : * A pointer to a mempool cache structure. May be NULL if not needed.
1679 : : * @return
1680 : : * - 0: Success; objects taken.
1681 : : * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1682 : : */
1683 : : static __rte_always_inline int
1684 : 0 : rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1685 : : unsigned int n, struct rte_mempool_cache *cache)
1686 : : {
1687 : 0 : int ret;
1688 : 0 : ret = rte_mempool_do_generic_get(mp, obj_table, n, cache);
1689 : 0 : if (likely(ret == 0))
1690 : 0 : RTE_MEMPOOL_CHECK_COOKIES(mp, obj_table, n, 1);
1691 : 0 : rte_mempool_trace_generic_get(mp, obj_table, n, cache);
1692 : 0 : return ret;
1693 : : }
1694 : :
1695 : : /**
1696 : : * Get several objects from the mempool.
1697 : : *
1698 : : * This function calls the multi-consumers or the single-consumer
1699 : : * version, depending on the default behaviour that was specified at
1700 : : * mempool creation time (see flags).
1701 : : *
1702 : : * If cache is enabled, objects will be retrieved first from cache,
1703 : : * subsequently from the common pool. Note that it can return -ENOENT when
1704 : : * the local cache and common pool are empty, even if cache from other
1705 : : * lcores are full.
1706 : : *
1707 : : * @param mp
1708 : : * A pointer to the mempool structure.
1709 : : * @param obj_table
1710 : : * A pointer to a table of void * pointers (objects) that will be filled.
1711 : : * @param n
1712 : : * The number of objects to get from the mempool to obj_table.
1713 : : * @return
1714 : : * - 0: Success; objects taken
1715 : : * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1716 : : */
1717 : : static __rte_always_inline int
1718 : 0 : rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1719 : : {
1720 : 0 : struct rte_mempool_cache *cache;
1721 [ # # # # : 0 : cache = rte_mempool_default_cache(mp, rte_lcore_id());
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1722 : 0 : rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
1723 [ # # # # : 0 : return rte_mempool_generic_get(mp, obj_table, n, cache);
# # ]
1724 : : }
1725 : :
1726 : : /**
1727 : : * Get one object from the mempool.
1728 : : *
1729 : : * This function calls the multi-consumers or the single-consumer
1730 : : * version, depending on the default behavior that was specified at
1731 : : * mempool creation (see flags).
1732 : : *
1733 : : * If cache is enabled, objects will be retrieved first from cache,
1734 : : * subsequently from the common pool. Note that it can return -ENOENT when
1735 : : * the local cache and common pool are empty, even if cache from other
1736 : : * lcores are full.
1737 : : *
1738 : : * @param mp
1739 : : * A pointer to the mempool structure.
1740 : : * @param obj_p
1741 : : * A pointer to a void * pointer (object) that will be filled.
1742 : : * @return
1743 : : * - 0: Success; objects taken.
1744 : : * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1745 : : */
1746 : : static __rte_always_inline int
1747 : 0 : rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1748 : : {
1749 [ # # # # ]: 0 : return rte_mempool_get_bulk(mp, obj_p, 1);
1750 : : }
1751 : :
1752 : : /**
1753 : : * Get a contiguous blocks of objects from the mempool.
1754 : : *
1755 : : * If cache is enabled, consider to flush it first, to reuse objects
1756 : : * as soon as possible.
1757 : : *
1758 : : * The application should check that the driver supports the operation
1759 : : * by calling rte_mempool_ops_get_info() and checking that `contig_block_size`
1760 : : * is not zero.
1761 : : *
1762 : : * @param mp
1763 : : * A pointer to the mempool structure.
1764 : : * @param first_obj_table
1765 : : * A pointer to a pointer to the first object in each block.
1766 : : * @param n
1767 : : * The number of blocks to get from mempool.
1768 : : * @return
1769 : : * - 0: Success; blocks taken.
1770 : : * - -ENOBUFS: Not enough entries in the mempool; no object is retrieved.
1771 : : * - -EOPNOTSUPP: The mempool driver does not support block dequeue
1772 : : */
1773 : : static __rte_always_inline int
1774 : : rte_mempool_get_contig_blocks(struct rte_mempool *mp,
1775 : : void **first_obj_table, unsigned int n)
1776 : : {
1777 : : int ret;
1778 : :
1779 : : ret = rte_mempool_ops_dequeue_contig_blocks(mp, first_obj_table, n);
1780 : : if (likely(ret == 0)) {
1781 : : RTE_MEMPOOL_STAT_ADD(mp, get_success_bulk, 1);
1782 : : RTE_MEMPOOL_STAT_ADD(mp, get_success_blks, n);
1783 : : RTE_MEMPOOL_CONTIG_BLOCKS_CHECK_COOKIES(mp, first_obj_table, n,
1784 : : 1);
1785 : : } else {
1786 : : RTE_MEMPOOL_STAT_ADD(mp, get_fail_bulk, 1);
1787 : : RTE_MEMPOOL_STAT_ADD(mp, get_fail_blks, n);
1788 : : }
1789 : :
1790 : : rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
1791 : : return ret;
1792 : : }
1793 : :
1794 : : /**
1795 : : * Return the number of entries in the mempool.
1796 : : *
1797 : : * When cache is enabled, this function has to browse the length of
1798 : : * all lcores, so it should not be used in a data path, but only for
1799 : : * debug purposes. User-owned mempool caches are not accounted for.
1800 : : *
1801 : : * @param mp
1802 : : * A pointer to the mempool structure.
1803 : : * @return
1804 : : * The number of entries in the mempool.
1805 : : */
1806 : : unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1807 : :
1808 : : /**
1809 : : * Return the number of elements which have been allocated from the mempool
1810 : : *
1811 : : * When cache is enabled, this function has to browse the length of
1812 : : * all lcores, so it should not be used in a data path, but only for
1813 : : * debug purposes.
1814 : : *
1815 : : * @param mp
1816 : : * A pointer to the mempool structure.
1817 : : * @return
1818 : : * The number of free entries in the mempool.
1819 : : */
1820 : : unsigned int
1821 : : rte_mempool_in_use_count(const struct rte_mempool *mp);
1822 : :
1823 : : /**
1824 : : * Test if the mempool is full.
1825 : : *
1826 : : * When cache is enabled, this function has to browse the length of all
1827 : : * lcores, so it should not be used in a data path, but only for debug
1828 : : * purposes. User-owned mempool caches are not accounted for.
1829 : : *
1830 : : * @param mp
1831 : : * A pointer to the mempool structure.
1832 : : * @return
1833 : : * - 1: The mempool is full.
1834 : : * - 0: The mempool is not full.
1835 : : */
1836 : : static inline int
1837 : : rte_mempool_full(const struct rte_mempool *mp)
1838 : : {
1839 [ + + - + : 6 : return rte_mempool_avail_count(mp) == mp->size;
- + - + +
- - + ]
1840 : : }
1841 : :
1842 : : /**
1843 : : * Test if the mempool is empty.
1844 : : *
1845 : : * When cache is enabled, this function has to browse the length of all
1846 : : * lcores, so it should not be used in a data path, but only for debug
1847 : : * purposes. User-owned mempool caches are not accounted for.
1848 : : *
1849 : : * @param mp
1850 : : * A pointer to the mempool structure.
1851 : : * @return
1852 : : * - 1: The mempool is empty.
1853 : : * - 0: The mempool is not empty.
1854 : : */
1855 : : static inline int
1856 : : rte_mempool_empty(const struct rte_mempool *mp)
1857 : : {
1858 : 5 : return rte_mempool_avail_count(mp) == 0;
1859 : : }
1860 : :
1861 : : /**
1862 : : * Return the IO address of elt, which is an element of the pool mp.
1863 : : *
1864 : : * @param elt
1865 : : * A pointer (virtual address) to the element of the pool.
1866 : : * @return
1867 : : * The IO address of the elt element.
1868 : : * If the mempool was created with RTE_MEMPOOL_F_NO_IOVA_CONTIG, the
1869 : : * returned value is RTE_BAD_IOVA.
1870 : : */
1871 : : static inline rte_iova_t
1872 : 0 : rte_mempool_virt2iova(const void *elt)
1873 : : {
1874 : 0 : const struct rte_mempool_objhdr *hdr;
1875 : 0 : RTE_ASSERT(elt != NULL);
1876 [ - + # # : 58 : __rte_assume(elt != NULL);
# # # # ]
1877 : 0 : hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1878 : : sizeof(*hdr));
1879 [ - + ]: 363 : return hdr->iova;
1880 : : }
1881 : :
1882 : : /**
1883 : : * Check the consistency of mempool objects.
1884 : : *
1885 : : * Verify the coherency of fields in the mempool structure. Also check
1886 : : * that the cookies of mempool objects (even the ones that are not
1887 : : * present in pool) have a correct value. If not, a panic will occur.
1888 : : *
1889 : : * @param mp
1890 : : * A pointer to the mempool structure.
1891 : : */
1892 : : void rte_mempool_audit(struct rte_mempool *mp);
1893 : :
1894 : : /**
1895 : : * Return a pointer to the private data in an mempool structure.
1896 : : *
1897 : : * @param mp
1898 : : * A pointer to the mempool structure.
1899 : : * @return
1900 : : * A pointer to the private data.
1901 : : */
1902 : : static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1903 : : {
1904 : 34 : return (void *)(mp + 1);
1905 : : }
1906 : :
1907 : : /**
1908 : : * Dump the status of all mempools on the console
1909 : : *
1910 : : * @param f
1911 : : * A pointer to a file for output
1912 : : */
1913 : : void rte_mempool_list_dump(FILE *f);
1914 : :
1915 : : /**
1916 : : * Search a mempool from its name
1917 : : *
1918 : : * @param name
1919 : : * The name of the mempool.
1920 : : * @return
1921 : : * The pointer to the mempool matching the name, or NULL if not found.
1922 : : * NULL on error
1923 : : * with rte_errno set appropriately. Possible rte_errno values include:
1924 : : * - ENOENT - required entry not available to return.
1925 : : */
1926 : : struct rte_mempool *rte_mempool_lookup(const char *name);
1927 : :
1928 : : /**
1929 : : * Get the header, trailer and total size of a mempool element.
1930 : : *
1931 : : * Given a desired size of the mempool element and mempool flags,
1932 : : * calculates header, trailer, body and total sizes of the mempool object.
1933 : : *
1934 : : * @param elt_size
1935 : : * The size of each element, without header and trailer.
1936 : : * @param flags
1937 : : * The flags used for the mempool creation.
1938 : : * Consult rte_mempool_create() for more information about possible values.
1939 : : * @param sz
1940 : : * The calculated detailed size the mempool object. May be NULL.
1941 : : * @return
1942 : : * Total size of the mempool object.
1943 : : */
1944 : : uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1945 : : struct rte_mempool_objsz *sz);
1946 : :
1947 : : /**
1948 : : * Walk list of all memory pools
1949 : : *
1950 : : * @param func
1951 : : * Iterator function
1952 : : * @param arg
1953 : : * Argument passed to iterator
1954 : : */
1955 : : void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1956 : : void *arg);
1957 : :
1958 : : /**
1959 : : * A structure used to retrieve information about the memory range
1960 : : * of the mempool.
1961 : : */
1962 : : struct rte_mempool_mem_range_info {
1963 : : /** Start of the memory range used by mempool objects */
1964 : : void *start;
1965 : : /** Length of the memory range used by mempool objects */
1966 : : size_t length;
1967 : : /** Are all memory addresses used by mempool objects contiguous */
1968 : : bool is_contiguous;
1969 : : };
1970 : :
1971 : : /**
1972 : : * @warning
1973 : : * @b EXPERIMENTAL: this API may change without prior notice.
1974 : : *
1975 : : * Get information about the memory range used to store objects in the mempool.
1976 : : *
1977 : : * @param[in] mp
1978 : : * Pointer to an initialized mempool.
1979 : : * @param[out] mem_range
1980 : : * Pointer to struct which is used to return lowest address,
1981 : : * length of the memory range containing all the addresses,
1982 : : * and whether these addresses are contiguous.
1983 : : * @return
1984 : : * 0 on success, -EINVAL if mempool is not valid or mem_range is NULL.
1985 : : */
1986 : : __rte_experimental
1987 : : int
1988 : : rte_mempool_get_mem_range(const struct rte_mempool *mp,
1989 : : struct rte_mempool_mem_range_info *mem_range);
1990 : :
1991 : : /**
1992 : : * @warning
1993 : : * @b EXPERIMENTAL: this API may change without prior notice.
1994 : : *
1995 : : * Return alignment of objects stored in the mempool.
1996 : : *
1997 : : * @param[in] mp
1998 : : * Pointer to a mempool.
1999 : : * @return
2000 : : * Object alignment if mp is valid. 0 if mp is NULL.
2001 : : */
2002 : : __rte_experimental
2003 : : size_t
2004 : : rte_mempool_get_obj_alignment(const struct rte_mempool *mp);
2005 : :
2006 : : /**
2007 : : * @internal Get page size used for mempool object allocation.
2008 : : * This function is internal to mempool library and mempool drivers.
2009 : : */
2010 : : int
2011 : : rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
2012 : :
2013 : : /**
2014 : : * Mempool event type.
2015 : : * @internal
2016 : : */
2017 : : enum rte_mempool_event {
2018 : : /** Occurs after a mempool is fully populated. */
2019 : : RTE_MEMPOOL_EVENT_READY = 0,
2020 : : /** Occurs before the destruction of a mempool begins. */
2021 : : RTE_MEMPOOL_EVENT_DESTROY = 1,
2022 : : };
2023 : :
2024 : : /**
2025 : : * @internal
2026 : : * Mempool event callback.
2027 : : *
2028 : : * rte_mempool_event_callback_register() may be called from within the callback,
2029 : : * but the callbacks registered this way will not be invoked for the same event.
2030 : : * rte_mempool_event_callback_unregister() may only be safely called
2031 : : * to remove the running callback.
2032 : : */
2033 : : typedef void (rte_mempool_event_callback)(
2034 : : enum rte_mempool_event event,
2035 : : struct rte_mempool *mp,
2036 : : void *user_data);
2037 : :
2038 : : /**
2039 : : * @internal
2040 : : * Register a callback function invoked on mempool life cycle event.
2041 : : * The function will be invoked in the process
2042 : : * that performs an action which triggers the callback.
2043 : : * Registration is process-private,
2044 : : * i.e. each process must manage callbacks on its own if needed.
2045 : : *
2046 : : * @param func
2047 : : * Callback function.
2048 : : * @param user_data
2049 : : * User data.
2050 : : *
2051 : : * @return
2052 : : * 0 on success, negative on failure and rte_errno is set.
2053 : : */
2054 : : __rte_internal
2055 : : int
2056 : : rte_mempool_event_callback_register(rte_mempool_event_callback *func,
2057 : : void *user_data);
2058 : :
2059 : : /**
2060 : : * @internal
2061 : : * Unregister a callback added with rte_mempool_event_callback_register().
2062 : : * @p func and @p user_data must exactly match registration parameters.
2063 : : *
2064 : : * @param func
2065 : : * Callback function.
2066 : : * @param user_data
2067 : : * User data.
2068 : : *
2069 : : * @return
2070 : : * 0 on success, negative on failure and rte_errno is set.
2071 : : */
2072 : : __rte_internal
2073 : : int
2074 : : rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
2075 : : void *user_data);
2076 : :
2077 : : #ifdef __cplusplus
2078 : : }
2079 : : #endif
2080 : :
2081 : : #endif /* _RTE_MEMPOOL_H_ */
|