DPDK  21.02.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_memory.h>
21 #include <rte_malloc.h>
22 #include <rte_ring.h>
23 #include <rte_ring_elem.h>
24 #include "rte_eventdev.h"
25 
26 #define RTE_TAILQ_EVENT_RING_NAME "RTE_EVENT_RING"
27 
36  struct rte_ring r;
37 };
38 
47 static __rte_always_inline unsigned int
49 {
50  return rte_ring_count(&r->r);
51 }
52 
62 static __rte_always_inline unsigned int
64 {
65  return rte_ring_free_count(&r->r);
66 }
67 
88 static __rte_always_inline unsigned int
90  const struct rte_event *events,
91  unsigned int n, uint16_t *free_space)
92 {
93  unsigned int num;
94  uint32_t space;
95 
96  num = rte_ring_enqueue_burst_elem(&r->r, events,
97  sizeof(struct rte_event), n,
98  &space);
99 
100  if (free_space != NULL)
101  *free_space = space;
102 
103  return num;
104 }
105 
124 static __rte_always_inline unsigned int
126  struct rte_event *events,
127  unsigned int n, uint16_t *available)
128 {
129  unsigned int num;
130  uint32_t remaining;
131 
132  num = rte_ring_dequeue_burst_elem(&r->r, events,
133  sizeof(struct rte_event), n,
134  &remaining);
135 
136  if (available != NULL)
137  *available = remaining;
138 
139  return num;
140 }
141 
142 /*
143  * Initializes an already-allocated ring structure
144  *
145  * @param r
146  * pointer to the ring memory to be initialized
147  * @param name
148  * name to be given to the ring
149  * @param count
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.
155  * @param flags
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.
167  * @return
168  * 0 on success, or a negative value on error.
169  */
170 int
171 rte_event_ring_init(struct rte_event_ring *r, const char *name,
172  unsigned int count, unsigned int flags);
173 
174 /*
175  * Create an event ring structure
176  *
177  * This function allocates memory and initializes an event ring inside that
178  * memory.
179  *
180  * @param name
181  * name to be given to the ring
182  * @param count
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.
188  * @param socket_id
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.
192  * @param flags
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.
204  * @return
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
213  */
214 struct rte_event_ring *
215 rte_event_ring_create(const char *name, unsigned int count, int socket_id,
216  unsigned int flags);
217 
228 struct rte_event_ring *
229 rte_event_ring_lookup(const char *name);
230 
237 void
239 
250 static inline unsigned int
252 {
253  return rte_ring_get_size(&r->r);
254 }
255 
264 static inline unsigned int
266 {
267  return rte_ring_get_capacity(&r->r);
268 }
269 #endif
#define __rte_always_inline
Definition: rte_common.h:226
struct rte_event_ring * rte_event_ring_lookup(const char *name)
void rte_event_ring_free(struct rte_event_ring *r)
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:568
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:554
static __rte_always_inline unsigned int rte_event_ring_free_count(const struct rte_event_ring *r)
static unsigned int rte_event_ring_get_capacity(const struct rte_event_ring *r)
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)
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_count(const struct rte_event_ring *r)
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:506
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:489