DPDK  22.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 
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 
121 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
122  unsigned int flags);
123 
189 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
190  int socket_id, unsigned int flags);
191 
199 void rte_ring_free(struct rte_ring *r);
200 
209 void rte_ring_dump(FILE *f, const struct rte_ring *r);
210 
229 static __rte_always_inline unsigned int
230 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
231  unsigned int n, unsigned int *free_space)
232 {
233  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
234  n, free_space);
235 }
236 
252 static __rte_always_inline unsigned int
253 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
254  unsigned int n, unsigned int *free_space)
255 {
256  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
257  n, free_space);
258 }
259 
279 static __rte_always_inline unsigned int
280 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
281  unsigned int n, unsigned int *free_space)
282 {
283  return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
284  n, free_space);
285 }
286 
301 static __rte_always_inline int
302 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
303 {
304  return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
305 }
306 
318 static __rte_always_inline int
319 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
320 {
321  return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
322 }
323 
339 static __rte_always_inline int
340 rte_ring_enqueue(struct rte_ring *r, void *obj)
341 {
342  return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
343 }
344 
363 static __rte_always_inline unsigned int
364 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
365  unsigned int n, unsigned int *available)
366 {
367  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
368  n, available);
369 }
370 
387 static __rte_always_inline unsigned int
388 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
389  unsigned int n, unsigned int *available)
390 {
391  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
392  n, available);
393 }
394 
414 static __rte_always_inline unsigned int
415 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
416  unsigned int *available)
417 {
418  return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
419  n, available);
420 }
421 
437 static __rte_always_inline int
438 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
439 {
440  return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
441 }
442 
455 static __rte_always_inline int
456 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
457 {
458  return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
459 }
460 
477 static __rte_always_inline int
478 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
479 {
480  return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
481 }
482 
494 void
495 rte_ring_reset(struct rte_ring *r);
496 
505 static inline unsigned int
506 rte_ring_count(const struct rte_ring *r)
507 {
508  uint32_t prod_tail = r->prod.tail;
509  uint32_t cons_tail = r->cons.tail;
510  uint32_t count = (prod_tail - cons_tail) & r->mask;
511  return (count > r->capacity) ? r->capacity : count;
512 }
513 
522 static inline unsigned int
524 {
525  return r->capacity - rte_ring_count(r);
526 }
527 
537 static inline int
538 rte_ring_full(const struct rte_ring *r)
539 {
540  return rte_ring_free_count(r) == 0;
541 }
542 
552 static inline int
553 rte_ring_empty(const struct rte_ring *r)
554 {
555  uint32_t prod_tail = r->prod.tail;
556  uint32_t cons_tail = r->cons.tail;
557  return cons_tail == prod_tail;
558 }
559 
570 static inline unsigned int
571 rte_ring_get_size(const struct rte_ring *r)
572 {
573  return r->size;
574 }
575 
584 static inline unsigned int
586 {
587  return r->capacity;
588 }
589 
598 static inline enum rte_ring_sync_type
600 {
601  return r->prod.sync_type;
602 }
603 
612 static inline int
614 {
616 }
617 
626 static inline enum rte_ring_sync_type
628 {
629  return r->cons.sync_type;
630 }
631 
640 static inline int
642 {
644 }
645 
652 void rte_ring_list_dump(FILE *f);
653 
664 struct rte_ring *rte_ring_lookup(const char *name);
665 
684 static __rte_always_inline unsigned int
685 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
686  unsigned int n, unsigned int *free_space)
687 {
688  return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
689  n, free_space);
690 }
691 
707 static __rte_always_inline unsigned int
708 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
709  unsigned int n, unsigned int *free_space)
710 {
711  return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
712  n, free_space);
713 }
714 
734 static __rte_always_inline unsigned int
735 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
736  unsigned int n, unsigned int *free_space)
737 {
738  return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
739  n, free_space);
740 }
741 
762 static __rte_always_inline unsigned int
763 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
764  unsigned int n, unsigned int *available)
765 {
766  return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
767  n, available);
768 }
769 
787 static __rte_always_inline unsigned int
788 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
789  unsigned int n, unsigned int *available)
790 {
791  return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
792  n, available);
793 }
794 
814 static __rte_always_inline unsigned int
815 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
816  unsigned int n, unsigned int *available)
817 {
818  return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
819  n, available);
820 }
821 
822 #ifdef __cplusplus
823 }
824 #endif
825 
826 #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:228
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:280
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:788
static enum rte_ring_sync_type rte_ring_get_prod_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:599
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:478
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:553
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:438
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:230
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:319
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:302
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:585
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:641
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:735
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:571
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:456
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:815
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:685
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:708
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:613
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:253
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:415
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:627
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:388
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:340
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:364
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:523
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:538
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:763
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:506