DPDK  25.03.0
rte_event_ring.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Intel Corporation
3  * Copyright(c) 2019 Arm Limited
4  */
5 
14 #ifndef _RTE_EVENT_RING_
15 #define _RTE_EVENT_RING_
16 
17 #include <stdint.h>
18 
19 #include <rte_common.h>
20 #include <rte_ring.h>
21 #include <rte_ring_elem.h>
22 #include "rte_eventdev.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define RTE_TAILQ_EVENT_RING_NAME "RTE_EVENT_RING"
29 
38  struct rte_ring r;
39 };
40 
49 static __rte_always_inline unsigned int
51 {
52  return rte_ring_count(&r->r);
53 }
54 
64 static __rte_always_inline unsigned int
66 {
67  return rte_ring_free_count(&r->r);
68 }
69 
70 
90 static __rte_always_inline unsigned int
92  const struct rte_event *events,
93  unsigned int n, uint16_t *free_space)
94 {
95  unsigned int num;
96  uint32_t space;
97 
98  num = rte_ring_enqueue_bulk_elem(&r->r, events,
99  sizeof(struct rte_event), n,
100  &space);
101 
102  if (free_space != NULL)
103  *free_space = space;
104 
105  return num;
106 }
107 
126 static __rte_always_inline unsigned int
128  struct rte_event *events,
129  unsigned int n, uint16_t *available)
130 {
131  unsigned int num;
132  uint32_t remaining;
133 
134  num = rte_ring_dequeue_bulk_elem(&r->r, events,
135  sizeof(struct rte_event), n,
136  &remaining);
137 
138  if (available != NULL)
139  *available = remaining;
140 
141  return num;
142 }
143 
164 static __rte_always_inline unsigned int
166  const struct rte_event *events,
167  unsigned int n, uint16_t *free_space)
168 {
169  unsigned int num;
170  uint32_t space;
171 
172  num = rte_ring_enqueue_burst_elem(&r->r, events,
173  sizeof(struct rte_event), n,
174  &space);
175 
176  if (free_space != NULL)
177  *free_space = space;
178 
179  return num;
180 }
181 
200 static __rte_always_inline unsigned int
202  struct rte_event *events,
203  unsigned int n, uint16_t *available)
204 {
205  unsigned int num;
206  uint32_t remaining;
207 
208  num = rte_ring_dequeue_burst_elem(&r->r, events,
209  sizeof(struct rte_event), n,
210  &remaining);
211 
212  if (available != NULL)
213  *available = remaining;
214 
215  return num;
216 }
217 
218 /*
219  * Initializes an already-allocated ring structure
220  *
221  * @param r
222  * pointer to the ring memory to be initialized
223  * @param name
224  * name to be given to the ring
225  * @param count
226  * the number of elements to be stored in the ring. If the flag
227  * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
228  * usable space in the ring will be ``count - 1`` entries. If the flag
229  * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
230  * limit - 1, and the usable space will be exactly that requested.
231  * @param flags
232  * An OR of the following:
233  * - RING_F_SP_ENQ: If this flag is set, the default behavior when
234  * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
235  * is "single-producer". Otherwise, it is "multi-producers".
236  * - RING_F_SC_DEQ: If this flag is set, the default behavior when
237  * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
238  * is "single-consumer". Otherwise, it is "multi-consumers".
239  * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
240  * be taken as the exact usable size of the ring, and as such does not
241  * need to be a power of 2. The underlying ring memory should be a
242  * power-of-2 size greater than the count value.
243  * @return
244  * 0 on success, or a negative value on error.
245  */
246 int
247 rte_event_ring_init(struct rte_event_ring *r, const char *name,
248  unsigned int count, unsigned int flags);
249 
257 void
259 
300 struct rte_event_ring *
301 rte_event_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
303 
314 struct rte_event_ring *
315 rte_event_ring_lookup(const char *name);
316 
327 static inline unsigned int
329 {
330  return rte_ring_get_size(&r->r);
331 }
332 
341 static inline unsigned int
343 {
344  return rte_ring_get_capacity(&r->r);
345 }
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 #endif
#define __rte_always_inline
Definition: rte_common.h:456
void rte_event_ring_free(struct rte_event_ring *r)
static __rte_always_inline unsigned int rte_ring_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned int rte_event_ring_enqueue_burst(struct rte_event_ring *r, const struct rte_event *events, unsigned int n, uint16_t *free_space)
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:601
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:587
static __rte_always_inline unsigned int rte_event_ring_free_count(const struct rte_event_ring *r)
struct rte_event_ring * rte_event_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags) __rte_malloc __rte_dealloc(rte_event_ring_free
static unsigned int rte_event_ring_get_capacity(const struct rte_event_ring *r)
#define __rte_dealloc(dealloc, argno)
Definition: rte_common.h:305
static __rte_always_inline unsigned int rte_ring_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
#define __rte_malloc
Definition: rte_common.h:294
static __rte_always_inline unsigned int rte_event_ring_dequeue_bulk(struct rte_event_ring *r, struct rte_event *events, unsigned int n, uint16_t *available)
static __rte_always_inline unsigned int rte_event_ring_dequeue_burst(struct rte_event_ring *r, struct rte_event *events, unsigned int n, uint16_t *available)
static __rte_always_inline unsigned int rte_event_ring_enqueue_bulk(struct rte_event_ring *r, const struct rte_event *events, unsigned int n, uint16_t *free_space)
struct rte_event_ring struct rte_event_ring * rte_event_ring_lookup(const char *name)
static __rte_always_inline unsigned int rte_event_ring_count(const struct rte_event_ring *r)
char name[RTE_RING_NAMESIZE]
static __rte_always_inline unsigned int rte_ring_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static unsigned int rte_event_ring_get_size(const struct rte_event_ring *r)
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:539
static __rte_always_inline unsigned int rte_ring_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static unsigned int rte_ring_count(const struct rte_ring *r)
Definition: rte_ring.h:522