1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
6 * Ring structure definitions used for the internal ring buffers of the
7 * SW eventdev implementation. These are designed for single-core use only.
14 #include <rte_common.h>
15 #include <rte_memory.h>
16 #include <rte_malloc.h>
17 #include <rte_eventdev.h>
19 #define IQ_RING_NAMESIZE 12
20 #define QID_IQ_DEPTH 512
21 #define QID_IQ_MASK (uint16_t)(QID_IQ_DEPTH - 1)
24 char name[IQ_RING_NAMESIZE] __rte_cache_aligned;
28 struct rte_event ring[QID_IQ_DEPTH];
31 static inline struct iq_ring *
32 iq_ring_create(const char *name, unsigned int socket_id)
34 struct iq_ring *retval;
36 retval = rte_malloc_socket(NULL, sizeof(*retval), 0, socket_id);
40 snprintf(retval->name, sizeof(retval->name), "%s", name);
41 retval->write_idx = retval->read_idx = 0;
47 iq_ring_destroy(struct iq_ring *r)
52 static __rte_always_inline uint16_t
53 iq_ring_count(const struct iq_ring *r)
55 return r->write_idx - r->read_idx;
58 static __rte_always_inline uint16_t
59 iq_ring_free_count(const struct iq_ring *r)
61 return QID_IQ_MASK - iq_ring_count(r);
64 static __rte_always_inline uint16_t
65 iq_ring_enqueue_burst(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
67 const uint16_t read = r->read_idx;
68 uint16_t write = r->write_idx;
69 const uint16_t space = read + QID_IQ_MASK - write;
75 for (i = 0; i < nb_qes; i++, write++)
76 r->ring[write & QID_IQ_MASK] = qes[i];
83 static __rte_always_inline uint16_t
84 iq_ring_dequeue_burst(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
86 uint16_t read = r->read_idx;
87 const uint16_t write = r->write_idx;
88 const uint16_t items = write - read;
91 for (i = 0; i < nb_qes; i++, read++)
92 qes[i] = r->ring[read & QID_IQ_MASK];
97 r->read_idx += nb_qes;
102 /* assumes there is space, from a previous dequeue_burst */
103 static __rte_always_inline uint16_t
104 iq_ring_put_back(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
106 uint16_t i, read = r->read_idx;
108 for (i = nb_qes; i-- > 0; )
109 r->ring[--read & QID_IQ_MASK] = qes[i];
115 static __rte_always_inline const struct rte_event *
116 iq_ring_peek(const struct iq_ring *r)
118 return &r->ring[r->read_idx & QID_IQ_MASK];
121 static __rte_always_inline void
122 iq_ring_pop(struct iq_ring *r)
127 static __rte_always_inline int
128 iq_ring_enqueue(struct iq_ring *r, const struct rte_event *qe)
130 const uint16_t read = r->read_idx;
131 const uint16_t write = r->write_idx;
132 const uint16_t space = read + QID_IQ_MASK - write;
137 r->ring[write & QID_IQ_MASK] = *qe;
139 r->write_idx = write + 1;