2 * Copyright (C) 2012 Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 #include <sys/ioctl.h>
29 #include <sys/queue.h>
42 #include "ioat_test.h"
44 static int prettyprint(struct ioat_test *);
50 printf("Usage: %s [-c period] [-EefmVxXz] channel-number num-txns [<bufsize> "
51 "[<chain-len> [duration]]]\n", getprogname());
52 printf(" %s -r [-c period] [-vVwz] channel-number address [<bufsize>]\n\n",
54 printf(" -c period - Enable interrupt coalescing (us) (default: 0)\n");
55 printf(" -E - Test contiguous 8k copy.\n");
56 printf(" -e - Test non-contiguous 8k copy.\n");
57 printf(" -f - Test block fill.\n");
58 printf(" -m - Test memcpy instead of DMA.\n");
59 printf(" -r - Issue DMA to or from a specific address.\n");
60 printf(" -V - Enable verification\n");
61 printf(" -v - <address> is a kernel virtual address\n");
62 printf(" -w - Write to the specified address\n");
63 printf(" -x - Test DMA CRC.\n");
64 printf(" -X - Test DMA CRC copy.\n");
65 printf(" -z - Zero device stats before test\n");
70 main_raw(struct ioat_test *t, int argc, char **argv)
74 /* Raw DMA defaults */
75 t->testkind = IOAT_TEST_RAW_DMA;
78 t->buffer_size = 4 * 1024;
80 t->raw_target = strtoull(argv[1], NULL, 0);
81 if (t->raw_target == 0) {
82 printf("Target shoudln't be NULL\n");
87 t->buffer_size = atoi(argv[2]);
88 if (t->buffer_size == 0) {
89 printf("Buffer size must be greater than zero\n");
94 fd = open("/dev/ioat_test", O_RDWR);
96 printf("Cannot open /dev/ioat_test\n");
100 (void)ioctl(fd, IOAT_DMATEST, t);
103 exit(prettyprint(t));
107 main(int argc, char **argv)
111 bool fflag, rflag, Eflag, eflag, mflag, xflag, Xflag;
114 memset(&t, 0, sizeof(t));
116 fflag = rflag = Eflag = eflag = mflag = xflag = Xflag = false;
119 while ((ch = getopt(argc, argv, "c:EefmrvVwxXz")) != -1) {
122 t.coalesce_period = atoi(optarg);
145 t.raw_is_virtual = true;
175 printf("Invalid: Cannot use >1 mode flag (-E, -e, -f, -m, -r, -x or -X)\n");
179 /* Defaults for optional args */
180 t.buffer_size = 256 * 1024;
183 t.testkind = IOAT_TEST_DMA;
186 t.testkind = IOAT_TEST_FILL;
187 else if (Eflag || eflag) {
188 t.testkind = IOAT_TEST_DMA_8K;
189 t.buffer_size = 8 * 1024;
191 t.testkind = IOAT_TEST_MEMCPY;
193 t.testkind = IOAT_TEST_DMA_CRC;
195 t.testkind = IOAT_TEST_DMA_CRC_COPY;
197 t.channel_index = atoi(argv[0]);
198 if (t.channel_index > 8) {
199 printf("Channel number must be between 0 and 7.\n");
204 main_raw(&t, argc, argv);
208 t.transactions = atoi(argv[1]);
211 t.buffer_size = atoi(argv[2]);
212 if (t.buffer_size == 0) {
213 printf("Buffer size must be greater than zero\n");
219 t.chain_depth = atoi(argv[3]);
220 if (t.chain_depth < 1) {
221 printf("Chain length must be greater than zero\n");
227 t.duration = atoi(argv[4]);
228 if (t.duration < 1) {
229 printf("Duration must be greater than zero\n");
234 fd = open("/dev/ioat_test", O_RDWR);
236 printf("Cannot open /dev/ioat_test\n");
237 return (EX_UNAVAILABLE);
240 (void)ioctl(fd, IOAT_DMATEST, &t);
243 return (prettyprint(&t));
247 prettyprint(struct ioat_test *t)
249 char bps[10], bytesh[10];
252 if (t->status[IOAT_TEST_NO_DMA_ENGINE] != 0 ||
253 t->status[IOAT_TEST_NO_MEMORY] != 0 ||
254 t->status[IOAT_TEST_MISCOMPARE] != 0) {
256 if (t->status[IOAT_TEST_NO_DMA_ENGINE] != 0)
257 printf("\tNo DMA engine present: %u\n",
258 (unsigned)t->status[IOAT_TEST_NO_DMA_ENGINE]);
259 if (t->status[IOAT_TEST_NO_MEMORY] != 0)
260 printf("\tOut of memory: %u\n",
261 (unsigned)t->status[IOAT_TEST_NO_MEMORY]);
262 if (t->status[IOAT_TEST_MISCOMPARE] != 0)
263 printf("\tMiscompares: %u\n",
264 (unsigned)t->status[IOAT_TEST_MISCOMPARE]);
267 printf("Processed %u txns\n", (unsigned)t->status[IOAT_TEST_OK] /
269 bytes = (uintmax_t)t->buffer_size * t->status[IOAT_TEST_OK];
271 humanize_number(bytesh, sizeof(bytesh), (int64_t)bytes, "B",
272 HN_AUTOSCALE, HN_DECIMAL);
274 humanize_number(bps, sizeof(bps),
275 (int64_t)1000 * bytes / t->duration, "B/s", HN_AUTOSCALE,
277 printf("%ju (%s) copied in %u ms (%s)\n", bytes, bytesh,
278 (unsigned)t->duration, bps);
280 printf("%ju (%s) copied\n", bytes, bytesh);