DPDK 22.11.7
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
39extern "C" {
40#endif
41
42#include <rte_ring_core.h>
43#include <rte_ring_elem.h>
44
59ssize_t rte_ring_get_memsize(unsigned int count);
60
120int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
121 unsigned int flags);
122
186struct rte_ring *rte_ring_create(const char *name, unsigned int count,
187 int socket_id, unsigned int flags);
188
196void rte_ring_free(struct rte_ring *r);
197
206void rte_ring_dump(FILE *f, const struct rte_ring *r);
207
226static __rte_always_inline unsigned int
227rte_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
249static __rte_always_inline unsigned int
250rte_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
276static __rte_always_inline unsigned int
277rte_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
298static __rte_always_inline int
299rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
300{
301 return rte_ring_mp_enqueue_elem(r, &obj, sizeof(void *));
302}
303
315static __rte_always_inline int
316rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
317{
318 return rte_ring_sp_enqueue_elem(r, &obj, sizeof(void *));
319}
320
336static __rte_always_inline int
337rte_ring_enqueue(struct rte_ring *r, void *obj)
338{
339 return rte_ring_enqueue_elem(r, &obj, sizeof(void *));
340}
341
360static __rte_always_inline unsigned int
361rte_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
384static __rte_always_inline unsigned int
385rte_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
411static __rte_always_inline unsigned int
412rte_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
434static __rte_always_inline int
435rte_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
452static __rte_always_inline int
453rte_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
474static __rte_always_inline int
475rte_ring_dequeue(struct rte_ring *r, void **obj_p)
476{
477 return rte_ring_dequeue_elem(r, obj_p, sizeof(void *));
478}
479
491void
493
502static inline unsigned int
503rte_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
519static inline unsigned int
521{
522 return r->capacity - rte_ring_count(r);
523}
524
534static inline int
535rte_ring_full(const struct rte_ring *r)
536{
537 return rte_ring_free_count(r) == 0;
538}
539
549static inline int
550rte_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
567static inline unsigned int
569{
570 return r->size;
571}
572
581static inline unsigned int
583{
584 return r->capacity;
585}
586
595static inline enum rte_ring_sync_type
597{
598 return r->prod.sync_type;
599}
600
609static inline int
611{
613}
614
623static inline enum rte_ring_sync_type
625{
626 return r->cons.sync_type;
627}
628
637static inline int
639{
641}
642
649void rte_ring_list_dump(FILE *f);
650
661struct rte_ring *rte_ring_lookup(const char *name);
662
681static __rte_always_inline unsigned int
682rte_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
704static __rte_always_inline unsigned int
705rte_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
731static __rte_always_inline unsigned int
732rte_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
759static __rte_always_inline unsigned int
760rte_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
784static __rte_always_inline unsigned int
785rte_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
811static __rte_always_inline unsigned int
812rte_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_ */
#define __rte_always_inline
Definition: rte_common.h:255
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 int rte_ring_full(const struct rte_ring *r)
Definition: rte_ring.h:535
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:385
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:503
static unsigned int rte_ring_free_count(const struct rte_ring *r)
Definition: rte_ring.h:520
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
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_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
Definition: rte_ring.h:361
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 __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
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:299
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:732
static __rte_always_inline int rte_ring_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:475
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:610
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 int rte_ring_is_cons_single(const struct rte_ring *r)
Definition: rte_ring.h:638
static __rte_always_inline int rte_ring_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:337
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
Definition: rte_ring.h:582
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
Definition: rte_ring.h:435
static unsigned int rte_ring_get_size(const struct rte_ring *r)
Definition: rte_ring.h:568
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 enum rte_ring_sync_type rte_ring_get_cons_sync_type(const struct rte_ring *r)
Definition: rte_ring.h:624
static int rte_ring_empty(const struct rte_ring *r)
Definition: rte_ring.h:550
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_mp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
Definition: rte_ring.h:227
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:453
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
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
Definition: rte_ring.h:316
rte_ring_sync_type
Definition: rte_ring_core.h:56
@ RTE_RING_SYNC_ST
Definition: rte_ring_core.h:58
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)
enum rte_ring_sync_type sync_type
Definition: rte_ring_core.h:74
volatile uint32_t tail
Definition: rte_ring_core.h:70
uint32_t capacity
uint32_t size
uint32_t mask