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 #if RTE_CACHE_LINE_SIZE < 128
66 #define PROD_ALIGN (RTE_CACHE_LINE_SIZE * 2)
67 #define CONS_ALIGN (RTE_CACHE_LINE_SIZE * 2)
69 #define PROD_ALIGN RTE_CACHE_LINE_SIZE
70 #define CONS_ALIGN RTE_CACHE_LINE_SIZE
73 /* structure to hold a pair of head/tail values and other metadata */
74 struct rte_ring_headtail {
75 volatile uint32_t head; /**< Prod/consumer head. */
76 volatile uint32_t tail; /**< Prod/consumer tail. */
77 uint32_t single; /**< True if single prod/cons */
81 * An RTE ring structure.
83 * The producer and the consumer have a head and a tail index. The particularity
84 * of these index is that they are not between 0 and size(ring). These indexes
85 * are between 0 and 2^32, and we mask their value when we access the ring[]
86 * field. Thanks to this assumption, we can do subtractions between 2 index
87 * values in a modulo-32bit base: that's why the overflow of the indexes is not
92 * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
93 * compatibility requirements, it could be changed to RTE_RING_NAMESIZE
94 * next time the ABI changes
96 char name[RTE_MEMZONE_NAMESIZE] __rte_cache_aligned; /**< Name of the ring. */
97 int flags; /**< Flags supplied at creation. */
98 const struct rte_memzone *memzone;
99 /**< Memzone, if any, containing the rte_ring */
100 uint32_t size; /**< Size of ring. */
101 uint32_t mask; /**< Mask (size-1) of ring. */
102 uint32_t capacity; /**< Usable size of ring */
104 /** Ring producer status. */
105 struct rte_ring_headtail prod __rte_aligned(PROD_ALIGN);
107 /** Ring consumer status. */
108 struct rte_ring_headtail cons __rte_aligned(CONS_ALIGN);
111 #define RING_F_SP_ENQ 0x0001 /**< The default enqueue is "single-producer". */
112 #define RING_F_SC_DEQ 0x0002 /**< The default dequeue is "single-consumer". */
114 * Ring is to hold exactly requested number of entries.
115 * Without this flag set, the ring size requested must be a power of 2, and the
116 * usable space will be that size - 1. With the flag, the requested size will
117 * be rounded up to the next power of two, but the usable space will be exactly
118 * that requested. Worst case, if a power-of-2 size is requested, half the
119 * ring space will be wasted.
121 #define RING_F_EXACT_SZ 0x0004
122 #define RTE_RING_SZ_MASK (0x7fffffffU) /**< Ring size mask */
124 /* @internal defines for passing to the enqueue dequeue worker functions */
131 * Calculate the memory size needed for a ring
133 * This function returns the number of bytes needed for a ring, given
134 * the number of elements in it. This value is the sum of the size of
135 * the structure rte_ring and the size of the memory needed by the
136 * objects pointers. The value is aligned to a cache line size.
139 * The number of elements in the ring (must be a power of 2).
141 * - The memory size needed for the ring on success.
142 * - -EINVAL if count is not a power of 2.
144 ssize_t rte_ring_get_memsize(unsigned count);
147 * Initialize a ring structure.
149 * Initialize a ring structure in memory pointed by "r". The size of the
150 * memory area must be large enough to store the ring structure and the
151 * object table. It is advised to use rte_ring_get_memsize() to get the
154 * The ring size is set to *count*, which must be a power of two. Water
155 * marking is disabled by default. The real usable ring size is
156 * *count-1* instead of *count* to differentiate a free ring from an
159 * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
160 * memory given by the caller may not be shareable among dpdk
164 * The pointer to the ring structure followed by the objects table.
166 * The name of the ring.
168 * The number of elements in the ring (must be a power of 2).
170 * An OR of the following:
171 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
172 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
173 * is "single-producer". Otherwise, it is "multi-producers".
174 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
175 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
176 * is "single-consumer". Otherwise, it is "multi-consumers".
178 * 0 on success, or a negative value on error.
180 int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
184 * Create a new ring named *name* in memory.
186 * This function uses ``memzone_reserve()`` to allocate memory. Then it
187 * calls rte_ring_init() to initialize an empty ring.
189 * The new ring size is set to *count*, which must be a power of
190 * two. Water marking is disabled by default. The real usable ring size
191 * is *count-1* instead of *count* to differentiate a free ring from an
194 * The ring is added in RTE_TAILQ_RING list.
197 * The name of the ring.
199 * The size of the ring (must be a power of 2).
201 * The *socket_id* argument is the socket identifier in case of
202 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
203 * constraint for the reserved zone.
205 * An OR of the following:
206 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
207 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
208 * is "single-producer". Otherwise, it is "multi-producers".
209 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
210 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
211 * is "single-consumer". Otherwise, it is "multi-consumers".
213 * On success, the pointer to the new allocated ring. NULL on error with
214 * rte_errno set appropriately. Possible errno values include:
215 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
216 * - E_RTE_SECONDARY - function was called from a secondary process instance
217 * - EINVAL - count provided is not a power of 2
218 * - ENOSPC - the maximum number of memzones has already been allocated
219 * - EEXIST - a memzone with the same name already exists
220 * - ENOMEM - no appropriate memory area found in which to create memzone
222 struct rte_ring *rte_ring_create(const char *name, unsigned count,
223 int socket_id, unsigned flags);
225 * De-allocate all memory used by the ring.
230 void rte_ring_free(struct rte_ring *r);
233 * Dump the status of the ring to a file.
236 * A pointer to a file for output
238 * A pointer to the ring structure.
240 void rte_ring_dump(FILE *f, const struct rte_ring *r);
242 /* the actual enqueue of pointers on the ring.
243 * Placed here since identical code needed in both
244 * single and multi producer enqueue functions */
245 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
247 const uint32_t size = (r)->size; \
248 uint32_t idx = prod_head & (r)->mask; \
249 obj_type *ring = (obj_type *)ring_start; \
250 if (likely(idx + n < size)) { \
251 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
252 ring[idx] = obj_table[i]; \
253 ring[idx+1] = obj_table[i+1]; \
254 ring[idx+2] = obj_table[i+2]; \
255 ring[idx+3] = obj_table[i+3]; \
259 ring[idx++] = obj_table[i++]; /* fallthrough */ \
261 ring[idx++] = obj_table[i++]; /* fallthrough */ \
263 ring[idx++] = obj_table[i++]; \
266 for (i = 0; idx < size; i++, idx++)\
267 ring[idx] = obj_table[i]; \
268 for (idx = 0; i < n; i++, idx++) \
269 ring[idx] = obj_table[i]; \
273 /* the actual copy of pointers on the ring to obj_table.
274 * Placed here since identical code needed in both
275 * single and multi consumer dequeue functions */
276 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
278 uint32_t idx = cons_head & (r)->mask; \
279 const uint32_t size = (r)->size; \
280 obj_type *ring = (obj_type *)ring_start; \
281 if (likely(idx + n < size)) { \
282 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
283 obj_table[i] = ring[idx]; \
284 obj_table[i+1] = ring[idx+1]; \
285 obj_table[i+2] = ring[idx+2]; \
286 obj_table[i+3] = ring[idx+3]; \
290 obj_table[i++] = ring[idx++]; /* fallthrough */ \
292 obj_table[i++] = ring[idx++]; /* fallthrough */ \
294 obj_table[i++] = ring[idx++]; \
297 for (i = 0; idx < size; i++, idx++) \
298 obj_table[i] = ring[idx]; \
299 for (idx = 0; i < n; i++, idx++) \
300 obj_table[i] = ring[idx]; \
304 /* Between load and load. there might be cpu reorder in weak model
306 * There are 2 choices for the users
307 * 1.use rmb() memory barrier
308 * 2.use one-direcion load_acquire/store_release barrier,defined by
309 * CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
310 * It depends on performance test results.
311 * By default, move common functions to rte_ring_generic.h
313 #ifdef RTE_RING_USE_C11_MEM_MODEL
314 #include "rte_ring_c11_mem.h"
316 #include "rte_ring_generic.h"
320 * @internal Enqueue several objects on the ring
323 * A pointer to the ring structure.
325 * A pointer to a table of void * pointers (objects).
327 * The number of objects to add in the ring from the obj_table.
329 * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
330 * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
332 * Indicates whether to use single producer or multi-producer head update
334 * returns the amount of space after the enqueue operation has finished
336 * Actual number of objects enqueued.
337 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
339 static __rte_always_inline unsigned int
340 __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
341 unsigned int n, enum rte_ring_queue_behavior behavior,
342 int is_sp, unsigned int *free_space)
344 uint32_t prod_head, prod_next;
345 uint32_t free_entries;
347 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
348 &prod_head, &prod_next, &free_entries);
352 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, void *);
354 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
356 if (free_space != NULL)
357 *free_space = free_entries - n;
362 * @internal Dequeue several objects from the ring
365 * A pointer to the ring structure.
367 * A pointer to a table of void * pointers (objects).
369 * The number of objects to pull from the ring.
371 * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
372 * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
374 * Indicates whether to use single consumer or multi-consumer head update
376 * returns the number of remaining ring entries after the dequeue has finished
378 * - Actual number of objects dequeued.
379 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
381 static __rte_always_inline unsigned int
382 __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
383 unsigned int n, enum rte_ring_queue_behavior behavior,
384 int is_sc, unsigned int *available)
386 uint32_t cons_head, cons_next;
389 n = __rte_ring_move_cons_head(r, is_sc, n, behavior,
390 &cons_head, &cons_next, &entries);
394 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, void *);
396 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
399 if (available != NULL)
400 *available = entries - n;
405 * Enqueue several objects on the ring (multi-producers safe).
407 * This function uses a "compare and set" instruction to move the
408 * producer index atomically.
411 * A pointer to the ring structure.
413 * A pointer to a table of void * pointers (objects).
415 * The number of objects to add in the ring from the obj_table.
417 * if non-NULL, returns the amount of space in the ring after the
418 * enqueue operation has finished.
420 * The number of objects enqueued, either 0 or n
422 static __rte_always_inline unsigned int
423 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
424 unsigned int n, unsigned int *free_space)
426 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
427 __IS_MP, free_space);
431 * Enqueue several objects on a ring (NOT multi-producers safe).
434 * A pointer to the ring structure.
436 * A pointer to a table of void * pointers (objects).
438 * The number of objects to add in the ring from the obj_table.
440 * if non-NULL, returns the amount of space in the ring after the
441 * enqueue operation has finished.
443 * The number of objects enqueued, either 0 or n
445 static __rte_always_inline unsigned int
446 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
447 unsigned int n, unsigned int *free_space)
449 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
450 __IS_SP, free_space);
454 * Enqueue several objects on a ring.
456 * This function calls the multi-producer or the single-producer
457 * version depending on the default behavior that was specified at
458 * ring creation time (see flags).
461 * A pointer to the ring structure.
463 * A pointer to a table of void * pointers (objects).
465 * The number of objects to add in the ring from the obj_table.
467 * if non-NULL, returns the amount of space in the ring after the
468 * enqueue operation has finished.
470 * The number of objects enqueued, either 0 or n
472 static __rte_always_inline unsigned int
473 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
474 unsigned int n, unsigned int *free_space)
476 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
477 r->prod.single, free_space);
481 * Enqueue one object on a ring (multi-producers safe).
483 * This function uses a "compare and set" instruction to move the
484 * producer index atomically.
487 * A pointer to the ring structure.
489 * A pointer to the object to be added.
491 * - 0: Success; objects enqueued.
492 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
494 static __rte_always_inline int
495 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
497 return rte_ring_mp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
501 * Enqueue one object on a ring (NOT multi-producers safe).
504 * A pointer to the ring structure.
506 * A pointer to the object to be added.
508 * - 0: Success; objects enqueued.
509 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
511 static __rte_always_inline int
512 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
514 return rte_ring_sp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
518 * Enqueue one object on a ring.
520 * This function calls the multi-producer or the single-producer
521 * version, depending on the default behaviour that was specified at
522 * ring creation time (see flags).
525 * A pointer to the ring structure.
527 * A pointer to the object to be added.
529 * - 0: Success; objects enqueued.
530 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
532 static __rte_always_inline int
533 rte_ring_enqueue(struct rte_ring *r, void *obj)
535 return rte_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
539 * Dequeue several objects from a ring (multi-consumers safe).
541 * This function uses a "compare and set" instruction to move the
542 * consumer index atomically.
545 * A pointer to the ring structure.
547 * A pointer to a table of void * pointers (objects) that will be filled.
549 * The number of objects to dequeue from the ring to the obj_table.
551 * If non-NULL, returns the number of remaining ring entries after the
552 * dequeue has finished.
554 * The number of objects dequeued, either 0 or n
556 static __rte_always_inline unsigned int
557 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
558 unsigned int n, unsigned int *available)
560 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
565 * Dequeue several objects from a ring (NOT multi-consumers safe).
568 * A pointer to the ring structure.
570 * A pointer to a table of void * pointers (objects) that will be filled.
572 * The number of objects to dequeue from the ring to the obj_table,
573 * must be strictly positive.
575 * If non-NULL, returns the number of remaining ring entries after the
576 * dequeue has finished.
578 * The number of objects dequeued, either 0 or n
580 static __rte_always_inline unsigned int
581 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
582 unsigned int n, unsigned int *available)
584 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
589 * Dequeue several objects from a ring.
591 * This function calls the multi-consumers or the single-consumer
592 * version, depending on the default behaviour that was specified at
593 * ring creation time (see flags).
596 * A pointer to the ring structure.
598 * A pointer to a table of void * pointers (objects) that will be filled.
600 * The number of objects to dequeue from the ring to the obj_table.
602 * If non-NULL, returns the number of remaining ring entries after the
603 * dequeue has finished.
605 * The number of objects dequeued, either 0 or n
607 static __rte_always_inline unsigned int
608 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
609 unsigned int *available)
611 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
612 r->cons.single, available);
616 * Dequeue one object from a ring (multi-consumers safe).
618 * This function uses a "compare and set" instruction to move the
619 * consumer index atomically.
622 * A pointer to the ring structure.
624 * A pointer to a void * pointer (object) that will be filled.
626 * - 0: Success; objects dequeued.
627 * - -ENOENT: Not enough entries in the ring to dequeue; no object is
630 static __rte_always_inline int
631 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
633 return rte_ring_mc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
637 * Dequeue one object from a ring (NOT multi-consumers safe).
640 * A pointer to the ring structure.
642 * A pointer to a void * pointer (object) that will be filled.
644 * - 0: Success; objects dequeued.
645 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
648 static __rte_always_inline int
649 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
651 return rte_ring_sc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
655 * Dequeue one object from a ring.
657 * This function calls the multi-consumers or the single-consumer
658 * version depending on the default behaviour that was specified at
659 * ring creation time (see flags).
662 * A pointer to the ring structure.
664 * A pointer to a void * pointer (object) that will be filled.
666 * - 0: Success, objects dequeued.
667 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
670 static __rte_always_inline int
671 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
673 return rte_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
677 * Return the number of entries in a ring.
680 * A pointer to the ring structure.
682 * The number of entries in the ring.
684 static inline unsigned
685 rte_ring_count(const struct rte_ring *r)
687 uint32_t prod_tail = r->prod.tail;
688 uint32_t cons_tail = r->cons.tail;
689 uint32_t count = (prod_tail - cons_tail) & r->mask;
690 return (count > r->capacity) ? r->capacity : count;
694 * Return the number of free entries in a ring.
697 * A pointer to the ring structure.
699 * The number of free entries in the ring.
701 static inline unsigned
702 rte_ring_free_count(const struct rte_ring *r)
704 return r->capacity - rte_ring_count(r);
708 * Test if a ring is full.
711 * A pointer to the ring structure.
713 * - 1: The ring is full.
714 * - 0: The ring is not full.
717 rte_ring_full(const struct rte_ring *r)
719 return rte_ring_free_count(r) == 0;
723 * Test if a ring is empty.
726 * A pointer to the ring structure.
728 * - 1: The ring is empty.
729 * - 0: The ring is not empty.
732 rte_ring_empty(const struct rte_ring *r)
734 return rte_ring_count(r) == 0;
738 * Return the size of the ring.
741 * A pointer to the ring structure.
743 * The size of the data store used by the ring.
744 * NOTE: this is not the same as the usable space in the ring. To query that
745 * use ``rte_ring_get_capacity()``.
747 static inline unsigned int
748 rte_ring_get_size(const struct rte_ring *r)
754 * Return the number of elements which can be stored in the ring.
757 * A pointer to the ring structure.
759 * The usable size of the ring.
761 static inline unsigned int
762 rte_ring_get_capacity(const struct rte_ring *r)
768 * Dump the status of all rings on the console
771 * A pointer to a file for output
773 void rte_ring_list_dump(FILE *f);
776 * Search a ring from its name
779 * The name of the ring.
781 * The pointer to the ring matching the name, or NULL if not found,
782 * with rte_errno set appropriately. Possible rte_errno values include:
783 * - ENOENT - required entry not available to return.
785 struct rte_ring *rte_ring_lookup(const char *name);
788 * Enqueue several objects on the ring (multi-producers safe).
790 * This function uses a "compare and set" instruction to move the
791 * producer index atomically.
794 * A pointer to the ring structure.
796 * A pointer to a table of void * pointers (objects).
798 * The number of objects to add in the ring from the obj_table.
800 * if non-NULL, returns the amount of space in the ring after the
801 * enqueue operation has finished.
803 * - n: Actual number of objects enqueued.
805 static __rte_always_inline unsigned
806 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
807 unsigned int n, unsigned int *free_space)
809 return __rte_ring_do_enqueue(r, obj_table, n,
810 RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space);
814 * Enqueue several objects on a ring (NOT multi-producers safe).
817 * A pointer to the ring structure.
819 * A pointer to a table of void * pointers (objects).
821 * The number of objects to add in the ring from the obj_table.
823 * if non-NULL, returns the amount of space in the ring after the
824 * enqueue operation has finished.
826 * - n: Actual number of objects enqueued.
828 static __rte_always_inline unsigned
829 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
830 unsigned int n, unsigned int *free_space)
832 return __rte_ring_do_enqueue(r, obj_table, n,
833 RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space);
837 * Enqueue several objects on a ring.
839 * This function calls the multi-producer or the single-producer
840 * version depending on the default behavior that was specified at
841 * ring creation time (see flags).
844 * A pointer to the ring structure.
846 * A pointer to a table of void * pointers (objects).
848 * The number of objects to add in the ring from the obj_table.
850 * if non-NULL, returns the amount of space in the ring after the
851 * enqueue operation has finished.
853 * - n: Actual number of objects enqueued.
855 static __rte_always_inline unsigned
856 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
857 unsigned int n, unsigned int *free_space)
859 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE,
860 r->prod.single, free_space);
864 * Dequeue several objects from a ring (multi-consumers safe). When the request
865 * objects are more than the available objects, only dequeue the actual number
868 * This function uses a "compare and set" instruction to move the
869 * consumer index atomically.
872 * A pointer to the ring structure.
874 * A pointer to a table of void * pointers (objects) that will be filled.
876 * The number of objects to dequeue from the ring to the obj_table.
878 * If non-NULL, returns the number of remaining ring entries after the
879 * dequeue has finished.
881 * - n: Actual number of objects dequeued, 0 if ring is empty
883 static __rte_always_inline unsigned
884 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
885 unsigned int n, unsigned int *available)
887 return __rte_ring_do_dequeue(r, obj_table, n,
888 RTE_RING_QUEUE_VARIABLE, __IS_MC, available);
892 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
893 * request objects are more than the available objects, only dequeue the
894 * actual number of objects
897 * A pointer to the ring structure.
899 * A pointer to a table of void * pointers (objects) that will be filled.
901 * The number of objects to dequeue from the ring to the obj_table.
903 * If non-NULL, returns the number of remaining ring entries after the
904 * dequeue has finished.
906 * - n: Actual number of objects dequeued, 0 if ring is empty
908 static __rte_always_inline unsigned
909 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
910 unsigned int n, unsigned int *available)
912 return __rte_ring_do_dequeue(r, obj_table, n,
913 RTE_RING_QUEUE_VARIABLE, __IS_SC, available);
917 * Dequeue multiple objects from a ring up to a maximum number.
919 * This function calls the multi-consumers or the single-consumer
920 * version, depending on the default behaviour that was specified at
921 * ring creation time (see flags).
924 * A pointer to the ring structure.
926 * A pointer to a table of void * pointers (objects) that will be filled.
928 * The number of objects to dequeue from the ring to the obj_table.
930 * If non-NULL, returns the number of remaining ring entries after the
931 * dequeue has finished.
933 * - Number of objects dequeued
935 static __rte_always_inline unsigned
936 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
937 unsigned int n, unsigned int *available)
939 return __rte_ring_do_dequeue(r, obj_table, n,
940 RTE_RING_QUEUE_VARIABLE,
941 r->cons.single, available);
948 #endif /* _RTE_RING_H_ */