DPDK  20.08.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 
113 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
114  unsigned int flags);
115 
173 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
174  int socket_id, unsigned int flags);
175 
182 void rte_ring_free(struct rte_ring *r);
183 
192 void rte_ring_dump(FILE *f, const struct rte_ring *r);
193 
212 static __rte_always_inline unsigned int
213 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
214  unsigned int n, unsigned int *free_space)
215 {
216  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
217  n, free_space);
218 }
219 
235 static __rte_always_inline unsigned int
236 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
237  unsigned int n, unsigned int *free_space)
238 {
239  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, sizeof(void *),
240  n, free_space);
241 }
242 
262 static __rte_always_inline unsigned int
263 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
264  unsigned int n, unsigned int *free_space)
265 {
266  return rte_ring_enqueue_bulk_elem(r, obj_table, sizeof(void *),
267  n, free_space);
268 }
269 
284 static __rte_always_inline int
285 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
286 {
287  return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
288 }
289 
301 static __rte_always_inline int
302 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
303 {
304  return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
305 }
306 
322 static __rte_always_inline int
323 rte_ring_enqueue(struct rte_ring *r, void *obj)
324 {
325  return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
326 }
327 
346 static __rte_always_inline unsigned int
347 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table,
348  unsigned int n, unsigned int *available)
349 {
350  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
351  n, available);
352 }
353 
370 static __rte_always_inline unsigned int
371 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table,
372  unsigned int n, unsigned int *available)
373 {
374  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, sizeof(void *),
375  n, available);
376 }
377 
397 static __rte_always_inline unsigned int
398 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
399  unsigned int *available)
400 {
401  return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
402  n, available);
403 }
404 
420 static __rte_always_inline int
421 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
422 {
423  return rte_ring_mc_dequeue_elem(r, obj_p, sizeof(void *));
424 }
425 
438 static __rte_always_inline int
439 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
440 {
441  return rte_ring_sc_dequeue_elem(r, obj_p, sizeof(void *));
442 }
443 
460 static __rte_always_inline int
461 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
462 {
463  return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
464 }
465 
477 void
478 rte_ring_reset(struct rte_ring *r);
479 
488 static inline unsigned int
489 rte_ring_count(const struct rte_ring *r)
490 {
491  uint32_t prod_tail = r->prod.tail;
492  uint32_t cons_tail = r->cons.tail;
493  uint32_t count = (prod_tail - cons_tail) & r->mask;
494  return (count > r->capacity) ? r->capacity : count;
495 }
496 
505 static inline unsigned int
507 {
508  return r->capacity - rte_ring_count(r);
509 }
510 
520 static inline int
521 rte_ring_full(const struct rte_ring *r)
522 {
523  return rte_ring_free_count(r) == 0;
524 }
525 
535 static inline int
536 rte_ring_empty(const struct rte_ring *r)
537 {
538  uint32_t prod_tail = r->prod.tail;
539  uint32_t cons_tail = r->cons.tail;
540  return cons_tail == prod_tail;
541 }
542 
553 static inline unsigned int
554 rte_ring_get_size(const struct rte_ring *r)
555 {
556  return r->size;
557 }
558 
567 static inline unsigned int
569 {
570  return r->capacity;
571 }
572 
581 static inline enum rte_ring_sync_type
583 {
584  return r->prod.sync_type;
585 }
586 
595 static inline int
597 {
599 }
600 
609 static inline enum rte_ring_sync_type
611 {
612  return r->cons.sync_type;
613 }
614 
623 static inline int
625 {
627 }
628 
635 void rte_ring_list_dump(FILE *f);
636 
647 struct rte_ring *rte_ring_lookup(const char *name);
648 
667 static __rte_always_inline unsigned int
668 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
669  unsigned int n, unsigned int *free_space)
670 {
671  return rte_ring_mp_enqueue_burst_elem(r, obj_table, sizeof(void *),
672  n, free_space);
673 }
674 
690 static __rte_always_inline unsigned int
691 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
692  unsigned int n, unsigned int *free_space)
693 {
694  return rte_ring_sp_enqueue_burst_elem(r, obj_table, sizeof(void *),
695  n, free_space);
696 }
697 
717 static __rte_always_inline unsigned int
718 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
719  unsigned int n, unsigned int *free_space)
720 {
721  return rte_ring_enqueue_burst_elem(r, obj_table, sizeof(void *),
722  n, free_space);
723 }
724 
745 static __rte_always_inline unsigned int
746 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table,
747  unsigned int n, unsigned int *available)
748 {
749  return rte_ring_mc_dequeue_burst_elem(r, obj_table, sizeof(void *),
750  n, available);
751 }
752 
770 static __rte_always_inline unsigned int
771 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table,
772  unsigned int n, unsigned int *available)
773 {
774  return rte_ring_sc_dequeue_burst_elem(r, obj_table, sizeof(void *),
775  n, available);
776 }
777 
797 static __rte_always_inline unsigned int
798 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table,
799  unsigned int n, unsigned int *available)
800 {
801  return rte_ring_dequeue_burst_elem(r, obj_table, sizeof(void *),
802  n, available);
803 }
804 
805 #ifdef __cplusplus
806 }
807 #endif
808 
809 #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:202
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:263
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:771
static enum rte_ring_sync_type rte_ring_get_prod_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:582
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:461
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:536
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:421
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:213
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:302
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:285
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:568
static int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:624
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:718
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:554
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:439
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:798
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:668
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:691
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:596
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:236
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:398
static enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:610
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:371
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:323
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:347
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:506
static int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:521
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:746
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:489