4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <rte_errno.h>
39 #include <rte_mempool.h>
42 common_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
45 return rte_ring_mp_enqueue_bulk(mp->pool_data,
46 obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
50 common_ring_sp_enqueue(struct rte_mempool *mp, void * const *obj_table,
53 return rte_ring_sp_enqueue_bulk(mp->pool_data,
54 obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
58 common_ring_mc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
60 return rte_ring_mc_dequeue_bulk(mp->pool_data,
61 obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
65 common_ring_sc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
67 return rte_ring_sc_dequeue_bulk(mp->pool_data,
68 obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
72 common_ring_get_count(const struct rte_mempool *mp)
74 return rte_ring_count(mp->pool_data);
79 common_ring_alloc(struct rte_mempool *mp)
81 int rg_flags = 0, ret;
82 char rg_name[RTE_RING_NAMESIZE];
85 ret = snprintf(rg_name, sizeof(rg_name),
86 RTE_MEMPOOL_MZ_FORMAT, mp->name);
87 if (ret < 0 || ret >= (int)sizeof(rg_name)) {
88 rte_errno = ENAMETOOLONG;
93 if (mp->flags & MEMPOOL_F_SP_PUT)
94 rg_flags |= RING_F_SP_ENQ;
95 if (mp->flags & MEMPOOL_F_SC_GET)
96 rg_flags |= RING_F_SC_DEQ;
99 * Allocate the ring that will be used to store objects.
100 * Ring functions will return appropriate errors if we are
101 * running as a secondary process etc., so no checks made
102 * in this function for that condition.
104 r = rte_ring_create(rg_name, rte_align32pow2(mp->size + 1),
105 mp->socket_id, rg_flags);
115 common_ring_free(struct rte_mempool *mp)
117 rte_ring_free(mp->pool_data);
121 * The following 4 declarations of mempool ops structs address
122 * the need for the backward compatible mempool handlers for
123 * single/multi producers and single/multi consumers as dictated by the
124 * flags provided to the rte_mempool_create function
126 static const struct rte_mempool_ops ops_mp_mc = {
127 .name = "ring_mp_mc",
128 .alloc = common_ring_alloc,
129 .free = common_ring_free,
130 .enqueue = common_ring_mp_enqueue,
131 .dequeue = common_ring_mc_dequeue,
132 .get_count = common_ring_get_count,
135 static const struct rte_mempool_ops ops_sp_sc = {
136 .name = "ring_sp_sc",
137 .alloc = common_ring_alloc,
138 .free = common_ring_free,
139 .enqueue = common_ring_sp_enqueue,
140 .dequeue = common_ring_sc_dequeue,
141 .get_count = common_ring_get_count,
144 static const struct rte_mempool_ops ops_mp_sc = {
145 .name = "ring_mp_sc",
146 .alloc = common_ring_alloc,
147 .free = common_ring_free,
148 .enqueue = common_ring_mp_enqueue,
149 .dequeue = common_ring_sc_dequeue,
150 .get_count = common_ring_get_count,
153 static const struct rte_mempool_ops ops_sp_mc = {
154 .name = "ring_sp_mc",
155 .alloc = common_ring_alloc,
156 .free = common_ring_free,
157 .enqueue = common_ring_sp_enqueue,
158 .dequeue = common_ring_mc_dequeue,
159 .get_count = common_ring_get_count,
162 MEMPOOL_REGISTER_OPS(ops_mp_mc);
163 MEMPOOL_REGISTER_OPS(ops_sp_sc);
164 MEMPOOL_REGISTER_OPS(ops_mp_sc);
165 MEMPOOL_REGISTER_OPS(ops_sp_mc);