4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Ring structure definitions used for the internal ring buffers of the
35 * SW eventdev implementation. These are designed for single-core use only.
42 #include <rte_common.h>
43 #include <rte_memory.h>
44 #include <rte_malloc.h>
45 #include <rte_eventdev.h>
47 #define IQ_RING_NAMESIZE 12
48 #define QID_IQ_DEPTH 512
49 #define QID_IQ_MASK (uint16_t)(QID_IQ_DEPTH - 1)
52 char name[IQ_RING_NAMESIZE] __rte_cache_aligned;
56 struct rte_event ring[QID_IQ_DEPTH];
60 #define force_inline inline __attribute__((always_inline))
63 static inline struct iq_ring *
64 iq_ring_create(const char *name, unsigned int socket_id)
66 struct iq_ring *retval;
68 retval = rte_malloc_socket(NULL, sizeof(*retval), 0, socket_id);
72 snprintf(retval->name, sizeof(retval->name), "%s", name);
73 retval->write_idx = retval->read_idx = 0;
79 iq_ring_destroy(struct iq_ring *r)
84 static force_inline uint16_t
85 iq_ring_count(const struct iq_ring *r)
87 return r->write_idx - r->read_idx;
90 static force_inline uint16_t
91 iq_ring_free_count(const struct iq_ring *r)
93 return QID_IQ_MASK - iq_ring_count(r);
96 static force_inline uint16_t
97 iq_ring_enqueue_burst(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
99 const uint16_t read = r->read_idx;
100 uint16_t write = r->write_idx;
101 const uint16_t space = read + QID_IQ_MASK - write;
107 for (i = 0; i < nb_qes; i++, write++)
108 r->ring[write & QID_IQ_MASK] = qes[i];
110 r->write_idx = write;
115 static force_inline uint16_t
116 iq_ring_dequeue_burst(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
118 uint16_t read = r->read_idx;
119 const uint16_t write = r->write_idx;
120 const uint16_t items = write - read;
123 for (i = 0; i < nb_qes; i++, read++)
124 qes[i] = r->ring[read & QID_IQ_MASK];
129 r->read_idx += nb_qes;
134 /* assumes there is space, from a previous dequeue_burst */
135 static force_inline uint16_t
136 iq_ring_put_back(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
138 uint16_t i, read = r->read_idx;
140 for (i = nb_qes; i-- > 0; )
141 r->ring[--read & QID_IQ_MASK] = qes[i];
147 static force_inline const struct rte_event *
148 iq_ring_peek(const struct iq_ring *r)
150 return &r->ring[r->read_idx & QID_IQ_MASK];
153 static force_inline void
154 iq_ring_pop(struct iq_ring *r)
159 static force_inline int
160 iq_ring_enqueue(struct iq_ring *r, const struct rte_event *qe)
162 const uint16_t read = r->read_idx;
163 const uint16_t write = r->write_idx;
164 const uint16_t space = read + QID_IQ_MASK - write;
169 r->ring[write & QID_IQ_MASK] = *qe;
171 r->write_idx = write + 1;