DPDK  19.11.14
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  */
4 
13 #ifndef _RTE_EVENT_RING_
14 #define _RTE_EVENT_RING_
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <stdint.h>
21 
22 #include <rte_common.h>
23 #include <rte_memory.h>
24 #include <rte_malloc.h>
25 #include <rte_ring.h>
26 #include "rte_eventdev.h"
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 
90 static __rte_always_inline unsigned int
92  const struct rte_event *events,
93  unsigned int n, uint16_t *free_space)
94 {
95  uint32_t prod_head, prod_next;
96  uint32_t free_entries;
97 
98  n = __rte_ring_move_prod_head(&r->r, r->r.prod.single, n,
99  RTE_RING_QUEUE_VARIABLE,
100  &prod_head, &prod_next, &free_entries);
101  if (n == 0)
102  goto end;
103 
104  ENQUEUE_PTRS(&r->r, &r[1], prod_head, events, n, struct rte_event);
105 
106  update_tail(&r->r.prod, prod_head, prod_next, r->r.prod.single, 1);
107 end:
108  if (free_space != NULL)
109  *free_space = free_entries - n;
110  return n;
111 }
112 
131 static __rte_always_inline unsigned int
133  struct rte_event *events,
134  unsigned int n, uint16_t *available)
135 {
136  uint32_t cons_head, cons_next;
137  uint32_t entries;
138 
139  n = __rte_ring_move_cons_head(&r->r, r->r.cons.single, n,
140  RTE_RING_QUEUE_VARIABLE,
141  &cons_head, &cons_next, &entries);
142  if (n == 0)
143  goto end;
144 
145  DEQUEUE_PTRS(&r->r, &r[1], cons_head, events, n, struct rte_event);
146 
147  update_tail(&r->r.cons, cons_head, cons_next, r->r.cons.single, 0);
148 
149 end:
150  if (available != NULL)
151  *available = entries - n;
152  return n;
153 }
154 
155 /*
156  * Initializes an already-allocated ring structure
157  *
158  * @param r
159  * pointer to the ring memory to be initialized
160  * @param name
161  * name to be given to the ring
162  * @param count
163  * the number of elements to be stored in the ring. If the flag
164  * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
165  * usable space in the ring will be ``count - 1`` entries. If the flag
166  * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
167  * limit - 1, and the usable space will be exactly that requested.
168  * @param flags
169  * An OR of the following:
170  * - RING_F_SP_ENQ: If this flag is set, the default behavior when
171  * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
172  * is "single-producer". Otherwise, it is "multi-producers".
173  * - RING_F_SC_DEQ: If this flag is set, the default behavior when
174  * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
175  * is "single-consumer". Otherwise, it is "multi-consumers".
176  * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
177  * be taken as the exact usable size of the ring, and as such does not
178  * need to be a power of 2. The underlying ring memory should be a
179  * power-of-2 size greater than the count value.
180  * @return
181  * 0 on success, or a negative value on error.
182  */
183 int
184 rte_event_ring_init(struct rte_event_ring *r, const char *name,
185  unsigned int count, unsigned int flags);
186 
187 /*
188  * Create an event ring structure
189  *
190  * This function allocates memory and initializes an event ring inside that
191  * memory.
192  *
193  * @param name
194  * name to be given to the ring
195  * @param count
196  * the number of elements to be stored in the ring. If the flag
197  * ``RING_F_EXACT_SZ`` is not set, this must be a power of 2, and the actual
198  * usable space in the ring will be ``count - 1`` entries. If the flag
199  * ``RING_F_EXACT_SZ`` is set, the this can be any value up to the ring size
200  * limit - 1, and the usable space will be exactly that requested.
201  * @param socket_id
202  * The *socket_id* argument is the socket identifier in case of
203  * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
204  * constraint for the reserved zone.
205  * @param flags
206  * An OR of the following:
207  * - RING_F_SP_ENQ: If this flag is set, the default behavior when
208  * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
209  * is "single-producer". Otherwise, it is "multi-producers".
210  * - RING_F_SC_DEQ: If this flag is set, the default behavior when
211  * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
212  * is "single-consumer". Otherwise, it is "multi-consumers".
213  * - RING_F_EXACT_SZ: If this flag is set, the ``count`` parameter is to
214  * be taken as the exact usable size of the ring, and as such does not
215  * need to be a power of 2. The underlying ring memory should be a
216  * power-of-2 size greater than the count value.
217  * @return
218  * On success, the pointer to the new allocated ring. NULL on error with
219  * rte_errno set appropriately. Possible errno values include:
220  * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
221  * - E_RTE_SECONDARY - function was called from a secondary process instance
222  * - EINVAL - count provided is not a power of 2
223  * - ENOSPC - the maximum number of memzones has already been allocated
224  * - EEXIST - a memzone with the same name already exists
225  * - ENOMEM - no appropriate memory area found in which to create memzone
226  */
227 struct rte_event_ring *
228 rte_event_ring_create(const char *name, unsigned int count, int socket_id,
229  unsigned int flags);
230 
241 struct rte_event_ring *
242 rte_event_ring_lookup(const char *name);
243 
250 void
252 
263 static inline unsigned int
265 {
266  return rte_ring_get_size(&r->r);
267 }
268 
277 static inline unsigned int
279 {
280  return rte_ring_get_capacity(&r->r);
281 }
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif
#define __rte_always_inline
Definition: rte_common.h:158
struct rte_event_ring * rte_event_ring_lookup(const char *name)
int flags
Definition: rte_ring.h:88
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:772
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:758
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_event_ring_dequeue_burst(struct rte_event_ring *r, struct rte_event *events, unsigned int n, uint16_t *available)
static unsigned rte_ring_count(const struct rte_ring *r)
Definition: rte_ring.h:695
static __rte_always_inline unsigned int rte_event_ring_count(const struct rte_event_ring *r)
static unsigned rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:712
static unsigned int rte_event_ring_get_size(const struct rte_event_ring *r)