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>
43 #include <rte_ring_elem.h>
46 * Calculate the memory size needed for a ring
48 * This function returns the number of bytes needed for a ring, given
49 * the number of elements in it. This value is the sum of the size of
50 * the structure rte_ring and the size of the memory needed by the
51 * objects pointers. The value is aligned to a cache line size.
54 * The number of elements in the ring (must be a power of 2).
56 * - The memory size needed for the ring on success.
57 * - -EINVAL if count is not a power of 2.
59 ssize_t rte_ring_get_memsize(unsigned int count);
62 * Initialize a ring structure.
64 * Initialize a ring structure in memory pointed by "r". The size of the
65 * memory area must be large enough to store the ring structure and the
66 * object table. It is advised to use rte_ring_get_memsize() to get the
69 * The ring size is set to *count*, which must be a power of two. Water
70 * marking is disabled by default. The real usable ring size is
71 * *count-1* instead of *count* to differentiate a free ring from an
74 * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
75 * memory given by the caller may not be shareable among dpdk
79 * The pointer to the ring structure followed by the objects table.
81 * The name of the ring.
83 * The number of elements in the ring (must be a power of 2).
85 * An OR of the following:
86 * - One of mutually exclusive flags that define producer behavior:
87 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
88 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
89 * is "single-producer".
90 * - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
91 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
92 * is "multi-producer RTS mode".
93 * - RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when
94 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
95 * is "multi-producer HTS mode".
96 * If none of these flags is set, then default "multi-producer"
97 * behavior is selected.
98 * - One of mutually exclusive flags that define consumer behavior:
99 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
100 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
101 * is "single-consumer". Otherwise, it is "multi-consumers".
102 * - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
103 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
104 * is "multi-consumer RTS mode".
105 * - RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when
106 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
107 * is "multi-consumer HTS mode".
108 * If none of these flags is set, then default "multi-consumer"
109 * behavior is selected.
111 * 0 on success, or a negative value on error.
113 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
117 * Create a new ring named *name* in memory.
119 * This function uses ``memzone_reserve()`` to allocate memory. Then it
120 * calls rte_ring_init() to initialize an empty ring.
122 * The new ring size is set to *count*, which must be a power of
123 * two. Water marking is disabled by default. The real usable ring size
124 * is *count-1* instead of *count* to differentiate a free ring from an
127 * The ring is added in RTE_TAILQ_RING list.
130 * The name of the ring.
132 * The size of the ring (must be a power of 2).
134 * The *socket_id* argument is the socket identifier in case of
135 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
136 * constraint for the reserved zone.
138 * An OR of the following:
139 * - One of mutually exclusive flags that define producer behavior:
140 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
141 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
142 * is "single-producer".
143 * - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
144 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
145 * is "multi-producer RTS mode".
146 * - RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when
147 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
148 * is "multi-producer HTS mode".
149 * If none of these flags is set, then default "multi-producer"
150 * behavior is selected.
151 * - One of mutually exclusive flags that define consumer behavior:
152 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
153 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
154 * is "single-consumer". Otherwise, it is "multi-consumers".
155 * - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
156 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
157 * is "multi-consumer RTS mode".
158 * - RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when
159 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
160 * is "multi-consumer HTS mode".
161 * If none of these flags is set, then default "multi-consumer"
162 * behavior is selected.
164 * On success, the pointer to the new allocated ring. NULL on error with
165 * rte_errno set appropriately. Possible errno values include:
166 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
167 * - E_RTE_SECONDARY - function was called from a secondary process instance
168 * - EINVAL - count provided is not a power of 2
169 * - ENOSPC - the maximum number of memzones has already been allocated
170 * - EEXIST - a memzone with the same name already exists
171 * - ENOMEM - no appropriate memory area found in which to create memzone
173 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
174 int socket_id, unsigned int flags);
177 * De-allocate all memory used by the ring.
182 void rte_ring_free(struct rte_ring *r);
185 * Dump the status of the ring to a file.
188 * A pointer to a file for output
190 * A pointer to the ring structure.
192 void rte_ring_dump(FILE *f, const struct rte_ring *r);
194 /* the actual enqueue of pointers on the ring.
195 * Placed here since identical code needed in both
196 * single and multi producer enqueue functions */
197 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
199 const uint32_t size = (r)->size; \
200 uint32_t idx = prod_head & (r)->mask; \
201 obj_type *ring = (obj_type *)ring_start; \
202 if (likely(idx + n < size)) { \
203 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) { \
204 ring[idx] = obj_table[i]; \
205 ring[idx + 1] = obj_table[i + 1]; \
206 ring[idx + 2] = obj_table[i + 2]; \
207 ring[idx + 3] = obj_table[i + 3]; \
211 ring[idx++] = obj_table[i++]; /* fallthrough */ \
213 ring[idx++] = obj_table[i++]; /* fallthrough */ \
215 ring[idx++] = obj_table[i++]; \
218 for (i = 0; idx < size; i++, idx++)\
219 ring[idx] = obj_table[i]; \
220 for (idx = 0; i < n; i++, idx++) \
221 ring[idx] = obj_table[i]; \
225 /* the actual copy of pointers on the ring to obj_table.
226 * Placed here since identical code needed in both
227 * single and multi consumer dequeue functions */
228 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
230 uint32_t idx = cons_head & (r)->mask; \
231 const uint32_t size = (r)->size; \
232 obj_type *ring = (obj_type *)ring_start; \
233 if (likely(idx + n < size)) { \
234 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {\
235 obj_table[i] = ring[idx]; \
236 obj_table[i + 1] = ring[idx + 1]; \
237 obj_table[i + 2] = ring[idx + 2]; \
238 obj_table[i + 3] = ring[idx + 3]; \
242 obj_table[i++] = ring[idx++]; /* fallthrough */ \
244 obj_table[i++] = ring[idx++]; /* fallthrough */ \
246 obj_table[i++] = ring[idx++]; \
249 for (i = 0; idx < size; i++, idx++) \
250 obj_table[i] = ring[idx]; \
251 for (idx = 0; i < n; i++, idx++) \
252 obj_table[i] = ring[idx]; \
256 /* Between load and load. there might be cpu reorder in weak model
258 * There are 2 choices for the users
259 * 1.use rmb() memory barrier
260 * 2.use one-direction load_acquire/store_release barrier,defined by
261 * CONFIG_RTE_USE_C11_MEM_MODEL=y
262 * It depends on performance test results.
263 * By default, move common functions to rte_ring_generic.h
265 #ifdef RTE_USE_C11_MEM_MODEL
266 #include "rte_ring_c11_mem.h"
268 #include "rte_ring_generic.h"
272 * @internal Enqueue several objects on the ring
275 * A pointer to the ring structure.
277 * A pointer to a table of void * pointers (objects).
279 * The number of objects to add in the ring from the obj_table.
281 * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
282 * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
284 * Indicates whether to use single producer or multi-producer head update
286 * returns the amount of space after the enqueue operation has finished
288 * Actual number of objects enqueued.
289 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
291 static __rte_always_inline unsigned int
292 __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table,
293 unsigned int n, enum rte_ring_queue_behavior behavior,
294 unsigned int is_sp, unsigned int *free_space)
296 uint32_t prod_head, prod_next;
297 uint32_t free_entries;
299 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
300 &prod_head, &prod_next, &free_entries);
304 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, void *);
306 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
308 if (free_space != NULL)
309 *free_space = free_entries - n;
314 * @internal Dequeue several objects from the ring
317 * A pointer to the ring structure.
319 * A pointer to a table of void * pointers (objects).
321 * The number of objects to pull from the ring.
323 * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
324 * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
326 * Indicates whether to use single consumer or multi-consumer head update
328 * returns the number of remaining ring entries after the dequeue has finished
330 * - Actual number of objects dequeued.
331 * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
333 static __rte_always_inline unsigned int
334 __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table,
335 unsigned int n, enum rte_ring_queue_behavior behavior,
336 unsigned int is_sc, unsigned int *available)
338 uint32_t cons_head, cons_next;
341 n = __rte_ring_move_cons_head(r, (int)is_sc, n, behavior,
342 &cons_head, &cons_next, &entries);
346 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, void *);
348 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
351 if (available != NULL)
352 *available = entries - n;
357 * Enqueue several objects on the ring (multi-producers safe).
359 * This function uses a "compare and set" instruction to move the
360 * producer index atomically.
363 * A pointer to the ring structure.
365 * A pointer to a table of void * pointers (objects).
367 * The number of objects to add in the ring from the obj_table.
369 * if non-NULL, returns the amount of space in the ring after the
370 * enqueue operation has finished.
372 * The number of objects enqueued, either 0 or n
374 static __rte_always_inline unsigned int
375 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
376 unsigned int n, unsigned int *free_space)
378 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
379 RTE_RING_SYNC_MT, free_space);
383 * Enqueue several objects on a ring (NOT multi-producers safe).
386 * A pointer to the ring structure.
388 * A pointer to a table of void * pointers (objects).
390 * The number of objects to add in the ring from the obj_table.
392 * if non-NULL, returns the amount of space in the ring after the
393 * enqueue operation has finished.
395 * The number of objects enqueued, either 0 or n
397 static __rte_always_inline unsigned int
398 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
399 unsigned int n, unsigned int *free_space)
401 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
402 RTE_RING_SYNC_ST, free_space);
406 * Enqueue several objects on a ring.
408 * This function calls the multi-producer or the single-producer
409 * version depending on the default behavior that was specified at
410 * ring creation time (see flags).
413 * A pointer to the ring structure.
415 * A pointer to a table of void * pointers (objects).
417 * The number of objects to add in the ring from the obj_table.
419 * if non-NULL, returns the amount of space in the ring after the
420 * enqueue operation has finished.
422 * The number of objects enqueued, either 0 or n
424 static __rte_always_inline unsigned int
425 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
426 unsigned int n, unsigned int *free_space)
428 switch (r->prod.sync_type) {
429 case RTE_RING_SYNC_MT:
430 return rte_ring_mp_enqueue_bulk(r, obj_table, n, free_space);
431 case RTE_RING_SYNC_ST:
432 return rte_ring_sp_enqueue_bulk(r, obj_table, n, free_space);
433 #ifdef ALLOW_EXPERIMENTAL_API
434 case RTE_RING_SYNC_MT_RTS:
435 return rte_ring_mp_rts_enqueue_bulk(r, obj_table, n,
437 case RTE_RING_SYNC_MT_HTS:
438 return rte_ring_mp_hts_enqueue_bulk(r, obj_table, n,
443 /* valid ring should never reach this point */
449 * Enqueue one object on a ring (multi-producers safe).
451 * This function uses a "compare and set" instruction to move the
452 * producer index atomically.
455 * A pointer to the ring structure.
457 * A pointer to the object to be added.
459 * - 0: Success; objects enqueued.
460 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
462 static __rte_always_inline int
463 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
465 return rte_ring_mp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
469 * Enqueue one object on a ring (NOT multi-producers safe).
472 * A pointer to the ring structure.
474 * A pointer to the object to be added.
476 * - 0: Success; objects enqueued.
477 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
479 static __rte_always_inline int
480 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
482 return rte_ring_sp_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
486 * Enqueue one object on a ring.
488 * This function calls the multi-producer or the single-producer
489 * version, depending on the default behaviour that was specified at
490 * ring creation time (see flags).
493 * A pointer to the ring structure.
495 * A pointer to the object to be added.
497 * - 0: Success; objects enqueued.
498 * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
500 static __rte_always_inline int
501 rte_ring_enqueue(struct rte_ring *r, void *obj)
503 return rte_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
507 * Dequeue several objects from a ring (multi-consumers safe).
509 * This function uses a "compare and set" instruction to move the
510 * consumer index atomically.
513 * A pointer to the ring structure.
515 * A pointer to a table of void * pointers (objects) that will be filled.
517 * The number of objects to dequeue from the ring to the obj_table.
519 * If non-NULL, returns the number of remaining ring entries after the
520 * dequeue has finished.
522 * The number of objects dequeued, either 0 or n
524 static __rte_always_inline unsigned int
525 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
526 unsigned int n, unsigned int *available)
528 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
529 RTE_RING_SYNC_MT, available);
533 * Dequeue several objects from a ring (NOT multi-consumers safe).
536 * A pointer to the ring structure.
538 * A pointer to a table of void * pointers (objects) that will be filled.
540 * The number of objects to dequeue from the ring to the obj_table,
541 * must be strictly positive.
543 * If non-NULL, returns the number of remaining ring entries after the
544 * dequeue has finished.
546 * The number of objects dequeued, either 0 or n
548 static __rte_always_inline unsigned int
549 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
550 unsigned int n, unsigned int *available)
552 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
553 RTE_RING_SYNC_ST, available);
557 * Dequeue several objects from a ring.
559 * This function calls the multi-consumers or the single-consumer
560 * version, depending on the default behaviour that was specified at
561 * ring creation time (see flags).
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.
570 * If non-NULL, returns the number of remaining ring entries after the
571 * dequeue has finished.
573 * The number of objects dequeued, either 0 or n
575 static __rte_always_inline unsigned int
576 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
577 unsigned int *available)
579 switch (r->cons.sync_type) {
580 case RTE_RING_SYNC_MT:
581 return rte_ring_mc_dequeue_bulk(r, obj_table, n, available);
582 case RTE_RING_SYNC_ST:
583 return rte_ring_sc_dequeue_bulk(r, obj_table, n, available);
584 #ifdef ALLOW_EXPERIMENTAL_API
585 case RTE_RING_SYNC_MT_RTS:
586 return rte_ring_mc_rts_dequeue_bulk(r, obj_table, n, available);
587 case RTE_RING_SYNC_MT_HTS:
588 return rte_ring_mc_hts_dequeue_bulk(r, obj_table, n, available);
592 /* valid ring should never reach this point */
598 * Dequeue one object from a ring (multi-consumers safe).
600 * This function uses a "compare and set" instruction to move the
601 * consumer index atomically.
604 * A pointer to the ring structure.
606 * A pointer to a void * pointer (object) that will be filled.
608 * - 0: Success; objects dequeued.
609 * - -ENOENT: Not enough entries in the ring to dequeue; no object is
612 static __rte_always_inline int
613 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
615 return rte_ring_mc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
619 * Dequeue one object from a ring (NOT multi-consumers safe).
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_sc_dequeue(struct rte_ring *r, void **obj_p)
633 return rte_ring_sc_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
637 * Dequeue one object from a ring.
639 * This function calls the multi-consumers or the single-consumer
640 * version depending on the default behaviour that was specified at
641 * ring creation time (see flags).
644 * A pointer to the ring structure.
646 * A pointer to a void * pointer (object) that will be filled.
648 * - 0: Success, objects dequeued.
649 * - -ENOENT: Not enough entries in the ring to dequeue, no object is
652 static __rte_always_inline int
653 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
655 return rte_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
661 * This function flush all the elements in a ring
664 * Make sure the ring is not in use while calling this function.
667 * A pointer to the ring structure.
670 rte_ring_reset(struct rte_ring *r);
673 * Return the number of entries in a ring.
676 * A pointer to the ring structure.
678 * The number of entries in the ring.
680 static inline unsigned int
681 rte_ring_count(const struct rte_ring *r)
683 uint32_t prod_tail = r->prod.tail;
684 uint32_t cons_tail = r->cons.tail;
685 uint32_t count = (prod_tail - cons_tail) & r->mask;
686 return (count > r->capacity) ? r->capacity : count;
690 * Return the number of free entries in a ring.
693 * A pointer to the ring structure.
695 * The number of free entries in the ring.
697 static inline unsigned int
698 rte_ring_free_count(const struct rte_ring *r)
700 return r->capacity - rte_ring_count(r);
704 * Test if a ring is full.
707 * A pointer to the ring structure.
709 * - 1: The ring is full.
710 * - 0: The ring is not full.
713 rte_ring_full(const struct rte_ring *r)
715 return rte_ring_free_count(r) == 0;
719 * Test if a ring is empty.
722 * A pointer to the ring structure.
724 * - 1: The ring is empty.
725 * - 0: The ring is not empty.
728 rte_ring_empty(const struct rte_ring *r)
730 uint32_t prod_tail = r->prod.tail;
731 uint32_t cons_tail = r->cons.tail;
732 return cons_tail == prod_tail;
736 * Return the size of the ring.
739 * A pointer to the ring structure.
741 * The size of the data store used by the ring.
742 * NOTE: this is not the same as the usable space in the ring. To query that
743 * use ``rte_ring_get_capacity()``.
745 static inline unsigned int
746 rte_ring_get_size(const struct rte_ring *r)
752 * Return the number of elements which can be stored in the ring.
755 * A pointer to the ring structure.
757 * The usable size of the ring.
759 static inline unsigned int
760 rte_ring_get_capacity(const struct rte_ring *r)
766 * Return sync type used by producer in the ring.
769 * A pointer to the ring structure.
771 * Producer sync type value.
773 static inline enum rte_ring_sync_type
774 rte_ring_get_prod_sync_type(const struct rte_ring *r)
776 return r->prod.sync_type;
780 * Check is the ring for single producer.
783 * A pointer to the ring structure.
785 * true if ring is SP, zero otherwise.
788 rte_ring_is_prod_single(const struct rte_ring *r)
790 return (rte_ring_get_prod_sync_type(r) == RTE_RING_SYNC_ST);
794 * Return sync type used by consumer in the ring.
797 * A pointer to the ring structure.
799 * Consumer sync type value.
801 static inline enum rte_ring_sync_type
802 rte_ring_get_cons_sync_type(const struct rte_ring *r)
804 return r->cons.sync_type;
808 * Check is the ring for single consumer.
811 * A pointer to the ring structure.
813 * true if ring is SC, zero otherwise.
816 rte_ring_is_cons_single(const struct rte_ring *r)
818 return (rte_ring_get_cons_sync_type(r) == RTE_RING_SYNC_ST);
822 * Dump the status of all rings on the console
825 * A pointer to a file for output
827 void rte_ring_list_dump(FILE *f);
830 * Search a ring from its name
833 * The name of the ring.
835 * The pointer to the ring matching the name, or NULL if not found,
836 * with rte_errno set appropriately. Possible rte_errno values include:
837 * - ENOENT - required entry not available to return.
839 struct rte_ring *rte_ring_lookup(const char *name);
842 * Enqueue several objects on the ring (multi-producers safe).
844 * This function uses a "compare and set" instruction to move the
845 * producer index atomically.
848 * A pointer to the ring structure.
850 * A pointer to a table of void * pointers (objects).
852 * The number of objects to add in the ring from the obj_table.
854 * if non-NULL, returns the amount of space in the ring after the
855 * enqueue operation has finished.
857 * - n: Actual number of objects enqueued.
859 static __rte_always_inline unsigned int
860 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
861 unsigned int n, unsigned int *free_space)
863 return __rte_ring_do_enqueue(r, obj_table, n,
864 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_MT, free_space);
868 * Enqueue several objects on a ring (NOT multi-producers safe).
871 * A pointer to the ring structure.
873 * A pointer to a table of void * pointers (objects).
875 * The number of objects to add in the ring from the obj_table.
877 * if non-NULL, returns the amount of space in the ring after the
878 * enqueue operation has finished.
880 * - n: Actual number of objects enqueued.
882 static __rte_always_inline unsigned int
883 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
884 unsigned int n, unsigned int *free_space)
886 return __rte_ring_do_enqueue(r, obj_table, n,
887 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_ST, free_space);
891 * Enqueue several objects on a ring.
893 * This function calls the multi-producer or the single-producer
894 * version depending on the default behavior that was specified at
895 * ring creation time (see flags).
898 * A pointer to the ring structure.
900 * A pointer to a table of void * pointers (objects).
902 * The number of objects to add in the ring from the obj_table.
904 * if non-NULL, returns the amount of space in the ring after the
905 * enqueue operation has finished.
907 * - n: Actual number of objects enqueued.
909 static __rte_always_inline unsigned int
910 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
911 unsigned int n, unsigned int *free_space)
913 switch (r->prod.sync_type) {
914 case RTE_RING_SYNC_MT:
915 return rte_ring_mp_enqueue_burst(r, obj_table, n, free_space);
916 case RTE_RING_SYNC_ST:
917 return rte_ring_sp_enqueue_burst(r, obj_table, n, free_space);
918 #ifdef ALLOW_EXPERIMENTAL_API
919 case RTE_RING_SYNC_MT_RTS:
920 return rte_ring_mp_rts_enqueue_burst(r, obj_table, n,
922 case RTE_RING_SYNC_MT_HTS:
923 return rte_ring_mp_hts_enqueue_burst(r, obj_table, n,
928 /* valid ring should never reach this point */
934 * Dequeue several objects from a ring (multi-consumers safe). When the request
935 * objects are more than the available objects, only dequeue the actual number
938 * This function uses a "compare and set" instruction to move the
939 * consumer index atomically.
942 * A pointer to the ring structure.
944 * A pointer to a table of void * pointers (objects) that will be filled.
946 * The number of objects to dequeue from the ring to the obj_table.
948 * If non-NULL, returns the number of remaining ring entries after the
949 * dequeue has finished.
951 * - n: Actual number of objects dequeued, 0 if ring is empty
953 static __rte_always_inline unsigned int
954 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
955 unsigned int n, unsigned int *available)
957 return __rte_ring_do_dequeue(r, obj_table, n,
958 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_MT, available);
962 * Dequeue several objects from a ring (NOT multi-consumers safe).When the
963 * request objects are more than the available objects, only dequeue the
964 * actual number of objects
967 * A pointer to the ring structure.
969 * A pointer to a table of void * pointers (objects) that will be filled.
971 * The number of objects to dequeue from the ring to the obj_table.
973 * If non-NULL, returns the number of remaining ring entries after the
974 * dequeue has finished.
976 * - n: Actual number of objects dequeued, 0 if ring is empty
978 static __rte_always_inline unsigned int
979 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
980 unsigned int n, unsigned int *available)
982 return __rte_ring_do_dequeue(r, obj_table, n,
983 RTE_RING_QUEUE_VARIABLE, RTE_RING_SYNC_ST, available);
987 * Dequeue multiple objects from a ring up to a maximum number.
989 * This function calls the multi-consumers or the single-consumer
990 * version, depending on the default behaviour that was specified at
991 * ring creation time (see flags).
994 * A pointer to the ring structure.
996 * A pointer to a table of void * pointers (objects) that will be filled.
998 * The number of objects to dequeue from the ring to the obj_table.
1000 * If non-NULL, returns the number of remaining ring entries after the
1001 * dequeue has finished.
1003 * - Number of objects dequeued
1005 static __rte_always_inline unsigned int
1006 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
1007 unsigned int n, unsigned int *available)
1009 switch (r->cons.sync_type) {
1010 case RTE_RING_SYNC_MT:
1011 return rte_ring_mc_dequeue_burst(r, obj_table, n, available);
1012 case RTE_RING_SYNC_ST:
1013 return rte_ring_sc_dequeue_burst(r, obj_table, n, available);
1014 #ifdef ALLOW_EXPERIMENTAL_API
1015 case RTE_RING_SYNC_MT_RTS:
1016 return rte_ring_mc_rts_dequeue_burst(r, obj_table, n,
1018 case RTE_RING_SYNC_MT_HTS:
1019 return rte_ring_mc_hts_dequeue_burst(r, obj_table, n,
1024 /* valid ring should never reach this point */
1033 #endif /* _RTE_RING_H_ */