xref: /dpdk/lib/ring/rte_ring.h (revision 700989f512bbc2ee9758a8a9cb6973cfdeda6f27)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  *
399a2dd95SBruce Richardson  * Copyright (c) 2010-2020 Intel Corporation
499a2dd95SBruce Richardson  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
599a2dd95SBruce Richardson  * All rights reserved.
699a2dd95SBruce Richardson  * Derived from FreeBSD's bufring.h
799a2dd95SBruce Richardson  * Used as BSD-3 Licensed with permission from Kip Macy.
899a2dd95SBruce Richardson  */
999a2dd95SBruce Richardson 
1099a2dd95SBruce Richardson #ifndef _RTE_RING_H_
1199a2dd95SBruce Richardson #define _RTE_RING_H_
1299a2dd95SBruce Richardson 
1399a2dd95SBruce Richardson /**
1499a2dd95SBruce Richardson  * @file
1599a2dd95SBruce Richardson  * RTE Ring
1699a2dd95SBruce Richardson  *
1799a2dd95SBruce Richardson  * The Ring Manager is a fixed-size queue, implemented as a table of
1899a2dd95SBruce Richardson  * pointers. Head and tail pointers are modified atomically, allowing
1999a2dd95SBruce Richardson  * concurrent access to it. It has the following features:
2099a2dd95SBruce Richardson  *
2199a2dd95SBruce Richardson  * - FIFO (First In First Out)
2299a2dd95SBruce Richardson  * - Maximum size is fixed; the pointers are stored in a table.
2399a2dd95SBruce Richardson  * - Lockless implementation.
2499a2dd95SBruce Richardson  * - Multi- or single-consumer dequeue.
2599a2dd95SBruce Richardson  * - Multi- or single-producer enqueue.
2699a2dd95SBruce Richardson  * - Bulk dequeue.
2799a2dd95SBruce Richardson  * - Bulk enqueue.
2899a2dd95SBruce Richardson  * - Ability to select different sync modes for producer/consumer.
2999a2dd95SBruce Richardson  * - Dequeue start/finish (depending on consumer sync modes).
3099a2dd95SBruce Richardson  * - Enqueue start/finish (depending on producer sync mode).
3199a2dd95SBruce Richardson  *
3299a2dd95SBruce Richardson  * Note: the ring implementation is not preemptible. Refer to Programmer's
3399a2dd95SBruce Richardson  * guide/Environment Abstraction Layer/Multiple pthread/Known Issues/rte_ring
3499a2dd95SBruce Richardson  * for more information.
3599a2dd95SBruce Richardson  */
3699a2dd95SBruce Richardson 
37719834a6SMattias Rönnblom #include <rte_ring_core.h>
38719834a6SMattias Rönnblom #include <rte_ring_elem.h>
39719834a6SMattias Rönnblom 
4099a2dd95SBruce Richardson #ifdef __cplusplus
4199a2dd95SBruce Richardson extern "C" {
4299a2dd95SBruce Richardson #endif
4399a2dd95SBruce Richardson 
4499a2dd95SBruce Richardson /**
4599a2dd95SBruce Richardson  * Calculate the memory size needed for a ring
4699a2dd95SBruce Richardson  *
4799a2dd95SBruce Richardson  * This function returns the number of bytes needed for a ring, given
4899a2dd95SBruce Richardson  * the number of elements in it. This value is the sum of the size of
4999a2dd95SBruce Richardson  * the structure rte_ring and the size of the memory needed by the
5099a2dd95SBruce Richardson  * objects pointers. The value is aligned to a cache line size.
5199a2dd95SBruce Richardson  *
5299a2dd95SBruce Richardson  * @param count
5399a2dd95SBruce Richardson  *   The number of elements in the ring (must be a power of 2).
5499a2dd95SBruce Richardson  * @return
5599a2dd95SBruce Richardson  *   - The memory size needed for the ring on success.
5699a2dd95SBruce Richardson  *   - -EINVAL if count is not a power of 2.
5799a2dd95SBruce Richardson  */
5899a2dd95SBruce Richardson ssize_t rte_ring_get_memsize(unsigned int count);
5999a2dd95SBruce Richardson 
6099a2dd95SBruce Richardson /**
6199a2dd95SBruce Richardson  * Initialize a ring structure.
6299a2dd95SBruce Richardson  *
6399a2dd95SBruce Richardson  * Initialize a ring structure in memory pointed by "r". The size of the
6499a2dd95SBruce Richardson  * memory area must be large enough to store the ring structure and the
6599a2dd95SBruce Richardson  * object table. It is advised to use rte_ring_get_memsize() to get the
6699a2dd95SBruce Richardson  * appropriate size.
6799a2dd95SBruce Richardson  *
6821dc24b7SStephen Hemminger  * The ring size is set to *count*, which must be a power of two.
6921dc24b7SStephen Hemminger  * The real usable ring size is *count-1* instead of *count* to
7021dc24b7SStephen Hemminger  * differentiate a full ring from an empty ring.
7199a2dd95SBruce Richardson  *
7299a2dd95SBruce Richardson  * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
7399a2dd95SBruce Richardson  * memory given by the caller may not be shareable among dpdk
7499a2dd95SBruce Richardson  * processes.
7599a2dd95SBruce Richardson  *
7699a2dd95SBruce Richardson  * @param r
7799a2dd95SBruce Richardson  *   The pointer to the ring structure followed by the objects table.
7899a2dd95SBruce Richardson  * @param name
7999a2dd95SBruce Richardson  *   The name of the ring.
8099a2dd95SBruce Richardson  * @param count
81436e82b7SRobert Sanford  *   The number of elements in the ring (must be a power of 2,
82436e82b7SRobert Sanford  *   unless RING_F_EXACT_SZ is set in flags).
8399a2dd95SBruce Richardson  * @param flags
8499a2dd95SBruce Richardson  *   An OR of the following:
8599a2dd95SBruce Richardson  *   - One of mutually exclusive flags that define producer behavior:
8699a2dd95SBruce Richardson  *      - RING_F_SP_ENQ: If this flag is set, the default behavior when
8799a2dd95SBruce Richardson  *        using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
8899a2dd95SBruce Richardson  *        is "single-producer".
8999a2dd95SBruce Richardson  *      - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
9099a2dd95SBruce Richardson  *        using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
9199a2dd95SBruce Richardson  *        is "multi-producer RTS mode".
9299a2dd95SBruce Richardson  *      - RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when
9399a2dd95SBruce Richardson  *        using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
9499a2dd95SBruce Richardson  *        is "multi-producer HTS mode".
9599a2dd95SBruce Richardson  *     If none of these flags is set, then default "multi-producer"
9699a2dd95SBruce Richardson  *     behavior is selected.
9799a2dd95SBruce Richardson  *   - One of mutually exclusive flags that define consumer behavior:
9899a2dd95SBruce Richardson  *      - RING_F_SC_DEQ: If this flag is set, the default behavior when
9999a2dd95SBruce Richardson  *        using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
10099a2dd95SBruce Richardson  *        is "single-consumer". Otherwise, it is "multi-consumers".
10199a2dd95SBruce Richardson  *      - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
10299a2dd95SBruce Richardson  *        using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
10399a2dd95SBruce Richardson  *        is "multi-consumer RTS mode".
10499a2dd95SBruce Richardson  *      - RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when
10599a2dd95SBruce Richardson  *        using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
10699a2dd95SBruce Richardson  *        is "multi-consumer HTS mode".
10799a2dd95SBruce Richardson  *     If none of these flags is set, then default "multi-consumer"
10899a2dd95SBruce Richardson  *     behavior is selected.
109436e82b7SRobert Sanford  *   - RING_F_EXACT_SZ: If this flag is set, the ring will hold exactly the
110436e82b7SRobert Sanford  *     requested number of entries, and the requested size will be rounded up
111436e82b7SRobert Sanford  *     to the next power of two, but the usable space will be exactly that
112436e82b7SRobert Sanford  *     requested. Worst case, if a power-of-2 size is requested, half the
113436e82b7SRobert Sanford  *     ring space will be wasted.
114436e82b7SRobert Sanford  *     Without this flag set, the ring size requested must be a power of 2,
115436e82b7SRobert Sanford  *     and the usable space will be that size - 1.
11699a2dd95SBruce Richardson  * @return
11799a2dd95SBruce Richardson  *   0 on success, or a negative value on error.
11899a2dd95SBruce Richardson  */
11999a2dd95SBruce Richardson int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
12099a2dd95SBruce Richardson 	unsigned int flags);
12199a2dd95SBruce Richardson 
12299a2dd95SBruce Richardson /**
12399a2dd95SBruce Richardson  * Create a new ring named *name* in memory.
12499a2dd95SBruce Richardson  *
12599a2dd95SBruce Richardson  * This function uses ``memzone_reserve()`` to allocate memory. Then it
12699a2dd95SBruce Richardson  * calls rte_ring_init() to initialize an empty ring.
12799a2dd95SBruce Richardson  *
12821dc24b7SStephen Hemminger  * The new ring size is set to *count*, which must be a power of two.
12921dc24b7SStephen Hemminger  * The real usable ring size is *count-1* instead of *count* to
13021dc24b7SStephen Hemminger  * differentiate a full ring from an empty ring.
13199a2dd95SBruce Richardson  *
13299a2dd95SBruce Richardson  * The ring is added in RTE_TAILQ_RING list.
13399a2dd95SBruce Richardson  *
13499a2dd95SBruce Richardson  * @param name
13599a2dd95SBruce Richardson  *   The name of the ring.
13699a2dd95SBruce Richardson  * @param count
137436e82b7SRobert Sanford  *   The size of the ring (must be a power of 2,
138436e82b7SRobert Sanford  *   unless RING_F_EXACT_SZ is set in flags).
13999a2dd95SBruce Richardson  * @param socket_id
14099a2dd95SBruce Richardson  *   The *socket_id* argument is the socket identifier in case of
14199a2dd95SBruce Richardson  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
14299a2dd95SBruce Richardson  *   constraint for the reserved zone.
14399a2dd95SBruce Richardson  * @param flags
14499a2dd95SBruce Richardson  *   An OR of the following:
14599a2dd95SBruce Richardson  *   - One of mutually exclusive flags that define producer behavior:
14699a2dd95SBruce Richardson  *      - RING_F_SP_ENQ: If this flag is set, the default behavior when
14799a2dd95SBruce Richardson  *        using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
14899a2dd95SBruce Richardson  *        is "single-producer".
14999a2dd95SBruce Richardson  *      - RING_F_MP_RTS_ENQ: If this flag is set, the default behavior when
15099a2dd95SBruce Richardson  *        using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
15199a2dd95SBruce Richardson  *        is "multi-producer RTS mode".
15299a2dd95SBruce Richardson  *      - RING_F_MP_HTS_ENQ: If this flag is set, the default behavior when
15399a2dd95SBruce Richardson  *        using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
15499a2dd95SBruce Richardson  *        is "multi-producer HTS mode".
15599a2dd95SBruce Richardson  *     If none of these flags is set, then default "multi-producer"
15699a2dd95SBruce Richardson  *     behavior is selected.
15799a2dd95SBruce Richardson  *   - One of mutually exclusive flags that define consumer behavior:
15899a2dd95SBruce Richardson  *      - RING_F_SC_DEQ: If this flag is set, the default behavior when
15999a2dd95SBruce Richardson  *        using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
16099a2dd95SBruce Richardson  *        is "single-consumer". Otherwise, it is "multi-consumers".
16199a2dd95SBruce Richardson  *      - RING_F_MC_RTS_DEQ: If this flag is set, the default behavior when
16299a2dd95SBruce Richardson  *        using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
16399a2dd95SBruce Richardson  *        is "multi-consumer RTS mode".
16499a2dd95SBruce Richardson  *      - RING_F_MC_HTS_DEQ: If this flag is set, the default behavior when
16599a2dd95SBruce Richardson  *        using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
16699a2dd95SBruce Richardson  *        is "multi-consumer HTS mode".
16799a2dd95SBruce Richardson  *     If none of these flags is set, then default "multi-consumer"
16899a2dd95SBruce Richardson  *     behavior is selected.
169436e82b7SRobert Sanford  *   - RING_F_EXACT_SZ: If this flag is set, the ring will hold exactly the
170436e82b7SRobert Sanford  *     requested number of entries, and the requested size will be rounded up
171436e82b7SRobert Sanford  *     to the next power of two, but the usable space will be exactly that
172436e82b7SRobert Sanford  *     requested. Worst case, if a power-of-2 size is requested, half the
173436e82b7SRobert Sanford  *     ring space will be wasted.
174436e82b7SRobert Sanford  *     Without this flag set, the ring size requested must be a power of 2,
175436e82b7SRobert Sanford  *     and the usable space will be that size - 1.
17699a2dd95SBruce Richardson  * @return
17799a2dd95SBruce Richardson  *   On success, the pointer to the new allocated ring. NULL on error with
17899a2dd95SBruce Richardson  *    rte_errno set appropriately. Possible errno values include:
17999a2dd95SBruce Richardson  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
18099a2dd95SBruce Richardson  *    - EINVAL - count provided is not a power of 2
18199a2dd95SBruce Richardson  *    - ENOSPC - the maximum number of memzones has already been allocated
18299a2dd95SBruce Richardson  *    - EEXIST - a memzone with the same name already exists
18399a2dd95SBruce Richardson  *    - ENOMEM - no appropriate memory area found in which to create memzone
18499a2dd95SBruce Richardson  */
18599a2dd95SBruce Richardson struct rte_ring *rte_ring_create(const char *name, unsigned int count,
18699a2dd95SBruce Richardson 				 int socket_id, unsigned int flags);
18799a2dd95SBruce Richardson 
18899a2dd95SBruce Richardson /**
18999a2dd95SBruce Richardson  * De-allocate all memory used by the ring.
19099a2dd95SBruce Richardson  *
19199a2dd95SBruce Richardson  * @param r
192e7b1c466SStephen Hemminger  *   Ring to free.
193e7b1c466SStephen Hemminger  *   If NULL then, the function does nothing.
19499a2dd95SBruce Richardson  */
19599a2dd95SBruce Richardson void rte_ring_free(struct rte_ring *r);
19699a2dd95SBruce Richardson 
19799a2dd95SBruce Richardson /**
19899a2dd95SBruce Richardson  * Dump the status of the ring to a file.
19999a2dd95SBruce Richardson  *
20099a2dd95SBruce Richardson  * @param f
20199a2dd95SBruce Richardson  *   A pointer to a file for output
20299a2dd95SBruce Richardson  * @param r
20399a2dd95SBruce Richardson  *   A pointer to the ring structure.
20499a2dd95SBruce Richardson  */
20599a2dd95SBruce Richardson void rte_ring_dump(FILE *f, const struct rte_ring *r);
20699a2dd95SBruce Richardson 
20799a2dd95SBruce Richardson /**
208*700989f5SEimear Morrissey  * @warning
209*700989f5SEimear Morrissey  * @b EXPERIMENTAL: this API may change without prior notice.
210*700989f5SEimear Morrissey  *
211*700989f5SEimear Morrissey  * Dump the status of a headtail to a file.
212*700989f5SEimear Morrissey  *
213*700989f5SEimear Morrissey  * @param f
214*700989f5SEimear Morrissey  *   A pointer to a file for output
215*700989f5SEimear Morrissey  * @param prefix
216*700989f5SEimear Morrissey  *   A string to prefix each output line with
217*700989f5SEimear Morrissey  * @param r
218*700989f5SEimear Morrissey  *   A pointer to a ring headtail structure.
219*700989f5SEimear Morrissey  */
220*700989f5SEimear Morrissey __rte_experimental
221*700989f5SEimear Morrissey void
222*700989f5SEimear Morrissey rte_ring_headtail_dump(FILE *f, const char *prefix,
223*700989f5SEimear Morrissey 		const struct rte_ring_headtail *r);
224*700989f5SEimear Morrissey 
225*700989f5SEimear Morrissey /**
22699a2dd95SBruce Richardson  * Enqueue several objects on the ring (multi-producers safe).
22799a2dd95SBruce Richardson  *
22899a2dd95SBruce Richardson  * This function uses a "compare and set" instruction to move the
22999a2dd95SBruce Richardson  * producer index atomically.
23099a2dd95SBruce Richardson  *
23199a2dd95SBruce Richardson  * @param r
23299a2dd95SBruce Richardson  *   A pointer to the ring structure.
23399a2dd95SBruce Richardson  * @param obj_table
23499a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects).
23599a2dd95SBruce Richardson  * @param n
23699a2dd95SBruce Richardson  *   The number of objects to add in the ring from the obj_table.
23799a2dd95SBruce Richardson  * @param free_space
23899a2dd95SBruce Richardson  *   if non-NULL, returns the amount of space in the ring after the
23999a2dd95SBruce Richardson  *   enqueue operation has finished.
24099a2dd95SBruce Richardson  * @return
24199a2dd95SBruce Richardson  *   The number of objects enqueued, either 0 or n
24299a2dd95SBruce Richardson  */
24399a2dd95SBruce Richardson static __rte_always_inline unsigned int
24499a2dd95SBruce Richardson rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
24599a2dd95SBruce Richardson 			 unsigned int n, unsigned int *free_space)
24699a2dd95SBruce Richardson {
24799a2dd95SBruce Richardson 	return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
24899a2dd95SBruce Richardson 			n, free_space);
24999a2dd95SBruce Richardson }
25099a2dd95SBruce Richardson 
25199a2dd95SBruce Richardson /**
25299a2dd95SBruce Richardson  * Enqueue several objects on a ring (NOT multi-producers safe).
25399a2dd95SBruce Richardson  *
25499a2dd95SBruce Richardson  * @param r
25599a2dd95SBruce Richardson  *   A pointer to the ring structure.
25699a2dd95SBruce Richardson  * @param obj_table
25799a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects).
25899a2dd95SBruce Richardson  * @param n
25999a2dd95SBruce Richardson  *   The number of objects to add in the ring from the obj_table.
26099a2dd95SBruce Richardson  * @param free_space
26199a2dd95SBruce Richardson  *   if non-NULL, returns the amount of space in the ring after the
26299a2dd95SBruce Richardson  *   enqueue operation has finished.
26399a2dd95SBruce Richardson  * @return
26499a2dd95SBruce Richardson  *   The number of objects enqueued, either 0 or n
26599a2dd95SBruce Richardson  */
26699a2dd95SBruce Richardson static __rte_always_inline unsigned int
26799a2dd95SBruce Richardson rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
26899a2dd95SBruce Richardson 			 unsigned int n, unsigned int *free_space)
26999a2dd95SBruce Richardson {
27099a2dd95SBruce Richardson 	return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
27199a2dd95SBruce Richardson 			n, free_space);
27299a2dd95SBruce Richardson }
27399a2dd95SBruce Richardson 
27499a2dd95SBruce Richardson /**
27599a2dd95SBruce Richardson  * Enqueue several objects on a ring.
27699a2dd95SBruce Richardson  *
27799a2dd95SBruce Richardson  * This function calls the multi-producer or the single-producer
27899a2dd95SBruce Richardson  * version depending on the default behavior that was specified at
27999a2dd95SBruce Richardson  * ring creation time (see flags).
28099a2dd95SBruce Richardson  *
28199a2dd95SBruce Richardson  * @param r
28299a2dd95SBruce Richardson  *   A pointer to the ring structure.
28399a2dd95SBruce Richardson  * @param obj_table
28499a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects).
28599a2dd95SBruce Richardson  * @param n
28699a2dd95SBruce Richardson  *   The number of objects to add in the ring from the obj_table.
28799a2dd95SBruce Richardson  * @param free_space
28899a2dd95SBruce Richardson  *   if non-NULL, returns the amount of space in the ring after the
28999a2dd95SBruce Richardson  *   enqueue operation has finished.
29099a2dd95SBruce Richardson  * @return
29199a2dd95SBruce Richardson  *   The number of objects enqueued, either 0 or n
29299a2dd95SBruce Richardson  */
29399a2dd95SBruce Richardson static __rte_always_inline unsigned int
29499a2dd95SBruce Richardson rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
29599a2dd95SBruce Richardson 		      unsigned int n, unsigned int *free_space)
29699a2dd95SBruce Richardson {
29799a2dd95SBruce Richardson 	return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
29899a2dd95SBruce Richardson 			n, free_space);
29999a2dd95SBruce Richardson }
30099a2dd95SBruce Richardson 
30199a2dd95SBruce Richardson /**
30299a2dd95SBruce Richardson  * Enqueue one object on a ring (multi-producers safe).
30399a2dd95SBruce Richardson  *
30499a2dd95SBruce Richardson  * This function uses a "compare and set" instruction to move the
30599a2dd95SBruce Richardson  * producer index atomically.
30699a2dd95SBruce Richardson  *
30799a2dd95SBruce Richardson  * @param r
30899a2dd95SBruce Richardson  *   A pointer to the ring structure.
30999a2dd95SBruce Richardson  * @param obj
31099a2dd95SBruce Richardson  *   A pointer to the object to be added.
31199a2dd95SBruce Richardson  * @return
31299a2dd95SBruce Richardson  *   - 0: Success; objects enqueued.
31399a2dd95SBruce Richardson  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
31499a2dd95SBruce Richardson  */
31599a2dd95SBruce Richardson static __rte_always_inline int
31699a2dd95SBruce Richardson rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
31799a2dd95SBruce Richardson {
31899a2dd95SBruce Richardson 	return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
31999a2dd95SBruce Richardson }
32099a2dd95SBruce Richardson 
32199a2dd95SBruce Richardson /**
32299a2dd95SBruce Richardson  * Enqueue one object on a ring (NOT multi-producers safe).
32399a2dd95SBruce Richardson  *
32499a2dd95SBruce Richardson  * @param r
32599a2dd95SBruce Richardson  *   A pointer to the ring structure.
32699a2dd95SBruce Richardson  * @param obj
32799a2dd95SBruce Richardson  *   A pointer to the object to be added.
32899a2dd95SBruce Richardson  * @return
32999a2dd95SBruce Richardson  *   - 0: Success; objects enqueued.
33099a2dd95SBruce Richardson  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
33199a2dd95SBruce Richardson  */
33299a2dd95SBruce Richardson static __rte_always_inline int
33399a2dd95SBruce Richardson rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
33499a2dd95SBruce Richardson {
33599a2dd95SBruce Richardson 	return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
33699a2dd95SBruce Richardson }
33799a2dd95SBruce Richardson 
33899a2dd95SBruce Richardson /**
33999a2dd95SBruce Richardson  * Enqueue one object on a ring.
34099a2dd95SBruce Richardson  *
34199a2dd95SBruce Richardson  * This function calls the multi-producer or the single-producer
34299a2dd95SBruce Richardson  * version, depending on the default behaviour that was specified at
34399a2dd95SBruce Richardson  * ring creation time (see flags).
34499a2dd95SBruce Richardson  *
34599a2dd95SBruce Richardson  * @param r
34699a2dd95SBruce Richardson  *   A pointer to the ring structure.
34799a2dd95SBruce Richardson  * @param obj
34899a2dd95SBruce Richardson  *   A pointer to the object to be added.
34999a2dd95SBruce Richardson  * @return
35099a2dd95SBruce Richardson  *   - 0: Success; objects enqueued.
35199a2dd95SBruce Richardson  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
35299a2dd95SBruce Richardson  */
35399a2dd95SBruce Richardson static __rte_always_inline int
35499a2dd95SBruce Richardson rte_ring_enqueue(struct rte_ring *r, void *obj)
35599a2dd95SBruce Richardson {
35699a2dd95SBruce Richardson 	return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
35799a2dd95SBruce Richardson }
35899a2dd95SBruce Richardson 
35999a2dd95SBruce Richardson /**
36099a2dd95SBruce Richardson  * Dequeue several objects from a ring (multi-consumers safe).
36199a2dd95SBruce Richardson  *
36299a2dd95SBruce Richardson  * This function uses a "compare and set" instruction to move the
36399a2dd95SBruce Richardson  * consumer index atomically.
36499a2dd95SBruce Richardson  *
36599a2dd95SBruce Richardson  * @param r
36699a2dd95SBruce Richardson  *   A pointer to the ring structure.
36799a2dd95SBruce Richardson  * @param obj_table
36899a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects) that will be filled.
36999a2dd95SBruce Richardson  * @param n
37099a2dd95SBruce Richardson  *   The number of objects to dequeue from the ring to the obj_table.
37199a2dd95SBruce Richardson  * @param available
37299a2dd95SBruce Richardson  *   If non-NULL, returns the number of remaining ring entries after the
37399a2dd95SBruce Richardson  *   dequeue has finished.
37499a2dd95SBruce Richardson  * @return
37599a2dd95SBruce Richardson  *   The number of objects dequeued, either 0 or n
37699a2dd95SBruce Richardson  */
37799a2dd95SBruce Richardson static __rte_always_inline unsigned int
37899a2dd95SBruce Richardson rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
37999a2dd95SBruce Richardson 		unsigned int n, unsigned int *available)
38099a2dd95SBruce Richardson {
38199a2dd95SBruce Richardson 	return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
38299a2dd95SBruce Richardson 			n, available);
38399a2dd95SBruce Richardson }
38499a2dd95SBruce Richardson 
38599a2dd95SBruce Richardson /**
38699a2dd95SBruce Richardson  * Dequeue several objects from a ring (NOT multi-consumers safe).
38799a2dd95SBruce Richardson  *
38899a2dd95SBruce Richardson  * @param r
38999a2dd95SBruce Richardson  *   A pointer to the ring structure.
39099a2dd95SBruce Richardson  * @param obj_table
39199a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects) that will be filled.
39299a2dd95SBruce Richardson  * @param n
39399a2dd95SBruce Richardson  *   The number of objects to dequeue from the ring to the obj_table,
39499a2dd95SBruce Richardson  *   must be strictly positive.
39599a2dd95SBruce Richardson  * @param available
39699a2dd95SBruce Richardson  *   If non-NULL, returns the number of remaining ring entries after the
39799a2dd95SBruce Richardson  *   dequeue has finished.
39899a2dd95SBruce Richardson  * @return
39999a2dd95SBruce Richardson  *   The number of objects dequeued, either 0 or n
40099a2dd95SBruce Richardson  */
40199a2dd95SBruce Richardson static __rte_always_inline unsigned int
40299a2dd95SBruce Richardson rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
40399a2dd95SBruce Richardson 		unsigned int n, unsigned int *available)
40499a2dd95SBruce Richardson {
40599a2dd95SBruce Richardson 	return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
40699a2dd95SBruce Richardson 			n, available);
40799a2dd95SBruce Richardson }
40899a2dd95SBruce Richardson 
40999a2dd95SBruce Richardson /**
41099a2dd95SBruce Richardson  * Dequeue several objects from a ring.
41199a2dd95SBruce Richardson  *
41299a2dd95SBruce Richardson  * This function calls the multi-consumers or the single-consumer
41399a2dd95SBruce Richardson  * version, depending on the default behaviour that was specified at
41499a2dd95SBruce Richardson  * ring creation time (see flags).
41599a2dd95SBruce Richardson  *
41699a2dd95SBruce Richardson  * @param r
41799a2dd95SBruce Richardson  *   A pointer to the ring structure.
41899a2dd95SBruce Richardson  * @param obj_table
41999a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects) that will be filled.
42099a2dd95SBruce Richardson  * @param n
42199a2dd95SBruce Richardson  *   The number of objects to dequeue from the ring to the obj_table.
42299a2dd95SBruce Richardson  * @param available
42399a2dd95SBruce Richardson  *   If non-NULL, returns the number of remaining ring entries after the
42499a2dd95SBruce Richardson  *   dequeue has finished.
42599a2dd95SBruce Richardson  * @return
42699a2dd95SBruce Richardson  *   The number of objects dequeued, either 0 or n
42799a2dd95SBruce Richardson  */
42899a2dd95SBruce Richardson static __rte_always_inline unsigned int
42999a2dd95SBruce Richardson rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
43099a2dd95SBruce Richardson 		unsigned int *available)
43199a2dd95SBruce Richardson {
43299a2dd95SBruce Richardson 	return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
43399a2dd95SBruce Richardson 			n, available);
43499a2dd95SBruce Richardson }
43599a2dd95SBruce Richardson 
43699a2dd95SBruce Richardson /**
43799a2dd95SBruce Richardson  * Dequeue one object from a ring (multi-consumers safe).
43899a2dd95SBruce Richardson  *
43999a2dd95SBruce Richardson  * This function uses a "compare and set" instruction to move the
44099a2dd95SBruce Richardson  * consumer index atomically.
44199a2dd95SBruce Richardson  *
44299a2dd95SBruce Richardson  * @param r
44399a2dd95SBruce Richardson  *   A pointer to the ring structure.
44499a2dd95SBruce Richardson  * @param obj_p
44599a2dd95SBruce Richardson  *   A pointer to a void * pointer (object) that will be filled.
44699a2dd95SBruce Richardson  * @return
44799a2dd95SBruce Richardson  *   - 0: Success; objects dequeued.
44899a2dd95SBruce Richardson  *   - -ENOENT: Not enough entries in the ring to dequeue; no object is
44999a2dd95SBruce Richardson  *     dequeued.
45099a2dd95SBruce Richardson  */
45199a2dd95SBruce Richardson static __rte_always_inline int
45299a2dd95SBruce Richardson rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
45399a2dd95SBruce Richardson {
45499a2dd95SBruce Richardson 	return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
45599a2dd95SBruce Richardson }
45699a2dd95SBruce Richardson 
45799a2dd95SBruce Richardson /**
45899a2dd95SBruce Richardson  * Dequeue one object from a ring (NOT multi-consumers safe).
45999a2dd95SBruce Richardson  *
46099a2dd95SBruce Richardson  * @param r
46199a2dd95SBruce Richardson  *   A pointer to the ring structure.
46299a2dd95SBruce Richardson  * @param obj_p
46399a2dd95SBruce Richardson  *   A pointer to a void * pointer (object) that will be filled.
46499a2dd95SBruce Richardson  * @return
46599a2dd95SBruce Richardson  *   - 0: Success; objects dequeued.
46699a2dd95SBruce Richardson  *   - -ENOENT: Not enough entries in the ring to dequeue, no object is
46799a2dd95SBruce Richardson  *     dequeued.
46899a2dd95SBruce Richardson  */
46999a2dd95SBruce Richardson static __rte_always_inline int
47099a2dd95SBruce Richardson rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
47199a2dd95SBruce Richardson {
47299a2dd95SBruce Richardson 	return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
47399a2dd95SBruce Richardson }
47499a2dd95SBruce Richardson 
47599a2dd95SBruce Richardson /**
47699a2dd95SBruce Richardson  * Dequeue one object from a ring.
47799a2dd95SBruce Richardson  *
47899a2dd95SBruce Richardson  * This function calls the multi-consumers or the single-consumer
47999a2dd95SBruce Richardson  * version depending on the default behaviour that was specified at
48099a2dd95SBruce Richardson  * ring creation time (see flags).
48199a2dd95SBruce Richardson  *
48299a2dd95SBruce Richardson  * @param r
48399a2dd95SBruce Richardson  *   A pointer to the ring structure.
48499a2dd95SBruce Richardson  * @param obj_p
48599a2dd95SBruce Richardson  *   A pointer to a void * pointer (object) that will be filled.
48699a2dd95SBruce Richardson  * @return
48799a2dd95SBruce Richardson  *   - 0: Success, objects dequeued.
48899a2dd95SBruce Richardson  *   - -ENOENT: Not enough entries in the ring to dequeue, no object is
48999a2dd95SBruce Richardson  *     dequeued.
49099a2dd95SBruce Richardson  */
49199a2dd95SBruce Richardson static __rte_always_inline int
49299a2dd95SBruce Richardson rte_ring_dequeue(struct rte_ring *r, void **obj_p)
49399a2dd95SBruce Richardson {
49499a2dd95SBruce Richardson 	return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
49599a2dd95SBruce Richardson }
49699a2dd95SBruce Richardson 
49799a2dd95SBruce Richardson /**
49899a2dd95SBruce Richardson  * Flush a ring.
49999a2dd95SBruce Richardson  *
50099a2dd95SBruce Richardson  * This function flush all the elements in a ring
50199a2dd95SBruce Richardson  *
50299a2dd95SBruce Richardson  * @warning
50399a2dd95SBruce Richardson  * Make sure the ring is not in use while calling this function.
50499a2dd95SBruce Richardson  *
50599a2dd95SBruce Richardson  * @param r
50699a2dd95SBruce Richardson  *   A pointer to the ring structure.
50799a2dd95SBruce Richardson  */
50899a2dd95SBruce Richardson void
50999a2dd95SBruce Richardson rte_ring_reset(struct rte_ring *r);
51099a2dd95SBruce Richardson 
51199a2dd95SBruce Richardson /**
51299a2dd95SBruce Richardson  * Return the number of entries in a ring.
51399a2dd95SBruce Richardson  *
51499a2dd95SBruce Richardson  * @param r
51599a2dd95SBruce Richardson  *   A pointer to the ring structure.
51699a2dd95SBruce Richardson  * @return
51799a2dd95SBruce Richardson  *   The number of entries in the ring.
51899a2dd95SBruce Richardson  */
51999a2dd95SBruce Richardson static inline unsigned int
52099a2dd95SBruce Richardson rte_ring_count(const struct rte_ring *r)
52199a2dd95SBruce Richardson {
52299a2dd95SBruce Richardson 	uint32_t prod_tail = r->prod.tail;
52399a2dd95SBruce Richardson 	uint32_t cons_tail = r->cons.tail;
52499a2dd95SBruce Richardson 	uint32_t count = (prod_tail - cons_tail) & r->mask;
52599a2dd95SBruce Richardson 	return (count > r->capacity) ? r->capacity : count;
52699a2dd95SBruce Richardson }
52799a2dd95SBruce Richardson 
52899a2dd95SBruce Richardson /**
52999a2dd95SBruce Richardson  * Return the number of free entries in a ring.
53099a2dd95SBruce Richardson  *
53199a2dd95SBruce Richardson  * @param r
53299a2dd95SBruce Richardson  *   A pointer to the ring structure.
53399a2dd95SBruce Richardson  * @return
53499a2dd95SBruce Richardson  *   The number of free entries in the ring.
53599a2dd95SBruce Richardson  */
53699a2dd95SBruce Richardson static inline unsigned int
53799a2dd95SBruce Richardson rte_ring_free_count(const struct rte_ring *r)
53899a2dd95SBruce Richardson {
53999a2dd95SBruce Richardson 	return r->capacity - rte_ring_count(r);
54099a2dd95SBruce Richardson }
54199a2dd95SBruce Richardson 
54299a2dd95SBruce Richardson /**
54399a2dd95SBruce Richardson  * Test if a ring is full.
54499a2dd95SBruce Richardson  *
54599a2dd95SBruce Richardson  * @param r
54699a2dd95SBruce Richardson  *   A pointer to the ring structure.
54799a2dd95SBruce Richardson  * @return
54899a2dd95SBruce Richardson  *   - 1: The ring is full.
54999a2dd95SBruce Richardson  *   - 0: The ring is not full.
55099a2dd95SBruce Richardson  */
55199a2dd95SBruce Richardson static inline int
55299a2dd95SBruce Richardson rte_ring_full(const struct rte_ring *r)
55399a2dd95SBruce Richardson {
55499a2dd95SBruce Richardson 	return rte_ring_free_count(r) == 0;
55599a2dd95SBruce Richardson }
55699a2dd95SBruce Richardson 
55799a2dd95SBruce Richardson /**
55899a2dd95SBruce Richardson  * Test if a ring is empty.
55999a2dd95SBruce Richardson  *
56099a2dd95SBruce Richardson  * @param r
56199a2dd95SBruce Richardson  *   A pointer to the ring structure.
56299a2dd95SBruce Richardson  * @return
56399a2dd95SBruce Richardson  *   - 1: The ring is empty.
56499a2dd95SBruce Richardson  *   - 0: The ring is not empty.
56599a2dd95SBruce Richardson  */
56699a2dd95SBruce Richardson static inline int
56799a2dd95SBruce Richardson rte_ring_empty(const struct rte_ring *r)
56899a2dd95SBruce Richardson {
56999a2dd95SBruce Richardson 	uint32_t prod_tail = r->prod.tail;
57099a2dd95SBruce Richardson 	uint32_t cons_tail = r->cons.tail;
57199a2dd95SBruce Richardson 	return cons_tail == prod_tail;
57299a2dd95SBruce Richardson }
57399a2dd95SBruce Richardson 
57499a2dd95SBruce Richardson /**
57599a2dd95SBruce Richardson  * Return the size of the ring.
57699a2dd95SBruce Richardson  *
57799a2dd95SBruce Richardson  * @param r
57899a2dd95SBruce Richardson  *   A pointer to the ring structure.
57999a2dd95SBruce Richardson  * @return
58099a2dd95SBruce Richardson  *   The size of the data store used by the ring.
58199a2dd95SBruce Richardson  *   NOTE: this is not the same as the usable space in the ring. To query that
58299a2dd95SBruce Richardson  *   use ``rte_ring_get_capacity()``.
58399a2dd95SBruce Richardson  */
58499a2dd95SBruce Richardson static inline unsigned int
58599a2dd95SBruce Richardson rte_ring_get_size(const struct rte_ring *r)
58699a2dd95SBruce Richardson {
58799a2dd95SBruce Richardson 	return r->size;
58899a2dd95SBruce Richardson }
58999a2dd95SBruce Richardson 
59099a2dd95SBruce Richardson /**
59199a2dd95SBruce Richardson  * Return the number of elements which can be stored in the ring.
59299a2dd95SBruce Richardson  *
59399a2dd95SBruce Richardson  * @param r
59499a2dd95SBruce Richardson  *   A pointer to the ring structure.
59599a2dd95SBruce Richardson  * @return
59699a2dd95SBruce Richardson  *   The usable size of the ring.
59799a2dd95SBruce Richardson  */
59899a2dd95SBruce Richardson static inline unsigned int
59999a2dd95SBruce Richardson rte_ring_get_capacity(const struct rte_ring *r)
60099a2dd95SBruce Richardson {
60199a2dd95SBruce Richardson 	return r->capacity;
60299a2dd95SBruce Richardson }
60399a2dd95SBruce Richardson 
60499a2dd95SBruce Richardson /**
60599a2dd95SBruce Richardson  * Return sync type used by producer in the ring.
60699a2dd95SBruce Richardson  *
60799a2dd95SBruce Richardson  * @param r
60899a2dd95SBruce Richardson  *   A pointer to the ring structure.
60999a2dd95SBruce Richardson  * @return
61099a2dd95SBruce Richardson  *   Producer sync type value.
61199a2dd95SBruce Richardson  */
61299a2dd95SBruce Richardson static inline enum rte_ring_sync_type
61399a2dd95SBruce Richardson rte_ring_get_prod_sync_type(const struct rte_ring *r)
61499a2dd95SBruce Richardson {
61599a2dd95SBruce Richardson 	return r->prod.sync_type;
61699a2dd95SBruce Richardson }
61799a2dd95SBruce Richardson 
61899a2dd95SBruce Richardson /**
61999a2dd95SBruce Richardson  * Check is the ring for single producer.
62099a2dd95SBruce Richardson  *
62199a2dd95SBruce Richardson  * @param r
62299a2dd95SBruce Richardson  *   A pointer to the ring structure.
62399a2dd95SBruce Richardson  * @return
62499a2dd95SBruce Richardson  *   true if ring is SP, zero otherwise.
62599a2dd95SBruce Richardson  */
62699a2dd95SBruce Richardson static inline int
62799a2dd95SBruce Richardson rte_ring_is_prod_single(const struct rte_ring *r)
62899a2dd95SBruce Richardson {
62999a2dd95SBruce Richardson 	return (rte_ring_get_prod_sync_type(r) == RTE_RING_SYNC_ST);
63099a2dd95SBruce Richardson }
63199a2dd95SBruce Richardson 
63299a2dd95SBruce Richardson /**
63399a2dd95SBruce Richardson  * Return sync type used by consumer in the ring.
63499a2dd95SBruce Richardson  *
63599a2dd95SBruce Richardson  * @param r
63699a2dd95SBruce Richardson  *   A pointer to the ring structure.
63799a2dd95SBruce Richardson  * @return
63899a2dd95SBruce Richardson  *   Consumer sync type value.
63999a2dd95SBruce Richardson  */
64099a2dd95SBruce Richardson static inline enum rte_ring_sync_type
64199a2dd95SBruce Richardson rte_ring_get_cons_sync_type(const struct rte_ring *r)
64299a2dd95SBruce Richardson {
64399a2dd95SBruce Richardson 	return r->cons.sync_type;
64499a2dd95SBruce Richardson }
64599a2dd95SBruce Richardson 
64699a2dd95SBruce Richardson /**
64799a2dd95SBruce Richardson  * Check is the ring for single consumer.
64899a2dd95SBruce Richardson  *
64999a2dd95SBruce Richardson  * @param r
65099a2dd95SBruce Richardson  *   A pointer to the ring structure.
65199a2dd95SBruce Richardson  * @return
65299a2dd95SBruce Richardson  *   true if ring is SC, zero otherwise.
65399a2dd95SBruce Richardson  */
65499a2dd95SBruce Richardson static inline int
65599a2dd95SBruce Richardson rte_ring_is_cons_single(const struct rte_ring *r)
65699a2dd95SBruce Richardson {
65799a2dd95SBruce Richardson 	return (rte_ring_get_cons_sync_type(r) == RTE_RING_SYNC_ST);
65899a2dd95SBruce Richardson }
65999a2dd95SBruce Richardson 
66099a2dd95SBruce Richardson /**
66199a2dd95SBruce Richardson  * Dump the status of all rings on the console
66299a2dd95SBruce Richardson  *
66399a2dd95SBruce Richardson  * @param f
66499a2dd95SBruce Richardson  *   A pointer to a file for output
66599a2dd95SBruce Richardson  */
66699a2dd95SBruce Richardson void rte_ring_list_dump(FILE *f);
66799a2dd95SBruce Richardson 
66899a2dd95SBruce Richardson /**
66999a2dd95SBruce Richardson  * Search a ring from its name
67099a2dd95SBruce Richardson  *
67199a2dd95SBruce Richardson  * @param name
67299a2dd95SBruce Richardson  *   The name of the ring.
67399a2dd95SBruce Richardson  * @return
67499a2dd95SBruce Richardson  *   The pointer to the ring matching the name, or NULL if not found,
67599a2dd95SBruce Richardson  *   with rte_errno set appropriately. Possible rte_errno values include:
67699a2dd95SBruce Richardson  *    - ENOENT - required entry not available to return.
67799a2dd95SBruce Richardson  */
67899a2dd95SBruce Richardson struct rte_ring *rte_ring_lookup(const char *name);
67999a2dd95SBruce Richardson 
68099a2dd95SBruce Richardson /**
68199a2dd95SBruce Richardson  * Enqueue several objects on the ring (multi-producers safe).
68299a2dd95SBruce Richardson  *
68399a2dd95SBruce Richardson  * This function uses a "compare and set" instruction to move the
68499a2dd95SBruce Richardson  * producer index atomically.
68599a2dd95SBruce Richardson  *
68699a2dd95SBruce Richardson  * @param r
68799a2dd95SBruce Richardson  *   A pointer to the ring structure.
68899a2dd95SBruce Richardson  * @param obj_table
68999a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects).
69099a2dd95SBruce Richardson  * @param n
69199a2dd95SBruce Richardson  *   The number of objects to add in the ring from the obj_table.
69299a2dd95SBruce Richardson  * @param free_space
69399a2dd95SBruce Richardson  *   if non-NULL, returns the amount of space in the ring after the
69499a2dd95SBruce Richardson  *   enqueue operation has finished.
69599a2dd95SBruce Richardson  * @return
69699a2dd95SBruce Richardson  *   - n: Actual number of objects enqueued.
69799a2dd95SBruce Richardson  */
69899a2dd95SBruce Richardson static __rte_always_inline unsigned int
69999a2dd95SBruce Richardson rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
70099a2dd95SBruce Richardson 			 unsigned int n, unsigned int *free_space)
70199a2dd95SBruce Richardson {
70299a2dd95SBruce Richardson 	return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
70399a2dd95SBruce Richardson 			n, free_space);
70499a2dd95SBruce Richardson }
70599a2dd95SBruce Richardson 
70699a2dd95SBruce Richardson /**
70799a2dd95SBruce Richardson  * Enqueue several objects on a ring (NOT multi-producers safe).
70899a2dd95SBruce Richardson  *
70999a2dd95SBruce Richardson  * @param r
71099a2dd95SBruce Richardson  *   A pointer to the ring structure.
71199a2dd95SBruce Richardson  * @param obj_table
71299a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects).
71399a2dd95SBruce Richardson  * @param n
71499a2dd95SBruce Richardson  *   The number of objects to add in the ring from the obj_table.
71599a2dd95SBruce Richardson  * @param free_space
71699a2dd95SBruce Richardson  *   if non-NULL, returns the amount of space in the ring after the
71799a2dd95SBruce Richardson  *   enqueue operation has finished.
71899a2dd95SBruce Richardson  * @return
71999a2dd95SBruce Richardson  *   - n: Actual number of objects enqueued.
72099a2dd95SBruce Richardson  */
72199a2dd95SBruce Richardson static __rte_always_inline unsigned int
72299a2dd95SBruce Richardson rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
72399a2dd95SBruce Richardson 			 unsigned int n, unsigned int *free_space)
72499a2dd95SBruce Richardson {
72599a2dd95SBruce Richardson 	return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
72699a2dd95SBruce Richardson 			n, free_space);
72799a2dd95SBruce Richardson }
72899a2dd95SBruce Richardson 
72999a2dd95SBruce Richardson /**
73099a2dd95SBruce Richardson  * Enqueue several objects on a ring.
73199a2dd95SBruce Richardson  *
73299a2dd95SBruce Richardson  * This function calls the multi-producer or the single-producer
73399a2dd95SBruce Richardson  * version depending on the default behavior that was specified at
73499a2dd95SBruce Richardson  * ring creation time (see flags).
73599a2dd95SBruce Richardson  *
73699a2dd95SBruce Richardson  * @param r
73799a2dd95SBruce Richardson  *   A pointer to the ring structure.
73899a2dd95SBruce Richardson  * @param obj_table
73999a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects).
74099a2dd95SBruce Richardson  * @param n
74199a2dd95SBruce Richardson  *   The number of objects to add in the ring from the obj_table.
74299a2dd95SBruce Richardson  * @param free_space
74399a2dd95SBruce Richardson  *   if non-NULL, returns the amount of space in the ring after the
74499a2dd95SBruce Richardson  *   enqueue operation has finished.
74599a2dd95SBruce Richardson  * @return
74699a2dd95SBruce Richardson  *   - n: Actual number of objects enqueued.
74799a2dd95SBruce Richardson  */
74899a2dd95SBruce Richardson static __rte_always_inline unsigned int
74999a2dd95SBruce Richardson rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
75099a2dd95SBruce Richardson 		      unsigned int n, unsigned int *free_space)
75199a2dd95SBruce Richardson {
75299a2dd95SBruce Richardson 	return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
75399a2dd95SBruce Richardson 			n, free_space);
75499a2dd95SBruce Richardson }
75599a2dd95SBruce Richardson 
75699a2dd95SBruce Richardson /**
75799a2dd95SBruce Richardson  * Dequeue several objects from a ring (multi-consumers safe). When the request
75899a2dd95SBruce Richardson  * objects are more than the available objects, only dequeue the actual number
75999a2dd95SBruce Richardson  * of objects
76099a2dd95SBruce Richardson  *
76199a2dd95SBruce Richardson  * This function uses a "compare and set" instruction to move the
76299a2dd95SBruce Richardson  * consumer index atomically.
76399a2dd95SBruce Richardson  *
76499a2dd95SBruce Richardson  * @param r
76599a2dd95SBruce Richardson  *   A pointer to the ring structure.
76699a2dd95SBruce Richardson  * @param obj_table
76799a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects) that will be filled.
76899a2dd95SBruce Richardson  * @param n
76999a2dd95SBruce Richardson  *   The number of objects to dequeue from the ring to the obj_table.
77099a2dd95SBruce Richardson  * @param available
77199a2dd95SBruce Richardson  *   If non-NULL, returns the number of remaining ring entries after the
77299a2dd95SBruce Richardson  *   dequeue has finished.
77399a2dd95SBruce Richardson  * @return
77499a2dd95SBruce Richardson  *   - n: Actual number of objects dequeued, 0 if ring is empty
77599a2dd95SBruce Richardson  */
77699a2dd95SBruce Richardson static __rte_always_inline unsigned int
77799a2dd95SBruce Richardson rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
77899a2dd95SBruce Richardson 		unsigned int n, unsigned int *available)
77999a2dd95SBruce Richardson {
78099a2dd95SBruce Richardson 	return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
78199a2dd95SBruce Richardson 			n, available);
78299a2dd95SBruce Richardson }
78399a2dd95SBruce Richardson 
78499a2dd95SBruce Richardson /**
78599a2dd95SBruce Richardson  * Dequeue several objects from a ring (NOT multi-consumers safe).When the
78699a2dd95SBruce Richardson  * request objects are more than the available objects, only dequeue the
78799a2dd95SBruce Richardson  * actual number of objects
78899a2dd95SBruce Richardson  *
78999a2dd95SBruce Richardson  * @param r
79099a2dd95SBruce Richardson  *   A pointer to the ring structure.
79199a2dd95SBruce Richardson  * @param obj_table
79299a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects) that will be filled.
79399a2dd95SBruce Richardson  * @param n
79499a2dd95SBruce Richardson  *   The number of objects to dequeue from the ring to the obj_table.
79599a2dd95SBruce Richardson  * @param available
79699a2dd95SBruce Richardson  *   If non-NULL, returns the number of remaining ring entries after the
79799a2dd95SBruce Richardson  *   dequeue has finished.
79899a2dd95SBruce Richardson  * @return
79999a2dd95SBruce Richardson  *   - n: Actual number of objects dequeued, 0 if ring is empty
80099a2dd95SBruce Richardson  */
80199a2dd95SBruce Richardson static __rte_always_inline unsigned int
80299a2dd95SBruce Richardson rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
80399a2dd95SBruce Richardson 		unsigned int n, unsigned int *available)
80499a2dd95SBruce Richardson {
80599a2dd95SBruce Richardson 	return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
80699a2dd95SBruce Richardson 			n, available);
80799a2dd95SBruce Richardson }
80899a2dd95SBruce Richardson 
80999a2dd95SBruce Richardson /**
81099a2dd95SBruce Richardson  * Dequeue multiple objects from a ring up to a maximum number.
81199a2dd95SBruce Richardson  *
81299a2dd95SBruce Richardson  * This function calls the multi-consumers or the single-consumer
81399a2dd95SBruce Richardson  * version, depending on the default behaviour that was specified at
81499a2dd95SBruce Richardson  * ring creation time (see flags).
81599a2dd95SBruce Richardson  *
81699a2dd95SBruce Richardson  * @param r
81799a2dd95SBruce Richardson  *   A pointer to the ring structure.
81899a2dd95SBruce Richardson  * @param obj_table
81999a2dd95SBruce Richardson  *   A pointer to a table of void * pointers (objects) that will be filled.
82099a2dd95SBruce Richardson  * @param n
82199a2dd95SBruce Richardson  *   The number of objects to dequeue from the ring to the obj_table.
82299a2dd95SBruce Richardson  * @param available
82399a2dd95SBruce Richardson  *   If non-NULL, returns the number of remaining ring entries after the
82499a2dd95SBruce Richardson  *   dequeue has finished.
82599a2dd95SBruce Richardson  * @return
82699a2dd95SBruce Richardson  *   - Number of objects dequeued
82799a2dd95SBruce Richardson  */
82899a2dd95SBruce Richardson static __rte_always_inline unsigned int
82999a2dd95SBruce Richardson rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
83099a2dd95SBruce Richardson 		unsigned int n, unsigned int *available)
83199a2dd95SBruce Richardson {
83299a2dd95SBruce Richardson 	return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
83399a2dd95SBruce Richardson 			n, available);
83499a2dd95SBruce Richardson }
83599a2dd95SBruce Richardson 
83699a2dd95SBruce Richardson #ifdef __cplusplus
83799a2dd95SBruce Richardson }
83899a2dd95SBruce Richardson #endif
83999a2dd95SBruce Richardson 
84099a2dd95SBruce Richardson #endif /* _RTE_RING_H_ */
841