Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019 Arm Limited
3 : : */
4 : :
5 : : #include <rte_malloc.h>
6 : : #include <rte_ring.h>
7 : : #include <rte_ring_elem.h>
8 : :
9 : : /* API type to call
10 : : * rte_ring_<sp/mp or sc/mc>_enqueue_<bulk/burst>
11 : : * TEST_RING_THREAD_DEF - Uses configured SPSC/MPMC calls
12 : : * TEST_RING_THREAD_SPSC - Calls SP or SC API
13 : : * TEST_RING_THREAD_MPMC - Calls MP or MC API
14 : : */
15 : : #define TEST_RING_THREAD_DEF 1
16 : : #define TEST_RING_THREAD_SPSC 2
17 : : #define TEST_RING_THREAD_MPMC 4
18 : :
19 : : /* API type to call
20 : : * TEST_RING_ELEM_SINGLE - Calls single element APIs
21 : : * TEST_RING_ELEM_BULK - Calls bulk APIs
22 : : * TEST_RING_ELEM_BURST - Calls burst APIs
23 : : */
24 : : #define TEST_RING_ELEM_SINGLE 8
25 : : #define TEST_RING_ELEM_BULK 16
26 : : #define TEST_RING_ELEM_BURST 32
27 : :
28 : : #define TEST_RING_IGNORE_API_TYPE ~0U
29 : :
30 : : /* This function is placed here as it is required for both
31 : : * performance and functional tests.
32 : : */
33 : : static inline struct rte_ring*
34 : 320 : test_ring_create(const char *name, int esize, unsigned int count,
35 : : int socket_id, unsigned int flags)
36 : : {
37 : : /* Legacy queue APIs? */
38 [ + + ]: 320 : if (esize == -1)
39 : 64 : return rte_ring_create(name, count, socket_id, flags);
40 : : else
41 : 257 : return rte_ring_create_elem(name, esize, count,
42 : : socket_id, flags);
43 : : }
44 : :
45 : : static inline void*
46 : : test_ring_inc_ptr(void *obj, int esize, unsigned int n)
47 : : {
48 : : size_t sz;
49 : :
50 : : sz = sizeof(void *);
51 : : /* Legacy queue APIs? */
52 [ + + + + : 59258 : if (esize != -1)
+ + + + +
+ + + + +
+ + + + +
- ]
53 : : sz = esize;
54 : :
55 [ - + ]: 77375 : return (void *)((uint32_t *)obj + (n * sz / sizeof(uint32_t)));
56 : : }
57 : :
58 : : static inline void
59 : : test_ring_mem_copy(void *dst, void * const *src, int esize, unsigned int num)
60 : : {
61 : : size_t sz;
62 : :
63 : 11506 : sz = num * sizeof(void *);
64 : 11506 : if (esize != -1)
65 : 11506 : sz = esize * num;
66 : :
67 : : memcpy(dst, src, sz);
68 : 466 : }
69 : :
70 : : /* Copy to the ring memory */
71 : : static inline void
72 : 5520 : test_ring_copy_to(struct rte_ring_zc_data *zcd, void * const *src, int esize,
73 : : unsigned int num)
74 : : {
75 [ + - ]: 5520 : test_ring_mem_copy(zcd->ptr1, src, esize, zcd->n1);
76 [ + + ]: 5520 : if (zcd->n1 != num) {
77 [ - + ]: 233 : if (esize == -1)
78 : 0 : src = src + zcd->n1;
79 : : else
80 : 233 : src = (void * const *)((const uint32_t *)src +
81 : 233 : (zcd->n1 * esize / sizeof(uint32_t)));
82 [ + - ]: 233 : test_ring_mem_copy(zcd->ptr2, src,
83 : : esize, num - zcd->n1);
84 : : }
85 : 5520 : }
86 : :
87 : : /* Copy from the ring memory */
88 : : static inline void
89 : 5520 : test_ring_copy_from(struct rte_ring_zc_data *zcd, void *dst, int esize,
90 : : unsigned int num)
91 : : {
92 [ + - ]: 5520 : test_ring_mem_copy(dst, zcd->ptr1, esize, zcd->n1);
93 : :
94 [ + + ]: 5520 : if (zcd->n1 != num) {
95 : : dst = test_ring_inc_ptr(dst, esize, zcd->n1);
96 [ + - ]: 233 : test_ring_mem_copy(dst, zcd->ptr2, esize, num - zcd->n1);
97 : : }
98 : 5520 : }
99 : :
100 : : static inline unsigned int
101 : 20645 : test_ring_enqueue(struct rte_ring *r, void **obj, int esize, unsigned int n,
102 : : unsigned int api_type)
103 : : {
104 : : /* Legacy queue APIs? */
105 [ + + ]: 20645 : if (esize == -1)
106 [ + - - + : 4129 : switch (api_type) {
- - + - -
- ]
107 : 4127 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
108 [ - + - - : 8254 : return rte_ring_enqueue(r, *obj);
- ]
109 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
110 : 0 : return rte_ring_sp_enqueue(r, *obj);
111 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
112 : 0 : return rte_ring_mp_enqueue(r, *obj);
113 : : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
114 : 1 : return rte_ring_enqueue_bulk(r, obj, n, NULL);
115 : : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
116 : 0 : return rte_ring_sp_enqueue_bulk(r, obj, n, NULL);
117 : : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
118 : 0 : return rte_ring_mp_enqueue_bulk(r, obj, n, NULL);
119 : : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
120 : 1 : return rte_ring_enqueue_burst(r, obj, n, NULL);
121 : : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
122 : 0 : return rte_ring_sp_enqueue_burst(r, obj, n, NULL);
123 : : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
124 : 0 : return rte_ring_mp_enqueue_burst(r, obj, n, NULL);
125 : : default:
126 : : printf("Invalid API type\n");
127 : 0 : return 0;
128 : : }
129 : : else
130 [ + - - + : 16516 : switch (api_type) {
- - + - -
- ]
131 : 16508 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
132 [ - + - - : 33016 : return rte_ring_enqueue_elem(r, obj, esize);
- ]
133 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
134 : 0 : return rte_ring_sp_enqueue_elem(r, obj, esize);
135 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
136 : 0 : return rte_ring_mp_enqueue_elem(r, obj, esize);
137 : 4 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
138 [ - + - - : 4 : return rte_ring_enqueue_bulk_elem(r, obj, esize, n,
- ]
139 : : NULL);
140 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
141 : 0 : return rte_ring_sp_enqueue_bulk_elem(r, obj, esize, n,
142 : : NULL);
143 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
144 : 0 : return rte_ring_mp_enqueue_bulk_elem(r, obj, esize, n,
145 : : NULL);
146 : 4 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
147 [ - + - - : 4 : return rte_ring_enqueue_burst_elem(r, obj, esize, n,
- ]
148 : : NULL);
149 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
150 : 0 : return rte_ring_sp_enqueue_burst_elem(r, obj, esize, n,
151 : : NULL);
152 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
153 : 0 : return rte_ring_mp_enqueue_burst_elem(r, obj, esize, n,
154 : : NULL);
155 : : default:
156 : : printf("Invalid API type\n");
157 : 0 : return 0;
158 : : }
159 : : }
160 : :
161 : : static inline unsigned int
162 : 20490 : test_ring_dequeue(struct rte_ring *r, void **obj, int esize, unsigned int n,
163 : : unsigned int api_type)
164 : : {
165 : : /* Legacy queue APIs? */
166 [ + + ]: 20490 : if (esize == -1)
167 [ + - - + : 4098 : switch (api_type) {
- - + - -
- ]
168 : : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
169 : 4095 : return rte_ring_dequeue(r, obj);
170 : : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
171 : 0 : return rte_ring_sc_dequeue(r, obj);
172 : : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
173 : 0 : return rte_ring_mc_dequeue(r, obj);
174 : : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
175 : 1 : return rte_ring_dequeue_bulk(r, obj, n, NULL);
176 : : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
177 : 0 : return rte_ring_sc_dequeue_bulk(r, obj, n, NULL);
178 : : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
179 : 0 : return rte_ring_mc_dequeue_bulk(r, obj, n, NULL);
180 : : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
181 : 2 : return rte_ring_dequeue_burst(r, obj, n, NULL);
182 : : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
183 : 0 : return rte_ring_sc_dequeue_burst(r, obj, n, NULL);
184 : : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
185 : 0 : return rte_ring_mc_dequeue_burst(r, obj, n, NULL);
186 : : default:
187 : : printf("Invalid API type\n");
188 : 0 : return 0;
189 : : }
190 : : else
191 [ + - - + : 16392 : switch (api_type) {
- - + - -
- ]
192 : 16380 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
193 [ - + - - : 32760 : return rte_ring_dequeue_elem(r, obj, esize);
- ]
194 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
195 : 0 : return rte_ring_sc_dequeue_elem(r, obj, esize);
196 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
197 : 0 : return rte_ring_mc_dequeue_elem(r, obj, esize);
198 : 4 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
199 [ - + - - : 4 : return rte_ring_dequeue_bulk_elem(r, obj, esize,
- ]
200 : : n, NULL);
201 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
202 : 0 : return rte_ring_sc_dequeue_bulk_elem(r, obj, esize,
203 : : n, NULL);
204 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
205 : 0 : return rte_ring_mc_dequeue_bulk_elem(r, obj, esize,
206 : : n, NULL);
207 : 8 : case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
208 [ - + - - : 8 : return rte_ring_dequeue_burst_elem(r, obj, esize,
- ]
209 : : n, NULL);
210 : 0 : case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
211 : 0 : return rte_ring_sc_dequeue_burst_elem(r, obj, esize,
212 : : n, NULL);
213 : 0 : case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
214 : 0 : return rte_ring_mc_dequeue_burst_elem(r, obj, esize,
215 : : n, NULL);
216 : : default:
217 : : printf("Invalid API type\n");
218 : 0 : return 0;
219 : : }
220 : : }
221 : :
222 : : /* This function is placed here as it is required for both
223 : : * performance and functional tests.
224 : : */
225 : : static inline void *
226 : 580 : test_ring_calloc(unsigned int rsize, int esize)
227 : : {
228 : : unsigned int sz;
229 : : void *p;
230 : :
231 : : /* Legacy queue APIs? */
232 [ + + ]: 580 : if (esize == -1)
233 : : sz = sizeof(void *);
234 : : else
235 : : sz = esize;
236 : :
237 : 580 : p = rte_zmalloc(NULL, rsize * sz, RTE_CACHE_LINE_SIZE);
238 [ - + ]: 580 : if (p == NULL)
239 : : printf("Failed to allocate memory\n");
240 : :
241 : 580 : return p;
242 : : }
|