DPDK 21.11.9
rte_ring.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_H_
11#define _RTE_RING_H_
12
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#include <rte_ring_core.h>
43#include <rte_ring_elem.h>
44
59ssize_t rte_ring_get_memsize(unsigned int count);
60
112int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
113 unsigned int flags);
114
170struct rte_ring *rte_ring_create(const char *name, unsigned int count,
171 int socket_id, unsigned int flags);
172
179void rte_ring_free(struct rte_ring *r);
180
189void rte_ring_dump(FILE *f, const struct rte_ring *r);
190
209static __rte_always_inline unsigned int
210rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
211 unsigned int n, unsigned int *free_space)
212{
213 return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
214 n, free_space);
215}
216
232static __rte_always_inline unsigned int
233rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
234 unsigned int n, unsigned int *free_space)
235{
236 return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
237 n, free_space);
238}
239
259static __rte_always_inline unsigned int
260rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
261 unsigned int n, unsigned int *free_space)
262{
263 return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
264 n, free_space);
265}
266
281static __rte_always_inline int
282rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
283{
284 return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
285}
286
298static __rte_always_inline int
299rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
300{
301 return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
302}
303
319static __rte_always_inline int
320rte_ring_enqueue(struct rte_ring *r, void *obj)
321{
322 return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
323}
324
343static __rte_always_inline unsigned int
344rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
345 unsigned int n, unsigned int *available)
346{
347 return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
348 n, available);
349}
350
367static __rte_always_inline unsigned int
368rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
369 unsigned int n, unsigned int *available)
370{
371 return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
372 n, available);
373}
374
394static __rte_always_inline unsigned int
395rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
396 unsigned int *available)
397{
398 return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
399 n, available);
400}
401
417static __rte_always_inline int
418rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
419{
420 return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
421}
422
435static __rte_always_inline int
436rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
437{
438 return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
439}
440
457static __rte_always_inline int
458rte_ring_dequeue(struct rte_ring *r, void **obj_p)
459{
460 return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
461}
462
474void
476
485static inline unsigned int
486rte_ring_count(const struct rte_ring *r)
487{
488 uint32_t prod_tail = r->prod.tail;
489 uint32_t cons_tail = r->cons.tail;
490 uint32_t count = (prod_tail - cons_tail) & r->mask;
491 return (count > r->capacity) ? r->capacity : count;
492}
493
502static inline unsigned int
504{
505 return r->capacity - rte_ring_count(r);
506}
507
517static inline int
518rte_ring_full(const struct rte_ring *r)
519{
520 return rte_ring_free_count(r) == 0;
521}
522
532static inline int
533rte_ring_empty(const struct rte_ring *r)
534{
535 uint32_t prod_tail = r->prod.tail;
536 uint32_t cons_tail = r->cons.tail;
537 return cons_tail == prod_tail;
538}
539
550static inline unsigned int
552{
553 return r->size;
554}
555
564static inline unsigned int
566{
567 return r->capacity;
568}
569
578static inline enum rte_ring_sync_type
580{
581 return r->prod.sync_type;
582}
583
592static inline int
594{
596}
597
606static inline enum rte_ring_sync_type
608{
609 return r->cons.sync_type;
610}
611
620static inline int
622{
624}
625
632void rte_ring_list_dump(FILE *f);
633
644struct rte_ring *rte_ring_lookup(const char *name);
645
664static __rte_always_inline unsigned int
665rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
666 unsigned int n, unsigned int *free_space)
667{
668 return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
669 n, free_space);
670}
671
687static __rte_always_inline unsigned int
688rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
689 unsigned int n, unsigned int *free_space)
690{
691 return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
692 n, free_space);
693}
694
714static __rte_always_inline unsigned int
715rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
716 unsigned int n, unsigned int *free_space)
717{
718 return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
719 n, free_space);
720}
721
742static __rte_always_inline unsigned int
743rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
744 unsigned int n, unsigned int *available)
745{
746 return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
747 n, available);
748}
749
767static __rte_always_inline unsigned int
768rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
769 unsigned int n, unsigned int *available)
770{
771 return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
772 n, available);
773}
774
794static __rte_always_inline unsigned int
795rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
796 unsigned int n, unsigned int *available)
797{
798 return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
799 n, available);
800}
801
802#ifdef __cplusplus
803}
804#endif
805
806#endif /* _RTE_RING_H_ */
#define __rte_always_inline
Definition: rte_common.h:233
static __rte_always_inline unsigned int rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:768
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:518
void rte_ring_dump(FILE *f, const struct rte_ring *r)
ssize_t rte_ring_get_memsize(unsigned int count)
struct rte_ring * rte_ring_lookup(const char *name)
static __rte_always_inline unsigned int rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:368
int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count, unsigned int flags)
static unsigned int rte_ring_count(const struct rte_ring *r)
Definition: rte_ring.h:486
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_mp_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:665
static __rte_always_inline unsigned int rte_ring_sp_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:688
static __rte_always_inline unsigned int rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:344
static __rte_always_inline unsigned int rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:395
static __rte_always_inline unsigned int rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:743
void rte_ring_free(struct rte_ring *r)
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:282
void rte_ring_list_dump(FILE *f)
static __rte_always_inline unsigned int rte_ring_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:715
static __rte_always_inline int rte_ring_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:458
struct rte_ring * rte_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
static int rte_ring_is_prod_single(const struct rte_ring *r)
Definition: rte_ring.h:593
static __rte_always_inline unsigned int rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:795
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:621
static __rte_always_inline int rte_ring_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:320
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:565
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:418
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:551
static __rte_always_inline unsigned int rte_ring_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:260
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:607
static int rte_ring_empty(const struct rte_ring *r)
Definition: rte_ring.h:533
static enum rte_ring_sync_type rte_ring_get_prod_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:579
static __rte_always_inline unsigned int rte_ring_mp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:210
void rte_ring_reset(struct rte_ring *r)
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:436
static __rte_always_inline unsigned int rte_ring_sp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:233
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:299
rte_ring_sync_type
Definition: rte_ring_core.h:56
@ RTE_RING_SYNC_ST
Definition: rte_ring_core.h:58
static __rte_always_inline int rte_ring_sp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline int rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
static __rte_always_inline unsigned int rte_ring_sc_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_mc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline int rte_ring_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline int rte_ring_sc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
static __rte_always_inline int rte_ring_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
static __rte_always_inline unsigned int rte_ring_mc_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline int rte_ring_mp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline unsigned int rte_ring_sc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_mp_enqueue_bulk_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_ring_mp_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_ring_sp_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_ring_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
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_ring_sp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
enum rte_ring_sync_type sync_type
Definition: rte_ring_core.h:74
volatile uint32_t tail
Definition: rte_ring_core.h:70
uint32_t capacity
uint32_t size
uint32_t mask