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 preemptable. A lcore must not
30 * be interrupted by another task that uses the same ring.
40 #include <sys/queue.h>
42 #include <rte_common.h>
43 #include <rte_config.h>
44 #include <rte_memory.h>
45 #include <rte_lcore.h>
46 #include <rte_atomic.h>
47 #include <rte_branch_prediction.h>
48 #include <rte_memzone.h>
49 #include <rte_pause.h>
51 #define RTE_TAILQ_RING_NAME "RTE_RING"
53 enum rte_ring_queue_behavior {
54 RTE_RING_QUEUE_FIXED = 0, /* Enq/Deq a fixed number of items from a ring */
55 RTE_RING_QUEUE_VARIABLE /* Enq/Deq as many items as possible from ring */
58 #define RTE_RING_MZ_PREFIX "RG_"
59 /**< The maximum length of a ring name. */
60 #define RTE_RING_NAMESIZE (RTE_MEMZONE_NAMESIZE - \
61 sizeof(RTE_RING_MZ_PREFIX) + 1)
63 struct rte_memzone; /* forward declaration, so as not to require memzone.h */
65 /* structure to hold a pair of head/tail values and other metadata */
66 struct rte_ring_headtail {
67 volatile uint32_t head; /**< Prod/consumer head. */
68 volatile uint32_t tail; /**< Prod/consumer tail. */
69 uint32_t single; /**< True if single prod/cons */
73 * An RTE ring structure.
75 * The producer and the consumer have a head and a tail index. The particularity
76 * of these index is that they are not between 0 and size(ring). These indexes
77 * are between 0 and 2^32, and we mask their value when we access the ring[]
78 * field. Thanks to this assumption, we can do subtractions between 2 index
79 * values in a modulo-32bit base: that's why the overflow of the indexes is not
84 * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
85 * compatibility requirements, it could be changed to RTE_RING_NAMESIZE
86 * next time the ABI changes
88 char name[RTE_MEMZONE_NAMESIZE] __rte_cache_aligned; /**< Name of the ring. */
89 int flags; /**< Flags supplied at creation. */
90 const struct rte_memzone *memzone;
91 /**< Memzone, if any, containing the rte_ring */
92 uint32_t size; /**< Size of ring. */
93 uint32_t mask; /**< Mask (size-1) of ring. */
94 uint32_t capacity; /**< Usable size of ring */
96 char pad0 __rte_cache_aligned; /**< empty cache line */
98 /** Ring producer status. */
99 struct rte_ring_headtail prod __rte_cache_aligned;
100 char pad1 __rte_cache_aligned; /**< empty cache line */
102 /** Ring consumer status. */
103 struct rte_ring_headtail cons __rte_cache_aligned;
104 char pad2 __rte_cache_aligned; /**< empty cache line */
107 #define RING_F_SP_ENQ 0x0001 /**< The default enqueue is "single-producer". */
108 #define RING_F_SC_DEQ 0x0002 /**< The default dequeue is "single-consumer". */
110 * Ring is to hold exactly requested number of entries.
111 * Without this flag set, the ring size requested must be a power of 2, and the
112 * usable space will be that size - 1. With the flag, the requested size will
113 * be rounded up to the next power of two, but the usable space will be exactly
114 * that requested. Worst case, if a power-of-2 size is requested, half the
115 * ring space will be wasted.
117 #define RING_F_EXACT_SZ 0x0004
118 #define RTE_RING_SZ_MASK (0x7fffffffU) /**< Ring size mask */
120 /* @internal defines for passing to the enqueue dequeue worker functions */
127 * Calculate the memory size needed for a ring
129 * This function returns the number of bytes needed for a ring, given
130 * the number of elements in it. This value is the sum of the size of
131 * the structure rte_ring and the size of the memory needed by the
132 * objects pointers. The value is aligned to a cache line size.
135 * The number of elements in the ring (must be a power of 2).
137 * - The memory size needed for the ring on success.
138 * - -EINVAL if count is not a power of 2.
140 ssize_t rte_ring_get_memsize(unsigned count);
143 * Initialize a ring structure.
145 * Initialize a ring structure in memory pointed by "r". The size of the
146 * memory area must be large enough to store the ring structure and the
147 * object table. It is advised to use rte_ring_get_memsize() to get the
150 * The ring size is set to *count*, which must be a power of two. Water
151 * marking is disabled by default. The real usable ring size is
152 * *count-1* instead of *count* to differentiate a free ring from an
155 * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
156 * memory given by the caller may not be shareable among dpdk
160 * The pointer to the ring structure followed by the objects table.
162 * The name of the ring.
164 * The number of elements in the ring (must be a power of 2).
166 * An OR of the following:
167 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
168 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
169 * is "single-producer". Otherwise, it is "multi-producers".
170 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
171 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
172 * is "single-consumer". Otherwise, it is "multi-consumers".
174 * 0 on success, or a negative value on error.
176 int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
180 * Create a new ring named *name* in memory.
182 * This function uses ``memzone_reserve()`` to allocate memory. Then it
183 * calls rte_ring_init() to initialize an empty ring.
185 * The new ring size is set to *count*, which must be a power of
186 * two. Water marking is disabled by default. The real usable ring size
187 * is *count-1* instead of *count* to differentiate a free ring from an
190 * The ring is added in RTE_TAILQ_RING list.
193 * The name of the ring.
195 * The size of the ring (must be a power of 2).
197 * The *socket_id* argument is the socket identifier in case of
198 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
199 * constraint for the reserved zone.
201 * An OR of the following:
202 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
203 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
204 * is "single-producer". Otherwise, it is "multi-producers".
205 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
206 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
207 * is "single-consumer". Otherwise, it is "multi-consumers".
209 * On success, the pointer to the new allocated ring. NULL on error with
210 * rte_errno set appropriately. Possible errno values include:
211 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
212 * - E_RTE_SECONDARY - function was called from a secondary process instance
213 * - EINVAL - count provided is not a power of 2
214 * - ENOSPC - the maximum number of memzones has already been allocated
215 * - EEXIST - a memzone with the same name already exists
216 * - ENOMEM - no appropriate memory area found in which to create memzone
218 struct rte_ring *rte_ring_create(const char *name, unsigned count,
219 int socket_id, unsigned flags);
221 * De-allocate all memory used by the ring.
226 void rte_ring_free(struct rte_ring *r);
229 * Dump the status of the ring to a file.
232 * A pointer to a file for output
234 * A pointer to the ring structure.
236 void rte_ring_dump(FILE *f, const struct rte_ring *r);
238 /* the actual enqueue of pointers on the ring.
239 * Placed here since identical code needed in both
240 * single and multi producer enqueue functions */
241 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
243 const uint32_t size = (r)->size; \
244 uint32_t idx = prod_head & (r)->mask; \
245 obj_type *ring = (obj_type *)ring_start; \
246 if (likely(idx + n < size)) { \
247 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
248 ring[idx] = obj_table[i]; \
249 ring[idx+1] = obj_table[i+1]; \
250 ring[idx+2] = obj_table[i+2]; \
251 ring[idx+3] = obj_table[i+3]; \
255 ring[idx++] = obj_table[i++]; /* fallthrough */ \
257 ring[idx++] = obj_table[i++]; /* fallthrough */ \
259 ring[idx++] = obj_table[i++]; \
262 for (i = 0; idx < size; i++, idx++)\
263 ring[idx] = obj_table[i]; \
264 for (idx = 0; i < n; i++, idx++) \
265 ring[idx] = obj_table[i]; \
269 /* the actual copy of pointers on the ring to obj_table.
270 * Placed here since identical code needed in both
271 * single and multi consumer dequeue functions */
272 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
274 uint32_t idx = cons_head & (r)->mask; \
275 const uint32_t size = (r)->size; \
276 obj_type *ring = (obj_type *)ring_start; \
277 if (likely(idx + n < size)) { \
278 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
279 obj_table[i] = ring[idx]; \
280 obj_table[i+1] = ring[idx+1]; \
281 obj_table[i+2] = ring[idx+2]; \
282 obj_table[i+3] = ring[idx+3]; \
286 obj_table[i++] = ring[idx++]; /* fallthrough */ \
288 obj_table[i++] = ring[idx++]; /* fallthrough */ \
290 obj_table[i++] = ring[idx++]; \
293 for (i = 0; idx < size; i++, idx++) \
294 obj_table[i] = ring[idx]; \
295 for (idx = 0; i < n; i++, idx++) \
296 obj_table[i] = ring[idx]; \
300 /* Between load and load. there might be cpu reorder in weak model
302 * There are 2 choices for the users
303 * 1.use rmb() memory barrier
304 * 2.use one-direcion load_acquire/store_release barrier,defined by
305 * CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
306 * It depends on performance test results.
307 * By default, move common functions to rte_ring_generic.h
309 #ifdef RTE_RING_USE_C11_MEM_MODEL
310 #include "rte_ring_c11_mem.h"
312 #include "rte_ring_generic.h"
316 * @internal Enqueue several objects on the ring
319 * A pointer to the ring structure.
321 * A pointer to a table of void * pointers (objects).
323 * The number of objects to add in the ring from the obj_table.
325 * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
326 * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
328 * Indicates whether to use single producer or multi-producer head update
330 * returns the amount of space after the enqueue operation has finished
332 * Actual number of objects enqueued.
333 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
335 static __rte_always_inline unsigned int
336 __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
337 unsigned int n, enum rte_ring_queue_behavior behavior,
338 int is_sp, unsigned int *free_space)
340 uint32_t prod_head, prod_next;
341 uint32_t free_entries;
343 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
344 &prod_head, &prod_next, &free_entries);
348 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, void *);
350 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
352 if (free_space != NULL)
353 *free_space = free_entries - n;
358 * @internal Dequeue several objects from the ring
361 * A pointer to the ring structure.
363 * A pointer to a table of void * pointers (objects).
365 * The number of objects to pull from the ring.
367 * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
368 * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
370 * Indicates whether to use single consumer or multi-consumer head update
372 * returns the number of remaining ring entries after the dequeue has finished
374 * - Actual number of objects dequeued.
375 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
377 static __rte_always_inline unsigned int
378 __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
379 unsigned int n, enum rte_ring_queue_behavior behavior,
380 int is_sc, unsigned int *available)
382 uint32_t cons_head, cons_next;
385 n = __rte_ring_move_cons_head(r, is_sc, n, behavior,
386 &cons_head, &cons_next, &entries);
390 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, void *);
392 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
395 if (available != NULL)
396 *available = entries - n;
401 * Enqueue several objects on the ring (multi-producers safe).
403 * This function uses a "compare and set" instruction to move the
404 * producer index atomically.
407 * A pointer to the ring structure.
409 * A pointer to a table of void * pointers (objects).
411 * The number of objects to add in the ring from the obj_table.
413 * if non-NULL, returns the amount of space in the ring after the
414 * enqueue operation has finished.
416 * The number of objects enqueued, either 0 or n
418 static __rte_always_inline unsigned int
419 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
420 unsigned int n, unsigned int *free_space)
422 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
423 __IS_MP, free_space);
427 * Enqueue several objects on a ring (NOT multi-producers safe).
430 * A pointer to the ring structure.
432 * A pointer to a table of void * pointers (objects).
434 * The number of objects to add in the ring from the obj_table.
436 * if non-NULL, returns the amount of space in the ring after the
437 * enqueue operation has finished.
439 * The number of objects enqueued, either 0 or n
441 static __rte_always_inline unsigned int
442 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
443 unsigned int n, unsigned int *free_space)
445 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
446 __IS_SP, free_space);
450 * Enqueue several objects on a ring.
452 * This function calls the multi-producer or the single-producer
453 * version depending on the default behavior that was specified at
454 * ring creation time (see flags).
457 * A pointer to the ring structure.
459 * A pointer to a table of void * pointers (objects).
461 * The number of objects to add in the ring from the obj_table.
463 * if non-NULL, returns the amount of space in the ring after the
464 * enqueue operation has finished.
466 * The number of objects enqueued, either 0 or n
468 static __rte_always_inline unsigned int
469 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
470 unsigned int n, unsigned int *free_space)
472 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
473 r->prod.single, free_space);
477 * Enqueue one object on a ring (multi-producers safe).
479 * This function uses a "compare and set" instruction to move the
480 * producer index atomically.
483 * A pointer to the ring structure.
485 * A pointer to the object to be added.
487 * - 0: Success; objects enqueued.
488 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
490 static __rte_always_inline int
491 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
493 return rte_ring_mp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
497 * Enqueue one object on a ring (NOT multi-producers safe).
500 * A pointer to the ring structure.
502 * A pointer to the object to be added.
504 * - 0: Success; objects enqueued.
505 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
507 static __rte_always_inline int
508 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
510 return rte_ring_sp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
514 * Enqueue one object on a ring.
516 * This function calls the multi-producer or the single-producer
517 * version, depending on the default behaviour that was specified at
518 * ring creation time (see flags).
521 * A pointer to the ring structure.
523 * A pointer to the object to be added.
525 * - 0: Success; objects enqueued.
526 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
528 static __rte_always_inline int
529 rte_ring_enqueue(struct rte_ring *r, void *obj)
531 return rte_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
535 * Dequeue several objects from a ring (multi-consumers safe).
537 * This function uses a "compare and set" instruction to move the
538 * consumer index atomically.
541 * A pointer to the ring structure.
543 * A pointer to a table of void * pointers (objects) that will be filled.
545 * The number of objects to dequeue from the ring to the obj_table.
547 * If non-NULL, returns the number of remaining ring entries after the
548 * dequeue has finished.
550 * The number of objects dequeued, either 0 or n
552 static __rte_always_inline unsigned int
553 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
554 unsigned int n, unsigned int *available)
556 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
561 * Dequeue several objects from a ring (NOT multi-consumers safe).
564 * A pointer to the ring structure.
566 * A pointer to a table of void * pointers (objects) that will be filled.
568 * The number of objects to dequeue from the ring to the obj_table,
569 * must be strictly positive.
571 * If non-NULL, returns the number of remaining ring entries after the
572 * dequeue has finished.
574 * The number of objects dequeued, either 0 or n
576 static __rte_always_inline unsigned int
577 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
578 unsigned int n, unsigned int *available)
580 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
585 * Dequeue several objects from a ring.
587 * This function calls the multi-consumers or the single-consumer
588 * version, depending on the default behaviour that was specified at
589 * ring creation time (see flags).
592 * A pointer to the ring structure.
594 * A pointer to a table of void * pointers (objects) that will be filled.
596 * The number of objects to dequeue from the ring to the obj_table.
598 * If non-NULL, returns the number of remaining ring entries after the
599 * dequeue has finished.
601 * The number of objects dequeued, either 0 or n
603 static __rte_always_inline unsigned int
604 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
605 unsigned int *available)
607 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
608 r->cons.single, available);
612 * Dequeue one object from a ring (multi-consumers safe).
614 * This function uses a "compare and set" instruction to move the
615 * consumer index atomically.
618 * A pointer to the ring structure.
620 * A pointer to a void * pointer (object) that will be filled.
622 * - 0: Success; objects dequeued.
623 * - -ENOENT: Not enough entries in the ring to dequeue; no object is
626 static __rte_always_inline int
627 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
629 return rte_ring_mc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
633 * Dequeue one object from a ring (NOT multi-consumers safe).
636 * A pointer to the ring structure.
638 * A pointer to a void * pointer (object) that will be filled.
640 * - 0: Success; objects dequeued.
641 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
644 static __rte_always_inline int
645 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
647 return rte_ring_sc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
651 * Dequeue one object from a ring.
653 * This function calls the multi-consumers or the single-consumer
654 * version depending on the default behaviour that was specified at
655 * ring creation time (see flags).
658 * A pointer to the ring structure.
660 * A pointer to a void * pointer (object) that will be filled.
662 * - 0: Success, objects dequeued.
663 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
666 static __rte_always_inline int
667 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
669 return rte_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
673 * Return the number of entries in a ring.
676 * A pointer to the ring structure.
678 * The number of entries in the ring.
680 static inline unsigned
681 rte_ring_count(const struct rte_ring *r)
683 uint32_t prod_tail = r->prod.tail;
684 uint32_t cons_tail = r->cons.tail;
685 uint32_t count = (prod_tail - cons_tail) & r->mask;
686 return (count > r->capacity) ? r->capacity : count;
690 * Return the number of free entries in a ring.
693 * A pointer to the ring structure.
695 * The number of free entries in the ring.
697 static inline unsigned
698 rte_ring_free_count(const struct rte_ring *r)
700 return r->capacity - rte_ring_count(r);
704 * Test if a ring is full.
707 * A pointer to the ring structure.
709 * - 1: The ring is full.
710 * - 0: The ring is not full.
713 rte_ring_full(const struct rte_ring *r)
715 return rte_ring_free_count(r) == 0;
719 * Test if a ring is empty.
722 * A pointer to the ring structure.
724 * - 1: The ring is empty.
725 * - 0: The ring is not empty.
728 rte_ring_empty(const struct rte_ring *r)
730 return rte_ring_count(r) == 0;
734 * Return the size of the ring.
737 * A pointer to the ring structure.
739 * The size of the data store used by the ring.
740 * NOTE: this is not the same as the usable space in the ring. To query that
741 * use ``rte_ring_get_capacity()``.
743 static inline unsigned int
744 rte_ring_get_size(const struct rte_ring *r)
750 * Return the number of elements which can be stored in the ring.
753 * A pointer to the ring structure.
755 * The usable size of the ring.
757 static inline unsigned int
758 rte_ring_get_capacity(const struct rte_ring *r)
764 * Dump the status of all rings on the console
767 * A pointer to a file for output
769 void rte_ring_list_dump(FILE *f);
772 * Search a ring from its name
775 * The name of the ring.
777 * The pointer to the ring matching the name, or NULL if not found,
778 * with rte_errno set appropriately. Possible rte_errno values include:
779 * - ENOENT - required entry not available to return.
781 struct rte_ring *rte_ring_lookup(const char *name);
784 * Enqueue several objects on the ring (multi-producers safe).
786 * This function uses a "compare and set" instruction to move the
787 * producer index atomically.
790 * A pointer to the ring structure.
792 * A pointer to a table of void * pointers (objects).
794 * The number of objects to add in the ring from the obj_table.
796 * if non-NULL, returns the amount of space in the ring after the
797 * enqueue operation has finished.
799 * - n: Actual number of objects enqueued.
801 static __rte_always_inline unsigned
802 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
803 unsigned int n, unsigned int *free_space)
805 return __rte_ring_do_enqueue(r, obj_table, n,
806 RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space);
810 * Enqueue several objects on a ring (NOT multi-producers safe).
813 * A pointer to the ring structure.
815 * A pointer to a table of void * pointers (objects).
817 * The number of objects to add in the ring from the obj_table.
819 * if non-NULL, returns the amount of space in the ring after the
820 * enqueue operation has finished.
822 * - n: Actual number of objects enqueued.
824 static __rte_always_inline unsigned
825 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
826 unsigned int n, unsigned int *free_space)
828 return __rte_ring_do_enqueue(r, obj_table, n,
829 RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space);
833 * Enqueue several objects on a ring.
835 * This function calls the multi-producer or the single-producer
836 * version depending on the default behavior that was specified at
837 * ring creation time (see flags).
840 * A pointer to the ring structure.
842 * A pointer to a table of void * pointers (objects).
844 * The number of objects to add in the ring from the obj_table.
846 * if non-NULL, returns the amount of space in the ring after the
847 * enqueue operation has finished.
849 * - n: Actual number of objects enqueued.
851 static __rte_always_inline unsigned
852 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
853 unsigned int n, unsigned int *free_space)
855 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE,
856 r->prod.single, free_space);
860 * Dequeue several objects from a ring (multi-consumers safe). When the request
861 * objects are more than the available objects, only dequeue the actual number
864 * This function uses a "compare and set" instruction to move the
865 * consumer index atomically.
868 * A pointer to the ring structure.
870 * A pointer to a table of void * pointers (objects) that will be filled.
872 * The number of objects to dequeue from the ring to the obj_table.
874 * If non-NULL, returns the number of remaining ring entries after the
875 * dequeue has finished.
877 * - n: Actual number of objects dequeued, 0 if ring is empty
879 static __rte_always_inline unsigned
880 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
881 unsigned int n, unsigned int *available)
883 return __rte_ring_do_dequeue(r, obj_table, n,
884 RTE_RING_QUEUE_VARIABLE, __IS_MC, available);
888 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
889 * request objects are more than the available objects, only dequeue the
890 * actual number of objects
893 * A pointer to the ring structure.
895 * A pointer to a table of void * pointers (objects) that will be filled.
897 * The number of objects to dequeue from the ring to the obj_table.
899 * If non-NULL, returns the number of remaining ring entries after the
900 * dequeue has finished.
902 * - n: Actual number of objects dequeued, 0 if ring is empty
904 static __rte_always_inline unsigned
905 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
906 unsigned int n, unsigned int *available)
908 return __rte_ring_do_dequeue(r, obj_table, n,
909 RTE_RING_QUEUE_VARIABLE, __IS_SC, available);
913 * Dequeue multiple objects from a ring up to a maximum number.
915 * This function calls the multi-consumers or the single-consumer
916 * version, depending on the default behaviour that was specified at
917 * ring creation time (see flags).
920 * A pointer to the ring structure.
922 * A pointer to a table of void * pointers (objects) that will be filled.
924 * The number of objects to dequeue from the ring to the obj_table.
926 * If non-NULL, returns the number of remaining ring entries after the
927 * dequeue has finished.
929 * - Number of objects dequeued
931 static __rte_always_inline unsigned
932 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
933 unsigned int n, unsigned int *available)
935 return __rte_ring_do_dequeue(r, obj_table, n,
936 RTE_RING_QUEUE_VARIABLE,
937 r->cons.single, available);
944 #endif /* _RTE_RING_H_ */