11 #ifndef _RTE_RING_ELEM_H_
12 #define _RTE_RING_ELEM_H_
114 unsigned int count,
int socket_id,
unsigned int flags);
117 __rte_ring_enqueue_elems_32(
struct rte_ring *r,
const uint32_t
size,
118 uint32_t idx,
const void *obj_table, uint32_t n)
121 uint32_t *ring = (uint32_t *)&r[1];
122 const uint32_t *obj = (
const uint32_t *)obj_table;
123 if (
likely(idx + n < size)) {
124 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
126 ring[idx + 1] = obj[i + 1];
127 ring[idx + 2] = obj[i + 2];
128 ring[idx + 3] = obj[i + 3];
129 ring[idx + 4] = obj[i + 4];
130 ring[idx + 5] = obj[i + 5];
131 ring[idx + 6] = obj[i + 6];
132 ring[idx + 7] = obj[i + 7];
136 ring[idx++] = obj[i++];
138 ring[idx++] = obj[i++];
140 ring[idx++] = obj[i++];
142 ring[idx++] = obj[i++];
144 ring[idx++] = obj[i++];
146 ring[idx++] = obj[i++];
148 ring[idx++] = obj[i++];
151 for (i = 0; idx <
size; i++, idx++)
154 for (idx = 0; i < n; i++, idx++)
160 __rte_ring_enqueue_elems_64(
struct rte_ring *r, uint32_t prod_head,
161 const void *obj_table, uint32_t n)
164 const uint32_t size = r->
size;
165 uint32_t idx = prod_head & r->
mask;
166 uint64_t *ring = (uint64_t *)&r[1];
167 const unaligned_uint64_t *obj = (
const unaligned_uint64_t *)obj_table;
168 if (
likely(idx + n < size)) {
169 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
171 ring[idx + 1] = obj[i + 1];
172 ring[idx + 2] = obj[i + 2];
173 ring[idx + 3] = obj[i + 3];
177 ring[idx++] = obj[i++];
179 ring[idx++] = obj[i++];
181 ring[idx++] = obj[i++];
184 for (i = 0; idx <
size; i++, idx++)
187 for (idx = 0; i < n; i++, idx++)
193 __rte_ring_enqueue_elems_128(
struct rte_ring *r, uint32_t prod_head,
194 const void *obj_table, uint32_t n)
197 const uint32_t size = r->
size;
198 uint32_t idx = prod_head & r->
mask;
199 rte_int128_t *ring = (rte_int128_t *)&r[1];
200 const rte_int128_t *obj = (
const rte_int128_t *)obj_table;
201 if (
likely(idx + n < size)) {
202 for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
203 memcpy((
void *)(ring + idx),
204 (
const void *)(obj + i), 32);
207 memcpy((
void *)(ring + idx),
208 (
const void *)(obj + i), 16);
211 for (i = 0; idx <
size; i++, idx++)
212 memcpy((
void *)(ring + idx),
213 (
const void *)(obj + i), 16);
215 for (idx = 0; i < n; i++, idx++)
216 memcpy((
void *)(ring + idx),
217 (
const void *)(obj + i), 16);
226 __rte_ring_enqueue_elems(
struct rte_ring *r, uint32_t prod_head,
227 const void *obj_table, uint32_t esize, uint32_t num)
233 __rte_ring_enqueue_elems_64(r, prod_head, obj_table, num);
234 else if (esize == 16)
235 __rte_ring_enqueue_elems_128(r, prod_head, obj_table, num);
237 uint32_t idx, scale, nr_idx, nr_num, nr_size;
240 scale = esize /
sizeof(uint32_t);
241 nr_num = num * scale;
242 idx = prod_head & r->
mask;
243 nr_idx = idx * scale;
244 nr_size = r->
size * scale;
245 __rte_ring_enqueue_elems_32(r, nr_size, nr_idx,
251 __rte_ring_dequeue_elems_32(
struct rte_ring *r,
const uint32_t size,
252 uint32_t idx,
void *obj_table, uint32_t n)
255 uint32_t *ring = (uint32_t *)&r[1];
256 uint32_t *obj = (uint32_t *)obj_table;
257 if (
likely(idx + n < size)) {
258 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
260 obj[i + 1] = ring[idx + 1];
261 obj[i + 2] = ring[idx + 2];
262 obj[i + 3] = ring[idx + 3];
263 obj[i + 4] = ring[idx + 4];
264 obj[i + 5] = ring[idx + 5];
265 obj[i + 6] = ring[idx + 6];
266 obj[i + 7] = ring[idx + 7];
270 obj[i++] = ring[idx++];
272 obj[i++] = ring[idx++];
274 obj[i++] = ring[idx++];
276 obj[i++] = ring[idx++];
278 obj[i++] = ring[idx++];
280 obj[i++] = ring[idx++];
282 obj[i++] = ring[idx++];
285 for (i = 0; idx <
size; i++, idx++)
288 for (idx = 0; i < n; i++, idx++)
294 __rte_ring_dequeue_elems_64(
struct rte_ring *r, uint32_t prod_head,
295 void *obj_table, uint32_t n)
298 const uint32_t size = r->
size;
299 uint32_t idx = prod_head & r->
mask;
300 uint64_t *ring = (uint64_t *)&r[1];
301 unaligned_uint64_t *obj = (unaligned_uint64_t *)obj_table;
302 if (
likely(idx + n < size)) {
303 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
305 obj[i + 1] = ring[idx + 1];
306 obj[i + 2] = ring[idx + 2];
307 obj[i + 3] = ring[idx + 3];
311 obj[i++] = ring[idx++];
313 obj[i++] = ring[idx++];
315 obj[i++] = ring[idx++];
318 for (i = 0; idx <
size; i++, idx++)
321 for (idx = 0; i < n; i++, idx++)
327 __rte_ring_dequeue_elems_128(
struct rte_ring *r, uint32_t prod_head,
328 void *obj_table, uint32_t n)
331 const uint32_t size = r->
size;
332 uint32_t idx = prod_head & r->
mask;
333 rte_int128_t *ring = (rte_int128_t *)&r[1];
334 rte_int128_t *obj = (rte_int128_t *)obj_table;
335 if (
likely(idx + n < size)) {
336 for (i = 0; i < (n & ~0x1); i += 2, idx += 2)
337 memcpy((
void *)(obj + i), (
void *)(ring + idx), 32);
340 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
343 for (i = 0; idx <
size; i++, idx++)
344 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
346 for (idx = 0; i < n; i++, idx++)
347 memcpy((
void *)(obj + i), (
void *)(ring + idx), 16);
356 __rte_ring_dequeue_elems(
struct rte_ring *r, uint32_t cons_head,
357 void *obj_table, uint32_t esize, uint32_t num)
363 __rte_ring_dequeue_elems_64(r, cons_head, obj_table, num);
364 else if (esize == 16)
365 __rte_ring_dequeue_elems_128(r, cons_head, obj_table, num);
367 uint32_t idx, scale, nr_idx, nr_num, nr_size;
370 scale = esize /
sizeof(uint32_t);
371 nr_num = num * scale;
372 idx = cons_head & r->
mask;
373 nr_idx = idx * scale;
374 nr_size = r->
size * scale;
375 __rte_ring_dequeue_elems_32(r, nr_size, nr_idx,
389 #ifdef RTE_USE_C11_MEM_MODEL
390 #include "rte_ring_c11_mem.h"
392 #include "rte_ring_generic.h"
420 __rte_ring_do_enqueue_elem(
struct rte_ring *r,
const void *obj_table,
421 unsigned int esize,
unsigned int n,
423 unsigned int *free_space)
425 uint32_t prod_head, prod_next;
426 uint32_t free_entries;
428 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
429 &prod_head, &prod_next, &free_entries);
433 __rte_ring_enqueue_elems(r, prod_head, obj_table, esize, n);
435 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
437 if (free_space != NULL)
438 *free_space = free_entries - n;
467 __rte_ring_do_dequeue_elem(
struct rte_ring *r,
void *obj_table,
468 unsigned int esize,
unsigned int n,
470 unsigned int *available)
472 uint32_t cons_head, cons_next;
475 n = __rte_ring_move_cons_head(r, (
int)is_sc, n, behavior,
476 &cons_head, &cons_next, &entries);
480 __rte_ring_dequeue_elems(r, cons_head, obj_table, esize, n);
482 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
485 if (available != NULL)
486 *available = entries - n;
514 unsigned int esize,
unsigned int n,
unsigned int *free_space)
516 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
543 unsigned int esize,
unsigned int n,
unsigned int *free_space)
545 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
549 #ifdef ALLOW_EXPERIMENTAL_API
579 unsigned int esize,
unsigned int n,
unsigned int *free_space)
581 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
591 #ifdef ALLOW_EXPERIMENTAL_API
592 case RTE_RING_SYNC_MT_RTS:
595 case RTE_RING_SYNC_MT_HTS:
603 if (free_space != NULL)
707 unsigned int esize,
unsigned int n,
unsigned int *available)
709 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
735 unsigned int esize,
unsigned int n,
unsigned int *available)
737 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
766 unsigned int esize,
unsigned int n,
unsigned int *available)
775 #ifdef ALLOW_EXPERIMENTAL_API
776 case RTE_RING_SYNC_MT_RTS:
779 case RTE_RING_SYNC_MT_HTS:
787 if (available != NULL)
894 unsigned int esize,
unsigned int n,
unsigned int *free_space)
896 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
923 unsigned int esize,
unsigned int n,
unsigned int *free_space)
925 return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
954 unsigned int esize,
unsigned int n,
unsigned int *free_space)
963 #ifdef ALLOW_EXPERIMENTAL_API
964 case RTE_RING_SYNC_MT_RTS:
967 case RTE_RING_SYNC_MT_HTS:
975 if (free_space != NULL)
1006 unsigned int esize,
unsigned int n,
unsigned int *available)
1008 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
1035 unsigned int esize,
unsigned int n,
unsigned int *available)
1037 return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
1066 unsigned int esize,
unsigned int n,
unsigned int *available)
1075 #ifdef ALLOW_EXPERIMENTAL_API
1076 case RTE_RING_SYNC_MT_RTS:
1079 case RTE_RING_SYNC_MT_HTS:
1087 if (available != NULL)
1092 #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_always_inline int rte_ring_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline unsigned rte_ring_mc_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 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_hts_enqueue_bulk_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 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_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 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_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_always_inline unsigned rte_ring_sc_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
__rte_experimental 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_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 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_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_experimental __rte_always_inline unsigned 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)
__rte_experimental ssize_t rte_ring_get_memsize_elem(unsigned int esize, unsigned int count)
static __rte_always_inline unsigned 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_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_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)
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)
static __rte_always_inline unsigned rte_ring_sp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)