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),
42 (socket_id), (flags));
45 static __rte_always_inline unsigned int
46 test_ring_enqueue(struct rte_ring *r, void **obj, int esize, unsigned int n,
47 unsigned int api_type)
49 /* Legacy queue APIs? */
52 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
53 return rte_ring_enqueue(r, obj);
54 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
55 return rte_ring_sp_enqueue(r, obj);
56 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
57 return rte_ring_mp_enqueue(r, obj);
58 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
59 return rte_ring_enqueue_bulk(r, obj, n, NULL);
60 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
61 return rte_ring_sp_enqueue_bulk(r, obj, n, NULL);
62 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
63 return rte_ring_mp_enqueue_bulk(r, obj, n, NULL);
64 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
65 return rte_ring_enqueue_burst(r, obj, n, NULL);
66 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
67 return rte_ring_sp_enqueue_burst(r, obj, n, NULL);
68 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
69 return rte_ring_mp_enqueue_burst(r, obj, n, NULL);
71 printf("Invalid API type\n");
76 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
77 return rte_ring_enqueue_elem(r, obj, esize);
78 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
79 return rte_ring_sp_enqueue_elem(r, obj, esize);
80 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
81 return rte_ring_mp_enqueue_elem(r, obj, esize);
82 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
83 return rte_ring_enqueue_bulk_elem(r, obj, esize, n,
85 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
86 return rte_ring_sp_enqueue_bulk_elem(r, obj, esize, n,
88 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
89 return rte_ring_mp_enqueue_bulk_elem(r, obj, esize, n,
91 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
92 return rte_ring_enqueue_burst_elem(r, obj, esize, n,
94 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
95 return rte_ring_sp_enqueue_burst_elem(r, obj, esize, n,
97 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
98 return rte_ring_mp_enqueue_burst_elem(r, obj, esize, n,
101 printf("Invalid API type\n");
106 static __rte_always_inline unsigned int
107 test_ring_dequeue(struct rte_ring *r, void **obj, int esize, unsigned int n,
108 unsigned int api_type)
110 /* Legacy queue APIs? */
113 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
114 return rte_ring_dequeue(r, obj);
115 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
116 return rte_ring_sc_dequeue(r, obj);
117 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
118 return rte_ring_mc_dequeue(r, obj);
119 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
120 return rte_ring_dequeue_bulk(r, obj, n, NULL);
121 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
122 return rte_ring_sc_dequeue_bulk(r, obj, n, NULL);
123 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
124 return rte_ring_mc_dequeue_bulk(r, obj, n, NULL);
125 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
126 return rte_ring_dequeue_burst(r, obj, n, NULL);
127 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
128 return rte_ring_sc_dequeue_burst(r, obj, n, NULL);
129 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
130 return rte_ring_mc_dequeue_burst(r, obj, n, NULL);
132 printf("Invalid API type\n");
137 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE):
138 return rte_ring_dequeue_elem(r, obj, esize);
139 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_SINGLE):
140 return rte_ring_sc_dequeue_elem(r, obj, esize);
141 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_SINGLE):
142 return rte_ring_mc_dequeue_elem(r, obj, esize);
143 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BULK):
144 return rte_ring_dequeue_bulk_elem(r, obj, esize,
146 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BULK):
147 return rte_ring_sc_dequeue_bulk_elem(r, obj, esize,
149 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BULK):
150 return rte_ring_mc_dequeue_bulk_elem(r, obj, esize,
152 case (TEST_RING_THREAD_DEF | TEST_RING_ELEM_BURST):
153 return rte_ring_dequeue_burst_elem(r, obj, esize,
155 case (TEST_RING_THREAD_SPSC | TEST_RING_ELEM_BURST):
156 return rte_ring_sc_dequeue_burst_elem(r, obj, esize,
158 case (TEST_RING_THREAD_MPMC | TEST_RING_ELEM_BURST):
159 return rte_ring_mc_dequeue_burst_elem(r, obj, esize,
162 printf("Invalid API type\n");
167 /* This function is placed here as it is required for both
168 * performance and functional tests.
170 static __rte_always_inline void *
171 test_ring_calloc(unsigned int rsize, int esize)
176 /* Legacy queue APIs? */
182 p = rte_zmalloc(NULL, rsize * sz, RTE_CACHE_LINE_SIZE);
184 printf("Failed to allocate memory\n");