DPDK  25.03.0
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 
37 #include <rte_common.h>
38 #include <rte_ring_core.h>
39 #include <rte_ring_elem.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
59 ssize_t rte_ring_get_memsize(unsigned int count);
60 
120 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
121  unsigned int flags);
122 
130 void rte_ring_free(struct rte_ring *r);
131 
195 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
196  int socket_id, unsigned int flags)
198 
207 void rte_ring_dump(FILE *f, const struct rte_ring *r);
208 
222 __rte_experimental
223 void
224 rte_ring_headtail_dump(FILE *f, const char *prefix,
225  const struct rte_ring_headtail *r);
226 
245 static __rte_always_inline unsigned int
246 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
247  unsigned int n, unsigned int *free_space)
248 {
249  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
250  n, free_space);
251 }
252 
268 static __rte_always_inline unsigned int
269 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
270  unsigned int n, unsigned int *free_space)
271 {
272  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
273  n, free_space);
274 }
275 
295 static __rte_always_inline unsigned int
296 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
297  unsigned int n, unsigned int *free_space)
298 {
299  return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
300  n, free_space);
301 }
302 
317 static __rte_always_inline int
318 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
319 {
320  return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
321 }
322 
334 static __rte_always_inline int
335 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
336 {
337  return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
338 }
339 
355 static __rte_always_inline int
356 rte_ring_enqueue(struct rte_ring *r, void *obj)
357 {
358  return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
359 }
360 
379 static __rte_always_inline unsigned int
380 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
381  unsigned int n, unsigned int *available)
382 {
383  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
384  n, available);
385 }
386 
403 static __rte_always_inline unsigned int
404 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
405  unsigned int n, unsigned int *available)
406 {
407  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
408  n, available);
409 }
410 
430 static __rte_always_inline unsigned int
431 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
432  unsigned int *available)
433 {
434  return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
435  n, available);
436 }
437 
453 static __rte_always_inline int
454 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
455 {
456  return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
457 }
458 
471 static __rte_always_inline int
472 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
473 {
474  return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
475 }
476 
493 static __rte_always_inline int
494 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
495 {
496  return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
497 }
498 
510 void
511 rte_ring_reset(struct rte_ring *r);
512 
521 static inline unsigned int
522 rte_ring_count(const struct rte_ring *r)
523 {
524  uint32_t prod_tail = r->prod.tail;
525  uint32_t cons_tail = r->cons.tail;
526  uint32_t count = (prod_tail - cons_tail) & r->mask;
527  return (count > r->capacity) ? r->capacity : count;
528 }
529 
538 static inline unsigned int
540 {
541  return r->capacity - rte_ring_count(r);
542 }
543 
553 static inline int
554 rte_ring_full(const struct rte_ring *r)
555 {
556  return rte_ring_free_count(r) == 0;
557 }
558 
568 static inline int
569 rte_ring_empty(const struct rte_ring *r)
570 {
571  uint32_t prod_tail = r->prod.tail;
572  uint32_t cons_tail = r->cons.tail;
573  return cons_tail == prod_tail;
574 }
575 
586 static inline unsigned int
587 rte_ring_get_size(const struct rte_ring *r)
588 {
589  return r->size;
590 }
591 
600 static inline unsigned int
602 {
603  return r->capacity;
604 }
605 
614 static inline enum rte_ring_sync_type
616 {
617  return r->prod.sync_type;
618 }
619 
628 static inline int
630 {
632 }
633 
642 static inline enum rte_ring_sync_type
644 {
645  return r->cons.sync_type;
646 }
647 
656 static inline int
658 {
660 }
661 
668 void rte_ring_list_dump(FILE *f);
669 
680 struct rte_ring *rte_ring_lookup(const char *name);
681 
700 static __rte_always_inline unsigned int
701 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
702  unsigned int n, unsigned int *free_space)
703 {
704  return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
705  n, free_space);
706 }
707 
723 static __rte_always_inline unsigned int
724 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
725  unsigned int n, unsigned int *free_space)
726 {
727  return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
728  n, free_space);
729 }
730 
750 static __rte_always_inline unsigned int
751 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
752  unsigned int n, unsigned int *free_space)
753 {
754  return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
755  n, free_space);
756 }
757 
778 static __rte_always_inline unsigned int
779 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
780  unsigned int n, unsigned int *available)
781 {
782  return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
783  n, available);
784 }
785 
803 static __rte_always_inline unsigned int
804 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
805  unsigned int n, unsigned int *available)
806 {
807  return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
808  n, available);
809 }
810 
830 static __rte_always_inline unsigned int
831 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
832  unsigned int n, unsigned int *available)
833 {
834  return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
835  n, available);
836 }
837 
838 #ifdef __cplusplus
839 }
840 #endif
841 
842 #endif /* _RTE_RING_H_ */
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_sc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
#define __rte_always_inline
Definition: rte_common.h:456
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:296
static __rte_always_inline int rte_ring_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
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:804
static enum rte_ring_sync_type rte_ring_get_prod_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:615
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)
struct rte_ring * rte_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags) __rte_malloc __rte_dealloc(rte_ring_free
static __rte_always_inline int rte_ring_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:494
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)
ssize_t rte_ring_get_memsize(unsigned int count)
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 int rte_ring_empty(const struct rte_ring *r)
Definition: rte_ring.h:569
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:454
void rte_ring_list_dump(FILE *f)
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_mc_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(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:246
struct rte_ring void rte_ring_dump(FILE *f, const struct rte_ring *r)
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:335
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:318
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:601
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:657
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:751
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:587
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:472
static __rte_always_inline int rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
uint32_t size
#define __rte_dealloc(dealloc, argno)
Definition: rte_common.h:305
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)
void rte_ring_free(struct rte_ring *r)
#define __rte_malloc
Definition: rte_common.h:294
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:831
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:701
rte_ring_sync_type
Definition: rte_ring_core.h:53
__rte_experimental void rte_ring_headtail_dump(FILE *f, const char *prefix, const struct rte_ring_headtail *r)
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_sp_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:724
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 int rte_ring_is_prod_single(const struct rte_ring *r)
Definition: rte_ring.h:629
int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count, unsigned int flags)
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_sp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:269
uint32_t mask
void rte_ring_reset(struct rte_ring *r)
char name[RTE_RING_NAMESIZE]
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:431
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:643
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_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:404
static __rte_always_inline int rte_ring_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
struct rte_ring * rte_ring_lookup(const char *name)
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)
uint32_t capacity
static __rte_always_inline int rte_ring_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:356
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_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:380
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:539
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:554
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:779
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:522