1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
8 #include "rte_rawdev.h"
9 #include "rte_ioat_rawdev.h"
10 #include "ioat_private.h"
12 #define MAX_SUPPORTED_RAWDEVS 64
13 #define TEST_SKIPPED 77
16 int ioat_rawdev_test(uint16_t dev_id); /* pre-define to keep compiler happy */
18 static struct rte_mempool *pool;
19 static unsigned short expected_ring_size[MAX_SUPPORTED_RAWDEVS];
21 #define PRINT_ERR(...) print_err(__func__, __LINE__, __VA_ARGS__)
24 __rte_format_printf(3, 4)
25 print_err(const char *func, int lineno, const char *format, ...)
30 ret = fprintf(stderr, "In %s:%d - ", func, lineno);
32 ret += vfprintf(stderr, format, ap);
39 do_multi_copies(int dev_id, int split_batches, int split_completions)
41 struct rte_mbuf *srcs[32], *dsts[32];
42 struct rte_mbuf *completed_src[64];
43 struct rte_mbuf *completed_dst[64];
46 for (i = 0; i < RTE_DIM(srcs); i++) {
49 if (split_batches && i == RTE_DIM(srcs) / 2)
50 rte_ioat_perform_ops(dev_id);
52 srcs[i] = rte_pktmbuf_alloc(pool);
53 dsts[i] = rte_pktmbuf_alloc(pool);
54 src_data = rte_pktmbuf_mtod(srcs[i], char *);
56 for (j = 0; j < COPY_LEN; j++)
57 src_data[j] = rand() & 0xFF;
59 if (rte_ioat_enqueue_copy(dev_id,
60 srcs[i]->buf_iova + srcs[i]->data_off,
61 dsts[i]->buf_iova + dsts[i]->data_off,
64 (uintptr_t)dsts[i]) != 1) {
65 PRINT_ERR("Error with rte_ioat_enqueue_copy for buffer %u\n",
70 rte_ioat_perform_ops(dev_id);
73 if (split_completions) {
74 /* gather completions in two halves */
75 uint16_t half_len = RTE_DIM(srcs) / 2;
76 if (rte_ioat_completed_ops(dev_id, half_len, (void *)completed_src,
77 (void *)completed_dst) != half_len) {
78 PRINT_ERR("Error with rte_ioat_completed_ops - first half request\n");
79 rte_rawdev_dump(dev_id, stdout);
82 if (rte_ioat_completed_ops(dev_id, half_len, (void *)&completed_src[half_len],
83 (void *)&completed_dst[half_len]) != half_len) {
84 PRINT_ERR("Error with rte_ioat_completed_ops - second half request\n");
85 rte_rawdev_dump(dev_id, stdout);
89 /* gather all completions in one go */
90 if (rte_ioat_completed_ops(dev_id, 64, (void *)completed_src,
91 (void *)completed_dst) != RTE_DIM(srcs)) {
92 PRINT_ERR("Error with rte_ioat_completed_ops\n");
93 rte_rawdev_dump(dev_id, stdout);
97 for (i = 0; i < RTE_DIM(srcs); i++) {
98 char *src_data, *dst_data;
100 if (completed_src[i] != srcs[i]) {
101 PRINT_ERR("Error with source pointer %u\n", i);
104 if (completed_dst[i] != dsts[i]) {
105 PRINT_ERR("Error with dest pointer %u\n", i);
109 src_data = rte_pktmbuf_mtod(srcs[i], char *);
110 dst_data = rte_pktmbuf_mtod(dsts[i], char *);
111 for (j = 0; j < COPY_LEN; j++)
112 if (src_data[j] != dst_data[j]) {
113 PRINT_ERR("Error with copy of packet %u, byte %u\n",
117 rte_pktmbuf_free(srcs[i]);
118 rte_pktmbuf_free(dsts[i]);
124 test_enqueue_copies(int dev_id)
128 /* test doing a single copy */
130 struct rte_mbuf *src, *dst;
131 char *src_data, *dst_data;
132 struct rte_mbuf *completed[2] = {0};
134 src = rte_pktmbuf_alloc(pool);
135 dst = rte_pktmbuf_alloc(pool);
136 src_data = rte_pktmbuf_mtod(src, char *);
137 dst_data = rte_pktmbuf_mtod(dst, char *);
139 for (i = 0; i < COPY_LEN; i++)
140 src_data[i] = rand() & 0xFF;
142 if (rte_ioat_enqueue_copy(dev_id,
143 src->buf_iova + src->data_off,
144 dst->buf_iova + dst->data_off,
147 (uintptr_t)dst) != 1) {
148 PRINT_ERR("Error with rte_ioat_enqueue_copy\n");
151 rte_ioat_perform_ops(dev_id);
154 if (rte_ioat_completed_ops(dev_id, 1, (void *)&completed[0],
155 (void *)&completed[1]) != 1) {
156 PRINT_ERR("Error with rte_ioat_completed_ops\n");
159 if (completed[0] != src || completed[1] != dst) {
160 PRINT_ERR("Error with completions: got (%p, %p), not (%p,%p)\n",
161 completed[0], completed[1], src, dst);
165 for (i = 0; i < COPY_LEN; i++)
166 if (dst_data[i] != src_data[i]) {
167 PRINT_ERR("Data mismatch at char %u [Got %02x not %02x]\n",
168 i, dst_data[i], src_data[i]);
171 rte_pktmbuf_free(src);
172 rte_pktmbuf_free(dst);
175 /* test doing a multiple single copies */
177 const uint16_t max_ops = 4;
178 struct rte_mbuf *src, *dst;
179 char *src_data, *dst_data;
180 struct rte_mbuf *completed[32] = {0};
181 const uint16_t max_completions = RTE_DIM(completed) / 2;
183 src = rte_pktmbuf_alloc(pool);
184 dst = rte_pktmbuf_alloc(pool);
185 src_data = rte_pktmbuf_mtod(src, char *);
186 dst_data = rte_pktmbuf_mtod(dst, char *);
188 for (i = 0; i < COPY_LEN; i++)
189 src_data[i] = rand() & 0xFF;
191 /* perform the same copy <max_ops> times */
192 for (i = 0; i < max_ops; i++) {
193 if (rte_ioat_enqueue_copy(dev_id,
194 src->buf_iova + src->data_off,
195 dst->buf_iova + dst->data_off,
198 (uintptr_t)dst) != 1) {
199 PRINT_ERR("Error with rte_ioat_enqueue_copy\n");
202 rte_ioat_perform_ops(dev_id);
206 if (rte_ioat_completed_ops(dev_id, max_completions, (void *)&completed[0],
207 (void *)&completed[max_completions]) != max_ops) {
208 PRINT_ERR("Error with rte_ioat_completed_ops\n");
209 rte_rawdev_dump(dev_id, stdout);
212 if (completed[0] != src || completed[max_completions] != dst) {
213 PRINT_ERR("Error with completions: got (%p, %p), not (%p,%p)\n",
214 completed[0], completed[max_completions], src, dst);
218 for (i = 0; i < COPY_LEN; i++)
219 if (dst_data[i] != src_data[i]) {
220 PRINT_ERR("Data mismatch at char %u\n", i);
223 rte_pktmbuf_free(src);
224 rte_pktmbuf_free(dst);
227 /* test doing multiple copies */
228 do_multi_copies(dev_id, 0, 0); /* enqueue and complete one batch at a time */
229 do_multi_copies(dev_id, 1, 0); /* enqueue 2 batches and then complete both */
230 do_multi_copies(dev_id, 0, 1); /* enqueue 1 batch, then complete in two halves */
235 test_enqueue_fill(int dev_id)
237 const unsigned int lengths[] = {8, 64, 1024, 50, 100, 89};
238 struct rte_mbuf *dst = rte_pktmbuf_alloc(pool);
239 char *dst_data = rte_pktmbuf_mtod(dst, char *);
240 struct rte_mbuf *completed[2] = {0};
241 uint64_t pattern = 0xfedcba9876543210;
244 for (i = 0; i < RTE_DIM(lengths); i++) {
246 memset(dst_data, 0, lengths[i]);
248 /* perform the fill operation */
249 if (rte_ioat_enqueue_fill(dev_id, pattern,
250 dst->buf_iova + dst->data_off, lengths[i],
251 (uintptr_t)dst) != 1) {
252 PRINT_ERR("Error with rte_ioat_enqueue_fill\n");
256 rte_ioat_perform_ops(dev_id);
259 if (rte_ioat_completed_ops(dev_id, 1, (void *)&completed[0],
260 (void *)&completed[1]) != 1) {
261 PRINT_ERR("Error with completed ops\n");
264 /* check the result */
265 for (j = 0; j < lengths[i]; j++) {
266 char pat_byte = ((char *)&pattern)[j % 8];
267 if (dst_data[j] != pat_byte) {
268 PRINT_ERR("Error with fill operation (lengths = %u): got (%x), not (%x)\n",
269 lengths[i], dst_data[j],
276 rte_pktmbuf_free(dst);
281 ioat_rawdev_test(uint16_t dev_id)
283 #define IOAT_TEST_RINGSIZE 512
284 struct rte_ioat_rawdev_config p = { .ring_size = -1 };
285 struct rte_rawdev_info info = { .dev_private = &p };
286 struct rte_rawdev_xstats_name *snames = NULL;
287 uint64_t *stats = NULL;
288 unsigned int *ids = NULL;
289 unsigned int nb_xstats;
292 if (dev_id >= MAX_SUPPORTED_RAWDEVS) {
293 printf("Skipping test. Cannot test rawdevs with id's greater than %d\n",
294 MAX_SUPPORTED_RAWDEVS);
298 rte_rawdev_info_get(dev_id, &info, sizeof(p));
299 if (p.ring_size != expected_ring_size[dev_id]) {
300 PRINT_ERR("Error, initial ring size is not as expected (Actual: %d, Expected: %d)\n",
301 (int)p.ring_size, expected_ring_size[dev_id]);
305 p.ring_size = IOAT_TEST_RINGSIZE;
306 if (rte_rawdev_configure(dev_id, &info, sizeof(p)) != 0) {
307 PRINT_ERR("Error with rte_rawdev_configure()\n");
310 rte_rawdev_info_get(dev_id, &info, sizeof(p));
311 if (p.ring_size != IOAT_TEST_RINGSIZE) {
312 PRINT_ERR("Error, ring size is not %d (%d)\n",
313 IOAT_TEST_RINGSIZE, (int)p.ring_size);
316 expected_ring_size[dev_id] = p.ring_size;
318 if (rte_rawdev_start(dev_id) != 0) {
319 PRINT_ERR("Error with rte_rawdev_start()\n");
323 pool = rte_pktmbuf_pool_create("TEST_IOAT_POOL",
324 256, /* n == num elements */
327 2048, /* data room size */
330 PRINT_ERR("Error with mempool creation\n");
334 /* allocate memory for xstats names and values */
335 nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
337 snames = malloc(sizeof(*snames) * nb_xstats);
338 if (snames == NULL) {
339 PRINT_ERR("Error allocating xstat names memory\n");
342 rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
344 ids = malloc(sizeof(*ids) * nb_xstats);
346 PRINT_ERR("Error allocating xstat ids memory\n");
349 for (i = 0; i < nb_xstats; i++)
352 stats = malloc(sizeof(*stats) * nb_xstats);
354 PRINT_ERR("Error allocating xstat memory\n");
358 /* run the test cases */
359 printf("Running Copy Tests\n");
360 for (i = 0; i < 100; i++) {
363 if (test_enqueue_copies(dev_id) != 0)
366 rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
367 for (j = 0; j < nb_xstats; j++)
368 printf("%s: %"PRIu64" ", snames[j].name, stats[j]);
373 /* test enqueue fill operation */
374 printf("Running Fill Tests\n");
375 for (i = 0; i < 100; i++) {
378 if (test_enqueue_fill(dev_id) != 0)
381 rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
382 for (j = 0; j < nb_xstats; j++)
383 printf("%s: %"PRIu64" ", snames[j].name, stats[j]);
388 rte_rawdev_stop(dev_id);
389 if (rte_rawdev_xstats_reset(dev_id, NULL, 0) != 0) {
390 PRINT_ERR("Error resetting xstat values\n");
394 rte_mempool_free(pool);
401 rte_rawdev_stop(dev_id);
402 rte_rawdev_xstats_reset(dev_id, NULL, 0);
403 rte_mempool_free(pool);