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);
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-direction load_acquire/store_release barrier,defined by
305 * CONFIG_RTE_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_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 unsigned 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 unsigned int is_sc, unsigned int *available)
382 uint32_t cons_head, cons_next;
385 n = __rte_ring_move_cons_head(r, (int)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;
675 * This function flush all the elements in a ring
677 * @b EXPERIMENTAL: this API may change without prior notice
680 * Make sure the ring is not in use while calling this function.
683 * A pointer to the ring structure.
687 rte_ring_reset(struct rte_ring *r);
690 * Return the number of entries in a ring.
693 * A pointer to the ring structure.
695 * The number of entries in the ring.
697 static inline unsigned
698 rte_ring_count(const struct rte_ring *r)
700 uint32_t prod_tail = r->prod.tail;
701 uint32_t cons_tail = r->cons.tail;
702 uint32_t count = (prod_tail - cons_tail) & r->mask;
703 return (count > r->capacity) ? r->capacity : count;
707 * Return the number of free entries in a ring.
710 * A pointer to the ring structure.
712 * The number of free entries in the ring.
714 static inline unsigned
715 rte_ring_free_count(const struct rte_ring *r)
717 return r->capacity - rte_ring_count(r);
721 * Test if a ring is full.
724 * A pointer to the ring structure.
726 * - 1: The ring is full.
727 * - 0: The ring is not full.
730 rte_ring_full(const struct rte_ring *r)
732 return rte_ring_free_count(r) == 0;
736 * Test if a ring is empty.
739 * A pointer to the ring structure.
741 * - 1: The ring is empty.
742 * - 0: The ring is not empty.
745 rte_ring_empty(const struct rte_ring *r)
747 return rte_ring_count(r) == 0;
751 * Return the size of the ring.
754 * A pointer to the ring structure.
756 * The size of the data store used by the ring.
757 * NOTE: this is not the same as the usable space in the ring. To query that
758 * use ``rte_ring_get_capacity()``.
760 static inline unsigned int
761 rte_ring_get_size(const struct rte_ring *r)
767 * Return the number of elements which can be stored in the ring.
770 * A pointer to the ring structure.
772 * The usable size of the ring.
774 static inline unsigned int
775 rte_ring_get_capacity(const struct rte_ring *r)
781 * Dump the status of all rings on the console
784 * A pointer to a file for output
786 void rte_ring_list_dump(FILE *f);
789 * Search a ring from its name
792 * The name of the ring.
794 * The pointer to the ring matching the name, or NULL if not found,
795 * with rte_errno set appropriately. Possible rte_errno values include:
796 * - ENOENT - required entry not available to return.
798 struct rte_ring *rte_ring_lookup(const char *name);
801 * Enqueue several objects on the ring (multi-producers safe).
803 * This function uses a "compare and set" instruction to move the
804 * producer index atomically.
807 * A pointer to the ring structure.
809 * A pointer to a table of void * pointers (objects).
811 * The number of objects to add in the ring from the obj_table.
813 * if non-NULL, returns the amount of space in the ring after the
814 * enqueue operation has finished.
816 * - n: Actual number of objects enqueued.
818 static __rte_always_inline unsigned
819 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
820 unsigned int n, unsigned int *free_space)
822 return __rte_ring_do_enqueue(r, obj_table, n,
823 RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space);
827 * Enqueue several objects on a ring (NOT multi-producers safe).
830 * A pointer to the ring structure.
832 * A pointer to a table of void * pointers (objects).
834 * The number of objects to add in the ring from the obj_table.
836 * if non-NULL, returns the amount of space in the ring after the
837 * enqueue operation has finished.
839 * - n: Actual number of objects enqueued.
841 static __rte_always_inline unsigned
842 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
843 unsigned int n, unsigned int *free_space)
845 return __rte_ring_do_enqueue(r, obj_table, n,
846 RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space);
850 * Enqueue several objects on a ring.
852 * This function calls the multi-producer or the single-producer
853 * version depending on the default behavior that was specified at
854 * ring creation time (see flags).
857 * A pointer to the ring structure.
859 * A pointer to a table of void * pointers (objects).
861 * The number of objects to add in the ring from the obj_table.
863 * if non-NULL, returns the amount of space in the ring after the
864 * enqueue operation has finished.
866 * - n: Actual number of objects enqueued.
868 static __rte_always_inline unsigned
869 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
870 unsigned int n, unsigned int *free_space)
872 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE,
873 r->prod.single, free_space);
877 * Dequeue several objects from a ring (multi-consumers safe). When the request
878 * objects are more than the available objects, only dequeue the actual number
881 * This function uses a "compare and set" instruction to move the
882 * consumer index atomically.
885 * A pointer to the ring structure.
887 * A pointer to a table of void * pointers (objects) that will be filled.
889 * The number of objects to dequeue from the ring to the obj_table.
891 * If non-NULL, returns the number of remaining ring entries after the
892 * dequeue has finished.
894 * - n: Actual number of objects dequeued, 0 if ring is empty
896 static __rte_always_inline unsigned
897 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
898 unsigned int n, unsigned int *available)
900 return __rte_ring_do_dequeue(r, obj_table, n,
901 RTE_RING_QUEUE_VARIABLE, __IS_MC, available);
905 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
906 * request objects are more than the available objects, only dequeue the
907 * actual number of objects
910 * A pointer to the ring structure.
912 * A pointer to a table of void * pointers (objects) that will be filled.
914 * The number of objects to dequeue from the ring to the obj_table.
916 * If non-NULL, returns the number of remaining ring entries after the
917 * dequeue has finished.
919 * - n: Actual number of objects dequeued, 0 if ring is empty
921 static __rte_always_inline unsigned
922 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
923 unsigned int n, unsigned int *available)
925 return __rte_ring_do_dequeue(r, obj_table, n,
926 RTE_RING_QUEUE_VARIABLE, __IS_SC, available);
930 * Dequeue multiple objects from a ring up to a maximum number.
932 * This function calls the multi-consumers or the single-consumer
933 * version, depending on the default behaviour that was specified at
934 * ring creation time (see flags).
937 * A pointer to the ring structure.
939 * A pointer to a table of void * pointers (objects) that will be filled.
941 * The number of objects to dequeue from the ring to the obj_table.
943 * If non-NULL, returns the number of remaining ring entries after the
944 * dequeue has finished.
946 * - Number of objects dequeued
948 static __rte_always_inline unsigned
949 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
950 unsigned int n, unsigned int *available)
952 return __rte_ring_do_dequeue(r, obj_table, n,
953 RTE_RING_QUEUE_VARIABLE,
954 r->cons.single, available);
961 #endif /* _RTE_RING_H_ */