DPDK  22.11.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 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include <rte_ring_core.h>
43 #include <rte_ring_elem.h>
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 
186 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
187  int socket_id, unsigned int flags);
188 
196 void rte_ring_free(struct rte_ring *r);
197 
206 void rte_ring_dump(FILE *f, const struct rte_ring *r);
207 
226 static __rte_always_inline unsigned int
227 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
228  unsigned int n, unsigned int *free_space)
229 {
230  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
231  n, free_space);
232 }
233 
249 static __rte_always_inline unsigned int
250 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
251  unsigned int n, unsigned int *free_space)
252 {
253  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
254  n, free_space);
255 }
256 
276 static __rte_always_inline unsigned int
277 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
278  unsigned int n, unsigned int *free_space)
279 {
280  return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
281  n, free_space);
282 }
283 
298 static __rte_always_inline int
299 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
300 {
301  return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
302 }
303 
315 static __rte_always_inline int
316 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
317 {
318  return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
319 }
320 
336 static __rte_always_inline int
337 rte_ring_enqueue(struct rte_ring *r, void *obj)
338 {
339  return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
340 }
341 
360 static __rte_always_inline unsigned int
361 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
362  unsigned int n, unsigned int *available)
363 {
364  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
365  n, available);
366 }
367 
384 static __rte_always_inline unsigned int
385 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
386  unsigned int n, unsigned int *available)
387 {
388  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
389  n, available);
390 }
391 
411 static __rte_always_inline unsigned int
412 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
413  unsigned int *available)
414 {
415  return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
416  n, available);
417 }
418 
434 static __rte_always_inline int
435 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
436 {
437  return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
438 }
439 
452 static __rte_always_inline int
453 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
454 {
455  return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
456 }
457 
474 static __rte_always_inline int
475 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
476 {
477  return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
478 }
479 
491 void
492 rte_ring_reset(struct rte_ring *r);
493 
502 static inline unsigned int
503 rte_ring_count(const struct rte_ring *r)
504 {
505  uint32_t prod_tail = r->prod.tail;
506  uint32_t cons_tail = r->cons.tail;
507  uint32_t count = (prod_tail - cons_tail) & r->mask;
508  return (count > r->capacity) ? r->capacity : count;
509 }
510 
519 static inline unsigned int
521 {
522  return r->capacity - rte_ring_count(r);
523 }
524 
534 static inline int
535 rte_ring_full(const struct rte_ring *r)
536 {
537  return rte_ring_free_count(r) == 0;
538 }
539 
549 static inline int
550 rte_ring_empty(const struct rte_ring *r)
551 {
552  uint32_t prod_tail = r->prod.tail;
553  uint32_t cons_tail = r->cons.tail;
554  return cons_tail == prod_tail;
555 }
556 
567 static inline unsigned int
568 rte_ring_get_size(const struct rte_ring *r)
569 {
570  return r->size;
571 }
572 
581 static inline unsigned int
583 {
584  return r->capacity;
585 }
586 
595 static inline enum rte_ring_sync_type
597 {
598  return r->prod.sync_type;
599 }
600 
609 static inline int
611 {
613 }
614 
623 static inline enum rte_ring_sync_type
625 {
626  return r->cons.sync_type;
627 }
628 
637 static inline int
639 {
641 }
642 
649 void rte_ring_list_dump(FILE *f);
650 
661 struct rte_ring *rte_ring_lookup(const char *name);
662 
681 static __rte_always_inline unsigned int
682 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
683  unsigned int n, unsigned int *free_space)
684 {
685  return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
686  n, free_space);
687 }
688 
704 static __rte_always_inline unsigned int
705 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
706  unsigned int n, unsigned int *free_space)
707 {
708  return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
709  n, free_space);
710 }
711 
731 static __rte_always_inline unsigned int
732 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
733  unsigned int n, unsigned int *free_space)
734 {
735  return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
736  n, free_space);
737 }
738 
759 static __rte_always_inline unsigned int
760 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
761  unsigned int n, unsigned int *available)
762 {
763  return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
764  n, available);
765 }
766 
784 static __rte_always_inline unsigned int
785 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
786  unsigned int n, unsigned int *available)
787 {
788  return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
789  n, available);
790 }
791 
811 static __rte_always_inline unsigned int
812 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
813  unsigned int n, unsigned int *available)
814 {
815  return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
816  n, available);
817 }
818 
819 #ifdef __cplusplus
820 }
821 #endif
822 
823 #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:255
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:277
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:785
static enum rte_ring_sync_type rte_ring_get_prod_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:596
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:475
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:550
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:435
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:227
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:316
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:299
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:582
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:638
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:732
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:568
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:453
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:812
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:682
rte_ring_sync_type
Definition: rte_ring_core.h:56
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:705
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:610
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:250
void rte_ring_dump(FILE *f, const struct rte_ring *r)
uint32_t mask
void rte_ring_reset(struct rte_ring *r)
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:412
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:624
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:385
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)
enum rte_ring_sync_type sync_type
Definition: rte_ring_core.h:74
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:337
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:361
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:520
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:535
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:760
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)
volatile uint32_t tail
Definition: rte_ring_core.h:70
static unsigned int rte_ring_count(const struct rte_ring *r)
Definition: rte_ring.h:503