10 #ifndef _RTE_RING_ELEM_PVT_H_
11 #define _RTE_RING_ELEM_PVT_H_
14 __rte_ring_enqueue_elems_32(
struct rte_ring *r,
const uint32_t
size,
15 uint32_t idx,
const void *obj_table, uint32_t n)
18 uint32_t *ring = (uint32_t *)&r[1];
19 const uint32_t *obj = (
const uint32_t *)obj_table;
20 if (
likely(idx + n < size)) {
21 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
23 ring[idx + 1] = obj[i + 1];
24 ring[idx + 2] = obj[i + 2];
25 ring[idx + 3] = obj[i + 3];
26 ring[idx + 4] = obj[i + 4];
27 ring[idx + 5] = obj[i + 5];
28 ring[idx + 6] = obj[i + 6];
29 ring[idx + 7] = obj[i + 7];
33 ring[idx++] = obj[i++];
35 ring[idx++] = obj[i++];
37 ring[idx++] = obj[i++];
39 ring[idx++] = obj[i++];
41 ring[idx++] = obj[i++];
43 ring[idx++] = obj[i++];
45 ring[idx++] = obj[i++];
48 for (i = 0; idx <
size; i++, idx++)
51 for (idx = 0; i < n; i++, idx++)
57 __rte_ring_enqueue_elems_64(
struct rte_ring *r, uint32_t prod_head,
58 const void *obj_table, uint32_t n)
61 const uint32_t size = r->
size;
62 uint32_t idx = prod_head & r->
mask;
63 uint64_t *ring = (uint64_t *)&r[1];
64 const unaligned_uint64_t *obj = (
const unaligned_uint64_t *)obj_table;
65 if (
likely(idx + n < size)) {
66 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
68 ring[idx + 1] = obj[i + 1];
69 ring[idx + 2] = obj[i + 2];
70 ring[idx + 3] = obj[i + 3];
74 ring[idx++] = obj[i++];
76 ring[idx++] = obj[i++];
78 ring[idx++] = obj[i++];
81 for (i = 0; idx <
size; i++, idx++)
84 for (idx = 0; i < n; i++, idx++)
90 __rte_ring_enqueue_elems_128(
struct rte_ring *r, uint32_t prod_head,
91 const void *obj_table, uint32_t n)
94 const uint32_t size = r->
size;
95 uint32_t idx = prod_head & r->
mask;
96 rte_int128_t *ring = (rte_int128_t *)&r[1];
97 const rte_int128_t *obj = (
const rte_int128_t *)obj_table;
98 if (
likely(idx + n < size)) {
99 for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
100 memcpy((
void *)(ring + idx),
101 (
const void *)(obj + i), 32);
104 memcpy((
void *)(ring + idx),
105 (
const void *)(obj + i), 16);
108 for (i = 0; idx <
size; i++, idx++)
109 memcpy((
void *)(ring + idx),
110 (
const void *)(obj + i), 16);
112 for (idx = 0; i < n; i++, idx++)
113 memcpy((
void *)(ring + idx),
114 (
const void *)(obj + i), 16);
123 __rte_ring_enqueue_elems(
struct rte_ring *r, uint32_t prod_head,
124 const void *obj_table, uint32_t esize, uint32_t num)
130 __rte_ring_enqueue_elems_64(r, prod_head, obj_table, num);
131 else if (esize == 16)
132 __rte_ring_enqueue_elems_128(r, prod_head, obj_table, num);
134 uint32_t idx, scale, nr_idx, nr_num, nr_size;
137 scale = esize /
sizeof(uint32_t);
138 nr_num = num * scale;
139 idx = prod_head & r->
mask;
140 nr_idx = idx * scale;
141 nr_size = r->
size * scale;
142 __rte_ring_enqueue_elems_32(r, nr_size, nr_idx,
148 __rte_ring_dequeue_elems_32(
struct rte_ring *r,
const uint32_t size,
149 uint32_t idx,
void *obj_table, uint32_t n)
152 uint32_t *ring = (uint32_t *)&r[1];
153 uint32_t *obj = (uint32_t *)obj_table;
154 if (
likely(idx + n < size)) {
155 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
157 obj[i + 1] = ring[idx + 1];
158 obj[i + 2] = ring[idx + 2];
159 obj[i + 3] = ring[idx + 3];
160 obj[i + 4] = ring[idx + 4];
161 obj[i + 5] = ring[idx + 5];
162 obj[i + 6] = ring[idx + 6];
163 obj[i + 7] = ring[idx + 7];
167 obj[i++] = ring[idx++];
169 obj[i++] = ring[idx++];
171 obj[i++] = ring[idx++];
173 obj[i++] = ring[idx++];
175 obj[i++] = ring[idx++];
177 obj[i++] = ring[idx++];
179 obj[i++] = ring[idx++];
182 for (i = 0; idx <
size; i++, idx++)
185 for (idx = 0; i < n; i++, idx++)
191 __rte_ring_dequeue_elems_64(
struct rte_ring *r, uint32_t prod_head,
192 void *obj_table, uint32_t n)
195 const uint32_t size = r->
size;
196 uint32_t idx = prod_head & r->
mask;
197 uint64_t *ring = (uint64_t *)&r[1];
198 unaligned_uint64_t *obj = (unaligned_uint64_t *)obj_table;
199 if (
likely(idx + n < size)) {
200 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
202 obj[i + 1] = ring[idx + 1];
203 obj[i + 2] = ring[idx + 2];
204 obj[i + 3] = ring[idx + 3];
208 obj[i++] = ring[idx++];
210 obj[i++] = ring[idx++];
212 obj[i++] = ring[idx++];
215 for (i = 0; idx <
size; i++, idx++)
218 for (idx = 0; i < n; i++, idx++)
224 __rte_ring_dequeue_elems_128(
struct rte_ring *r, uint32_t prod_head,
225 void *obj_table, uint32_t n)
228 const uint32_t size = r->
size;
229 uint32_t idx = prod_head & r->
mask;
230 rte_int128_t *ring = (rte_int128_t *)&r[1];
231 rte_int128_t *obj = (rte_int128_t *)obj_table;
232 if (
likely(idx + n < size)) {
233 for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
234 memcpy((
void *)(obj + i), (
void *)(ring + idx), 32);
237 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
240 for (i = 0; idx <
size; i++, idx++)
241 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
243 for (idx = 0; i < n; i++, idx++)
244 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
253 __rte_ring_dequeue_elems(
struct rte_ring *r, uint32_t cons_head,
254 void *obj_table, uint32_t esize, uint32_t num)
260 __rte_ring_dequeue_elems_64(r, cons_head, obj_table, num);
261 else if (esize == 16)
262 __rte_ring_dequeue_elems_128(r, cons_head, obj_table, num);
264 uint32_t idx, scale, nr_idx, nr_num, nr_size;
267 scale = esize /
sizeof(uint32_t);
268 nr_num = num * scale;
269 idx = cons_head & r->
mask;
270 nr_idx = idx * scale;
271 nr_size = r->
size * scale;
272 __rte_ring_dequeue_elems_32(r, nr_size, nr_idx,
284 #ifdef RTE_USE_C11_MEM_MODEL
285 #include "rte_ring_c11_pvt.h"
287 #include "rte_ring_generic_pvt.h"
315 __rte_ring_do_enqueue_elem(
struct rte_ring *r,
const void *obj_table,
316 unsigned int esize,
unsigned int n,
318 unsigned int *free_space)
320 uint32_t prod_head, prod_next;
321 uint32_t free_entries;
323 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
324 &prod_head, &prod_next, &free_entries);
328 __rte_ring_enqueue_elems(r, prod_head, obj_table, esize, n);
330 __rte_ring_update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
332 if (free_space != NULL)
333 *free_space = free_entries - n;
362 __rte_ring_do_dequeue_elem(
struct rte_ring *r,
void *obj_table,
363 unsigned int esize,
unsigned int n,
365 unsigned int *available)
367 uint32_t cons_head, cons_next;
370 n = __rte_ring_move_cons_head(r, (
int)is_sc, n, behavior,
371 &cons_head, &cons_next, &entries);
375 __rte_ring_dequeue_elems(r, cons_head, obj_table, esize, n);
377 __rte_ring_update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
380 if (available != NULL)
381 *available = entries - n;
#define __rte_always_inline