Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright (c) 2017,2018 HXT-semitech 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_ELEM_PVT_H_
11 : : #define _RTE_RING_ELEM_PVT_H_
12 : :
13 : : static __rte_always_inline void
14 : : __rte_ring_enqueue_elems_32(void *ring_table, const void *obj_table,
15 : : uint32_t size, uint32_t idx, uint32_t n)
16 : : {
17 : : unsigned int i;
18 : :
19 : : uint32_t *ring = (uint32_t *)ring_table;
20 : : const uint32_t *obj = (const uint32_t *)obj_table;
21 : :
22 : 76645270 : if (likely(idx + n <= size)) {
23 [ + + + + : 224603 : for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
+ + + + -
- - - - -
+ + - - -
- - - - -
- - - - -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
24 : 189984 : ring[idx] = obj[i];
25 : 189984 : ring[idx + 1] = obj[i + 1];
26 : 189984 : ring[idx + 2] = obj[i + 2];
27 : 189984 : ring[idx + 3] = obj[i + 3];
28 : 189984 : ring[idx + 4] = obj[i + 4];
29 : 189984 : ring[idx + 5] = obj[i + 5];
30 : 189984 : ring[idx + 6] = obj[i + 6];
31 : 189984 : ring[idx + 7] = obj[i + 7];
32 : : }
33 [ - - + - : 34619 : switch (n & 0x7) {
- - - + -
- + - - +
+ + - + -
- + - - +
- - + - -
- - + - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - + - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
+ + + + +
+ + + - -
- - - - -
- + + + +
+ + + + +
- + - + +
+ + + + +
+ + + + +
+ + + + +
+ + + - +
+ + - + +
+ - - - -
- - - - -
+ + + + +
+ + + + +
+ + + + +
+ - + + +
+ + + + +
+ + + + +
+ ]
34 : 12 : case 7:
35 : 12 : ring[idx++] = obj[i++]; /* fallthrough */
36 : 1064 : case 6:
37 : 1064 : ring[idx++] = obj[i++]; /* fallthrough */
38 : 5227 : case 5:
39 : 5227 : ring[idx++] = obj[i++]; /* fallthrough */
40 : 5241 : case 4:
41 : 5241 : ring[idx++] = obj[i++]; /* fallthrough */
42 : 5256 : case 3:
43 : 5256 : ring[idx++] = obj[i++]; /* fallthrough */
44 : 5327 : case 2:
45 : 5327 : ring[idx++] = obj[i++]; /* fallthrough */
46 : 9488 : case 1:
47 : 76619911 : ring[idx++] = obj[i++]; /* fallthrough */
48 : : }
49 : : } else {
50 [ - - - - : 1220083 : for (i = 0; idx < size; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
51 : 1219855 : ring[idx] = obj[i];
52 : : /* Start at the beginning */
53 [ - - - - : 1245420 : for (idx = 0; i < n; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
54 : 1245192 : ring[idx] = obj[i];
55 : : }
56 : : }
57 : :
58 : : static __rte_always_inline void
59 : : __rte_ring_enqueue_elems_64(void *ring_table, const void *obj_table,
60 : : uint32_t size, uint32_t idx, uint32_t n)
61 : : {
62 : : unsigned int i;
63 : :
64 : : uint64_t *ring = (uint64_t *)ring_table;
65 : : const unaligned_uint64_t *obj = (const unaligned_uint64_t *)obj_table;
66 : :
67 [ + - + - : 48092765 : if (likely(idx + n <= size)) {
- - - - -
- - - - -
+ - - - -
- - - - -
- - - + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
68 [ + + + + : 53165167 : for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
- + + + -
- - - - -
- - - - -
- - - - -
- - - + -
- - - - -
- - - - -
- - - - -
- - - - +
+ - - + +
+ + + + +
+ + + - -
+ + + + +
+ + + + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + ]
69 : 5410454 : ring[idx] = obj[i];
70 : 5410454 : ring[idx + 1] = obj[i + 1];
71 : 5410454 : ring[idx + 2] = obj[i + 2];
72 : 5410454 : ring[idx + 3] = obj[i + 3];
73 : : }
74 [ - - + - : 47754713 : switch (n & 0x3) {
- + + + -
- + - + +
+ + - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - +
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - + + +
+ - - - -
+ + + + +
+ + + + +
+ + + + +
+ + + + +
- - - - -
+ + + - +
+ + - + +
+ - + + +
- + + + -
- - - + +
+ + + + +
+ - + + +
+ + + + +
+ + + - -
- - - + +
+ - + + +
- + + + +
+ + + ]
75 : 87 : case 3:
76 : 87 : ring[idx++] = obj[i++]; /* fallthrough */
77 : 2405685 : case 2:
78 : 2405685 : ring[idx++] = obj[i++]; /* fallthrough */
79 : 47619198 : case 1:
80 : 47885281 : ring[idx++] = obj[i++];
81 : : }
82 : : } else {
83 [ - - + + : 947485 : for (i = 0; idx < size; i++, idx++)
- - + + -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - + +
- - - - -
- - - + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
84 : 868628 : ring[idx] = obj[i];
85 : : /* Start at the beginning */
86 [ - - + + : 850885 : for (idx = 0; i < n; i++, idx++)
- - + + -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - + +
- - - - -
- - - + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
87 : 772028 : ring[idx] = obj[i];
88 : : }
89 : : }
90 : :
91 : : static __rte_always_inline void
92 : : __rte_ring_enqueue_elems_128(void *ring_table, const void *obj_table,
93 : : uint32_t size, uint32_t idx, uint32_t n)
94 : : {
95 : : unsigned int i;
96 : :
97 : : rte_int128_t *ring = (rte_int128_t *)ring_table;
98 : : const rte_int128_t *obj = (const rte_int128_t *)obj_table;
99 : :
100 [ - - + - : 29913 : if (likely(idx + n <= size)) {
+ - - - -
- - - - -
+ - - - -
- - - - -
- - - + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
101 [ - - + + : 98142 : for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
- - - - -
- + + - -
- - - - -
- - - - -
+ + - + +
+ + + + +
+ + + + -
- + + + +
+ + + + ]
102 : 72504 : memcpy((void *)(ring + idx),
103 : 72504 : (const void *)(obj + i), 32);
104 [ - - + + : 25638 : switch (n & 0x1) {
- - - - -
- + + - -
- - - - -
- - - - -
+ + + - +
+ + + + +
+ + + + -
- + + + +
+ + + + ]
105 : 23026 : case 1:
106 : 27141 : memcpy((void *)(ring + idx),
107 : 23026 : (const void *)(obj + i), 16);
108 : : }
109 : : } else {
110 [ - - - - : 220324 : for (i = 0; idx < size; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
111 : 220206 : memcpy((void *)(ring + idx),
112 : 220206 : (const void *)(obj + i), 16);
113 : : /* Start at the beginning */
114 [ - - - - : 211997 : for (idx = 0; i < n; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
115 : 211879 : memcpy((void *)(ring + idx),
116 : 211879 : (const void *)(obj + i), 16);
117 : : }
118 : : }
119 : :
120 : : /* the actual enqueue of elements on the ring.
121 : : * Placed here since identical code needed in both
122 : : * single and multi producer enqueue functions.
123 : : */
124 : : static __rte_always_inline void
125 : : __rte_ring_do_enqueue_elems(void *ring_table, const void *obj_table,
126 : : uint32_t size, uint32_t idx, uint32_t esize, uint32_t num)
127 : : {
128 : : /* 8B and 16B copies implemented individually to retain
129 : : * the current performance.
130 : : */
131 [ + + - + : 48660 : if (esize == 8)
- + - + -
- ]
132 : : __rte_ring_enqueue_elems_64(ring_table, obj_table, size,
133 : : idx, num);
134 [ - + + + : 41766 : else if (esize == 16)
+ + - + -
- - - - -
+ + - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
135 : : __rte_ring_enqueue_elems_128(ring_table, obj_table, size,
136 : : idx, num);
137 : : else {
138 : : uint32_t scale, nr_idx, nr_num, nr_size;
139 : :
140 : : /* Normalize to uint32_t */
141 : 34847 : scale = esize / sizeof(uint32_t);
142 : 25530 : nr_num = num * scale;
143 : 34847 : nr_idx = idx * scale;
144 [ + - + - : 34847 : nr_size = size * scale;
+ - + - -
- - - - -
+ - - - -
- - - - -
- - - + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
145 : : __rte_ring_enqueue_elems_32(ring_table, obj_table, nr_size,
146 : : nr_idx, nr_num);
147 : : }
148 : : }
149 : :
150 : : static __rte_always_inline void
151 : : __rte_ring_enqueue_elems(struct rte_ring *r, uint32_t prod_head,
152 : : const void *obj_table, uint32_t esize, uint32_t num)
153 : : {
154 : 124754824 : __rte_ring_do_enqueue_elems(&r[1], obj_table, r->size,
155 [ + - + + : 124754824 : prod_head & r->mask, esize, num);
+ + + + +
- + - + -
+ - + - -
- - - - -
- - + + -
- - - - -
+ - - - +
+ - - + -
- - - - -
- + + - -
- - - - -
- - - + +
- - - - -
- - - + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
156 : : }
157 : :
158 : : static __rte_always_inline void
159 : : __rte_ring_dequeue_elems_32(void *obj_table, const void *ring_table,
160 : : uint32_t size, uint32_t idx, uint32_t n)
161 : : {
162 : : unsigned int i;
163 : : uint32_t *obj = (uint32_t *)obj_table;
164 : : const uint32_t *ring = (const uint32_t *)ring_table;
165 : :
166 : 438155 : if (likely(idx + n <= size)) {
167 [ + + + + : 225574 : for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
+ + + + -
- + + + +
+ + - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
168 : 190044 : obj[i] = ring[idx];
169 : 190044 : obj[i + 1] = ring[idx + 1];
170 : 190044 : obj[i + 2] = ring[idx + 2];
171 : 190044 : obj[i + 3] = ring[idx + 3];
172 : 190044 : obj[i + 4] = ring[idx + 4];
173 : 190044 : obj[i + 5] = ring[idx + 5];
174 : 190044 : obj[i + 6] = ring[idx + 6];
175 : 190044 : obj[i + 7] = ring[idx + 7];
176 : : }
177 [ - + - - : 35530 : switch (n & 0x7) {
+ + - + -
- + - - +
+ + - - +
- - + - -
- - + - -
+ - - - -
- - - - -
- - - - -
- - - + -
- - - - -
- + - - -
- - + - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - + - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
+ + + + +
+ + + - -
- - - - -
- + + + +
+ + + + +
- + - + +
+ + + + +
+ + + + +
+ + + + +
+ + + - +
+ + - + +
+ - - - -
- - - - -
+ + + + +
+ + + + +
+ + + + +
+ - + + +
+ + + + +
+ + + + +
+ ]
178 : 12 : case 7:
179 : 12 : obj[i++] = ring[idx++]; /* fallthrough */
180 : 2020 : case 6:
181 : 2020 : obj[i++] = ring[idx++]; /* fallthrough */
182 : 6152 : case 5:
183 : 6152 : obj[i++] = ring[idx++]; /* fallthrough */
184 : 6166 : case 4:
185 : 6166 : obj[i++] = ring[idx++]; /* fallthrough */
186 : 6182 : case 3:
187 : 6182 : obj[i++] = ring[idx++]; /* fallthrough */
188 : 6266 : case 2:
189 : 6266 : obj[i++] = ring[idx++]; /* fallthrough */
190 : 10396 : case 1:
191 : 412793 : obj[i++] = ring[idx++]; /* fallthrough */
192 : : }
193 : : } else {
194 [ - - - - : 1220083 : for (i = 0; idx < size; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
195 : 1219855 : obj[i] = ring[idx];
196 : : /* Start at the beginning */
197 [ - - - - : 1245420 : for (idx = 0; i < n; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
198 : 1245192 : obj[i] = ring[idx];
199 : : }
200 : : }
201 : :
202 : : static __rte_always_inline void
203 : : __rte_ring_dequeue_elems_64(void *obj_table, const void *ring_table,
204 : : uint32_t size, uint32_t idx, uint32_t n)
205 : : {
206 : : unsigned int i;
207 : : unaligned_uint64_t *obj = (unaligned_uint64_t *)obj_table;
208 : : const uint64_t *ring = (const uint64_t *)ring_table;
209 : :
210 [ + - + - : 48023099 : if (likely(idx + n <= size)) {
- - - - -
- - - - -
+ - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
211 [ + + + + : 53100576 : for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
- + + + -
- - - - -
+ + - - -
- - - - -
- - - + -
- - - - -
- - - - +
+ - - - -
- - - - +
+ - - + +
+ + + + +
+ + + - -
+ + + + +
+ + + + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + ]
212 : 5414118 : obj[i] = ring[idx];
213 : 5414118 : obj[i + 1] = ring[idx + 1];
214 : 5414118 : obj[i + 2] = ring[idx + 2];
215 : 5414118 : obj[i + 3] = ring[idx + 3];
216 : : }
217 [ - + - + : 47686458 : switch (n & 0x3) {
- + + + -
- + - + +
+ + - - -
- - - - -
- - - - -
+ - + - -
- - - - -
- - - - -
- - - - -
- - - - +
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
+ - - - -
- - - - -
- - - - -
- - + + +
+ - - - -
+ + + + +
+ + + + +
+ + + + +
+ + + + +
- - - - -
+ + + - +
+ + - + +
+ - + + +
- + + + -
- - - + +
+ + + + +
+ - + + +
+ + + + +
+ + + - -
- - - + +
+ - + + +
- + + + +
+ + + ]
218 : 19 : case 3:
219 : 19 : obj[i++] = ring[idx++]; /* fallthrough */
220 : 2405583 : case 2:
221 : 2405583 : obj[i++] = ring[idx++]; /* fallthrough */
222 : 47615552 : case 1:
223 : 47881221 : obj[i++] = ring[idx++]; /* fallthrough */
224 : : }
225 : : } else {
226 [ - - + + : 945418 : for (i = 0; idx < size; i++, idx++)
- - + + -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - + +
- - - - -
- - - + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
227 : 867588 : obj[i] = ring[idx];
228 : : /* Start at the beginning */
229 [ - - + + : 833421 : for (idx = 0; i < n; i++, idx++)
- - + + -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - + +
- - - - -
- - - + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
230 : 755591 : obj[i] = ring[idx];
231 : : }
232 : : }
233 : :
234 : : static __rte_always_inline void
235 : : __rte_ring_dequeue_elems_128(void *obj_table, const void *ring_table,
236 : : uint32_t size, uint32_t idx, uint32_t n)
237 : : {
238 : : unsigned int i;
239 : : rte_int128_t *obj = (rte_int128_t *)obj_table;
240 : : const rte_int128_t *ring = (const rte_int128_t *)ring_table;
241 : :
242 [ + - + - : 29664 : if (likely(idx + n <= size)) {
- - - - -
- - - - -
+ - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
243 [ - - + + : 98033 : for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
- - - - -
- + + - -
+ + - - +
+ - - - -
+ + + + +
+ + + + +
+ + + + -
- + + + +
+ + + + ]
244 : 72625 : memcpy((obj + i), (const void *)(ring + idx), 32);
245 [ - - + + : 25408 : switch (n & 0x1) {
- - - - -
- + + - -
- + - - +
+ - - - -
+ + + + +
+ + + + +
+ + + + -
- + + + +
+ + + + ]
246 : 22785 : case 1:
247 : 26923 : memcpy((obj + i), (const void *)(ring + idx), 16);
248 : : }
249 : : } else {
250 [ - - - - : 220324 : for (i = 0; idx < size; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
251 : 220206 : memcpy((obj + i), (const void *)(ring + idx), 16);
252 : : /* Start at the beginning */
253 [ - - - - : 211997 : for (idx = 0; i < n; i++, idx++)
- - - - -
- - - - -
- - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
254 : 211879 : memcpy((obj + i), (const void *)(ring + idx), 16);
255 : : }
256 : : }
257 : :
258 : : /* the actual dequeue of elements from the ring.
259 : : * Placed here since identical code needed in both
260 : : * single and multi producer enqueue functions.
261 : : */
262 : : static __rte_always_inline void
263 : : __rte_ring_do_dequeue_elems(void *obj_table, const void *ring_table,
264 : : uint32_t size, uint32_t idx, uint32_t esize, uint32_t num)
265 : : {
266 : : /* 8B and 16B copies implemented individually to retain
267 : : * the current performance.
268 : : */
269 [ + + - + : 49526 : if (esize == 8)
- + - + -
- - + - +
+ - ]
270 : : __rte_ring_dequeue_elems_64(obj_table, ring_table, size,
271 : : idx, num);
272 [ + + + + : 42658 : else if (esize == 16)
- + - + -
- - + - +
+ + - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
273 : : __rte_ring_dequeue_elems_128(obj_table, ring_table, size,
274 : : idx, num);
275 : : else {
276 : : uint32_t scale, nr_idx, nr_num, nr_size;
277 : :
278 : : /* Normalize to uint32_t */
279 : 35757 : scale = esize / sizeof(uint32_t);
280 : 27567 : nr_num = num * scale;
281 : 35757 : nr_idx = idx * scale;
282 [ + - + - : 35757 : nr_size = size * scale;
+ - + - -
- + - + -
+ - - - -
- - - - -
- - + + -
- - - - -
- - + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ ]
283 : : __rte_ring_dequeue_elems_32(obj_table, ring_table, nr_size,
284 : : nr_idx, nr_num);
285 : : }
286 : : }
287 : :
288 : : static __rte_always_inline void
289 : : __rte_ring_dequeue_elems(struct rte_ring *r, uint32_t cons_head,
290 : : void *obj_table, uint32_t esize, uint32_t num)
291 : : {
292 : 48477756 : __rte_ring_do_dequeue_elems(obj_table, &r[1], r->size,
293 [ + + + + : 48477756 : cons_head & r->mask, esize, num);
+ - + + -
- + - - -
+ - - - +
- - - - -
- - + + -
- - - - -
- - - - +
+ - - - -
- - - - -
- + + - -
- - - - -
- - - + +
- - - - -
- - - + +
- - + + +
+ + + + +
+ + - - +
+ + + + +
+ + + + -
- + + + +
+ + + + +
+ - - + +
+ + + + +
+ # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
294 : : }
295 : :
296 : : static __rte_always_inline void
297 : : __rte_ring_update_tail(struct rte_ring_headtail *ht, uint32_t old_val,
298 : : uint32_t new_val, uint32_t single)
299 : : {
300 : : /*
301 : : * If there are other enqueues/dequeues in progress that preceded us,
302 : : * we need to wait for them to complete
303 : : */
304 [ + - + - ]: 9 : if (!single)
305 : 90593040 : rte_wait_until_equal_32((uint32_t *)(uintptr_t)&ht->tail, old_val,
306 : : rte_memory_order_relaxed);
307 : :
308 : : /*
309 : : * R0: Establishes a synchronizing edge with load-acquire of tail at A1.
310 : : * Ensures that memory effects by this thread on ring elements array
311 : : * is observed by a different thread of the other type.
312 : : */
313 [ - + ]: 82876458 : rte_atomic_store_explicit(&ht->tail, new_val, rte_memory_order_release);
314 : 95362093 : }
315 : :
316 : : /*
317 : : * The function __rte_ring_headtail_move_head_mt,st has two versions
318 : : * based on what is most efficient on a given architecture.
319 : : *
320 : : * The C11 is preferred but on x86 GCC has 10% performance drop.
321 : : */
322 : : #ifdef RTE_USE_C11_MEM_MODEL
323 : : #include "rte_ring_c11_pvt.h"
324 : : #else
325 : : #include "rte_ring_gcc_pvt.h"
326 : : #endif
327 : :
328 : : /**
329 : : * @internal This function updates the producer head for enqueue
330 : : *
331 : : * @param r
332 : : * A pointer to the ring structure
333 : : * @param is_sp
334 : : * Indicates whether multi-producer path is needed or not
335 : : * @param n
336 : : * The number of elements we will want to enqueue, i.e. how far should the
337 : : * head be moved
338 : : * @param behavior
339 : : * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
340 : : * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
341 : : * @param old_head
342 : : * Returns head value as it was before the move, i.e. where enqueue starts
343 : : * @param new_head
344 : : * Returns the current/new head value i.e. where enqueue finishes
345 : : * @param free_entries
346 : : * Returns the amount of free space in the ring BEFORE head was moved
347 : : * @return
348 : : * Actual number of objects enqueued.
349 : : * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
350 : : */
351 : : static __rte_always_inline unsigned int
352 : : __rte_ring_move_prod_head(struct rte_ring *r, unsigned int is_sp,
353 : : unsigned int n, enum rte_ring_queue_behavior behavior,
354 : : uint32_t *old_head, uint32_t *new_head,
355 : : uint32_t *free_entries)
356 : : {
357 : : if (is_sp)
358 [ + + + + : 79545867 : return __rte_ring_headtail_move_head_st(&r->prod, &r->cons, r->capacity,
+ + + + +
+ + - + -
+ - - + -
- + + - -
+ - - - -
+ - - - -
- - - - -
- + + - -
+ + - - +
+ - - + +
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
359 : : n, behavior, old_head, new_head, free_entries);
360 : : else
361 : 45205192 : return __rte_ring_headtail_move_head_mt(&r->prod, &r->cons, r->capacity,
362 : : n, behavior, old_head, new_head, free_entries);
363 : : }
364 : :
365 : : /**
366 : : * @internal This function updates the consumer head for dequeue
367 : : *
368 : : * @param r
369 : : * A pointer to the ring structure
370 : : * @param is_sc
371 : : * Indicates whether multi-consumer path is needed or not
372 : : * @param n
373 : : * The number of elements we will want to dequeue, i.e. how far should the
374 : : * head be moved
375 : : * @param behavior
376 : : * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
377 : : * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
378 : : * @param old_head
379 : : * Returns head value as it was before the move, i.e. where dequeue starts
380 : : * @param new_head
381 : : * Returns the current/new head value i.e. where dequeue finishes
382 : : * @param entries
383 : : * Returns the number of entries in the ring BEFORE head was moved
384 : : * @return
385 : : * - Actual number of objects dequeued.
386 : : * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
387 : : */
388 : : static __rte_always_inline unsigned int
389 : : __rte_ring_move_cons_head(struct rte_ring *r, unsigned int is_sc,
390 : : unsigned int n, enum rte_ring_queue_behavior behavior,
391 : : uint32_t *old_head, uint32_t *new_head,
392 : : uint32_t *entries)
393 : : {
394 : : if (is_sc)
395 : : return __rte_ring_headtail_move_head_st(&r->cons, &r->prod, 0,
396 : : n, behavior, old_head, new_head, entries);
397 : : else
398 : : return __rte_ring_headtail_move_head_mt(&r->cons, &r->prod, 0,
399 : : n, behavior, old_head, new_head, entries);
400 : : }
401 : :
402 : : /**
403 : : * @internal Enqueue several objects on the ring
404 : : *
405 : : * @param r
406 : : * A pointer to the ring structure.
407 : : * @param obj_table
408 : : * A pointer to a table of objects.
409 : : * @param esize
410 : : * The size of ring element, in bytes. It must be a multiple of 4.
411 : : * This must be the same value used while creating the ring. Otherwise
412 : : * the results are undefined.
413 : : * @param n
414 : : * The number of objects to add in the ring from the obj_table.
415 : : * @param behavior
416 : : * RTE_RING_QUEUE_FIXED: Enqueue a fixed number of items from a ring
417 : : * RTE_RING_QUEUE_VARIABLE: Enqueue as many items as possible from ring
418 : : * @param is_sp
419 : : * Indicates whether to use single producer or multi-producer head update
420 : : * @param free_space
421 : : * returns the amount of space after the enqueue operation has finished
422 : : * @return
423 : : * Actual number of objects enqueued.
424 : : * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
425 : : */
426 : : static __rte_always_inline unsigned int
427 : : __rte_ring_do_enqueue_elem(struct rte_ring *r, const void *obj_table,
428 : : unsigned int esize, unsigned int n,
429 : : enum rte_ring_queue_behavior behavior, unsigned int is_sp,
430 : : unsigned int *free_space)
431 : : {
432 : : uint32_t prod_head, prod_next;
433 : : uint32_t free_entries;
434 : :
435 : : n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
436 : : &prod_head, &prod_next, &free_entries);
437 [ - + - - : 45205192 : if (n == 0)
- - - - -
- - - - -
- - - - -
- - - - -
+ + + + +
+ + + + +
+ + + + +
+ ]
438 : 43 : goto end;
439 : :
440 : : __rte_ring_enqueue_elems(r, prod_head, obj_table, esize, n);
441 : :
442 : : __rte_ring_update_tail(&r->prod, prod_head, prod_next, is_sp);
443 [ + - # # ]: 45222648 : end:
444 [ - + - - : 8310 : if (free_space != NULL)
- + - + -
+ - - - +
- + - + -
- - + - +
- + - - -
+ - + ]
445 : 9297 : *free_space = free_entries - n;
446 : : return n;
447 : : }
448 : :
449 : : /**
450 : : * @internal Dequeue several objects from the ring
451 : : *
452 : : * @param r
453 : : * A pointer to the ring structure.
454 : : * @param obj_table
455 : : * A pointer to a table of objects.
456 : : * @param esize
457 : : * The size of ring element, in bytes. It must be a multiple of 4.
458 : : * This must be the same value used while creating the ring. Otherwise
459 : : * the results are undefined.
460 : : * @param n
461 : : * The number of objects to pull from the ring.
462 : : * @param behavior
463 : : * RTE_RING_QUEUE_FIXED: Dequeue a fixed number of items from a ring
464 : : * RTE_RING_QUEUE_VARIABLE: Dequeue as many items as possible from ring
465 : : * @param is_sc
466 : : * Indicates whether to use single consumer or multi-consumer head update
467 : : * @param available
468 : : * returns the number of remaining ring entries after the dequeue has finished
469 : : * @return
470 : : * - Actual number of objects dequeued.
471 : : * If behavior == RTE_RING_QUEUE_FIXED, this will be 0 or n only.
472 : : */
473 : : static __rte_always_inline unsigned int
474 : : __rte_ring_do_dequeue_elem(struct rte_ring *r, void *obj_table,
475 : : unsigned int esize, unsigned int n,
476 : : enum rte_ring_queue_behavior behavior, unsigned int is_sc,
477 : : unsigned int *available)
478 : : {
479 : : uint32_t cons_head, cons_next;
480 : : uint32_t entries;
481 : :
482 : : n = __rte_ring_move_cons_head(r, (int)is_sc, n, behavior,
483 : : &cons_head, &cons_next, &entries);
484 [ + + - - : 45420747 : if (n == 0)
- - - - -
- - - - -
- - - - -
- - - - -
- + - + -
+ - + - +
- + - + -
+ # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
485 : 16836043 : goto end;
486 : :
487 : : __rte_ring_dequeue_elems(r, cons_head, obj_table, esize, n);
488 : :
489 : : __rte_ring_update_tail(&r->cons, cons_head, cons_next, is_sc);
490 : :
491 [ + + # # ]: 49333971 : end:
492 [ - + - - : 8280 : if (available != NULL)
- + - + -
+ - - - +
- + - + -
- - + - +
- + - - -
+ - + ]
493 : 2 : *available = entries - n;
494 : : return n;
495 : : }
496 : :
497 : : #endif /* _RTE_RING_ELEM_PVT_H_ */
|