Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2016-2019 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <rte_mempool.h>
7 : : #include <rte_stack.h>
8 : :
9 : : static int
10 : 1 : __stack_alloc(struct rte_mempool *mp, uint32_t flags)
11 : : {
12 : : char name[RTE_STACK_NAMESIZE];
13 : : struct rte_stack *s;
14 : : int ret;
15 : :
16 : : ret = snprintf(name, sizeof(name),
17 [ - + ]: 1 : RTE_MEMPOOL_MZ_FORMAT, mp->name);
18 [ - + ]: 1 : if (ret < 0 || ret >= (int)sizeof(name)) {
19 : 0 : rte_errno = ENAMETOOLONG;
20 : 0 : return -rte_errno;
21 : : }
22 : :
23 : 1 : s = rte_stack_create(name, mp->size, mp->socket_id, flags);
24 [ - + ]: 1 : if (s == NULL)
25 : 0 : return -rte_errno;
26 : :
27 : 1 : mp->pool_data = s;
28 : :
29 : 1 : return 0;
30 : : }
31 : :
32 : : static int
33 : 1 : std_stack_alloc(struct rte_mempool *mp)
34 : : {
35 : 1 : return __stack_alloc(mp, 0);
36 : : }
37 : :
38 : : static int
39 : 0 : lf_stack_alloc(struct rte_mempool *mp)
40 : : {
41 : 0 : return __stack_alloc(mp, RTE_STACK_F_LF);
42 : : }
43 : :
44 : : static int
45 : 0 : pile_alloc(struct rte_mempool *mp)
46 : : {
47 : 0 : return __stack_alloc(mp, RTE_STACK_F_PILE);
48 : : }
49 : :
50 : : static int
51 : 1059 : std_stack_enqueue(struct rte_mempool *mp, void * const *obj_table,
52 : : unsigned int n)
53 : : {
54 : 1059 : struct rte_stack *s = mp->pool_data;
55 : :
56 : : RTE_ASSERT(s != NULL);
57 : : RTE_ASSERT(obj_table != NULL);
58 : :
59 [ + - ]: 1059 : return __rte_stack_std_push(s, obj_table, n) == 0 ? -ENOBUFS : 0;
60 : : }
61 : :
62 : : static int
63 : 1121 : std_stack_dequeue(struct rte_mempool *mp, void **obj_table,
64 : : unsigned int n)
65 : : {
66 : 1121 : struct rte_stack *s = mp->pool_data;
67 : :
68 : : RTE_ASSERT(s != NULL);
69 : : RTE_ASSERT(obj_table != NULL);
70 : :
71 [ + - ]: 1090 : return __rte_stack_std_pop(s, obj_table, n) == 0 ? -ENOBUFS : 0;
72 : : }
73 : :
74 : : static int
75 : 0 : lf_stack_enqueue(struct rte_mempool *mp, void * const *obj_table,
76 : : unsigned int n)
77 : : {
78 [ # # ]: 0 : struct rte_stack *s = mp->pool_data;
79 : :
80 : : RTE_ASSERT(s != NULL);
81 : : RTE_ASSERT(obj_table != NULL);
82 : :
83 [ # # ]: 0 : return __rte_stack_lf_push(s, obj_table, n) == 0 ? -ENOBUFS : 0;
84 : : }
85 : :
86 : : static int
87 : 0 : lf_stack_dequeue(struct rte_mempool *mp, void **obj_table,
88 : : unsigned int n)
89 : : {
90 [ # # ]: 0 : struct rte_stack *s = mp->pool_data;
91 : :
92 : : RTE_ASSERT(s != NULL);
93 : : RTE_ASSERT(obj_table != NULL);
94 : :
95 [ # # ]: 0 : return __rte_stack_lf_pop(s, obj_table, n) == 0 ? -ENOBUFS : 0;
96 : : }
97 : :
98 : : static int
99 : 0 : pile_enqueue(struct rte_mempool *mp, void * const *obj_table,
100 : : unsigned int n)
101 : : {
102 [ # # ]: 0 : struct rte_stack *s = mp->pool_data;
103 : :
104 : : RTE_ASSERT(s != NULL);
105 : : RTE_ASSERT(obj_table != NULL);
106 : :
107 [ # # ]: 0 : return __rte_stack_pile_push(s, obj_table, n) == 0 ? -ENOBUFS : 0;
108 : : }
109 : :
110 : : static int
111 : 0 : pile_dequeue(struct rte_mempool *mp, void **obj_table,
112 : : unsigned int n)
113 : : {
114 [ # # ]: 0 : struct rte_stack *s = mp->pool_data;
115 : :
116 : : RTE_ASSERT(s != NULL);
117 : : RTE_ASSERT(obj_table != NULL);
118 : :
119 [ # # ]: 0 : return __rte_stack_pile_pop(s, obj_table, n) == 0 ? -ENOBUFS : 0;
120 : : }
121 : :
122 : : static unsigned
123 : 8 : stack_get_count(const struct rte_mempool *mp)
124 : : {
125 [ - + ]: 8 : struct rte_stack *s = mp->pool_data;
126 : :
127 : 8 : return rte_stack_count(s);
128 : : }
129 : :
130 : : static void
131 : 1 : stack_free(struct rte_mempool *mp)
132 : : {
133 : 1 : struct rte_stack *s = mp->pool_data;
134 : :
135 : 1 : rte_stack_free(s);
136 : 1 : }
137 : :
138 : : static struct rte_mempool_ops ops_stack = {
139 : : .name = "stack",
140 : : .alloc = std_stack_alloc,
141 : : .free = stack_free,
142 : : .enqueue = std_stack_enqueue,
143 : : .dequeue = std_stack_dequeue,
144 : : .get_count = stack_get_count
145 : : };
146 : :
147 : : static struct rte_mempool_ops ops_lf_stack = {
148 : : .name = "lf_stack",
149 : : .alloc = lf_stack_alloc,
150 : : .free = stack_free,
151 : : .enqueue = lf_stack_enqueue,
152 : : .dequeue = lf_stack_dequeue,
153 : : .get_count = stack_get_count
154 : : };
155 : :
156 : : static struct rte_mempool_ops ops_pile = {
157 : : .name = "pile",
158 : : .alloc = pile_alloc,
159 : : .free = stack_free,
160 : : .enqueue = pile_enqueue,
161 : : .dequeue = pile_dequeue,
162 : : .get_count = stack_get_count
163 : : };
164 : :
165 : 305 : RTE_MEMPOOL_REGISTER_OPS(ops_stack);
166 : 305 : RTE_MEMPOOL_REGISTER_OPS(ops_lf_stack);
167 : 305 : RTE_MEMPOOL_REGISTER_OPS(ops_pile);
|