DPDK  20.11.10
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 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <stdint.h>
22 
23 #include <rte_common.h>
24 #include <rte_memory.h>
25 #include <rte_malloc.h>
26 #include <rte_ring.h>
27 #include <rte_ring_elem.h>
28 #include "rte_eventdev.h"
29 
30 #define RTE_TAILQ_EVENT_RING_NAME "RTE_EVENT_RING"
31 
40  struct rte_ring r;
41 };
42 
51 static __rte_always_inline unsigned int
53 {
54  return rte_ring_count(&r->r);
55 }
56 
66 static __rte_always_inline unsigned int
68 {
69  return rte_ring_free_count(&r->r);
70 }
71 
92 static __rte_always_inline unsigned int
94  const struct rte_event *events,
95  unsigned int n, uint16_t *free_space)
96 {
97  unsigned int num;
98  uint32_t space;
99 
100  num = rte_ring_enqueue_burst_elem(&r->r, events,
101  sizeof(struct rte_event), n,
102  &space);
103 
104  if (free_space != NULL)
105  *free_space = space;
106 
107  return num;
108 }
109 
128 static __rte_always_inline unsigned int
130  struct rte_event *events,
131  unsigned int n, uint16_t *available)
132 {
133  unsigned int num;
134  uint32_t remaining;
135 
136  num = rte_ring_dequeue_burst_elem(&r->r, events,
137  sizeof(struct rte_event), n,
138  &remaining);
139 
140  if (available != NULL)
141  *available = remaining;
142 
143  return num;
144 }
145 
146 /*
147  * Initializes an already-allocated ring structure
148  *
149  * @param r
150  * pointer to the ring memory to be initialized
151  * @param name
152  * name to be given to the ring
153  * @param count
154  * the number of elements to be stored in the ring. If the flag
155  * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
156  * usable space in the ring will be ``count - 1`` entries. If the flag
157  * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
158  * limit - 1, and the usable space will be exactly that requested.
159  * @param flags
160  * An OR of the following:
161  * - RING_F_SP_ENQ: If this flag is set, the default behavior when
162  * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
163  * is "single-producer". Otherwise, it is "multi-producers".
164  * - RING_F_SC_DEQ: If this flag is set, the default behavior when
165  * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
166  * is "single-consumer". Otherwise, it is "multi-consumers".
167  * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
168  * be taken as the exact usable size of the ring, and as such does not
169  * need to be a power of 2. The underlying ring memory should be a
170  * power-of-2 size greater than the count value.
171  * @return
172  * 0 on success, or a negative value on error.
173  */
174 int
175 rte_event_ring_init(struct rte_event_ring *r, const char *name,
176  unsigned int count, unsigned int flags);
177 
178 /*
179  * Create an event ring structure
180  *
181  * This function allocates memory and initializes an event ring inside that
182  * memory.
183  *
184  * @param name
185  * name to be given to the ring
186  * @param count
187  * the number of elements to be stored in the ring. If the flag
188  * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
189  * usable space in the ring will be ``count - 1`` entries. If the flag
190  * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
191  * limit - 1, and the usable space will be exactly that requested.
192  * @param socket_id
193  * The *socket_id* argument is the socket identifier in case of
194  * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
195  * constraint for the reserved zone.
196  * @param flags
197  * An OR of the following:
198  * - RING_F_SP_ENQ: If this flag is set, the default behavior when
199  * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
200  * is "single-producer". Otherwise, it is "multi-producers".
201  * - RING_F_SC_DEQ: If this flag is set, the default behavior when
202  * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
203  * is "single-consumer". Otherwise, it is "multi-consumers".
204  * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
205  * be taken as the exact usable size of the ring, and as such does not
206  * need to be a power of 2. The underlying ring memory should be a
207  * power-of-2 size greater than the count value.
208  * @return
209  * On success, the pointer to the new allocated ring. NULL on error with
210  * rte_errno set appropriately. Possible errno values include:
211  * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
212  * - E_RTE_SECONDARY - function was called from a secondary process instance
213  * - EINVAL - count provided is not a power of 2
214  * - ENOSPC - the maximum number of memzones has already been allocated
215  * - EEXIST - a memzone with the same name already exists
216  * - ENOMEM - no appropriate memory area found in which to create memzone
217  */
218 struct rte_event_ring *
219 rte_event_ring_create(const char *name, unsigned int count, int socket_id,
220  unsigned int flags);
221 
232 struct rte_event_ring *
233 rte_event_ring_lookup(const char *name);
234 
241 void
243 
254 static inline unsigned int
256 {
257  return rte_ring_get_size(&r->r);
258 }
259 
268 static inline unsigned int
270 {
271  return rte_ring_get_capacity(&r->r);
272 }
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 
278 #endif
#define __rte_always_inline
Definition: rte_common.h:231
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:565
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:551
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:503
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:486