11 #ifndef _RTE_RING_ELEM_H_
12 #define _RTE_RING_ELEM_H_
106 unsigned int count,
int socket_id,
unsigned int flags);
109 __rte_ring_enqueue_elems_32(
struct rte_ring *r,
const uint32_t
size,
110 uint32_t idx,
const void *obj_table, uint32_t n)
113 uint32_t *ring = (uint32_t *)&r[1];
114 const uint32_t *obj = (
const uint32_t *)obj_table;
115 if (
likely(idx + n < size)) {
116 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
118 ring[idx + 1] = obj[i + 1];
119 ring[idx + 2] = obj[i + 2];
120 ring[idx + 3] = obj[i + 3];
121 ring[idx + 4] = obj[i + 4];
122 ring[idx + 5] = obj[i + 5];
123 ring[idx + 6] = obj[i + 6];
124 ring[idx + 7] = obj[i + 7];
128 ring[idx++] = obj[i++];
130 ring[idx++] = obj[i++];
132 ring[idx++] = obj[i++];
134 ring[idx++] = obj[i++];
136 ring[idx++] = obj[i++];
138 ring[idx++] = obj[i++];
140 ring[idx++] = obj[i++];
143 for (i = 0; idx <
size; i++, idx++)
146 for (idx = 0; i < n; i++, idx++)
152 __rte_ring_enqueue_elems_64(
struct rte_ring *r, uint32_t prod_head,
153 const void *obj_table, uint32_t n)
156 const uint32_t size = r->
size;
157 uint32_t idx = prod_head & r->
mask;
158 uint64_t *ring = (uint64_t *)&r[1];
159 const unaligned_uint64_t *obj = (
const unaligned_uint64_t *)obj_table;
160 if (
likely(idx + n < size)) {
161 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
163 ring[idx + 1] = obj[i + 1];
164 ring[idx + 2] = obj[i + 2];
165 ring[idx + 3] = obj[i + 3];
169 ring[idx++] = obj[i++];
171 ring[idx++] = obj[i++];
173 ring[idx++] = obj[i++];
176 for (i = 0; idx <
size; i++, idx++)
179 for (idx = 0; i < n; i++, idx++)
185 __rte_ring_enqueue_elems_128(
struct rte_ring *r, uint32_t prod_head,
186 const void *obj_table, uint32_t n)
189 const uint32_t size = r->
size;
190 uint32_t idx = prod_head & r->
mask;
191 rte_int128_t *ring = (rte_int128_t *)&r[1];
192 const rte_int128_t *obj = (
const rte_int128_t *)obj_table;
193 if (
likely(idx + n < size)) {
194 for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
195 memcpy((
void *)(ring + idx),
196 (
const void *)(obj + i), 32);
199 memcpy((
void *)(ring + idx),
200 (
const void *)(obj + i), 16);
203 for (i = 0; idx <
size; i++, idx++)
204 memcpy((
void *)(ring + idx),
205 (
const void *)(obj + i), 16);
207 for (idx = 0; i < n; i++, idx++)
208 memcpy((
void *)(ring + idx),
209 (
const void *)(obj + i), 16);
218 __rte_ring_enqueue_elems(
struct rte_ring *r, uint32_t prod_head,
219 const void *obj_table, uint32_t esize, uint32_t num)
225 __rte_ring_enqueue_elems_64(r, prod_head, obj_table, num);
226 else if (esize == 16)
227 __rte_ring_enqueue_elems_128(r, prod_head, obj_table, num);
229 uint32_t idx, scale, nr_idx, nr_num, nr_size;
232 scale = esize /
sizeof(uint32_t);
233 nr_num = num * scale;
234 idx = prod_head & r->
mask;
235 nr_idx = idx * scale;
236 nr_size = r->
size * scale;
237 __rte_ring_enqueue_elems_32(r, nr_size, nr_idx,
243 __rte_ring_dequeue_elems_32(
struct rte_ring *r,
const uint32_t size,
244 uint32_t idx,
void *obj_table, uint32_t n)
247 uint32_t *ring = (uint32_t *)&r[1];
248 uint32_t *obj = (uint32_t *)obj_table;
249 if (
likely(idx + n < size)) {
250 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
252 obj[i + 1] = ring[idx + 1];
253 obj[i + 2] = ring[idx + 2];
254 obj[i + 3] = ring[idx + 3];
255 obj[i + 4] = ring[idx + 4];
256 obj[i + 5] = ring[idx + 5];
257 obj[i + 6] = ring[idx + 6];
258 obj[i + 7] = ring[idx + 7];
262 obj[i++] = ring[idx++];
264 obj[i++] = ring[idx++];
266 obj[i++] = ring[idx++];
268 obj[i++] = ring[idx++];
270 obj[i++] = ring[idx++];
272 obj[i++] = ring[idx++];
274 obj[i++] = ring[idx++];
277 for (i = 0; idx <
size; i++, idx++)
280 for (idx = 0; i < n; i++, idx++)
286 __rte_ring_dequeue_elems_64(
struct rte_ring *r, uint32_t prod_head,
287 void *obj_table, uint32_t n)
290 const uint32_t size = r->
size;
291 uint32_t idx = prod_head & r->
mask;
292 uint64_t *ring = (uint64_t *)&r[1];
293 unaligned_uint64_t *obj = (unaligned_uint64_t *)obj_table;
294 if (
likely(idx + n < size)) {
295 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
297 obj[i + 1] = ring[idx + 1];
298 obj[i + 2] = ring[idx + 2];
299 obj[i + 3] = ring[idx + 3];
303 obj[i++] = ring[idx++];
305 obj[i++] = ring[idx++];
307 obj[i++] = ring[idx++];
310 for (i = 0; idx <
size; i++, idx++)
313 for (idx = 0; i < n; i++, idx++)
319 __rte_ring_dequeue_elems_128(
struct rte_ring *r, uint32_t prod_head,
320 void *obj_table, uint32_t n)
323 const uint32_t size = r->
size;
324 uint32_t idx = prod_head & r->
mask;
325 rte_int128_t *ring = (rte_int128_t *)&r[1];
326 rte_int128_t *obj = (rte_int128_t *)obj_table;
327 if (
likely(idx + n < size)) {
328 for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
329 memcpy((
void *)(obj + i), (
void *)(ring + idx), 32);
332 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
335 for (i = 0; idx <
size; i++, idx++)
336 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
338 for (idx = 0; i < n; i++, idx++)
339 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
348 __rte_ring_dequeue_elems(
struct rte_ring *r, uint32_t cons_head,
349 void *obj_table, uint32_t esize, uint32_t num)
355 __rte_ring_dequeue_elems_64(r, cons_head, obj_table, num);
356 else if (esize == 16)
357 __rte_ring_dequeue_elems_128(r, cons_head, obj_table, num);
359 uint32_t idx, scale, nr_idx, nr_num, nr_size;
362 scale = esize /
sizeof(uint32_t);
363 nr_num = num * scale;
364 idx = cons_head & r->
mask;
365 nr_idx = idx * scale;
366 nr_size = r->
size * scale;
367 __rte_ring_dequeue_elems_32(r, nr_size, nr_idx,
381 #ifdef RTE_USE_C11_MEM_MODEL
382 #include "rte_ring_c11_mem.h"
384 #include "rte_ring_generic.h"
412 __rte_ring_do_enqueue_elem(
struct rte_ring *r,
const void *obj_table,
413 unsigned int esize,
unsigned int n,
415 unsigned int *free_space)
417 uint32_t prod_head, prod_next;
418 uint32_t free_entries;
420 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
421 &prod_head, &prod_next, &free_entries);
425 __rte_ring_enqueue_elems(r, prod_head, obj_table, esize, n);
427 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
429 if (free_space != NULL)
430 *free_space = free_entries - n;
459 __rte_ring_do_dequeue_elem(
struct rte_ring *r,
void *obj_table,
460 unsigned int esize,
unsigned int n,
462 unsigned int *available)
464 uint32_t cons_head, cons_next;
467 n = __rte_ring_move_cons_head(r, (
int)is_sc, n, behavior,
468 &cons_head, &cons_next, &entries);
472 __rte_ring_dequeue_elems(r, cons_head, obj_table, esize, n);
474 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
477 if (available != NULL)
478 *available = entries - n;
506 unsigned int esize,
unsigned int n,
unsigned int *free_space)
508 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
535 unsigned int esize,
unsigned int n,
unsigned int *free_space)
537 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
541 #ifdef ALLOW_EXPERIMENTAL_API
571 unsigned int esize,
unsigned int n,
unsigned int *free_space)
580 #ifdef ALLOW_EXPERIMENTAL_API
581 case RTE_RING_SYNC_MT_RTS:
584 case RTE_RING_SYNC_MT_HTS:
592 if (free_space != NULL)
696 unsigned int esize,
unsigned int n,
unsigned int *available)
698 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
724 unsigned int esize,
unsigned int n,
unsigned int *available)
726 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
755 unsigned int esize,
unsigned int n,
unsigned int *available)
764 #ifdef ALLOW_EXPERIMENTAL_API
765 case RTE_RING_SYNC_MT_RTS:
768 case RTE_RING_SYNC_MT_HTS:
776 if (available != NULL)
883 unsigned int esize,
unsigned int n,
unsigned int *free_space)
885 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
912 unsigned int esize,
unsigned int n,
unsigned int *free_space)
914 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
943 unsigned int esize,
unsigned int n,
unsigned int *free_space)
952 #ifdef ALLOW_EXPERIMENTAL_API
953 case RTE_RING_SYNC_MT_RTS:
956 case RTE_RING_SYNC_MT_HTS:
964 if (free_space != NULL)
995 unsigned int esize,
unsigned int n,
unsigned int *available)
997 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
1024 unsigned int esize,
unsigned int n,
unsigned int *available)
1026 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
1055 unsigned int esize,
unsigned int n,
unsigned int *available)
1064 #ifdef ALLOW_EXPERIMENTAL_API
1065 case RTE_RING_SYNC_MT_RTS:
1068 case RTE_RING_SYNC_MT_HTS:
1076 if (available != NULL)
1081 #ifdef ALLOW_EXPERIMENTAL_API
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_sc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
#define __rte_always_inline
static __rte_experimental __rte_always_inline unsigned int rte_ring_mc_rts_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_experimental __rte_always_inline unsigned int rte_ring_mp_hts_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 int rte_ring_enqueue_elem(struct rte_ring *r, void *obj, 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_experimental __rte_always_inline unsigned int rte_ring_mp_hts_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_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_experimental __rte_always_inline unsigned int rte_ring_mc_rts_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_mc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_experimental __rte_always_inline unsigned int rte_ring_mp_rts_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 int rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
static __rte_experimental __rte_always_inline unsigned int rte_ring_mc_hts_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_experimental __rte_always_inline unsigned int rte_ring_mc_hts_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_experimental __rte_always_inline unsigned int rte_ring_mp_rts_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_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_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_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_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_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_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
enum rte_ring_sync_type sync_type
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)
ssize_t rte_ring_get_memsize_elem(unsigned int esize, unsigned int count)
struct rte_ring * rte_ring_create_elem(const char *name, unsigned int esize, unsigned int count, int socket_id, unsigned int flags)
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_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)