18#ifdef RTE_USE_C11_MEM_MODEL
19#define __KNI_LOAD_ACQUIRE(src) ({ \
20 __atomic_load_n((src), __ATOMIC_ACQUIRE); \
22#define __KNI_STORE_RELEASE(dst, value) do { \
23 __atomic_store_n((dst), value, __ATOMIC_RELEASE); \
26#define __KNI_LOAD_ACQUIRE(src) ({ \
27 typeof (*(src)) val = *(src); \
31#define __KNI_STORE_RELEASE(dst, value) do { \
41kni_fifo_init(
struct rte_kni_fifo *fifo,
unsigned size)
44 if (size & (size - 1))
45 rte_panic(
"KNI fifo size must be power of 2\n");
50 fifo->elem_size =
sizeof(
void *);
57kni_fifo_put(
struct rte_kni_fifo *fifo,
void **data,
unsigned num)
60 unsigned fifo_write = fifo->write;
61 unsigned new_write = fifo_write;
62 unsigned fifo_read = __KNI_LOAD_ACQUIRE(&fifo->read);
64 for (i = 0; i < num; i++) {
65 new_write = (new_write + 1) & (fifo->len - 1);
67 if (new_write == fifo_read)
69 fifo->buffer[fifo_write] = data[i];
70 fifo_write = new_write;
72 __KNI_STORE_RELEASE(&fifo->write, fifo_write);
80kni_fifo_get(
struct rte_kni_fifo *fifo,
void **data,
unsigned num)
83 unsigned new_read = fifo->read;
84 unsigned fifo_write = __KNI_LOAD_ACQUIRE(&fifo->write);
86 for (i = 0; i < num; i++) {
87 if (new_read == fifo_write)
90 data[i] = fifo->buffer[new_read];
91 new_read = (new_read + 1) & (fifo->len - 1);
93 __KNI_STORE_RELEASE(&fifo->read, new_read);
100static inline uint32_t
101kni_fifo_count(
struct rte_kni_fifo *fifo)
103 unsigned fifo_write = __KNI_LOAD_ACQUIRE(&fifo->write);
104 unsigned fifo_read = __KNI_LOAD_ACQUIRE(&fifo->read);
105 return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1);
111static inline uint32_t
112kni_fifo_free_count(
struct rte_kni_fifo *fifo)
114 uint32_t fifo_write = __KNI_LOAD_ACQUIRE(&fifo->write);
115 uint32_t fifo_read = __KNI_LOAD_ACQUIRE(&fifo->read);
116 return (fifo_read - fifo_write - 1) & (fifo->len - 1);