11 #ifndef _CNE_RING_ELEM_H_
12 #define _CNE_RING_ELEM_H_
26 #include <sys/queue.h>
34 __cne_ring_enqueue_elems_32(
struct cne_ring *r,
const uint32_t size, uint32_t idx,
35 const void *obj_table, uint32_t n)
38 uint32_t *ring = (uint32_t *)&r[1];
39 const uint32_t *obj = (
const uint32_t *)obj_table;
40 if (
likely(idx + n < size)) {
41 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
43 ring[idx + 1] = obj[i + 1];
44 ring[idx + 2] = obj[i + 2];
45 ring[idx + 3] = obj[i + 3];
46 ring[idx + 4] = obj[i + 4];
47 ring[idx + 5] = obj[i + 5];
48 ring[idx + 6] = obj[i + 6];
49 ring[idx + 7] = obj[i + 7];
53 ring[idx++] = obj[i++];
55 ring[idx++] = obj[i++];
57 ring[idx++] = obj[i++];
59 ring[idx++] = obj[i++];
61 ring[idx++] = obj[i++];
63 ring[idx++] = obj[i++];
65 ring[idx++] = obj[i++];
68 for (i = 0; idx < size; i++, idx++)
71 for (idx = 0; i < n; i++, idx++)
77 __cne_ring_enqueue_elems_64(
struct cne_ring *r, uint32_t prod_head,
const void *obj_table,
81 const uint32_t size = r->size;
82 uint32_t idx = prod_head & r->mask;
83 uint64_t *ring = (uint64_t *)&r[1];
84 const unaligned_uint64_t *obj = (
const unaligned_uint64_t *)obj_table;
85 if (
likely(idx + n < size)) {
86 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
88 ring[idx + 1] = obj[i + 1];
89 ring[idx + 2] = obj[i + 2];
90 ring[idx + 3] = obj[i + 3];
94 ring[idx++] = obj[i++];
96 ring[idx++] = obj[i++];
98 ring[idx++] = obj[i++];
101 for (i = 0; idx < size; i++, idx++)
104 for (idx = 0; i < n; i++, idx++)
114 __cne_ring_enqueue_elems(
struct cne_ring *r, uint32_t prod_head,
const void *obj_table,
115 uint32_t esize, uint32_t num)
121 __cne_ring_enqueue_elems_64(r, prod_head, obj_table, num);
123 uint32_t idx, scale, nr_idx, nr_num, nr_size;
126 scale = esize /
sizeof(uint32_t);
127 nr_num = num * scale;
128 idx = prod_head & r->mask;
129 nr_idx = idx * scale;
130 nr_size = r->size * scale;
131 __cne_ring_enqueue_elems_32(r, nr_size, nr_idx, obj_table, nr_num);
136 __cne_ring_dequeue_elems_32(
struct cne_ring *r,
const uint32_t size, uint32_t idx,
void *obj_table,
140 uint32_t *ring = (uint32_t *)&r[1];
141 uint32_t *obj = (uint32_t *)obj_table;
142 if (
likely(idx + n < size)) {
143 for (i = 0; i < (n & ~0x7); i += 8, idx += 8) {
145 obj[i + 1] = ring[idx + 1];
146 obj[i + 2] = ring[idx + 2];
147 obj[i + 3] = ring[idx + 3];
148 obj[i + 4] = ring[idx + 4];
149 obj[i + 5] = ring[idx + 5];
150 obj[i + 6] = ring[idx + 6];
151 obj[i + 7] = ring[idx + 7];
155 obj[i++] = ring[idx++];
157 obj[i++] = ring[idx++];
159 obj[i++] = ring[idx++];
161 obj[i++] = ring[idx++];
163 obj[i++] = ring[idx++];
165 obj[i++] = ring[idx++];
167 obj[i++] = ring[idx++];
170 for (i = 0; idx < size; i++, idx++)
173 for (idx = 0; i < n; i++, idx++)
179 __cne_ring_dequeue_elems_64(
struct cne_ring *r, uint32_t prod_head,
void *obj_table, uint32_t n)
182 const uint32_t size = r->size;
183 uint32_t idx = prod_head & r->mask;
184 uint64_t *ring = (uint64_t *)&r[1];
185 unaligned_uint64_t *obj = (unaligned_uint64_t *)obj_table;
186 if (
likely(idx + n < size)) {
187 for (i = 0; i < (n & ~0x3); i += 4, idx += 4) {
189 obj[i + 1] = ring[idx + 1];
190 obj[i + 2] = ring[idx + 2];
191 obj[i + 3] = ring[idx + 3];
195 obj[i++] = ring[idx++];
197 obj[i++] = ring[idx++];
199 obj[i++] = ring[idx++];
202 for (i = 0; idx < size; i++, idx++)
205 for (idx = 0; i < n; i++, idx++)
215 __cne_ring_dequeue_elems(
struct cne_ring *r, uint32_t cons_head,
void *obj_table, uint32_t esize,
222 __cne_ring_dequeue_elems_64(r, cons_head, obj_table, num);
224 uint32_t idx, scale, nr_idx, nr_num, nr_size;
227 scale = esize /
sizeof(uint32_t);
228 nr_num = num * scale;
229 idx = cons_head & r->mask;
230 nr_idx = idx * scale;
231 nr_size = r->size * scale;
232 __cne_ring_dequeue_elems_32(r, nr_size, nr_idx, obj_table, nr_num);
263 __cne_ring_do_enqueue_elem(
struct cne_ring *r,
const void *obj_table,
unsigned int esize,
264 unsigned int n,
enum cne_ring_queue_behavior behavior,
265 unsigned int is_sp,
unsigned int *free_space)
267 uint32_t prod_head, prod_next;
268 uint32_t free_entries;
270 n = __cne_ring_move_prod_head(r, is_sp, n, behavior, &prod_head, &prod_next, &free_entries);
274 __cne_ring_enqueue_elems(r, prod_head, obj_table, esize, n);
276 update_tail(&r->prod, prod_head, prod_next, is_sp);
278 if (free_space != NULL)
279 *free_space = free_entries - n;
308 __cne_ring_do_dequeue_elem(
struct cne_ring *r,
void *obj_table,
unsigned int esize,
unsigned int n,
309 enum cne_ring_queue_behavior behavior,
unsigned int is_sc,
310 unsigned int *available)
312 uint32_t cons_head, cons_next;
315 n = __cne_ring_move_cons_head(r, (
int)is_sc, n, behavior, &cons_head, &cons_next, &entries);
319 __cne_ring_dequeue_elems(r, cons_head, obj_table, esize, n);
321 update_tail(&r->cons, cons_head, cons_next, is_sc);
324 if (available != NULL)
325 *available = entries - n;
#define __cne_always_inline