1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2010-2020 Intel Corporation
4 * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
6 * Derived from FreeBSD's bufring.h
7 * Used as BSD-3 Licensed with permission from Kip Macy.
10 #ifndef _RTE_RING_CORE_H_
11 #define _RTE_RING_CORE_H_
15 * This file contains definion of RTE ring structure itself,
16 * init flags and some related macros.
17 * For majority of DPDK entities, it is not recommended to include
18 * this file directly, use include <rte_ring.h> or <rte_ring_elem.h>
29 #include <sys/queue.h>
31 #include <rte_common.h>
32 #include <rte_config.h>
33 #include <rte_memory.h>
34 #include <rte_lcore.h>
35 #include <rte_atomic.h>
36 #include <rte_branch_prediction.h>
37 #include <rte_memzone.h>
38 #include <rte_pause.h>
39 #include <rte_debug.h>
41 #define RTE_TAILQ_RING_NAME "RTE_RING"
43 /** enqueue/dequeue behavior types */
44 enum rte_ring_queue_behavior {
45 /** Enq/Deq a fixed number of items from a ring */
46 RTE_RING_QUEUE_FIXED = 0,
47 /** Enq/Deq as many items as possible from ring */
48 RTE_RING_QUEUE_VARIABLE
51 #define RTE_RING_MZ_PREFIX "RG_"
52 /** The maximum length of a ring name. */
53 #define RTE_RING_NAMESIZE (RTE_MEMZONE_NAMESIZE - \
54 sizeof(RTE_RING_MZ_PREFIX) + 1)
56 /** prod/cons sync types */
57 enum rte_ring_sync_type {
58 RTE_RING_SYNC_MT, /**< multi-thread safe (default mode) */
59 RTE_RING_SYNC_ST, /**< single thread only */
63 * structures to hold a pair of head/tail values and other metadata.
64 * Depending on sync_type format of that structure might be different,
65 * but offset for *sync_type* and *tail* values should remain the same.
67 struct rte_ring_headtail {
68 volatile uint32_t head; /**< prod/consumer head. */
69 volatile uint32_t tail; /**< prod/consumer tail. */
72 /** sync type of prod/cons */
73 enum rte_ring_sync_type sync_type;
74 /** deprecated - True if single prod/cons */
80 * An RTE ring structure.
82 * The producer and the consumer have a head and a tail index. The particularity
83 * of these index is that they are not between 0 and size(ring). These indexes
84 * are between 0 and 2^32, and we mask their value when we access the ring[]
85 * field. Thanks to this assumption, we can do subtractions between 2 index
86 * values in a modulo-32bit base: that's why the overflow of the indexes is not
91 * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
92 * compatibility requirements, it could be changed to RTE_RING_NAMESIZE
93 * next time the ABI changes
95 char name[RTE_MEMZONE_NAMESIZE] __rte_cache_aligned;
96 /**< Name of the ring. */
97 int flags; /**< Flags supplied at creation. */
98 const struct rte_memzone *memzone;
99 /**< Memzone, if any, containing the rte_ring */
100 uint32_t size; /**< Size of ring. */
101 uint32_t mask; /**< Mask (size-1) of ring. */
102 uint32_t capacity; /**< Usable size of ring */
104 char pad0 __rte_cache_aligned; /**< empty cache line */
106 /** Ring producer status. */
107 struct rte_ring_headtail prod __rte_cache_aligned;
108 char pad1 __rte_cache_aligned; /**< empty cache line */
110 /** Ring consumer status. */
111 struct rte_ring_headtail cons __rte_cache_aligned;
112 char pad2 __rte_cache_aligned; /**< empty cache line */
115 #define RING_F_SP_ENQ 0x0001 /**< The default enqueue is "single-producer". */
116 #define RING_F_SC_DEQ 0x0002 /**< The default dequeue is "single-consumer". */
118 * Ring is to hold exactly requested number of entries.
119 * Without this flag set, the ring size requested must be a power of 2, and the
120 * usable space will be that size - 1. With the flag, the requested size will
121 * be rounded up to the next power of two, but the usable space will be exactly
122 * that requested. Worst case, if a power-of-2 size is requested, half the
123 * ring space will be wasted.
125 #define RING_F_EXACT_SZ 0x0004
126 #define RTE_RING_SZ_MASK (0x7fffffffU) /**< Ring size mask */
132 #endif /* _RTE_RING_CORE_H_ */