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, obj_table, n);
49 common_ring_sp_enqueue(struct rte_mempool *mp, void * const *obj_table,
52 return rte_ring_sp_enqueue_bulk(mp->pool_data, obj_table, n);
56 common_ring_mc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
58 return rte_ring_mc_dequeue_bulk(mp->pool_data, obj_table, n);
62 common_ring_sc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
64 return rte_ring_sc_dequeue_bulk(mp->pool_data, obj_table, n);
68 common_ring_get_count(const struct rte_mempool *mp)
70 return rte_ring_count(mp->pool_data);
75 common_ring_alloc(struct rte_mempool *mp)
77 int rg_flags = 0, ret;
78 char rg_name[RTE_RING_NAMESIZE];
81 ret = snprintf(rg_name, sizeof(rg_name),
82 RTE_MEMPOOL_MZ_FORMAT, mp->name);
83 if (ret < 0 || ret >= (int)sizeof(rg_name)) {
84 rte_errno = ENAMETOOLONG;
89 if (mp->flags & MEMPOOL_F_SP_PUT)
90 rg_flags |= RING_F_SP_ENQ;
91 if (mp->flags & MEMPOOL_F_SC_GET)
92 rg_flags |= RING_F_SC_DEQ;
95 * Allocate the ring that will be used to store objects.
96 * Ring functions will return appropriate errors if we are
97 * running as a secondary process etc., so no checks made
98 * in this function for that condition.
100 r = rte_ring_create(rg_name, rte_align32pow2(mp->size + 1),
101 mp->socket_id, rg_flags);
111 common_ring_free(struct rte_mempool *mp)
113 rte_ring_free(mp->pool_data);
117 * The following 4 declarations of mempool ops structs address
118 * the need for the backward compatible mempool handlers for
119 * single/multi producers and single/multi consumers as dictated by the
120 * flags provided to the rte_mempool_create function
122 static const struct rte_mempool_ops ops_mp_mc = {
123 .name = "ring_mp_mc",
124 .alloc = common_ring_alloc,
125 .free = common_ring_free,
126 .enqueue = common_ring_mp_enqueue,
127 .dequeue = common_ring_mc_dequeue,
128 .get_count = common_ring_get_count,
131 static const struct rte_mempool_ops ops_sp_sc = {
132 .name = "ring_sp_sc",
133 .alloc = common_ring_alloc,
134 .free = common_ring_free,
135 .enqueue = common_ring_sp_enqueue,
136 .dequeue = common_ring_sc_dequeue,
137 .get_count = common_ring_get_count,
140 static const struct rte_mempool_ops ops_mp_sc = {
141 .name = "ring_mp_sc",
142 .alloc = common_ring_alloc,
143 .free = common_ring_free,
144 .enqueue = common_ring_mp_enqueue,
145 .dequeue = common_ring_sc_dequeue,
146 .get_count = common_ring_get_count,
149 static const struct rte_mempool_ops ops_sp_mc = {
150 .name = "ring_sp_mc",
151 .alloc = common_ring_alloc,
152 .free = common_ring_free,
153 .enqueue = common_ring_sp_enqueue,
154 .dequeue = common_ring_mc_dequeue,
155 .get_count = common_ring_get_count,
158 MEMPOOL_REGISTER_OPS(ops_mp_mc);
159 MEMPOOL_REGISTER_OPS(ops_sp_sc);
160 MEMPOOL_REGISTER_OPS(ops_mp_sc);
161 MEMPOOL_REGISTER_OPS(ops_sp_mc);