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) 65 struct rte_ring_headtail {
66 volatile uint32_t head;
67 volatile uint32_t tail;
98 struct rte_ring_headtail prod __rte_cache_aligned;
102 struct rte_ring_headtail cons __rte_cache_aligned;
106 #define RING_F_SP_ENQ 0x0001 107 #define RING_F_SC_DEQ 0x0002 116 #define RING_F_EXACT_SZ 0x0004 117 #define RTE_RING_SZ_MASK (0x7fffffffU) 216 int socket_id,
unsigned flags);
238 #define ENQUEUE_PTRS(r, ring_start, prod_head, obj_table, n, obj_type) do { \ 240 const uint32_t size = (r)->size; \ 241 uint32_t idx = prod_head & (r)->mask; \ 242 obj_type *ring = (obj_type *)ring_start; \ 243 if (likely(idx + n < size)) { \ 244 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \ 245 ring[idx] = obj_table[i]; \ 246 ring[idx+1] = obj_table[i+1]; \ 247 ring[idx+2] = obj_table[i+2]; \ 248 ring[idx+3] = obj_table[i+3]; \ 252 ring[idx++] = obj_table[i++]; \ 254 ring[idx++] = obj_table[i++]; \ 256 ring[idx++] = obj_table[i++]; \ 259 for (i = 0; idx < size; i++, idx++)\ 260 ring[idx] = obj_table[i]; \ 261 for (idx = 0; i < n; i++, idx++) \ 262 ring[idx] = obj_table[i]; \ 269 #define DEQUEUE_PTRS(r, ring_start, cons_head, obj_table, n, obj_type) do { \ 271 uint32_t idx = cons_head & (r)->mask; \ 272 const uint32_t size = (r)->size; \ 273 obj_type *ring = (obj_type *)ring_start; \ 274 if (likely(idx + n < size)) { \ 275 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\ 276 obj_table[i] = ring[idx]; \ 277 obj_table[i+1] = ring[idx+1]; \ 278 obj_table[i+2] = ring[idx+2]; \ 279 obj_table[i+3] = ring[idx+3]; \ 283 obj_table[i++] = ring[idx++]; \ 285 obj_table[i++] = ring[idx++]; \ 287 obj_table[i++] = ring[idx++]; \ 290 for (i = 0; idx < size; i++, idx++) \ 291 obj_table[i] = ring[idx]; \ 292 for (idx = 0; i < n; i++, idx++) \ 293 obj_table[i] = ring[idx]; \ 306 #ifdef RTE_USE_C11_MEM_MODEL 307 #include "rte_ring_c11_mem.h" 309 #include "rte_ring_generic.h" 333 __rte_ring_do_enqueue(
struct rte_ring *r,
void *
const *obj_table,
334 unsigned int n,
enum rte_ring_queue_behavior behavior,
335 unsigned int is_sp,
unsigned int *free_space)
337 uint32_t prod_head, prod_next;
338 uint32_t free_entries;
340 n = __rte_ring_move_prod_head(r, is_sp, n, behavior,
341 &prod_head, &prod_next, &free_entries);
345 ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n,
void *);
347 update_tail(&r->prod, prod_head, prod_next, is_sp, 1);
349 if (free_space != NULL)
350 *free_space = free_entries - n;
375 __rte_ring_do_dequeue(
struct rte_ring *r,
void **obj_table,
376 unsigned int n,
enum rte_ring_queue_behavior behavior,
377 unsigned int is_sc,
unsigned int *available)
379 uint32_t cons_head, cons_next;
382 n = __rte_ring_move_cons_head(r, (
int)is_sc, n, behavior,
383 &cons_head, &cons_next, &entries);
387 DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n,
void *);
389 update_tail(&r->cons, cons_head, cons_next, is_sc, 0);
392 if (available != NULL)
393 *available = entries - n;
417 unsigned int n,
unsigned int *free_space)
419 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
420 __IS_MP, free_space);
440 unsigned int n,
unsigned int *free_space)
442 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
443 __IS_SP, free_space);
467 unsigned int n,
unsigned int *free_space)
469 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
470 r->prod.single, free_space);
551 unsigned int n,
unsigned int *available)
553 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
575 unsigned int n,
unsigned int *available)
577 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
602 unsigned int *available)
604 return __rte_ring_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED,
605 r->cons.single, available);
694 static inline unsigned 697 uint32_t prod_tail = r->prod.tail;
698 uint32_t cons_tail = r->cons.tail;
699 uint32_t count = (prod_tail - cons_tail) & r->
mask;
711 static inline unsigned 757 static inline unsigned int 771 static inline unsigned int 817 unsigned int n,
unsigned int *free_space)
819 return __rte_ring_do_enqueue(r, obj_table, n,
820 RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space);
840 unsigned int n,
unsigned int *free_space)
842 return __rte_ring_do_enqueue(r, obj_table, n,
843 RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space);
867 unsigned int n,
unsigned int *free_space)
869 return __rte_ring_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE,
870 r->prod.single, free_space);
895 unsigned int n,
unsigned int *available)
897 return __rte_ring_do_dequeue(r, obj_table, n,
898 RTE_RING_QUEUE_VARIABLE, __IS_MC, available);
920 unsigned int n,
unsigned int *available)
922 return __rte_ring_do_dequeue(r, obj_table, n,
923 RTE_RING_QUEUE_VARIABLE, __IS_SC, available);
947 unsigned int n,
unsigned int *available)
949 return __rte_ring_do_dequeue(r, obj_table, n,
950 RTE_RING_QUEUE_VARIABLE,
951 r->cons.single, available);
#define __rte_always_inline
const struct rte_memzone * memzone
static __rte_always_inline unsigned int rte_ring_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
char pad2 __rte_cache_aligned
char name [RTE_MEMZONE_NAMESIZE] __rte_cache_aligned
static __rte_always_inline int rte_ring_dequeue(struct rte_ring *r, void **obj_p)
static __rte_always_inline unsigned rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
static int rte_ring_empty(const struct rte_ring *r)
static __rte_always_inline unsigned rte_ring_mp_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
static __rte_always_inline int rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
void rte_ring_list_dump(FILE *f)
static __rte_always_inline unsigned int rte_ring_mp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
static __rte_always_inline int rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
static __rte_always_inline int rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
static unsigned int rte_ring_get_capacity(const struct rte_ring *r)
static unsigned int rte_ring_get_size(const struct rte_ring *r)
char pad0 __rte_cache_aligned
static __rte_always_inline int rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
char pad1 __rte_cache_aligned
void rte_ring_free(struct rte_ring *r)
static __rte_always_inline unsigned rte_ring_sp_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_sp_enqueue_bulk(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
void rte_ring_dump(FILE *f, const struct rte_ring *r)
static unsigned rte_ring_count(const struct rte_ring *r)
struct rte_ring * rte_ring_create(const char *name, unsigned count, int socket_id, unsigned flags)
static __rte_always_inline unsigned int rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
struct rte_ring * rte_ring_lookup(const char *name)
static unsigned rte_ring_free_count(const struct rte_ring *r)
static __rte_always_inline int rte_ring_enqueue(struct rte_ring *r, void *obj)
static __rte_always_inline unsigned rte_ring_enqueue_burst(struct rte_ring *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
__rte_experimental void rte_ring_reset(struct rte_ring *r)
static __rte_always_inline unsigned int rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n, unsigned int *available)
int rte_ring_init(struct rte_ring *r, const char *name, unsigned count, unsigned flags)
static int rte_ring_full(const struct rte_ring *r)
ssize_t rte_ring_get_memsize(unsigned count)
#define RTE_MEMZONE_NAMESIZE