1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2010-2017 Intel Corporation
4 * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
6 * Derived from FreeBSD's bufring.h
7 * Used as BSD-3 Licensed with permission from Kip Macy.
17 * The Ring Manager is a fixed-size queue, implemented as a table of
18 * pointers. Head and tail pointers are modified atomically, allowing
19 * concurrent access to it. It has the following features:
21 * - FIFO (First In First Out)
22 * - Maximum size is fixed; the pointers are stored in a table.
23 * - Lockless implementation.
24 * - Multi- or single-consumer dequeue.
25 * - Multi- or single-producer enqueue.
29 * Note: the ring implementation is not preemptible. Refer to Programmer's
30 * guide/Environment Abstraction Layer/Multiple pthread/Known Issues/rte_ring
31 * for more information.
41 #include <sys/queue.h>
43 #include <rte_common.h>
44 #include <rte_config.h>
45 #include <rte_memory.h>
46 #include <rte_lcore.h>
47 #include <rte_atomic.h>
48 #include <rte_branch_prediction.h>
49 #include <rte_memzone.h>
50 #include <rte_pause.h>
52 #define RTE_TAILQ_RING_NAME "RTE_RING"
54 enum rte_ring_queue_behavior {
55 RTE_RING_QUEUE_FIXED = 0, /* Enq/Deq a fixed number of items from a ring */
56 RTE_RING_QUEUE_VARIABLE /* Enq/Deq as many items as possible from ring */
59 #define RTE_RING_MZ_PREFIX "RG_"
60 /** The maximum length of a ring name. */
61 #define RTE_RING_NAMESIZE (RTE_MEMZONE_NAMESIZE - \
62 sizeof(RTE_RING_MZ_PREFIX) + 1)
64 /* structure to hold a pair of head/tail values and other metadata */
65 struct rte_ring_headtail {
66 volatile uint32_t head; /**< Prod/consumer head. */
67 volatile uint32_t tail; /**< Prod/consumer tail. */
68 uint32_t single; /**< True if single prod/cons */
72 * An RTE ring structure.
74 * The producer and the consumer have a head and a tail index. The particularity
75 * of these index is that they are not between 0 and size(ring). These indexes
76 * are between 0 and 2^32, and we mask their value when we access the ring[]
77 * field. Thanks to this assumption, we can do subtractions between 2 index
78 * values in a modulo-32bit base: that's why the overflow of the indexes is not
83 * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
84 * compatibility requirements, it could be changed to RTE_RING_NAMESIZE
85 * next time the ABI changes
87 char name[RTE_MEMZONE_NAMESIZE] __rte_cache_aligned; /**< Name of the ring. */
88 int flags; /**< Flags supplied at creation. */
89 const struct rte_memzone *memzone;
90 /**< Memzone, if any, containing the rte_ring */
91 uint32_t size; /**< Size of ring. */
92 uint32_t mask; /**< Mask (size-1) of ring. */
93 uint32_t capacity; /**< Usable size of ring */
95 char pad0 __rte_cache_aligned; /**< empty cache line */
97 /** Ring producer status. */
98 struct rte_ring_headtail prod __rte_cache_aligned;
99 char pad1 __rte_cache_aligned; /**< empty cache line */
101 /** Ring consumer status. */
102 struct rte_ring_headtail cons __rte_cache_aligned;
103 char pad2 __rte_cache_aligned; /**< empty cache line */
106 #define RING_F_SP_ENQ 0x0001 /**< The default enqueue is "single-producer". */
107 #define RING_F_SC_DEQ 0x0002 /**< The default dequeue is "single-consumer". */
109 * Ring is to hold exactly requested number of entries.
110 * Without this flag set, the ring size requested must be a power of 2, and the
111 * usable space will be that size - 1. With the flag, the requested size will
112 * be rounded up to the next power of two, but the usable space will be exactly
113 * that requested. Worst case, if a power-of-2 size is requested, half the
114 * ring space will be wasted.
116 #define RING_F_EXACT_SZ 0x0004
117 #define RTE_RING_SZ_MASK (0x7fffffffU) /**< Ring size mask */
119 /* @internal defines for passing to the enqueue dequeue worker functions */
126 * Calculate the memory size needed for a ring
128 * This function returns the number of bytes needed for a ring, given
129 * the number of elements in it. This value is the sum of the size of
130 * the structure rte_ring and the size of the memory needed by the
131 * objects pointers. The value is aligned to a cache line size.
134 * The number of elements in the ring (must be a power of 2).
136 * - The memory size needed for the ring on success.
137 * - -EINVAL if count is not a power of 2.
139 ssize_t rte_ring_get_memsize(unsigned count);
142 * Initialize a ring structure.
144 * Initialize a ring structure in memory pointed by "r". The size of the
145 * memory area must be large enough to store the ring structure and the
146 * object table. It is advised to use rte_ring_get_memsize() to get the
149 * The ring size is set to *count*, which must be a power of two. Water
150 * marking is disabled by default. The real usable ring size is
151 * *count-1* instead of *count* to differentiate a free ring from an
154 * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
155 * memory given by the caller may not be shareable among dpdk
159 * The pointer to the ring structure followed by the objects table.
161 * The name of the ring.
163 * The number of elements in the ring (must be a power of 2).
165 * An OR of the following:
166 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
167 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
168 * is "single-producer". Otherwise, it is "multi-producers".
169 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
170 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
171 * is "single-consumer". Otherwise, it is "multi-consumers".
173 * 0 on success, or a negative value on error.
175 int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
179 * Create a new ring named *name* in memory.
181 * This function uses ``memzone_reserve()`` to allocate memory. Then it
182 * calls rte_ring_init() to initialize an empty ring.
184 * The new ring size is set to *count*, which must be a power of
185 * two. Water marking is disabled by default. The real usable ring size
186 * is *count-1* instead of *count* to differentiate a free ring from an
189 * The ring is added in RTE_TAILQ_RING list.
192 * The name of the ring.
194 * The size of the ring (must be a power of 2).
196 * The *socket_id* argument is the socket identifier in case of
197 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
198 * constraint for the reserved zone.
200 * An OR of the following:
201 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
202 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
203 * is "single-producer". Otherwise, it is "multi-producers".
204 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
205 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
206 * is "single-consumer". Otherwise, it is "multi-consumers".
208 * On success, the pointer to the new allocated ring. NULL on error with
209 * rte_errno set appropriately. Possible errno values include:
210 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
211 * - E_RTE_SECONDARY - function was called from a secondary process instance
212 * - EINVAL - count provided is not a power of 2
213 * - ENOSPC - the maximum number of memzones has already been allocated
214 * - EEXIST - a memzone with the same name already exists
215 * - ENOMEM - no appropriate memory area found in which to create memzone
217 struct rte_ring *rte_ring_create(const char *name, unsigned count,
218 int socket_id, unsigned flags);
220 * De-allocate all memory used by the ring.
225 void rte_ring_free(struct rte_ring *r);
228 * Dump the status of the ring to a file.
231 * A pointer to a file for output
233 * A pointer to the ring structure.
235 void rte_ring_dump(FILE *f, const struct rte_ring *r);
237 /* the actual enqueue of pointers on the ring.
238 * Placed here since identical code needed in both
239 * single and multi producer enqueue functions */
240 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
242 const uint32_t size = (r)->size; \
243 uint32_t idx = prod_head & (r)->mask; \
244 obj_type *ring = (obj_type *)ring_start; \
245 if (likely(idx + n < size)) { \
246 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
247 ring[idx] = obj_table[i]; \
248 ring[idx+1] = obj_table[i+1]; \
249 ring[idx+2] = obj_table[i+2]; \
250 ring[idx+3] = obj_table[i+3]; \
254 ring[idx++] = obj_table[i++]; /* fallthrough */ \
256 ring[idx++] = obj_table[i++]; /* fallthrough */ \
258 ring[idx++] = obj_table[i++]; \
261 for (i = 0; idx < size; i++, idx++)\
262 ring[idx] = obj_table[i]; \
263 for (idx = 0; i < n; i++, idx++) \
264 ring[idx] = obj_table[i]; \
268 /* the actual copy of pointers on the ring to obj_table.
269 * Placed here since identical code needed in both
270 * single and multi consumer dequeue functions */
271 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
273 uint32_t idx = cons_head & (r)->mask; \
274 const uint32_t size = (r)->size; \
275 obj_type *ring = (obj_type *)ring_start; \
276 if (likely(idx + n < size)) { \
277 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
278 obj_table[i] = ring[idx]; \
279 obj_table[i+1] = ring[idx+1]; \
280 obj_table[i+2] = ring[idx+2]; \
281 obj_table[i+3] = ring[idx+3]; \
285 obj_table[i++] = ring[idx++]; /* fallthrough */ \
287 obj_table[i++] = ring[idx++]; /* fallthrough */ \
289 obj_table[i++] = ring[idx++]; \
292 for (i = 0; idx < size; i++, idx++) \
293 obj_table[i] = ring[idx]; \
294 for (idx = 0; i < n; i++, idx++) \
295 obj_table[i] = ring[idx]; \
299 /* Between load and load. there might be cpu reorder in weak model
301 * There are 2 choices for the users
302 * 1.use rmb() memory barrier
303 * 2.use one-direction load_acquire/store_release barrier,defined by
304 * CONFIG_RTE_USE_C11_MEM_MODEL=y
305 * It depends on performance test results.
306 * By default, move common functions to rte_ring_generic.h
308 #ifdef RTE_USE_C11_MEM_MODEL
309 #include "rte_ring_c11_mem.h"
311 #include "rte_ring_generic.h"
315 * @internal Enqueue several objects on the ring
318 * A pointer to the ring structure.
320 * A pointer to a table of void * pointers (objects).
322 * The number of objects to add in the ring from the obj_table.
324 * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
325 * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
327 * Indicates whether to use single producer or multi-producer head update
329 * returns the amount of space after the enqueue operation has finished
331 * Actual number of objects enqueued.
332 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
334 static __rte_always_inline unsigned int
335 __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
336 unsigned int n, enum rte_ring_queue_behavior behavior,
337 unsigned int is_sp, unsigned int *free_space)
339 uint32_t prod_head, prod_next;
340 uint32_t free_entries;
342 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
343 &prod_head, &prod_next, &free_entries);
347 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, void *);
349 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
351 if (free_space != NULL)
352 *free_space = free_entries - n;
357 * @internal Dequeue several objects from the ring
360 * A pointer to the ring structure.
362 * A pointer to a table of void * pointers (objects).
364 * The number of objects to pull from the ring.
366 * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
367 * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
369 * Indicates whether to use single consumer or multi-consumer head update
371 * returns the number of remaining ring entries after the dequeue has finished
373 * - Actual number of objects dequeued.
374 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
376 static __rte_always_inline unsigned int
377 __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
378 unsigned int n, enum rte_ring_queue_behavior behavior,
379 unsigned int is_sc, unsigned int *available)
381 uint32_t cons_head, cons_next;
384 n = __rte_ring_move_cons_head(r, (int)is_sc, n, behavior,
385 &cons_head, &cons_next, &entries);
389 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, void *);
391 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
394 if (available != NULL)
395 *available = entries - n;
400 * Enqueue several objects on the ring (multi-producers safe).
402 * This function uses a "compare and set" instruction to move the
403 * producer index atomically.
406 * A pointer to the ring structure.
408 * A pointer to a table of void * pointers (objects).
410 * The number of objects to add in the ring from the obj_table.
412 * if non-NULL, returns the amount of space in the ring after the
413 * enqueue operation has finished.
415 * The number of objects enqueued, either 0 or n
417 static __rte_always_inline unsigned int
418 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
419 unsigned int n, unsigned int *free_space)
421 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
422 __IS_MP, free_space);
426 * Enqueue several objects on a ring (NOT multi-producers safe).
429 * A pointer to the ring structure.
431 * A pointer to a table of void * pointers (objects).
433 * The number of objects to add in the ring from the obj_table.
435 * if non-NULL, returns the amount of space in the ring after the
436 * enqueue operation has finished.
438 * The number of objects enqueued, either 0 or n
440 static __rte_always_inline unsigned int
441 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
442 unsigned int n, unsigned int *free_space)
444 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
445 __IS_SP, free_space);
449 * Enqueue several objects on a ring.
451 * This function calls the multi-producer or the single-producer
452 * version depending on the default behavior that was specified at
453 * ring creation time (see flags).
456 * A pointer to the ring structure.
458 * A pointer to a table of void * pointers (objects).
460 * The number of objects to add in the ring from the obj_table.
462 * if non-NULL, returns the amount of space in the ring after the
463 * enqueue operation has finished.
465 * The number of objects enqueued, either 0 or n
467 static __rte_always_inline unsigned int
468 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
469 unsigned int n, unsigned int *free_space)
471 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
472 r->prod.single, free_space);
476 * Enqueue one object on a ring (multi-producers safe).
478 * This function uses a "compare and set" instruction to move the
479 * producer index atomically.
482 * A pointer to the ring structure.
484 * A pointer to the object to be added.
486 * - 0: Success; objects enqueued.
487 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
489 static __rte_always_inline int
490 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
492 return rte_ring_mp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
496 * Enqueue one object on a ring (NOT multi-producers safe).
499 * A pointer to the ring structure.
501 * A pointer to the object to be added.
503 * - 0: Success; objects enqueued.
504 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
506 static __rte_always_inline int
507 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
509 return rte_ring_sp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
513 * Enqueue one object on a ring.
515 * This function calls the multi-producer or the single-producer
516 * version, depending on the default behaviour that was specified at
517 * ring creation time (see flags).
520 * A pointer to the ring structure.
522 * A pointer to the object to be added.
524 * - 0: Success; objects enqueued.
525 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
527 static __rte_always_inline int
528 rte_ring_enqueue(struct rte_ring *r, void *obj)
530 return rte_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
534 * Dequeue several objects from a ring (multi-consumers safe).
536 * This function uses a "compare and set" instruction to move the
537 * consumer index atomically.
540 * A pointer to the ring structure.
542 * A pointer to a table of void * pointers (objects) that will be filled.
544 * The number of objects to dequeue from the ring to the obj_table.
546 * If non-NULL, returns the number of remaining ring entries after the
547 * dequeue has finished.
549 * The number of objects dequeued, either 0 or n
551 static __rte_always_inline unsigned int
552 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
553 unsigned int n, unsigned int *available)
555 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
560 * Dequeue several objects from a ring (NOT multi-consumers safe).
563 * A pointer to the ring structure.
565 * A pointer to a table of void * pointers (objects) that will be filled.
567 * The number of objects to dequeue from the ring to the obj_table,
568 * must be strictly positive.
570 * If non-NULL, returns the number of remaining ring entries after the
571 * dequeue has finished.
573 * The number of objects dequeued, either 0 or n
575 static __rte_always_inline unsigned int
576 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
577 unsigned int n, unsigned int *available)
579 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
584 * Dequeue several objects from a ring.
586 * This function calls the multi-consumers or the single-consumer
587 * version, depending on the default behaviour that was specified at
588 * ring creation time (see flags).
591 * A pointer to the ring structure.
593 * A pointer to a table of void * pointers (objects) that will be filled.
595 * The number of objects to dequeue from the ring to the obj_table.
597 * If non-NULL, returns the number of remaining ring entries after the
598 * dequeue has finished.
600 * The number of objects dequeued, either 0 or n
602 static __rte_always_inline unsigned int
603 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
604 unsigned int *available)
606 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
607 r->cons.single, available);
611 * Dequeue one object from a ring (multi-consumers safe).
613 * This function uses a "compare and set" instruction to move the
614 * consumer index atomically.
617 * A pointer to the ring structure.
619 * A pointer to a void * pointer (object) that will be filled.
621 * - 0: Success; objects dequeued.
622 * - -ENOENT: Not enough entries in the ring to dequeue; no object is
625 static __rte_always_inline int
626 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
628 return rte_ring_mc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
632 * Dequeue one object from a ring (NOT multi-consumers safe).
635 * A pointer to the ring structure.
637 * A pointer to a void * pointer (object) that will be filled.
639 * - 0: Success; objects dequeued.
640 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
643 static __rte_always_inline int
644 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
646 return rte_ring_sc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
650 * Dequeue one object from a ring.
652 * This function calls the multi-consumers or the single-consumer
653 * version depending on the default behaviour that was specified at
654 * ring creation time (see flags).
657 * A pointer to the ring structure.
659 * A pointer to a void * pointer (object) that will be filled.
661 * - 0: Success, objects dequeued.
662 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
665 static __rte_always_inline int
666 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
668 return rte_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
672 * Return the number of entries in a ring.
675 * A pointer to the ring structure.
677 * The number of entries in the ring.
679 static inline unsigned
680 rte_ring_count(const struct rte_ring *r)
682 uint32_t prod_tail = r->prod.tail;
683 uint32_t cons_tail = r->cons.tail;
684 uint32_t count = (prod_tail - cons_tail) & r->mask;
685 return (count > r->capacity) ? r->capacity : count;
689 * Return the number of free entries in a ring.
692 * A pointer to the ring structure.
694 * The number of free entries in the ring.
696 static inline unsigned
697 rte_ring_free_count(const struct rte_ring *r)
699 return r->capacity - rte_ring_count(r);
703 * Test if a ring is full.
706 * A pointer to the ring structure.
708 * - 1: The ring is full.
709 * - 0: The ring is not full.
712 rte_ring_full(const struct rte_ring *r)
714 return rte_ring_free_count(r) == 0;
718 * Test if a ring is empty.
721 * A pointer to the ring structure.
723 * - 1: The ring is empty.
724 * - 0: The ring is not empty.
727 rte_ring_empty(const struct rte_ring *r)
729 return rte_ring_count(r) == 0;
733 * Return the size of the ring.
736 * A pointer to the ring structure.
738 * The size of the data store used by the ring.
739 * NOTE: this is not the same as the usable space in the ring. To query that
740 * use ``rte_ring_get_capacity()``.
742 static inline unsigned int
743 rte_ring_get_size(const struct rte_ring *r)
749 * Return the number of elements which can be stored in the ring.
752 * A pointer to the ring structure.
754 * The usable size of the ring.
756 static inline unsigned int
757 rte_ring_get_capacity(const struct rte_ring *r)
763 * Dump the status of all rings on the console
766 * A pointer to a file for output
768 void rte_ring_list_dump(FILE *f);
771 * Search a ring from its name
774 * The name of the ring.
776 * The pointer to the ring matching the name, or NULL if not found,
777 * with rte_errno set appropriately. Possible rte_errno values include:
778 * - ENOENT - required entry not available to return.
780 struct rte_ring *rte_ring_lookup(const char *name);
783 * Enqueue several objects on the ring (multi-producers safe).
785 * This function uses a "compare and set" instruction to move the
786 * producer index atomically.
789 * A pointer to the ring structure.
791 * A pointer to a table of void * pointers (objects).
793 * The number of objects to add in the ring from the obj_table.
795 * if non-NULL, returns the amount of space in the ring after the
796 * enqueue operation has finished.
798 * - n: Actual number of objects enqueued.
800 static __rte_always_inline unsigned
801 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
802 unsigned int n, unsigned int *free_space)
804 return __rte_ring_do_enqueue(r, obj_table, n,
805 RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space);
809 * Enqueue several objects on a ring (NOT multi-producers safe).
812 * A pointer to the ring structure.
814 * A pointer to a table of void * pointers (objects).
816 * The number of objects to add in the ring from the obj_table.
818 * if non-NULL, returns the amount of space in the ring after the
819 * enqueue operation has finished.
821 * - n: Actual number of objects enqueued.
823 static __rte_always_inline unsigned
824 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
825 unsigned int n, unsigned int *free_space)
827 return __rte_ring_do_enqueue(r, obj_table, n,
828 RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space);
832 * Enqueue several objects on a ring.
834 * This function calls the multi-producer or the single-producer
835 * version depending on the default behavior that was specified at
836 * ring creation time (see flags).
839 * A pointer to the ring structure.
841 * A pointer to a table of void * pointers (objects).
843 * The number of objects to add in the ring from the obj_table.
845 * if non-NULL, returns the amount of space in the ring after the
846 * enqueue operation has finished.
848 * - n: Actual number of objects enqueued.
850 static __rte_always_inline unsigned
851 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
852 unsigned int n, unsigned int *free_space)
854 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE,
855 r->prod.single, free_space);
859 * Dequeue several objects from a ring (multi-consumers safe). When the request
860 * objects are more than the available objects, only dequeue the actual number
863 * This function uses a "compare and set" instruction to move the
864 * consumer index atomically.
867 * A pointer to the ring structure.
869 * A pointer to a table of void * pointers (objects) that will be filled.
871 * The number of objects to dequeue from the ring to the obj_table.
873 * If non-NULL, returns the number of remaining ring entries after the
874 * dequeue has finished.
876 * - n: Actual number of objects dequeued, 0 if ring is empty
878 static __rte_always_inline unsigned
879 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
880 unsigned int n, unsigned int *available)
882 return __rte_ring_do_dequeue(r, obj_table, n,
883 RTE_RING_QUEUE_VARIABLE, __IS_MC, available);
887 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
888 * request objects are more than the available objects, only dequeue the
889 * actual number of objects
892 * A pointer to the ring structure.
894 * A pointer to a table of void * pointers (objects) that will be filled.
896 * The number of objects to dequeue from the ring to the obj_table.
898 * If non-NULL, returns the number of remaining ring entries after the
899 * dequeue has finished.
901 * - n: Actual number of objects dequeued, 0 if ring is empty
903 static __rte_always_inline unsigned
904 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
905 unsigned int n, unsigned int *available)
907 return __rte_ring_do_dequeue(r, obj_table, n,
908 RTE_RING_QUEUE_VARIABLE, __IS_SC, available);
912 * Dequeue multiple objects from a ring up to a maximum number.
914 * This function calls the multi-consumers or the single-consumer
915 * version, depending on the default behaviour that was specified at
916 * ring creation time (see flags).
919 * A pointer to the ring structure.
921 * A pointer to a table of void * pointers (objects) that will be filled.
923 * The number of objects to dequeue from the ring to the obj_table.
925 * If non-NULL, returns the number of remaining ring entries after the
926 * dequeue has finished.
928 * - Number of objects dequeued
930 static __rte_always_inline unsigned
931 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
932 unsigned int n, unsigned int *available)
934 return __rte_ring_do_dequeue(r, obj_table, n,
935 RTE_RING_QUEUE_VARIABLE,
936 r->cons.single, available);
943 #endif /* _RTE_RING_H_ */