41 #include <sys/queue.h>
44 #include <rte_config.h>
52 #define RTE_TAILQ_RING_NAME "RTE_RING"
54 enum rte_ring_queue_behavior {
55 RTE_RING_QUEUE_FIXED = 0,
56 RTE_RING_QUEUE_VARIABLE
59 #define RTE_RING_MZ_PREFIX "RG_"
61 #define RTE_RING_NAMESIZE (RTE_MEMZONE_NAMESIZE - \
62 sizeof(RTE_RING_MZ_PREFIX) + 1)
67 struct rte_ring_headtail {
68 volatile uint32_t head;
69 volatile uint32_t tail;
108 #define RING_F_SP_ENQ 0x0001
109 #define RING_F_SC_DEQ 0x0002
118 #define RING_F_EXACT_SZ 0x0004
119 #define RTE_RING_SZ_MASK (0x7fffffffU)
220 int socket_id,
unsigned flags);
242 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \
244 const uint32_t size = (r)->size; \
245 uint32_t idx = prod_head & (r)->mask; \
246 obj_type *ring = (obj_type *)ring_start; \
247 if (likely(idx + n < size)) { \
248 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
249 ring[idx] = obj_table[i]; \
250 ring[idx+1] = obj_table[i+1]; \
251 ring[idx+2] = obj_table[i+2]; \
252 ring[idx+3] = obj_table[i+3]; \
256 ring[idx++] = obj_table[i++]; \
258 ring[idx++] = obj_table[i++]; \
260 ring[idx++] = obj_table[i++]; \
263 for (i = 0; idx < size; i++, idx++)\
264 ring[idx] = obj_table[i]; \
265 for (idx = 0; i < n; i++, idx++) \
266 ring[idx] = obj_table[i]; \
273 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \
275 uint32_t idx = cons_head & (r)->mask; \
276 const uint32_t size = (r)->size; \
277 obj_type *ring = (obj_type *)ring_start; \
278 if (likely(idx + n < size)) { \
279 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
280 obj_table[i] = ring[idx]; \
281 obj_table[i+1] = ring[idx+1]; \
282 obj_table[i+2] = ring[idx+2]; \
283 obj_table[i+3] = ring[idx+3]; \
287 obj_table[i++] = ring[idx++]; \
289 obj_table[i++] = ring[idx++]; \
291 obj_table[i++] = ring[idx++]; \
294 for (i = 0; idx < size; i++, idx++) \
295 obj_table[i] = ring[idx]; \
296 for (idx = 0; i < n; i++, idx++) \
297 obj_table[i] = ring[idx]; \
310 #ifdef RTE_USE_C11_MEM_MODEL
311 #include "rte_ring_c11_mem.h"
313 #include "rte_ring_generic.h"
337 __rte_ring_do_enqueue(
struct rte_ring *r,
void *
const *obj_table,
338 unsigned int n,
enum rte_ring_queue_behavior behavior,
339 unsigned int is_sp,
unsigned int *free_space)
341 uint32_t prod_head, prod_next;
342 uint32_t free_entries;
344 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
345 &prod_head, &prod_next, &free_entries);
349 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n,
void *);
351 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
353 if (free_space != NULL)
354 *free_space = free_entries - n;
379 __rte_ring_do_dequeue(
struct rte_ring *r,
void **obj_table,
380 unsigned int n,
enum rte_ring_queue_behavior behavior,
381 unsigned int is_sc,
unsigned int *available)
383 uint32_t cons_head, cons_next;
386 n = __rte_ring_move_cons_head(r, (
int)is_sc, n, behavior,
387 &cons_head, &cons_next, &entries);
391 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n,
void *);
393 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
396 if (available != NULL)
397 *available = entries - n;
421 unsigned int n,
unsigned int *free_space)
423 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
424 __IS_MP, free_space);
444 unsigned int n,
unsigned int *free_space)
446 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
447 __IS_SP, free_space);
471 unsigned int n,
unsigned int *free_space)
473 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
474 r->prod.single, free_space);
555 unsigned int n,
unsigned int *available)
557 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
579 unsigned int n,
unsigned int *available)
581 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
606 unsigned int *available)
608 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
609 r->cons.single, available);
681 static inline unsigned
684 uint32_t prod_tail = r->prod.tail;
685 uint32_t cons_tail = r->cons.tail;
686 uint32_t count = (prod_tail - cons_tail) & r->
mask;
698 static inline unsigned
744 static inline unsigned int
758 static inline unsigned int
804 unsigned int n,
unsigned int *free_space)
806 return __rte_ring_do_enqueue(r, obj_table, n,
807 RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space);
827 unsigned int n,
unsigned int *free_space)
829 return __rte_ring_do_enqueue(r, obj_table, n,
830 RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space);
854 unsigned int n,
unsigned int *free_space)
856 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE,
857 r->prod.single, free_space);
882 unsigned int n,
unsigned int *available)
884 return __rte_ring_do_dequeue(r, obj_table, n,
885 RTE_RING_QUEUE_VARIABLE, __IS_MC, available);
907 unsigned int n,
unsigned int *available)
909 return __rte_ring_do_dequeue(r, obj_table, n,
910 RTE_RING_QUEUE_VARIABLE, __IS_SC, available);
934 unsigned int n,
unsigned int *available)
936 return __rte_ring_do_dequeue(r, obj_table, n,
937 RTE_RING_QUEUE_VARIABLE,
938 r->cons.single, available);