1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Arm Limited
5 #include <rte_malloc.h>
7 #include <rte_ring_elem.h>
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
15 #define TEST_RING_THREAD_DEF 1
16 #define TEST_RING_THREAD_SPSC 2
17 #define TEST_RING_THREAD_MPMC 4
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
24 #define TEST_RING_ELEM_SINGLE 8
25 #define TEST_RING_ELEM_BULK 16
26 #define TEST_RING_ELEM_BURST 32
28 #define TEST_RING_IGNORE_API_TYPE ~0U
30 /* This function is placed here as it is required for both
31 * performance and functional tests.
33 static inline struct rte_ring*
34 test_ring_create(const char *name, int esize, unsigned int count,
35 int socket_id, unsigned int flags)
37 /* Legacy queue APIs? */
39 return rte_ring_create(name, count, socket_id, flags);
41 return rte_ring_create_elem(name, esize, count,
46 test_ring_inc_ptr(void *obj, int esize, unsigned int n)
51 /* Legacy queue APIs? */
55 return (void *)((uint32_t *)obj + (n * sz / sizeof(uint32_t)));
59 test_ring_mem_copy(void *dst, void * const *src, int esize, unsigned int num)
63 sz = num * sizeof(void *);
70 /* Copy to the ring memory */
72 test_ring_copy_to(struct rte_ring_zc_data *zcd, void * const *src, int esize,
75 test_ring_mem_copy(zcd->ptr1, src, esize, zcd->n1);
80 src = (void * const *)((const uint32_t *)src +
81 (zcd->n1 * esize / sizeof(uint32_t)));
82 test_ring_mem_copy(zcd->ptr2, src,
83 esize, num - zcd->n1);
87 /* Copy from the ring memory */
89 test_ring_copy_from(struct rte_ring_zc_data *zcd, void *dst, int esize,
92 test_ring_mem_copy(dst, zcd->ptr1, esize, zcd->n1);
95 dst = test_ring_inc_ptr(dst, esize, zcd->n1);
96 test_ring_mem_copy(dst, zcd->ptr2, esize, num - zcd->n1);
100 static __rte_always_inline unsigned int
101 test_ring_enqueue(struct rte_ring *r, void **obj, int esize, unsigned int n,
102 unsigned int api_type)
104 /* Legacy queue APIs? */
107 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
108 return rte_ring_enqueue(r, *obj);
109 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
110 return rte_ring_sp_enqueue(r, *obj);
111 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
112 return rte_ring_mp_enqueue(r, *obj);
113 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
114 return rte_ring_enqueue_bulk(r, obj, n, NULL);
115 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
116 return rte_ring_sp_enqueue_bulk(r, obj, n, NULL);
117 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
118 return rte_ring_mp_enqueue_bulk(r, obj, n, NULL);
119 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
120 return rte_ring_enqueue_burst(r, obj, n, NULL);
121 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
122 return rte_ring_sp_enqueue_burst(r, obj, n, NULL);
123 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
124 return rte_ring_mp_enqueue_burst(r, obj, n, NULL);
126 printf("Invalid API type\n");
131 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
132 return rte_ring_enqueue_elem(r, obj, esize);
133 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
134 return rte_ring_sp_enqueue_elem(r, obj, esize);
135 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
136 return rte_ring_mp_enqueue_elem(r, obj, esize);
137 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
138 return rte_ring_enqueue_bulk_elem(r, obj, esize, n,
140 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
141 return rte_ring_sp_enqueue_bulk_elem(r, obj, esize, n,
143 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
144 return rte_ring_mp_enqueue_bulk_elem(r, obj, esize, n,
146 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
147 return rte_ring_enqueue_burst_elem(r, obj, esize, n,
149 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
150 return rte_ring_sp_enqueue_burst_elem(r, obj, esize, n,
152 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
153 return rte_ring_mp_enqueue_burst_elem(r, obj, esize, n,
156 printf("Invalid API type\n");
161 static __rte_always_inline unsigned int
162 test_ring_dequeue(struct rte_ring *r, void **obj, int esize, unsigned int n,
163 unsigned int api_type)
165 /* Legacy queue APIs? */
168 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
169 return rte_ring_dequeue(r, obj);
170 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
171 return rte_ring_sc_dequeue(r, obj);
172 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
173 return rte_ring_mc_dequeue(r, obj);
174 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
175 return rte_ring_dequeue_bulk(r, obj, n, NULL);
176 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
177 return rte_ring_sc_dequeue_bulk(r, obj, n, NULL);
178 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
179 return rte_ring_mc_dequeue_bulk(r, obj, n, NULL);
180 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
181 return rte_ring_dequeue_burst(r, obj, n, NULL);
182 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
183 return rte_ring_sc_dequeue_burst(r, obj, n, NULL);
184 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
185 return rte_ring_mc_dequeue_burst(r, obj, n, NULL);
187 printf("Invalid API type\n");
192 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
193 return rte_ring_dequeue_elem(r, obj, esize);
194 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
195 return rte_ring_sc_dequeue_elem(r, obj, esize);
196 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
197 return rte_ring_mc_dequeue_elem(r, obj, esize);
198 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
199 return rte_ring_dequeue_bulk_elem(r, obj, esize,
201 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
202 return rte_ring_sc_dequeue_bulk_elem(r, obj, esize,
204 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
205 return rte_ring_mc_dequeue_bulk_elem(r, obj, esize,
207 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
208 return rte_ring_dequeue_burst_elem(r, obj, esize,
210 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
211 return rte_ring_sc_dequeue_burst_elem(r, obj, esize,
213 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
214 return rte_ring_mc_dequeue_burst_elem(r, obj, esize,
217 printf("Invalid API type\n");
222 /* This function is placed here as it is required for both
223 * performance and functional tests.
225 static __rte_always_inline void *
226 test_ring_calloc(unsigned int rsize, int esize)
231 /* Legacy queue APIs? */
237 p = rte_zmalloc(NULL, rsize * sz, RTE_CACHE_LINE_SIZE);
239 printf("Failed to allocate memory\n");