DPDK  20.11.10
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 
112 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
113  unsigned int flags);
114 
170 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
171  int socket_id, unsigned int flags);
172 
179 void rte_ring_free(struct rte_ring *r);
180 
189 void rte_ring_dump(FILE *f, const struct rte_ring *r);
190 
209 static __rte_always_inline unsigned int
210 rte_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 
232 static __rte_always_inline unsigned int
233 rte_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 
259 static __rte_always_inline unsigned int
260 rte_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 
281 static __rte_always_inline int
282 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
283 {
284  return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
285 }
286 
298 static __rte_always_inline int
299 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
300 {
301  return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
302 }
303 
319 static __rte_always_inline int
320 rte_ring_enqueue(struct rte_ring *r, void *obj)
321 {
322  return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
323 }
324 
343 static __rte_always_inline unsigned int
344 rte_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 
367 static __rte_always_inline unsigned int
368 rte_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 
394 static __rte_always_inline unsigned int
395 rte_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 
417 static __rte_always_inline int
418 rte_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 
435 static __rte_always_inline int
436 rte_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 
457 static __rte_always_inline int
458 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
459 {
460  return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
461 }
462 
474 void
475 rte_ring_reset(struct rte_ring *r);
476 
485 static inline unsigned int
486 rte_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 
502 static inline unsigned int
504 {
505  return r->capacity - rte_ring_count(r);
506 }
507 
517 static inline int
518 rte_ring_full(const struct rte_ring *r)
519 {
520  return rte_ring_free_count(r) == 0;
521 }
522 
532 static inline int
533 rte_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 
550 static inline unsigned int
551 rte_ring_get_size(const struct rte_ring *r)
552 {
553  return r->size;
554 }
555 
564 static inline unsigned int
566 {
567  return r->capacity;
568 }
569 
578 static inline enum rte_ring_sync_type
580 {
581  return r->prod.sync_type;
582 }
583 
592 static inline int
594 {
596 }
597 
606 static inline enum rte_ring_sync_type
608 {
609  return r->cons.sync_type;
610 }
611 
620 static inline int
622 {
624 }
625 
632 void rte_ring_list_dump(FILE *f);
633 
644 struct rte_ring *rte_ring_lookup(const char *name);
645 
664 static __rte_always_inline unsigned int
665 rte_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 
687 static __rte_always_inline unsigned int
688 rte_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 
714 static __rte_always_inline unsigned int
715 rte_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 
742 static __rte_always_inline unsigned int
743 rte_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 
767 static __rte_always_inline unsigned int
768 rte_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 
794 static __rte_always_inline unsigned int
795 rte_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_ */
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:231
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 __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:768
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_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:458
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:533
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:418
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:210
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:299
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:282
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:565
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:621
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 unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:551
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 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:795
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
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:688
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:593
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:233
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:395
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:607
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:368
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:77
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:320
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:344
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:503
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:518
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
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:73
static unsigned int rte_ring_count(const struct rte_ring *r)
Definition: rte_ring.h:486