DPDK  20.05.0
rte_ring_rts.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2010-2020 Intel Corporation
4  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
5  * All rights reserved.
6  * Derived from FreeBSD's bufring.h
7  * Used as BSD-3 Licensed with permission from Kip Macy.
8  */
9 
10 #ifndef _RTE_RING_RTS_H_
11 #define _RTE_RING_RTS_H_
12 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 #include <rte_ring_rts_c11_mem.h>
60 
83 static __rte_always_inline unsigned int
84 __rte_ring_do_rts_enqueue_elem(struct rte_ring *r, const void *obj_table,
85  uint32_t esize, uint32_t n, enum rte_ring_queue_behavior behavior,
86  uint32_t *free_space)
87 {
88  uint32_t free, head;
89 
90  n = __rte_ring_rts_move_prod_head(r, n, behavior, &head, &free);
91 
92  if (n != 0) {
93  __rte_ring_enqueue_elems(r, head, obj_table, esize, n);
94  __rte_ring_rts_update_tail(&r->rts_prod);
95  }
96 
97  if (free_space != NULL)
98  *free_space = free - n;
99  return n;
100 }
101 
124 static __rte_always_inline unsigned int
125 __rte_ring_do_rts_dequeue_elem(struct rte_ring *r, void *obj_table,
126  uint32_t esize, uint32_t n, enum rte_ring_queue_behavior behavior,
127  uint32_t *available)
128 {
129  uint32_t entries, head;
130 
131  n = __rte_ring_rts_move_cons_head(r, n, behavior, &head, &entries);
132 
133  if (n != 0) {
134  __rte_ring_dequeue_elems(r, head, obj_table, esize, n);
135  __rte_ring_rts_update_tail(&r->rts_cons);
136  }
137 
138  if (available != NULL)
139  *available = entries - n;
140  return n;
141 }
142 
162 __rte_experimental
163 static __rte_always_inline unsigned int
164 rte_ring_mp_rts_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
165  unsigned int esize, unsigned int n, unsigned int *free_space)
166 {
167  return __rte_ring_do_rts_enqueue_elem(r, obj_table, esize, n,
168  RTE_RING_QUEUE_FIXED, free_space);
169 }
170 
190 __rte_experimental
191 static __rte_always_inline unsigned int
192 rte_ring_mc_rts_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
193  unsigned int esize, unsigned int n, unsigned int *available)
194 {
195  return __rte_ring_do_rts_dequeue_elem(r, obj_table, esize, n,
196  RTE_RING_QUEUE_FIXED, available);
197 }
198 
218 __rte_experimental
219 static __rte_always_inline unsigned
220 rte_ring_mp_rts_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
221  unsigned int esize, unsigned int n, unsigned int *free_space)
222 {
223  return __rte_ring_do_rts_enqueue_elem(r, obj_table, esize, n,
224  RTE_RING_QUEUE_VARIABLE, free_space);
225 }
226 
248 __rte_experimental
249 static __rte_always_inline unsigned
250 rte_ring_mc_rts_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
251  unsigned int esize, unsigned int n, unsigned int *available)
252 {
253  return __rte_ring_do_rts_dequeue_elem(r, obj_table, esize, n,
254  RTE_RING_QUEUE_VARIABLE, available);
255 }
256 
272 __rte_experimental
273 static __rte_always_inline unsigned int
274 rte_ring_mp_rts_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
275  unsigned int n, unsigned int *free_space)
276 {
277  return rte_ring_mp_rts_enqueue_bulk_elem(r, obj_table,
278  sizeof(uintptr_t), n, free_space);
279 }
280 
296 __rte_experimental
297 static __rte_always_inline unsigned int
298 rte_ring_mc_rts_dequeue_bulk(struct rte_ring *r, void **obj_table,
299  unsigned int n, unsigned int *available)
300 {
301  return rte_ring_mc_rts_dequeue_bulk_elem(r, obj_table,
302  sizeof(uintptr_t), n, available);
303 }
304 
320 __rte_experimental
321 static __rte_always_inline unsigned
322 rte_ring_mp_rts_enqueue_burst(struct rte_ring *r, void * const *obj_table,
323  unsigned int n, unsigned int *free_space)
324 {
325  return rte_ring_mp_rts_enqueue_burst_elem(r, obj_table,
326  sizeof(uintptr_t), n, free_space);
327 }
328 
346 __rte_experimental
347 static __rte_always_inline unsigned
348 rte_ring_mc_rts_dequeue_burst(struct rte_ring *r, void **obj_table,
349  unsigned int n, unsigned int *available)
350 {
351  return rte_ring_mc_rts_dequeue_burst_elem(r, obj_table,
352  sizeof(uintptr_t), n, available);
353 }
354 
364 __rte_experimental
365 static inline uint32_t
367 {
368  if (r->prod.sync_type == RTE_RING_SYNC_MT_RTS)
369  return r->rts_prod.htd_max;
370  return UINT32_MAX;
371 }
372 
384 __rte_experimental
385 static inline int
386 rte_ring_set_prod_htd_max(struct rte_ring *r, uint32_t v)
387 {
388  if (r->prod.sync_type != RTE_RING_SYNC_MT_RTS)
389  return -ENOTSUP;
390 
391  r->rts_prod.htd_max = v;
392  return 0;
393 }
394 
404 __rte_experimental
405 static inline uint32_t
407 {
408  if (r->cons.sync_type == RTE_RING_SYNC_MT_RTS)
409  return r->rts_cons.htd_max;
410  return UINT32_MAX;
411 }
412 
424 __rte_experimental
425 static inline int
426 rte_ring_set_cons_htd_max(struct rte_ring *r, uint32_t v)
427 {
428  if (r->cons.sync_type != RTE_RING_SYNC_MT_RTS)
429  return -ENOTSUP;
430 
431  r->rts_cons.htd_max = v;
432  return 0;
433 }
434 
435 #ifdef __cplusplus
436 }
437 #endif
438 
439 #endif /* _RTE_RING_RTS_H_ */
static __rte_experimental __rte_always_inline unsigned int rte_ring_mc_rts_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring_rts.h:298
#define __rte_always_inline
Definition: rte_common.h:193
static __rte_experimental __rte_always_inline unsigned rte_ring_mc_rts_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring_rts.h:348
rte_ring_queue_behavior
Definition: rte_ring_core.h:44
static __rte_experimental int rte_ring_set_cons_htd_max(struct rte_ring *r, uint32_t v)
Definition: rte_ring_rts.h:426
static __rte_experimental __rte_always_inline unsigned rte_ring_mc_rts_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
Definition: rte_ring_rts.h:250
static __rte_experimental __rte_always_inline unsigned int rte_ring_mc_rts_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
Definition: rte_ring_rts.h:192
static __rte_experimental int rte_ring_set_prod_htd_max(struct rte_ring *r, uint32_t v)
Definition: rte_ring_rts.h:386
static __rte_experimental __rte_always_inline unsigned rte_ring_mp_rts_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring_rts.h:322
static __rte_experimental __rte_always_inline unsigned int rte_ring_mp_rts_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
Definition: rte_ring_rts.h:164
static __rte_experimental __rte_always_inline unsigned rte_ring_mp_rts_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
Definition: rte_ring_rts.h:220
static __rte_experimental __rte_always_inline unsigned int rte_ring_mp_rts_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring_rts.h:274
static __rte_experimental uint32_t rte_ring_get_cons_htd_max(const struct rte_ring *r)
Definition: rte_ring_rts.h:406
enum rte_ring_sync_type sync_type
Definition: rte_ring_core.h:77
static __rte_experimental uint32_t rte_ring_get_prod_htd_max(const struct rte_ring *r)
Definition: rte_ring_rts.h:366