1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2010-2020 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.
39 #include <rte_ring_core.h>
42 * Calculate the memory size needed for a ring
44 * This function returns the number of bytes needed for a ring, given
45 * the number of elements in it. This value is the sum of the size of
46 * the structure rte_ring and the size of the memory needed by the
47 * objects pointers. The value is aligned to a cache line size.
50 * The number of elements in the ring (must be a power of 2).
52 * - The memory size needed for the ring on success.
53 * - -EINVAL if count is not a power of 2.
55 ssize_t rte_ring_get_memsize(unsigned count);
58 * Initialize a ring structure.
60 * Initialize a ring structure in memory pointed by "r". The size of the
61 * memory area must be large enough to store the ring structure and the
62 * object table. It is advised to use rte_ring_get_memsize() to get the
65 * The ring size is set to *count*, which must be a power of two. Water
66 * marking is disabled by default. The real usable ring size is
67 * *count-1* instead of *count* to differentiate a free ring from an
70 * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
71 * memory given by the caller may not be shareable among dpdk
75 * The pointer to the ring structure followed by the objects table.
77 * The name of the ring.
79 * The number of elements in the ring (must be a power of 2).
81 * An OR of the following:
82 * - One of mutually exclusive flags that define producer behavior:
83 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
84 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
85 * is "single-producer".
86 * - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
87 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
88 * is "multi-producer RTS mode".
89 * If none of these flags is set, then default "multi-producer"
90 * behavior is selected.
91 * - One of mutually exclusive flags that define consumer behavior:
92 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
93 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
94 * is "single-consumer". Otherwise, it is "multi-consumers".
95 * - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
96 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
97 * is "multi-consumer RTS mode".
98 * If none of these flags is set, then default "multi-consumer"
99 * behavior is selected.
101 * 0 on success, or a negative value on error.
103 int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
107 * Create a new ring named *name* in memory.
109 * This function uses ``memzone_reserve()`` to allocate memory. Then it
110 * calls rte_ring_init() to initialize an empty ring.
112 * The new ring size is set to *count*, which must be a power of
113 * two. Water marking is disabled by default. The real usable ring size
114 * is *count-1* instead of *count* to differentiate a free ring from an
117 * The ring is added in RTE_TAILQ_RING list.
120 * The name of the ring.
122 * The size of the ring (must be a power of 2).
124 * The *socket_id* argument is the socket identifier in case of
125 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
126 * constraint for the reserved zone.
128 * An OR of the following:
129 * - One of mutually exclusive flags that define producer behavior:
130 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
131 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
132 * is "single-producer".
133 * - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
134 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
135 * is "multi-producer RTS mode".
136 * If none of these flags is set, then default "multi-producer"
137 * behavior is selected.
138 * - One of mutually exclusive flags that define consumer behavior:
139 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
140 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
141 * is "single-consumer". Otherwise, it is "multi-consumers".
142 * - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
143 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
144 * is "multi-consumer RTS mode".
145 * If none of these flags is set, then default "multi-consumer"
146 * behavior is selected.
148 * On success, the pointer to the new allocated ring. NULL on error with
149 * rte_errno set appropriately. Possible errno values include:
150 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
151 * - E_RTE_SECONDARY - function was called from a secondary process instance
152 * - EINVAL - count provided is not a power of 2
153 * - ENOSPC - the maximum number of memzones has already been allocated
154 * - EEXIST - a memzone with the same name already exists
155 * - ENOMEM - no appropriate memory area found in which to create memzone
157 struct rte_ring *rte_ring_create(const char *name, unsigned count,
158 int socket_id, unsigned flags);
161 * De-allocate all memory used by the ring.
166 void rte_ring_free(struct rte_ring *r);
169 * Dump the status of the ring to a file.
172 * A pointer to a file for output
174 * A pointer to the ring structure.
176 void rte_ring_dump(FILE *f, const struct rte_ring *r);
178 /* the actual enqueue of pointers on the ring.
179 * Placed here since identical code needed in both
180 * single and multi producer enqueue functions */
181 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
183 const uint32_t size = (r)->size; \
184 uint32_t idx = prod_head & (r)->mask; \
185 obj_type *ring = (obj_type *)ring_start; \
186 if (likely(idx + n < size)) { \
187 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
188 ring[idx] = obj_table[i]; \
189 ring[idx+1] = obj_table[i+1]; \
190 ring[idx+2] = obj_table[i+2]; \
191 ring[idx+3] = obj_table[i+3]; \
195 ring[idx++] = obj_table[i++]; /* fallthrough */ \
197 ring[idx++] = obj_table[i++]; /* fallthrough */ \
199 ring[idx++] = obj_table[i++]; \
202 for (i = 0; idx < size; i++, idx++)\
203 ring[idx] = obj_table[i]; \
204 for (idx = 0; i < n; i++, idx++) \
205 ring[idx] = obj_table[i]; \
209 /* the actual copy of pointers on the ring to obj_table.
210 * Placed here since identical code needed in both
211 * single and multi consumer dequeue functions */
212 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
214 uint32_t idx = cons_head & (r)->mask; \
215 const uint32_t size = (r)->size; \
216 obj_type *ring = (obj_type *)ring_start; \
217 if (likely(idx + n < size)) { \
218 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
219 obj_table[i] = ring[idx]; \
220 obj_table[i+1] = ring[idx+1]; \
221 obj_table[i+2] = ring[idx+2]; \
222 obj_table[i+3] = ring[idx+3]; \
226 obj_table[i++] = ring[idx++]; /* fallthrough */ \
228 obj_table[i++] = ring[idx++]; /* fallthrough */ \
230 obj_table[i++] = ring[idx++]; \
233 for (i = 0; idx < size; i++, idx++) \
234 obj_table[i] = ring[idx]; \
235 for (idx = 0; i < n; i++, idx++) \
236 obj_table[i] = ring[idx]; \
240 /* Between load and load. there might be cpu reorder in weak model
242 * There are 2 choices for the users
243 * 1.use rmb() memory barrier
244 * 2.use one-direction load_acquire/store_release barrier,defined by
245 * CONFIG_RTE_USE_C11_MEM_MODEL=y
246 * It depends on performance test results.
247 * By default, move common functions to rte_ring_generic.h
249 #ifdef RTE_USE_C11_MEM_MODEL
250 #include "rte_ring_c11_mem.h"
252 #include "rte_ring_generic.h"
256 * @internal Enqueue several objects on the ring
259 * A pointer to the ring structure.
261 * A pointer to a table of void * pointers (objects).
263 * The number of objects to add in the ring from the obj_table.
265 * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
266 * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
268 * Indicates whether to use single producer or multi-producer head update
270 * returns the amount of space after the enqueue operation has finished
272 * Actual number of objects enqueued.
273 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
275 static __rte_always_inline unsigned int
276 __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
277 unsigned int n, enum rte_ring_queue_behavior behavior,
278 unsigned int is_sp, unsigned int *free_space)
280 uint32_t prod_head, prod_next;
281 uint32_t free_entries;
283 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
284 &prod_head, &prod_next, &free_entries);
288 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, void *);
290 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
292 if (free_space != NULL)
293 *free_space = free_entries - n;
298 * @internal Dequeue several objects from the ring
301 * A pointer to the ring structure.
303 * A pointer to a table of void * pointers (objects).
305 * The number of objects to pull from the ring.
307 * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
308 * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
310 * Indicates whether to use single consumer or multi-consumer head update
312 * returns the number of remaining ring entries after the dequeue has finished
314 * - Actual number of objects dequeued.
315 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
317 static __rte_always_inline unsigned int
318 __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
319 unsigned int n, enum rte_ring_queue_behavior behavior,
320 unsigned int is_sc, unsigned int *available)
322 uint32_t cons_head, cons_next;
325 n = __rte_ring_move_cons_head(r, (int)is_sc, n, behavior,
326 &cons_head, &cons_next, &entries);
330 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, void *);
332 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
335 if (available != NULL)
336 *available = entries - n;
341 * Enqueue several objects on the ring (multi-producers safe).
343 * This function uses a "compare and set" instruction to move the
344 * producer index atomically.
347 * A pointer to the ring structure.
349 * A pointer to a table of void * pointers (objects).
351 * The number of objects to add in the ring from the obj_table.
353 * if non-NULL, returns the amount of space in the ring after the
354 * enqueue operation has finished.
356 * The number of objects enqueued, either 0 or n
358 static __rte_always_inline unsigned int
359 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
360 unsigned int n, unsigned int *free_space)
362 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
363 RTE_RING_SYNC_MT, free_space);
367 * Enqueue several objects on a ring (NOT multi-producers safe).
370 * A pointer to the ring structure.
372 * A pointer to a table of void * pointers (objects).
374 * The number of objects to add in the ring from the obj_table.
376 * if non-NULL, returns the amount of space in the ring after the
377 * enqueue operation has finished.
379 * The number of objects enqueued, either 0 or n
381 static __rte_always_inline unsigned int
382 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
383 unsigned int n, unsigned int *free_space)
385 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
386 RTE_RING_SYNC_ST, free_space);
389 #ifdef ALLOW_EXPERIMENTAL_API
390 #include <rte_ring_elem.h>
394 * Enqueue several objects on a ring.
396 * This function calls the multi-producer or the single-producer
397 * version depending on the default behavior that was specified at
398 * ring creation time (see flags).
401 * A pointer to the ring structure.
403 * A pointer to a table of void * pointers (objects).
405 * The number of objects to add in the ring from the obj_table.
407 * if non-NULL, returns the amount of space in the ring after the
408 * enqueue operation has finished.
410 * The number of objects enqueued, either 0 or n
412 static __rte_always_inline unsigned int
413 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
414 unsigned int n, unsigned int *free_space)
416 switch (r->prod.sync_type) {
417 case RTE_RING_SYNC_MT:
418 return rte_ring_mp_enqueue_bulk(r, obj_table, n, free_space);
419 case RTE_RING_SYNC_ST:
420 return rte_ring_sp_enqueue_bulk(r, obj_table, n, free_space);
421 #ifdef ALLOW_EXPERIMENTAL_API
422 case RTE_RING_SYNC_MT_RTS:
423 return rte_ring_mp_rts_enqueue_bulk(r, obj_table, n,
428 /* valid ring should never reach this point */
434 * Enqueue one object on a ring (multi-producers safe).
436 * This function uses a "compare and set" instruction to move the
437 * producer index atomically.
440 * A pointer to the ring structure.
442 * A pointer to the object to be added.
444 * - 0: Success; objects enqueued.
445 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
447 static __rte_always_inline int
448 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
450 return rte_ring_mp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
454 * Enqueue one object on a ring (NOT multi-producers safe).
457 * A pointer to the ring structure.
459 * A pointer to the object to be added.
461 * - 0: Success; objects enqueued.
462 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
464 static __rte_always_inline int
465 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
467 return rte_ring_sp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
471 * Enqueue one object on a ring.
473 * This function calls the multi-producer or the single-producer
474 * version, depending on the default behaviour that was specified at
475 * ring creation time (see flags).
478 * A pointer to the ring structure.
480 * A pointer to the object to be added.
482 * - 0: Success; objects enqueued.
483 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
485 static __rte_always_inline int
486 rte_ring_enqueue(struct rte_ring *r, void *obj)
488 return rte_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
492 * Dequeue several objects from a ring (multi-consumers safe).
494 * This function uses a "compare and set" instruction to move the
495 * consumer index atomically.
498 * A pointer to the ring structure.
500 * A pointer to a table of void * pointers (objects) that will be filled.
502 * The number of objects to dequeue from the ring to the obj_table.
504 * If non-NULL, returns the number of remaining ring entries after the
505 * dequeue has finished.
507 * The number of objects dequeued, either 0 or n
509 static __rte_always_inline unsigned int
510 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
511 unsigned int n, unsigned int *available)
513 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
514 RTE_RING_SYNC_MT, available);
518 * Dequeue several objects from a ring (NOT multi-consumers safe).
521 * A pointer to the ring structure.
523 * A pointer to a table of void * pointers (objects) that will be filled.
525 * The number of objects to dequeue from the ring to the obj_table,
526 * must be strictly positive.
528 * If non-NULL, returns the number of remaining ring entries after the
529 * dequeue has finished.
531 * The number of objects dequeued, either 0 or n
533 static __rte_always_inline unsigned int
534 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
535 unsigned int n, unsigned int *available)
537 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
538 RTE_RING_SYNC_ST, available);
542 * Dequeue several objects from a ring.
544 * This function calls the multi-consumers or the single-consumer
545 * version, depending on the default behaviour that was specified at
546 * ring creation time (see flags).
549 * A pointer to the ring structure.
551 * A pointer to a table of void * pointers (objects) that will be filled.
553 * The number of objects to dequeue from the ring to the obj_table.
555 * If non-NULL, returns the number of remaining ring entries after the
556 * dequeue has finished.
558 * The number of objects dequeued, either 0 or n
560 static __rte_always_inline unsigned int
561 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
562 unsigned int *available)
564 switch (r->cons.sync_type) {
565 case RTE_RING_SYNC_MT:
566 return rte_ring_mc_dequeue_bulk(r, obj_table, n, available);
567 case RTE_RING_SYNC_ST:
568 return rte_ring_sc_dequeue_bulk(r, obj_table, n, available);
569 #ifdef ALLOW_EXPERIMENTAL_API
570 case RTE_RING_SYNC_MT_RTS:
571 return rte_ring_mc_rts_dequeue_bulk(r, obj_table, n, available);
575 /* valid ring should never reach this point */
581 * Dequeue one object from a ring (multi-consumers safe).
583 * This function uses a "compare and set" instruction to move the
584 * consumer index atomically.
587 * A pointer to the ring structure.
589 * A pointer to a void * pointer (object) that will be filled.
591 * - 0: Success; objects dequeued.
592 * - -ENOENT: Not enough entries in the ring to dequeue; no object is
595 static __rte_always_inline int
596 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
598 return rte_ring_mc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
602 * Dequeue one object from a ring (NOT multi-consumers safe).
605 * A pointer to the ring structure.
607 * A pointer to a void * pointer (object) that will be filled.
609 * - 0: Success; objects dequeued.
610 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
613 static __rte_always_inline int
614 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
616 return rte_ring_sc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
620 * Dequeue one object from a ring.
622 * This function calls the multi-consumers or the single-consumer
623 * version depending on the default behaviour that was specified at
624 * ring creation time (see flags).
627 * A pointer to the ring structure.
629 * A pointer to a void * pointer (object) that will be filled.
631 * - 0: Success, objects dequeued.
632 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
635 static __rte_always_inline int
636 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
638 return rte_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
644 * This function flush all the elements in a ring
646 * @b EXPERIMENTAL: this API may change without prior notice
649 * Make sure the ring is not in use while calling this function.
652 * A pointer to the ring structure.
656 rte_ring_reset(struct rte_ring *r);
659 * Return the number of entries in a ring.
662 * A pointer to the ring structure.
664 * The number of entries in the ring.
666 static inline unsigned
667 rte_ring_count(const struct rte_ring *r)
669 uint32_t prod_tail = r->prod.tail;
670 uint32_t cons_tail = r->cons.tail;
671 uint32_t count = (prod_tail - cons_tail) & r->mask;
672 return (count > r->capacity) ? r->capacity : count;
676 * Return the number of free entries in a ring.
679 * A pointer to the ring structure.
681 * The number of free entries in the ring.
683 static inline unsigned
684 rte_ring_free_count(const struct rte_ring *r)
686 return r->capacity - rte_ring_count(r);
690 * Test if a ring is full.
693 * A pointer to the ring structure.
695 * - 1: The ring is full.
696 * - 0: The ring is not full.
699 rte_ring_full(const struct rte_ring *r)
701 return rte_ring_free_count(r) == 0;
705 * Test if a ring is empty.
708 * A pointer to the ring structure.
710 * - 1: The ring is empty.
711 * - 0: The ring is not empty.
714 rte_ring_empty(const struct rte_ring *r)
716 return rte_ring_count(r) == 0;
720 * Return the size of the ring.
723 * A pointer to the ring structure.
725 * The size of the data store used by the ring.
726 * NOTE: this is not the same as the usable space in the ring. To query that
727 * use ``rte_ring_get_capacity()``.
729 static inline unsigned int
730 rte_ring_get_size(const struct rte_ring *r)
736 * Return the number of elements which can be stored in the ring.
739 * A pointer to the ring structure.
741 * The usable size of the ring.
743 static inline unsigned int
744 rte_ring_get_capacity(const struct rte_ring *r)
750 * Return sync type used by producer in the ring.
753 * A pointer to the ring structure.
755 * Producer sync type value.
757 static inline enum rte_ring_sync_type
758 rte_ring_get_prod_sync_type(const struct rte_ring *r)
760 return r->prod.sync_type;
764 * Check is the ring for single producer.
767 * A pointer to the ring structure.
769 * true if ring is SP, zero otherwise.
772 rte_ring_is_prod_single(const struct rte_ring *r)
774 return (rte_ring_get_prod_sync_type(r) == RTE_RING_SYNC_ST);
778 * Return sync type used by consumer in the ring.
781 * A pointer to the ring structure.
783 * Consumer sync type value.
785 static inline enum rte_ring_sync_type
786 rte_ring_get_cons_sync_type(const struct rte_ring *r)
788 return r->cons.sync_type;
792 * Check is the ring for single consumer.
795 * A pointer to the ring structure.
797 * true if ring is SC, zero otherwise.
800 rte_ring_is_cons_single(const struct rte_ring *r)
802 return (rte_ring_get_cons_sync_type(r) == RTE_RING_SYNC_ST);
806 * Dump the status of all rings on the console
809 * A pointer to a file for output
811 void rte_ring_list_dump(FILE *f);
814 * Search a ring from its name
817 * The name of the ring.
819 * The pointer to the ring matching the name, or NULL if not found,
820 * with rte_errno set appropriately. Possible rte_errno values include:
821 * - ENOENT - required entry not available to return.
823 struct rte_ring *rte_ring_lookup(const char *name);
826 * Enqueue several objects on the ring (multi-producers safe).
828 * This function uses a "compare and set" instruction to move the
829 * producer index atomically.
832 * A pointer to the ring structure.
834 * A pointer to a table of void * pointers (objects).
836 * The number of objects to add in the ring from the obj_table.
838 * if non-NULL, returns the amount of space in the ring after the
839 * enqueue operation has finished.
841 * - n: Actual number of objects enqueued.
843 static __rte_always_inline unsigned
844 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
845 unsigned int n, unsigned int *free_space)
847 return __rte_ring_do_enqueue(r, obj_table, n,
848 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_MT, free_space);
852 * Enqueue several objects on a ring (NOT multi-producers safe).
855 * A pointer to the ring structure.
857 * A pointer to a table of void * pointers (objects).
859 * The number of objects to add in the ring from the obj_table.
861 * if non-NULL, returns the amount of space in the ring after the
862 * enqueue operation has finished.
864 * - n: Actual number of objects enqueued.
866 static __rte_always_inline unsigned
867 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
868 unsigned int n, unsigned int *free_space)
870 return __rte_ring_do_enqueue(r, obj_table, n,
871 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_ST, free_space);
875 * Enqueue several objects on a ring.
877 * This function calls the multi-producer or the single-producer
878 * version depending on the default behavior that was specified at
879 * ring creation time (see flags).
882 * A pointer to the ring structure.
884 * A pointer to a table of void * pointers (objects).
886 * The number of objects to add in the ring from the obj_table.
888 * if non-NULL, returns the amount of space in the ring after the
889 * enqueue operation has finished.
891 * - n: Actual number of objects enqueued.
893 static __rte_always_inline unsigned
894 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
895 unsigned int n, unsigned int *free_space)
897 switch (r->prod.sync_type) {
898 case RTE_RING_SYNC_MT:
899 return rte_ring_mp_enqueue_burst(r, obj_table, n, free_space);
900 case RTE_RING_SYNC_ST:
901 return rte_ring_sp_enqueue_burst(r, obj_table, n, free_space);
902 #ifdef ALLOW_EXPERIMENTAL_API
903 case RTE_RING_SYNC_MT_RTS:
904 return rte_ring_mp_rts_enqueue_burst(r, obj_table, n,
909 /* valid ring should never reach this point */
915 * Dequeue several objects from a ring (multi-consumers safe). When the request
916 * objects are more than the available objects, only dequeue the actual number
919 * This function uses a "compare and set" instruction to move the
920 * consumer index atomically.
923 * A pointer to the ring structure.
925 * A pointer to a table of void * pointers (objects) that will be filled.
927 * The number of objects to dequeue from the ring to the obj_table.
929 * If non-NULL, returns the number of remaining ring entries after the
930 * dequeue has finished.
932 * - n: Actual number of objects dequeued, 0 if ring is empty
934 static __rte_always_inline unsigned
935 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
936 unsigned int n, unsigned int *available)
938 return __rte_ring_do_dequeue(r, obj_table, n,
939 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_MT, available);
943 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
944 * request objects are more than the available objects, only dequeue the
945 * actual number of objects
948 * A pointer to the ring structure.
950 * A pointer to a table of void * pointers (objects) that will be filled.
952 * The number of objects to dequeue from the ring to the obj_table.
954 * If non-NULL, returns the number of remaining ring entries after the
955 * dequeue has finished.
957 * - n: Actual number of objects dequeued, 0 if ring is empty
959 static __rte_always_inline unsigned
960 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
961 unsigned int n, unsigned int *available)
963 return __rte_ring_do_dequeue(r, obj_table, n,
964 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_ST, available);
968 * Dequeue multiple objects from a ring up to a maximum number.
970 * This function calls the multi-consumers or the single-consumer
971 * version, depending on the default behaviour that was specified at
972 * ring creation time (see flags).
975 * A pointer to the ring structure.
977 * A pointer to a table of void * pointers (objects) that will be filled.
979 * The number of objects to dequeue from the ring to the obj_table.
981 * If non-NULL, returns the number of remaining ring entries after the
982 * dequeue has finished.
984 * - Number of objects dequeued
986 static __rte_always_inline unsigned
987 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
988 unsigned int n, unsigned int *available)
990 switch (r->cons.sync_type) {
991 case RTE_RING_SYNC_MT:
992 return rte_ring_mc_dequeue_burst(r, obj_table, n, available);
993 case RTE_RING_SYNC_ST:
994 return rte_ring_sc_dequeue_burst(r, obj_table, n, available);
995 #ifdef ALLOW_EXPERIMENTAL_API
996 case RTE_RING_SYNC_MT_RTS:
997 return rte_ring_mc_rts_dequeue_burst(r, obj_table, n,
1002 /* valid ring should never reach this point */
1011 #endif /* _RTE_RING_H_ */