DPDK  24.07.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 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <rte_ring_core.h>
42 #include <rte_ring_elem.h>
43 
58 ssize_t rte_ring_get_memsize(unsigned int count);
59 
119 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
120  unsigned int flags);
121 
185 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
186  int socket_id, unsigned int flags);
187 
195 void rte_ring_free(struct rte_ring *r);
196 
205 void rte_ring_dump(FILE *f, const struct rte_ring *r);
206 
225 static __rte_always_inline unsigned int
226 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
227  unsigned int n, unsigned int *free_space)
228 {
229  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
230  n, free_space);
231 }
232 
248 static __rte_always_inline unsigned int
249 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
250  unsigned int n, unsigned int *free_space)
251 {
252  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
253  n, free_space);
254 }
255 
275 static __rte_always_inline unsigned int
276 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
277  unsigned int n, unsigned int *free_space)
278 {
279  return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
280  n, free_space);
281 }
282 
297 static __rte_always_inline int
298 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
299 {
300  return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
301 }
302 
314 static __rte_always_inline int
315 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
316 {
317  return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
318 }
319 
335 static __rte_always_inline int
336 rte_ring_enqueue(struct rte_ring *r, void *obj)
337 {
338  return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
339 }
340 
359 static __rte_always_inline unsigned int
360 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
361  unsigned int n, unsigned int *available)
362 {
363  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
364  n, available);
365 }
366 
383 static __rte_always_inline unsigned int
384 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
385  unsigned int n, unsigned int *available)
386 {
387  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
388  n, available);
389 }
390 
410 static __rte_always_inline unsigned int
411 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
412  unsigned int *available)
413 {
414  return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
415  n, available);
416 }
417 
433 static __rte_always_inline int
434 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
435 {
436  return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
437 }
438 
451 static __rte_always_inline int
452 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
453 {
454  return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
455 }
456 
473 static __rte_always_inline int
474 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
475 {
476  return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
477 }
478 
490 void
491 rte_ring_reset(struct rte_ring *r);
492 
501 static inline unsigned int
502 rte_ring_count(const struct rte_ring *r)
503 {
504  uint32_t prod_tail = r->prod.tail;
505  uint32_t cons_tail = r->cons.tail;
506  uint32_t count = (prod_tail - cons_tail) & r->mask;
507  return (count > r->capacity) ? r->capacity : count;
508 }
509 
518 static inline unsigned int
520 {
521  return r->capacity - rte_ring_count(r);
522 }
523 
533 static inline int
534 rte_ring_full(const struct rte_ring *r)
535 {
536  return rte_ring_free_count(r) == 0;
537 }
538 
548 static inline int
549 rte_ring_empty(const struct rte_ring *r)
550 {
551  uint32_t prod_tail = r->prod.tail;
552  uint32_t cons_tail = r->cons.tail;
553  return cons_tail == prod_tail;
554 }
555 
566 static inline unsigned int
567 rte_ring_get_size(const struct rte_ring *r)
568 {
569  return r->size;
570 }
571 
580 static inline unsigned int
582 {
583  return r->capacity;
584 }
585 
594 static inline enum rte_ring_sync_type
596 {
597  return r->prod.sync_type;
598 }
599 
608 static inline int
610 {
612 }
613 
622 static inline enum rte_ring_sync_type
624 {
625  return r->cons.sync_type;
626 }
627 
636 static inline int
638 {
640 }
641 
648 void rte_ring_list_dump(FILE *f);
649 
660 struct rte_ring *rte_ring_lookup(const char *name);
661 
680 static __rte_always_inline unsigned int
681 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
682  unsigned int n, unsigned int *free_space)
683 {
684  return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
685  n, free_space);
686 }
687 
703 static __rte_always_inline unsigned int
704 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
705  unsigned int n, unsigned int *free_space)
706 {
707  return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
708  n, free_space);
709 }
710 
730 static __rte_always_inline unsigned int
731 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
732  unsigned int n, unsigned int *free_space)
733 {
734  return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
735  n, free_space);
736 }
737 
758 static __rte_always_inline unsigned int
759 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
760  unsigned int n, unsigned int *available)
761 {
762  return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
763  n, available);
764 }
765 
783 static __rte_always_inline unsigned int
784 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
785  unsigned int n, unsigned int *available)
786 {
787  return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
788  n, available);
789 }
790 
810 static __rte_always_inline unsigned int
811 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
812  unsigned int n, unsigned int *available)
813 {
814  return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
815  n, available);
816 }
817 
818 #ifdef __cplusplus
819 }
820 #endif
821 
822 #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:370
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:276
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:784
static enum rte_ring_sync_type rte_ring_get_prod_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:595
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 int rte_ring_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:474
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:549
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:434
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:226
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:315
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:298
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:581
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:637
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:731
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:567
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:452
static __rte_always_inline int rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
uint32_t size
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)
struct rte_ring * rte_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
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:811
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:681
rte_ring_sync_type
Definition: rte_ring_core.h:57
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:704
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:609
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:249
void rte_ring_dump(FILE *f, const struct rte_ring *r)
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:411
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:623
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:384
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:336
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:360
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:519
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:534
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:759
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:502