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 __FBSDID("$FreeBSD$");
30 #include <sys/ioctl.h>
31 #include <sys/queue.h>
43 #include "ioat_test.h"
45 static int prettyprint(struct ioat_test *);
51 printf("Usage: %s [-E|-f|-m] OPTIONS <channel #> <txns> [<bufsize> "
52 "[<chain-len> [duration]]]\n", getprogname());
53 printf(" %s -r [-v] OPTIONS <channel #> <addr> [<bufsize>]\n\n",
55 printf(" OPTIONS:\n");
56 printf(" -c <period> - Enable interrupt coalescing (us)\n");
57 printf(" -V - Enable verification\n");
58 printf(" -z - Zero device stats before test\n");
63 main_raw(struct ioat_test *t, int argc, char **argv)
67 /* Raw DMA defaults */
68 t->testkind = IOAT_TEST_RAW_DMA;
71 t->buffer_size = 4 * 1024;
73 t->raw_target = strtoull(argv[1], NULL, 0);
74 if (t->raw_target == 0) {
75 printf("Target shoudln't be NULL\n");
80 t->buffer_size = atoi(argv[2]);
81 if (t->buffer_size == 0) {
82 printf("Buffer size must be greater than zero\n");
87 fd = open("/dev/ioat_test", O_RDWR);
89 printf("Cannot open /dev/ioat_test\n");
93 (void)ioctl(fd, IOAT_DMATEST, t);
100 main(int argc, char **argv)
104 bool fflag, rflag, Eflag, mflag;
107 fflag = rflag = Eflag = mflag = false;
110 while ((ch = getopt(argc, argv, "c:EfmrvVwz")) != -1) {
113 t.coalesce_period = atoi(optarg);
132 t.raw_is_virtual = true;
154 printf("Invalid: Cannot use >1 mode flag (-E, -f, -m, or -r)\n");
158 /* Defaults for optional args */
159 t.buffer_size = 256 * 1024;
162 t.testkind = IOAT_TEST_DMA;
165 t.testkind = IOAT_TEST_FILL;
167 t.testkind = IOAT_TEST_DMA_8K;
168 t.buffer_size = 8 * 1024;
170 t.testkind = IOAT_TEST_MEMCPY;
172 t.channel_index = atoi(argv[0]);
173 if (t.channel_index > 8) {
174 printf("Channel number must be between 0 and 7.\n");
179 main_raw(&t, argc, argv);
183 t.transactions = atoi(argv[1]);
186 t.buffer_size = atoi(argv[2]);
187 if (t.buffer_size == 0) {
188 printf("Buffer size must be greater than zero\n");
194 t.chain_depth = atoi(argv[3]);
195 if (t.chain_depth < 1) {
196 printf("Chain length must be greater than zero\n");
202 t.duration = atoi(argv[4]);
203 if (t.duration < 1) {
204 printf("Duration must be greater than zero\n");
209 fd = open("/dev/ioat_test", O_RDWR);
211 printf("Cannot open /dev/ioat_test\n");
212 return (EX_UNAVAILABLE);
215 (void)ioctl(fd, IOAT_DMATEST, &t);
218 return (prettyprint(&t));
222 prettyprint(struct ioat_test *t)
224 char bps[10], bytesh[10];
227 if (t->status[IOAT_TEST_NO_DMA_ENGINE] != 0 ||
228 t->status[IOAT_TEST_NO_MEMORY] != 0 ||
229 t->status[IOAT_TEST_MISCOMPARE] != 0) {
231 if (t->status[IOAT_TEST_NO_DMA_ENGINE] != 0)
232 printf("\tNo DMA engine present: %u\n",
233 (unsigned)t->status[IOAT_TEST_NO_DMA_ENGINE]);
234 if (t->status[IOAT_TEST_NO_MEMORY] != 0)
235 printf("\tOut of memory: %u\n",
236 (unsigned)t->status[IOAT_TEST_NO_MEMORY]);
237 if (t->status[IOAT_TEST_MISCOMPARE] != 0)
238 printf("\tMiscompares: %u\n",
239 (unsigned)t->status[IOAT_TEST_MISCOMPARE]);
242 printf("Processed %u txns\n", (unsigned)t->status[IOAT_TEST_OK] /
244 bytes = (uintmax_t)t->buffer_size * t->status[IOAT_TEST_OK];
246 humanize_number(bytesh, sizeof(bytesh), (int64_t)bytes, "B",
247 HN_AUTOSCALE, HN_DECIMAL);
249 humanize_number(bps, sizeof(bps),
250 (int64_t)1000 * bytes / t->duration, "B/s", HN_AUTOSCALE,
252 printf("%ju (%s) copied in %u ms (%s)\n", bytes, bytesh,
253 (unsigned)t->duration, bps);
255 printf("%ju (%s) copied\n", bytes, bytesh);