1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
3 * Copyright(c) 2019 Arm Limited
10 * This provides a ring implementation for passing rte_event structures
11 * from one core to another.
14 #ifndef _RTE_EVENT_RING_
15 #define _RTE_EVENT_RING_
19 #include <rte_common.h>
20 #include <rte_memory.h>
21 #include <rte_malloc.h>
23 #include <rte_ring_elem.h>
24 #include "rte_eventdev.h"
26 #define RTE_TAILQ_EVENT_RING_NAME "RTE_EVENT_RING"
29 * Generic ring structure for passing rte_event objects from core to core.
31 * Based on the primitives given in the rte_ring library. Designed to be
32 * used inside software eventdev implementations and by applications
35 struct rte_event_ring {
40 * Returns the number of events in the ring
43 * pointer to the event ring
45 * the number of events in the ring
47 static __rte_always_inline unsigned int
48 rte_event_ring_count(const struct rte_event_ring *r)
50 return rte_ring_count(&r->r);
54 * Returns the amount of free space in the ring
57 * pointer to the event ring
59 * the number of free slots in the ring, i.e. the number of events that
60 * can be successfully enqueued before dequeue must be called
62 static __rte_always_inline unsigned int
63 rte_event_ring_free_count(const struct rte_event_ring *r)
65 return rte_ring_free_count(&r->r);
69 * Enqueue a set of events onto a ring
71 * Note: this API enqueues by copying the events themselves onto the ring,
72 * rather than just placing a pointer to each event onto the ring. This
73 * means that statically-allocated events can safely be enqueued by this
77 * pointer to the event ring
79 * pointer to an array of struct rte_event objects
81 * number of events in the array to enqueue
83 * if non-null, is updated to indicate the amount of free space in the
84 * ring once the enqueue has completed.
86 * the number of elements, n', enqueued to the ring, 0 <= n' <= n
88 static __rte_always_inline unsigned int
89 rte_event_ring_enqueue_burst(struct rte_event_ring *r,
90 const struct rte_event *events,
91 unsigned int n, uint16_t *free_space)
96 num = rte_ring_enqueue_burst_elem(&r->r, events,
97 sizeof(struct rte_event), n,
100 if (free_space != NULL)
107 * Dequeue a set of events from a ring
109 * Note: this API does not work with pointers to events, rather it copies
110 * the events themselves to the destination ``events`` buffer.
113 * pointer to the event ring
115 * pointer to an array to hold the struct rte_event objects
117 * number of events that can be held in the ``events`` array
119 * if non-null, is updated to indicate the number of events remaining in
120 * the ring once the dequeue has completed
122 * the number of elements, n', dequeued from the ring, 0 <= n' <= n
124 static __rte_always_inline unsigned int
125 rte_event_ring_dequeue_burst(struct rte_event_ring *r,
126 struct rte_event *events,
127 unsigned int n, uint16_t *available)
132 num = rte_ring_dequeue_burst_elem(&r->r, events,
133 sizeof(struct rte_event), n,
136 if (available != NULL)
137 *available = remaining;
143 * Initializes an already-allocated ring structure
146 * pointer to the ring memory to be initialized
148 * name to be given to the ring
150 * the number of elements to be stored in the ring. If the flag
151 * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
152 * usable space in the ring will be ``count - 1`` entries. If the flag
153 * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
154 * limit - 1, and the usable space will be exactly that requested.
156 * An OR of the following:
157 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
158 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
159 * is "single-producer". Otherwise, it is "multi-producers".
160 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
161 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
162 * is "single-consumer". Otherwise, it is "multi-consumers".
163 * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
164 * be taken as the exact usable size of the ring, and as such does not
165 * need to be a power of 2. The underlying ring memory should be a
166 * power-of-2 size greater than the count value.
168 * 0 on success, or a negative value on error.
171 rte_event_ring_init(struct rte_event_ring *r, const char *name,
172 unsigned int count, unsigned int flags);
175 * Create an event ring structure
177 * This function allocates memory and initializes an event ring inside that
181 * name to be given to the ring
183 * the number of elements to be stored in the ring. If the flag
184 * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
185 * usable space in the ring will be ``count - 1`` entries. If the flag
186 * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
187 * limit - 1, and the usable space will be exactly that requested.
189 * The *socket_id* argument is the socket identifier in case of
190 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
191 * constraint for the reserved zone.
193 * An OR of the following:
194 * - RING_F_SP_ENQ: If this flag is set, the default behavior when
195 * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
196 * is "single-producer". Otherwise, it is "multi-producers".
197 * - RING_F_SC_DEQ: If this flag is set, the default behavior when
198 * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
199 * is "single-consumer". Otherwise, it is "multi-consumers".
200 * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
201 * be taken as the exact usable size of the ring, and as such does not
202 * need to be a power of 2. The underlying ring memory should be a
203 * power-of-2 size greater than the count value.
205 * On success, the pointer to the new allocated ring. NULL on error with
206 * rte_errno set appropriately. Possible errno values include:
207 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
208 * - E_RTE_SECONDARY - function was called from a secondary process instance
209 * - EINVAL - count provided is not a power of 2
210 * - ENOSPC - the maximum number of memzones has already been allocated
211 * - EEXIST - a memzone with the same name already exists
212 * - ENOMEM - no appropriate memory area found in which to create memzone
214 struct rte_event_ring *
215 rte_event_ring_create(const char *name, unsigned int count, int socket_id,
219 * Search for an event ring based on its name
222 * The name of the ring.
224 * The pointer to the ring matching the name, or NULL if not found,
225 * with rte_errno set appropriately. Possible rte_errno values include:
226 * - ENOENT - required entry not available to return.
228 struct rte_event_ring *
229 rte_event_ring_lookup(const char *name);
232 * De-allocate all memory used by the ring.
238 rte_event_ring_free(struct rte_event_ring *r);
241 * Return the size of the event ring.
244 * A pointer to the ring structure.
246 * The size of the data store used by the ring.
247 * NOTE: this is not the same as the usable space in the ring. To query that
248 * use ``rte_ring_get_capacity()``.
250 static inline unsigned int
251 rte_event_ring_get_size(const struct rte_event_ring *r)
253 return rte_ring_get_size(&r->r);
257 * Return the number of elements which can be stored in the event ring.
260 * A pointer to the ring structure.
262 * The usable size of the ring.
264 static inline unsigned int
265 rte_event_ring_get_capacity(const struct rte_event_ring *r)
267 return rte_ring_get_capacity(&r->r);