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.
28 * - Ability to select different sync modes for producer/consumer.
29 * - Dequeue start/finish (depending on consumer sync modes).
30 * - Enqueue start/finish (depending on producer sync mode).
32 * Note: the ring implementation is not preemptible. Refer to Programmer's
33 * guide/Environment Abstraction Layer/Multiple pthread/Known Issues/rte_ring
34 * for more information.
42 #include <rte_ring_core.h>
45 * Calculate the memory size needed for a ring
47 * This function returns the number of bytes needed for a ring, given
48 * the number of elements in it. This value is the sum of the size of
49 * the structure rte_ring and the size of the memory needed by the
50 * objects pointers. The value is aligned to a cache line size.
53 * The number of elements in the ring (must be a power of 2).
55 * - The memory size needed for the ring on success.
56 * - -EINVAL if count is not a power of 2.
58 ssize_t rte_ring_get_memsize(unsigned count);
61 * Initialize a ring structure.
63 * Initialize a ring structure in memory pointed by "r". The size of the
64 * memory area must be large enough to store the ring structure and the
65 * object table. It is advised to use rte_ring_get_memsize() to get the
68 * The ring size is set to *count*, which must be a power of two. Water
69 * marking is disabled by default. The real usable ring size is
70 * *count-1* instead of *count* to differentiate a free ring from an
73 * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
74 * memory given by the caller may not be shareable among dpdk
78 * The pointer to the ring structure followed by the objects table.
80 * The name of the ring.
82 * The number of elements in the ring (must be a power of 2).
84 * An OR of the following:
85 * - One of mutually exclusive flags that define producer behavior:
86 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
87 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
88 * is "single-producer".
89 * - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
90 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
91 * is "multi-producer RTS mode".
92 * - RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when
93 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
94 * is "multi-producer HTS mode".
95 * If none of these flags is set, then default "multi-producer"
96 * behavior is selected.
97 * - One of mutually exclusive flags that define consumer behavior:
98 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
99 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
100 * is "single-consumer". Otherwise, it is "multi-consumers".
101 * - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
102 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
103 * is "multi-consumer RTS mode".
104 * - RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when
105 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
106 * is "multi-consumer HTS mode".
107 * If none of these flags is set, then default "multi-consumer"
108 * behavior is selected.
110 * 0 on success, or a negative value on error.
112 int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
116 * Create a new ring named *name* in memory.
118 * This function uses ``memzone_reserve()`` to allocate memory. Then it
119 * calls rte_ring_init() to initialize an empty ring.
121 * The new ring size is set to *count*, which must be a power of
122 * two. Water marking is disabled by default. The real usable ring size
123 * is *count-1* instead of *count* to differentiate a free ring from an
126 * The ring is added in RTE_TAILQ_RING list.
129 * The name of the ring.
131 * The size of the ring (must be a power of 2).
133 * The *socket_id* argument is the socket identifier in case of
134 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
135 * constraint for the reserved zone.
137 * An OR of the following:
138 * - One of mutually exclusive flags that define producer behavior:
139 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
140 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
141 * is "single-producer".
142 * - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
143 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
144 * is "multi-producer RTS mode".
145 * - RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when
146 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
147 * is "multi-producer HTS mode".
148 * If none of these flags is set, then default "multi-producer"
149 * behavior is selected.
150 * - One of mutually exclusive flags that define consumer behavior:
151 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
152 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
153 * is "single-consumer". Otherwise, it is "multi-consumers".
154 * - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
155 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
156 * is "multi-consumer RTS mode".
157 * - RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when
158 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
159 * is "multi-consumer HTS mode".
160 * If none of these flags is set, then default "multi-consumer"
161 * behavior is selected.
163 * On success, the pointer to the new allocated ring. NULL on error with
164 * rte_errno set appropriately. Possible errno values include:
165 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
166 * - E_RTE_SECONDARY - function was called from a secondary process instance
167 * - EINVAL - count provided is not a power of 2
168 * - ENOSPC - the maximum number of memzones has already been allocated
169 * - EEXIST - a memzone with the same name already exists
170 * - ENOMEM - no appropriate memory area found in which to create memzone
172 struct rte_ring *rte_ring_create(const char *name, unsigned count,
173 int socket_id, unsigned flags);
176 * De-allocate all memory used by the ring.
181 void rte_ring_free(struct rte_ring *r);
184 * Dump the status of the ring to a file.
187 * A pointer to a file for output
189 * A pointer to the ring structure.
191 void rte_ring_dump(FILE *f, const struct rte_ring *r);
193 /* the actual enqueue of pointers on the ring.
194 * Placed here since identical code needed in both
195 * single and multi producer enqueue functions */
196 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
198 const uint32_t size = (r)->size; \
199 uint32_t idx = prod_head & (r)->mask; \
200 obj_type *ring = (obj_type *)ring_start; \
201 if (likely(idx + n < size)) { \
202 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
203 ring[idx] = obj_table[i]; \
204 ring[idx+1] = obj_table[i+1]; \
205 ring[idx+2] = obj_table[i+2]; \
206 ring[idx+3] = obj_table[i+3]; \
210 ring[idx++] = obj_table[i++]; /* fallthrough */ \
212 ring[idx++] = obj_table[i++]; /* fallthrough */ \
214 ring[idx++] = obj_table[i++]; \
217 for (i = 0; idx < size; i++, idx++)\
218 ring[idx] = obj_table[i]; \
219 for (idx = 0; i < n; i++, idx++) \
220 ring[idx] = obj_table[i]; \
224 /* the actual copy of pointers on the ring to obj_table.
225 * Placed here since identical code needed in both
226 * single and multi consumer dequeue functions */
227 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
229 uint32_t idx = cons_head & (r)->mask; \
230 const uint32_t size = (r)->size; \
231 obj_type *ring = (obj_type *)ring_start; \
232 if (likely(idx + n < size)) { \
233 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
234 obj_table[i] = ring[idx]; \
235 obj_table[i+1] = ring[idx+1]; \
236 obj_table[i+2] = ring[idx+2]; \
237 obj_table[i+3] = ring[idx+3]; \
241 obj_table[i++] = ring[idx++]; /* fallthrough */ \
243 obj_table[i++] = ring[idx++]; /* fallthrough */ \
245 obj_table[i++] = ring[idx++]; \
248 for (i = 0; idx < size; i++, idx++) \
249 obj_table[i] = ring[idx]; \
250 for (idx = 0; i < n; i++, idx++) \
251 obj_table[i] = ring[idx]; \
255 /* Between load and load. there might be cpu reorder in weak model
257 * There are 2 choices for the users
258 * 1.use rmb() memory barrier
259 * 2.use one-direction load_acquire/store_release barrier,defined by
260 * CONFIG_RTE_USE_C11_MEM_MODEL=y
261 * It depends on performance test results.
262 * By default, move common functions to rte_ring_generic.h
264 #ifdef RTE_USE_C11_MEM_MODEL
265 #include "rte_ring_c11_mem.h"
267 #include "rte_ring_generic.h"
271 * @internal Enqueue several objects on the ring
274 * A pointer to the ring structure.
276 * A pointer to a table of void * pointers (objects).
278 * The number of objects to add in the ring from the obj_table.
280 * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
281 * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
283 * Indicates whether to use single producer or multi-producer head update
285 * returns the amount of space after the enqueue operation has finished
287 * Actual number of objects enqueued.
288 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
290 static __rte_always_inline unsigned int
291 __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
292 unsigned int n, enum rte_ring_queue_behavior behavior,
293 unsigned int is_sp, unsigned int *free_space)
295 uint32_t prod_head, prod_next;
296 uint32_t free_entries;
298 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
299 &prod_head, &prod_next, &free_entries);
303 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, void *);
305 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
307 if (free_space != NULL)
308 *free_space = free_entries - n;
313 * @internal Dequeue several objects from the ring
316 * A pointer to the ring structure.
318 * A pointer to a table of void * pointers (objects).
320 * The number of objects to pull from the ring.
322 * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
323 * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
325 * Indicates whether to use single consumer or multi-consumer head update
327 * returns the number of remaining ring entries after the dequeue has finished
329 * - Actual number of objects dequeued.
330 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
332 static __rte_always_inline unsigned int
333 __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
334 unsigned int n, enum rte_ring_queue_behavior behavior,
335 unsigned int is_sc, unsigned int *available)
337 uint32_t cons_head, cons_next;
340 n = __rte_ring_move_cons_head(r, (int)is_sc, n, behavior,
341 &cons_head, &cons_next, &entries);
345 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, void *);
347 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
350 if (available != NULL)
351 *available = entries - n;
356 * Enqueue several objects on the ring (multi-producers safe).
358 * This function uses a "compare and set" instruction to move the
359 * producer index atomically.
362 * A pointer to the ring structure.
364 * A pointer to a table of void * pointers (objects).
366 * The number of objects to add in the ring from the obj_table.
368 * if non-NULL, returns the amount of space in the ring after the
369 * enqueue operation has finished.
371 * The number of objects enqueued, either 0 or n
373 static __rte_always_inline unsigned int
374 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
375 unsigned int n, unsigned int *free_space)
377 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
378 RTE_RING_SYNC_MT, free_space);
382 * Enqueue several objects on a ring (NOT multi-producers safe).
385 * A pointer to the ring structure.
387 * A pointer to a table of void * pointers (objects).
389 * The number of objects to add in the ring from the obj_table.
391 * if non-NULL, returns the amount of space in the ring after the
392 * enqueue operation has finished.
394 * The number of objects enqueued, either 0 or n
396 static __rte_always_inline unsigned int
397 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
398 unsigned int n, unsigned int *free_space)
400 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
401 RTE_RING_SYNC_ST, free_space);
404 #ifdef ALLOW_EXPERIMENTAL_API
405 #include <rte_ring_elem.h>
409 * Enqueue several objects on a ring.
411 * This function calls the multi-producer or the single-producer
412 * version depending on the default behavior that was specified at
413 * ring creation time (see flags).
416 * A pointer to the ring structure.
418 * A pointer to a table of void * pointers (objects).
420 * The number of objects to add in the ring from the obj_table.
422 * if non-NULL, returns the amount of space in the ring after the
423 * enqueue operation has finished.
425 * The number of objects enqueued, either 0 or n
427 static __rte_always_inline unsigned int
428 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
429 unsigned int n, unsigned int *free_space)
431 switch (r->prod.sync_type) {
432 case RTE_RING_SYNC_MT:
433 return rte_ring_mp_enqueue_bulk(r, obj_table, n, free_space);
434 case RTE_RING_SYNC_ST:
435 return rte_ring_sp_enqueue_bulk(r, obj_table, n, free_space);
436 #ifdef ALLOW_EXPERIMENTAL_API
437 case RTE_RING_SYNC_MT_RTS:
438 return rte_ring_mp_rts_enqueue_bulk(r, obj_table, n,
440 case RTE_RING_SYNC_MT_HTS:
441 return rte_ring_mp_hts_enqueue_bulk(r, obj_table, n,
446 /* valid ring should never reach this point */
452 * Enqueue one object on a ring (multi-producers safe).
454 * This function uses a "compare and set" instruction to move the
455 * producer index atomically.
458 * A pointer to the ring structure.
460 * A pointer to the object to be added.
462 * - 0: Success; objects enqueued.
463 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
465 static __rte_always_inline int
466 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
468 return rte_ring_mp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
472 * Enqueue one object on a ring (NOT multi-producers safe).
475 * A pointer to the ring structure.
477 * A pointer to the object to be added.
479 * - 0: Success; objects enqueued.
480 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
482 static __rte_always_inline int
483 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
485 return rte_ring_sp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
489 * Enqueue one object on a ring.
491 * This function calls the multi-producer or the single-producer
492 * version, depending on the default behaviour that was specified at
493 * ring creation time (see flags).
496 * A pointer to the ring structure.
498 * A pointer to the object to be added.
500 * - 0: Success; objects enqueued.
501 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
503 static __rte_always_inline int
504 rte_ring_enqueue(struct rte_ring *r, void *obj)
506 return rte_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
510 * Dequeue several objects from a ring (multi-consumers safe).
512 * This function uses a "compare and set" instruction to move the
513 * consumer index atomically.
516 * A pointer to the ring structure.
518 * A pointer to a table of void * pointers (objects) that will be filled.
520 * The number of objects to dequeue from the ring to the obj_table.
522 * If non-NULL, returns the number of remaining ring entries after the
523 * dequeue has finished.
525 * The number of objects dequeued, either 0 or n
527 static __rte_always_inline unsigned int
528 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
529 unsigned int n, unsigned int *available)
531 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
532 RTE_RING_SYNC_MT, available);
536 * Dequeue several objects from a ring (NOT multi-consumers safe).
539 * A pointer to the ring structure.
541 * A pointer to a table of void * pointers (objects) that will be filled.
543 * The number of objects to dequeue from the ring to the obj_table,
544 * must be strictly positive.
546 * If non-NULL, returns the number of remaining ring entries after the
547 * dequeue has finished.
549 * The number of objects dequeued, either 0 or n
551 static __rte_always_inline unsigned int
552 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
553 unsigned int n, unsigned int *available)
555 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
556 RTE_RING_SYNC_ST, available);
560 * Dequeue several objects from a ring.
562 * This function calls the multi-consumers or the single-consumer
563 * version, depending on the default behaviour that was specified at
564 * ring creation time (see flags).
567 * A pointer to the ring structure.
569 * A pointer to a table of void * pointers (objects) that will be filled.
571 * The number of objects to dequeue from the ring to the obj_table.
573 * If non-NULL, returns the number of remaining ring entries after the
574 * dequeue has finished.
576 * The number of objects dequeued, either 0 or n
578 static __rte_always_inline unsigned int
579 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
580 unsigned int *available)
582 switch (r->cons.sync_type) {
583 case RTE_RING_SYNC_MT:
584 return rte_ring_mc_dequeue_bulk(r, obj_table, n, available);
585 case RTE_RING_SYNC_ST:
586 return rte_ring_sc_dequeue_bulk(r, obj_table, n, available);
587 #ifdef ALLOW_EXPERIMENTAL_API
588 case RTE_RING_SYNC_MT_RTS:
589 return rte_ring_mc_rts_dequeue_bulk(r, obj_table, n, available);
590 case RTE_RING_SYNC_MT_HTS:
591 return rte_ring_mc_hts_dequeue_bulk(r, obj_table, n, available);
595 /* valid ring should never reach this point */
601 * Dequeue one object from a ring (multi-consumers safe).
603 * This function uses a "compare and set" instruction to move the
604 * consumer index atomically.
607 * A pointer to the ring structure.
609 * A pointer to a void * pointer (object) that will be filled.
611 * - 0: Success; objects dequeued.
612 * - -ENOENT: Not enough entries in the ring to dequeue; no object is
615 static __rte_always_inline int
616 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
618 return rte_ring_mc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
622 * Dequeue one object from a ring (NOT multi-consumers safe).
625 * A pointer to the ring structure.
627 * A pointer to a void * pointer (object) that will be filled.
629 * - 0: Success; objects dequeued.
630 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
633 static __rte_always_inline int
634 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
636 return rte_ring_sc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
640 * Dequeue one object from a ring.
642 * This function calls the multi-consumers or the single-consumer
643 * version depending on the default behaviour that was specified at
644 * ring creation time (see flags).
647 * A pointer to the ring structure.
649 * A pointer to a void * pointer (object) that will be filled.
651 * - 0: Success, objects dequeued.
652 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
655 static __rte_always_inline int
656 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
658 return rte_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
664 * This function flush all the elements in a ring
666 * @b EXPERIMENTAL: this API may change without prior notice
669 * Make sure the ring is not in use while calling this function.
672 * A pointer to the ring structure.
676 rte_ring_reset(struct rte_ring *r);
679 * Return the number of entries in a ring.
682 * A pointer to the ring structure.
684 * The number of entries in the ring.
686 static inline unsigned
687 rte_ring_count(const struct rte_ring *r)
689 uint32_t prod_tail = r->prod.tail;
690 uint32_t cons_tail = r->cons.tail;
691 uint32_t count = (prod_tail - cons_tail) & r->mask;
692 return (count > r->capacity) ? r->capacity : count;
696 * Return the number of free entries in a ring.
699 * A pointer to the ring structure.
701 * The number of free entries in the ring.
703 static inline unsigned
704 rte_ring_free_count(const struct rte_ring *r)
706 return r->capacity - rte_ring_count(r);
710 * Test if a ring is full.
713 * A pointer to the ring structure.
715 * - 1: The ring is full.
716 * - 0: The ring is not full.
719 rte_ring_full(const struct rte_ring *r)
721 return rte_ring_free_count(r) == 0;
725 * Test if a ring is empty.
728 * A pointer to the ring structure.
730 * - 1: The ring is empty.
731 * - 0: The ring is not empty.
734 rte_ring_empty(const struct rte_ring *r)
736 return rte_ring_count(r) == 0;
740 * Return the size of the ring.
743 * A pointer to the ring structure.
745 * The size of the data store used by the ring.
746 * NOTE: this is not the same as the usable space in the ring. To query that
747 * use ``rte_ring_get_capacity()``.
749 static inline unsigned int
750 rte_ring_get_size(const struct rte_ring *r)
756 * Return the number of elements which can be stored in the ring.
759 * A pointer to the ring structure.
761 * The usable size of the ring.
763 static inline unsigned int
764 rte_ring_get_capacity(const struct rte_ring *r)
770 * Return sync type used by producer in the ring.
773 * A pointer to the ring structure.
775 * Producer sync type value.
777 static inline enum rte_ring_sync_type
778 rte_ring_get_prod_sync_type(const struct rte_ring *r)
780 return r->prod.sync_type;
784 * Check is the ring for single producer.
787 * A pointer to the ring structure.
789 * true if ring is SP, zero otherwise.
792 rte_ring_is_prod_single(const struct rte_ring *r)
794 return (rte_ring_get_prod_sync_type(r) == RTE_RING_SYNC_ST);
798 * Return sync type used by consumer in the ring.
801 * A pointer to the ring structure.
803 * Consumer sync type value.
805 static inline enum rte_ring_sync_type
806 rte_ring_get_cons_sync_type(const struct rte_ring *r)
808 return r->cons.sync_type;
812 * Check is the ring for single consumer.
815 * A pointer to the ring structure.
817 * true if ring is SC, zero otherwise.
820 rte_ring_is_cons_single(const struct rte_ring *r)
822 return (rte_ring_get_cons_sync_type(r) == RTE_RING_SYNC_ST);
826 * Dump the status of all rings on the console
829 * A pointer to a file for output
831 void rte_ring_list_dump(FILE *f);
834 * Search a ring from its name
837 * The name of the ring.
839 * The pointer to the ring matching the name, or NULL if not found,
840 * with rte_errno set appropriately. Possible rte_errno values include:
841 * - ENOENT - required entry not available to return.
843 struct rte_ring *rte_ring_lookup(const char *name);
846 * Enqueue several objects on the ring (multi-producers safe).
848 * This function uses a "compare and set" instruction to move the
849 * producer index atomically.
852 * A pointer to the ring structure.
854 * A pointer to a table of void * pointers (objects).
856 * The number of objects to add in the ring from the obj_table.
858 * if non-NULL, returns the amount of space in the ring after the
859 * enqueue operation has finished.
861 * - n: Actual number of objects enqueued.
863 static __rte_always_inline unsigned
864 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
865 unsigned int n, unsigned int *free_space)
867 return __rte_ring_do_enqueue(r, obj_table, n,
868 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_MT, free_space);
872 * Enqueue several objects on a ring (NOT multi-producers safe).
875 * A pointer to the ring structure.
877 * A pointer to a table of void * pointers (objects).
879 * The number of objects to add in the ring from the obj_table.
881 * if non-NULL, returns the amount of space in the ring after the
882 * enqueue operation has finished.
884 * - n: Actual number of objects enqueued.
886 static __rte_always_inline unsigned
887 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
888 unsigned int n, unsigned int *free_space)
890 return __rte_ring_do_enqueue(r, obj_table, n,
891 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_ST, free_space);
895 * Enqueue several objects on a ring.
897 * This function calls the multi-producer or the single-producer
898 * version depending on the default behavior that was specified at
899 * ring creation time (see flags).
902 * A pointer to the ring structure.
904 * A pointer to a table of void * pointers (objects).
906 * The number of objects to add in the ring from the obj_table.
908 * if non-NULL, returns the amount of space in the ring after the
909 * enqueue operation has finished.
911 * - n: Actual number of objects enqueued.
913 static __rte_always_inline unsigned
914 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
915 unsigned int n, unsigned int *free_space)
917 switch (r->prod.sync_type) {
918 case RTE_RING_SYNC_MT:
919 return rte_ring_mp_enqueue_burst(r, obj_table, n, free_space);
920 case RTE_RING_SYNC_ST:
921 return rte_ring_sp_enqueue_burst(r, obj_table, n, free_space);
922 #ifdef ALLOW_EXPERIMENTAL_API
923 case RTE_RING_SYNC_MT_RTS:
924 return rte_ring_mp_rts_enqueue_burst(r, obj_table, n,
926 case RTE_RING_SYNC_MT_HTS:
927 return rte_ring_mp_hts_enqueue_burst(r, obj_table, n,
932 /* valid ring should never reach this point */
938 * Dequeue several objects from a ring (multi-consumers safe). When the request
939 * objects are more than the available objects, only dequeue the actual number
942 * This function uses a "compare and set" instruction to move the
943 * consumer index atomically.
946 * A pointer to the ring structure.
948 * A pointer to a table of void * pointers (objects) that will be filled.
950 * The number of objects to dequeue from the ring to the obj_table.
952 * If non-NULL, returns the number of remaining ring entries after the
953 * dequeue has finished.
955 * - n: Actual number of objects dequeued, 0 if ring is empty
957 static __rte_always_inline unsigned
958 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
959 unsigned int n, unsigned int *available)
961 return __rte_ring_do_dequeue(r, obj_table, n,
962 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_MT, available);
966 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
967 * request objects are more than the available objects, only dequeue the
968 * actual number of objects
971 * A pointer to the ring structure.
973 * A pointer to a table of void * pointers (objects) that will be filled.
975 * The number of objects to dequeue from the ring to the obj_table.
977 * If non-NULL, returns the number of remaining ring entries after the
978 * dequeue has finished.
980 * - n: Actual number of objects dequeued, 0 if ring is empty
982 static __rte_always_inline unsigned
983 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
984 unsigned int n, unsigned int *available)
986 return __rte_ring_do_dequeue(r, obj_table, n,
987 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_ST, available);
991 * Dequeue multiple objects from a ring up to a maximum number.
993 * This function calls the multi-consumers or the single-consumer
994 * version, depending on the default behaviour that was specified at
995 * ring creation time (see flags).
998 * A pointer to the ring structure.
1000 * A pointer to a table of void * pointers (objects) that will be filled.
1002 * The number of objects to dequeue from the ring to the obj_table.
1004 * If non-NULL, returns the number of remaining ring entries after the
1005 * dequeue has finished.
1007 * - Number of objects dequeued
1009 static __rte_always_inline unsigned
1010 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
1011 unsigned int n, unsigned int *available)
1013 switch (r->cons.sync_type) {
1014 case RTE_RING_SYNC_MT:
1015 return rte_ring_mc_dequeue_burst(r, obj_table, n, available);
1016 case RTE_RING_SYNC_ST:
1017 return rte_ring_sc_dequeue_burst(r, obj_table, n, available);
1018 #ifdef ALLOW_EXPERIMENTAL_API
1019 case RTE_RING_SYNC_MT_RTS:
1020 return rte_ring_mc_rts_dequeue_burst(r, obj_table, n,
1022 case RTE_RING_SYNC_MT_HTS:
1023 return rte_ring_mc_hts_dequeue_burst(r, obj_table, n,
1028 /* valid ring should never reach this point */
1037 #endif /* _RTE_RING_H_ */