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