DPDK 22.11.6
rte_ring_peek_elem_pvt.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_PEEK_ELEM_PVT_H_
11#define _RTE_RING_PEEK_ELEM_PVT_H_
12
30static __rte_always_inline uint32_t
31__rte_ring_st_get_tail(struct rte_ring_headtail *ht, uint32_t *tail,
32 uint32_t num)
33{
34 uint32_t h, n, t;
35
36 h = ht->head;
37 t = ht->tail;
38 n = h - t;
39
40 RTE_ASSERT(n >= num);
41 num = (n >= num) ? num : 0;
42
43 *tail = t;
44 return num;
45}
46
52static __rte_always_inline void
53__rte_ring_st_set_head_tail(struct rte_ring_headtail *ht, uint32_t tail,
54 uint32_t num, uint32_t enqueue)
55{
56 uint32_t pos;
57
58 RTE_SET_USED(enqueue);
59
60 pos = tail + num;
61 ht->head = pos;
62 __atomic_store_n(&ht->tail, pos, __ATOMIC_RELEASE);
63}
64
74static __rte_always_inline uint32_t
75__rte_ring_hts_get_tail(struct rte_ring_hts_headtail *ht, uint32_t *tail,
76 uint32_t num)
77{
78 uint32_t n;
79 union __rte_ring_hts_pos p;
80
81 p.raw = __atomic_load_n(&ht->ht.raw, __ATOMIC_RELAXED);
82 n = p.pos.head - p.pos.tail;
83
84 RTE_ASSERT(n >= num);
85 num = (n >= num) ? num : 0;
86
87 *tail = p.pos.tail;
88 return num;
89}
90
96static __rte_always_inline void
97__rte_ring_hts_set_head_tail(struct rte_ring_hts_headtail *ht, uint32_t tail,
98 uint32_t num, uint32_t enqueue)
99{
100 union __rte_ring_hts_pos p;
101
102 RTE_SET_USED(enqueue);
103
104 p.pos.head = tail + num;
105 p.pos.tail = p.pos.head;
106
107 __atomic_store_n(&ht->ht.raw, p.raw, __ATOMIC_RELEASE);
108}
109
113static __rte_always_inline unsigned int
114__rte_ring_do_enqueue_start(struct rte_ring *r, uint32_t n,
115 enum rte_ring_queue_behavior behavior, uint32_t *free_space)
116{
117 uint32_t free, head, next;
118
119 switch (r->prod.sync_type) {
120 case RTE_RING_SYNC_ST:
121 n = __rte_ring_move_prod_head(r, RTE_RING_SYNC_ST, n,
122 behavior, &head, &next, &free);
123 break;
125 n = __rte_ring_hts_move_prod_head(r, n, behavior,
126 &head, &free);
127 break;
128 case RTE_RING_SYNC_MT:
130 default:
131 /* unsupported mode, shouldn't be here */
132 RTE_ASSERT(0);
133 n = 0;
134 free = 0;
135 }
136
137 if (free_space != NULL)
138 *free_space = free - n;
139 return n;
140}
141
146static __rte_always_inline unsigned int
147__rte_ring_do_dequeue_start(struct rte_ring *r, void *obj_table,
148 uint32_t esize, uint32_t n, enum rte_ring_queue_behavior behavior,
149 uint32_t *available)
150{
151 uint32_t avail, head, next;
152
153 switch (r->cons.sync_type) {
154 case RTE_RING_SYNC_ST:
155 n = __rte_ring_move_cons_head(r, RTE_RING_SYNC_ST, n,
156 behavior, &head, &next, &avail);
157 break;
159 n = __rte_ring_hts_move_cons_head(r, n, behavior,
160 &head, &avail);
161 break;
162 case RTE_RING_SYNC_MT:
164 default:
165 /* unsupported mode, shouldn't be here */
166 RTE_ASSERT(0);
167 n = 0;
168 avail = 0;
169 }
170
171 if (n != 0)
172 __rte_ring_dequeue_elems(r, head, obj_table, esize, n);
173
174 if (available != NULL)
175 *available = avail - n;
176 return n;
177}
178
179#endif /* _RTE_RING_PEEK_ELEM_PVT_H_ */
#define RTE_SET_USED(x)
Definition: rte_common.h:135
#define __rte_always_inline
Definition: rte_common.h:255
rte_ring_queue_behavior
Definition: rte_ring_core.h:43
@ RTE_RING_SYNC_MT
Definition: rte_ring_core.h:57
@ RTE_RING_SYNC_MT_RTS
Definition: rte_ring_core.h:59
@ RTE_RING_SYNC_MT_HTS
Definition: rte_ring_core.h:60
@ RTE_RING_SYNC_ST
Definition: rte_ring_core.h:58
enum rte_ring_sync_type sync_type
Definition: rte_ring_core.h:74
volatile uint32_t head
Definition: rte_ring_core.h:69
volatile uint32_t tail
Definition: rte_ring_core.h:70