1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
10 #include <rte_mempool.h>
13 common_ring_mp_enqueue(struct rte_mempool
*mp
, void * const *obj_table
,
16 return rte_ring_mp_enqueue_bulk(mp
->pool_data
,
17 obj_table
, n
, NULL
) == 0 ? -ENOBUFS
: 0;
21 common_ring_sp_enqueue(struct rte_mempool
*mp
, void * const *obj_table
,
24 return rte_ring_sp_enqueue_bulk(mp
->pool_data
,
25 obj_table
, n
, NULL
) == 0 ? -ENOBUFS
: 0;
29 common_ring_mc_dequeue(struct rte_mempool
*mp
, void **obj_table
, unsigned n
)
31 return rte_ring_mc_dequeue_bulk(mp
->pool_data
,
32 obj_table
, n
, NULL
) == 0 ? -ENOBUFS
: 0;
36 common_ring_sc_dequeue(struct rte_mempool
*mp
, void **obj_table
, unsigned n
)
38 return rte_ring_sc_dequeue_bulk(mp
->pool_data
,
39 obj_table
, n
, NULL
) == 0 ? -ENOBUFS
: 0;
43 common_ring_get_count(const struct rte_mempool
*mp
)
45 return rte_ring_count(mp
->pool_data
);
50 common_ring_alloc(struct rte_mempool
*mp
)
52 int rg_flags
= 0, ret
;
53 char rg_name
[RTE_RING_NAMESIZE
];
56 ret
= snprintf(rg_name
, sizeof(rg_name
),
57 RTE_MEMPOOL_MZ_FORMAT
, mp
->name
);
58 if (ret
< 0 || ret
>= (int)sizeof(rg_name
)) {
59 rte_errno
= ENAMETOOLONG
;
64 if (mp
->flags
& MEMPOOL_F_SP_PUT
)
65 rg_flags
|= RING_F_SP_ENQ
;
66 if (mp
->flags
& MEMPOOL_F_SC_GET
)
67 rg_flags
|= RING_F_SC_DEQ
;
70 * Allocate the ring that will be used to store objects.
71 * Ring functions will return appropriate errors if we are
72 * running as a secondary process etc., so no checks made
73 * in this function for that condition.
75 r
= rte_ring_create(rg_name
, rte_align32pow2(mp
->size
+ 1),
76 mp
->socket_id
, rg_flags
);
86 common_ring_free(struct rte_mempool
*mp
)
88 rte_ring_free(mp
->pool_data
);
92 * The following 4 declarations of mempool ops structs address
93 * the need for the backward compatible mempool handlers for
94 * single/multi producers and single/multi consumers as dictated by the
95 * flags provided to the rte_mempool_create function
97 static const struct rte_mempool_ops ops_mp_mc
= {
99 .alloc
= common_ring_alloc
,
100 .free
= common_ring_free
,
101 .enqueue
= common_ring_mp_enqueue
,
102 .dequeue
= common_ring_mc_dequeue
,
103 .get_count
= common_ring_get_count
,
106 static const struct rte_mempool_ops ops_sp_sc
= {
107 .name
= "ring_sp_sc",
108 .alloc
= common_ring_alloc
,
109 .free
= common_ring_free
,
110 .enqueue
= common_ring_sp_enqueue
,
111 .dequeue
= common_ring_sc_dequeue
,
112 .get_count
= common_ring_get_count
,
115 static const struct rte_mempool_ops ops_mp_sc
= {
116 .name
= "ring_mp_sc",
117 .alloc
= common_ring_alloc
,
118 .free
= common_ring_free
,
119 .enqueue
= common_ring_mp_enqueue
,
120 .dequeue
= common_ring_sc_dequeue
,
121 .get_count
= common_ring_get_count
,
124 static const struct rte_mempool_ops ops_sp_mc
= {
125 .name
= "ring_sp_mc",
126 .alloc
= common_ring_alloc
,
127 .free
= common_ring_free
,
128 .enqueue
= common_ring_sp_enqueue
,
129 .dequeue
= common_ring_mc_dequeue
,
130 .get_count
= common_ring_get_count
,
133 MEMPOOL_REGISTER_OPS(ops_mp_mc
);
134 MEMPOOL_REGISTER_OPS(ops_sp_sc
);
135 MEMPOOL_REGISTER_OPS(ops_mp_sc
);
136 MEMPOOL_REGISTER_OPS(ops_sp_mc
);