DPDK 25.03.0-rc0
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#include <rte_ring_core.h>
38#include <rte_ring_elem.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
58ssize_t rte_ring_get_memsize(unsigned int count);
59
119int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
120 unsigned int flags);
121
185struct rte_ring *rte_ring_create(const char *name, unsigned int count,
186 int socket_id, unsigned int flags);
187
195void rte_ring_free(struct rte_ring *r);
196
205void rte_ring_dump(FILE *f, const struct rte_ring *r);
206
225static __rte_always_inline unsigned int
226rte_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
248static __rte_always_inline unsigned int
249rte_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
275static __rte_always_inline unsigned int
276rte_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
297static __rte_always_inline int
298rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
299{
300 return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
301}
302
314static __rte_always_inline int
315rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
316{
317 return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
318}
319
335static __rte_always_inline int
336rte_ring_enqueue(struct rte_ring *r, void *obj)
337{
338 return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
339}
340
359static __rte_always_inline unsigned int
360rte_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
383static __rte_always_inline unsigned int
384rte_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
410static __rte_always_inline unsigned int
411rte_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
433static __rte_always_inline int
434rte_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
451static __rte_always_inline int
452rte_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
473static __rte_always_inline int
474rte_ring_dequeue(struct rte_ring *r, void **obj_p)
475{
476 return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
477}
478
490void
492
501static inline unsigned int
502rte_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
518static inline unsigned int
520{
521 return r->capacity - rte_ring_count(r);
522}
523
533static inline int
534rte_ring_full(const struct rte_ring *r)
535{
536 return rte_ring_free_count(r) == 0;
537}
538
548static inline int
549rte_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
566static inline unsigned int
568{
569 return r->size;
570}
571
580static inline unsigned int
582{
583 return r->capacity;
584}
585
594static inline enum rte_ring_sync_type
596{
597 return r->prod.sync_type;
598}
599
608static inline int
610{
612}
613
622static inline enum rte_ring_sync_type
624{
625 return r->cons.sync_type;
626}
627
636static inline int
638{
640}
641
648void rte_ring_list_dump(FILE *f);
649
660struct rte_ring *rte_ring_lookup(const char *name);
661
680static __rte_always_inline unsigned int
681rte_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
703static __rte_always_inline unsigned int
704rte_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
730static __rte_always_inline unsigned int
731rte_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
758static __rte_always_inline unsigned int
759rte_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
783static __rte_always_inline unsigned int
784rte_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
810static __rte_always_inline unsigned int
811rte_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_ */
#define __rte_always_inline
Definition: rte_common.h:413
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 int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:534
void rte_ring_dump(FILE *f, const struct rte_ring *r)
ssize_t rte_ring_get_memsize(unsigned int count)
struct rte_ring * rte_ring_lookup(const char *name)
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
int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count, unsigned int flags)
static unsigned int rte_ring_count(const struct rte_ring *r)
Definition: rte_ring.h:502
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:519
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
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_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:360
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 __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
void rte_ring_free(struct rte_ring *r)
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:298
void rte_ring_list_dump(FILE *f)
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 __rte_always_inline int rte_ring_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:474
struct rte_ring * rte_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
static int rte_ring_is_prod_single(const struct rte_ring *r)
Definition: rte_ring.h:609
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 int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:637
static __rte_always_inline int rte_ring_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:336
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:581
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:434
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:567
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 enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:623
static int rte_ring_empty(const struct rte_ring *r)
Definition: rte_ring.h:549
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_mp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:226
void rte_ring_reset(struct rte_ring *r)
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 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
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:315
rte_ring_sync_type
Definition: rte_ring_core.h:53
@ RTE_RING_SYNC_ST
Definition: rte_ring_core.h:55
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_mc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
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 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_mc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline int rte_ring_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)
static __rte_always_inline int rte_ring_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
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_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 int rte_ring_mp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
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_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_mp_enqueue_burst_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_sp_enqueue_burst_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_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_enqueue_burst_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_sp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
char name[RTE_RING_NAMESIZE]
uint32_t capacity
uint32_t size
uint32_t mask