2 * Copyright (C) 2012-2013 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/param.h>
31 #include <sys/ioccom.h>
44 #include "nvmecontrol.h"
47 print_perftest(struct nvme_io_test *io_test, bool perthread)
49 uint64_t io_completed = 0, iops, mbps;
52 for (i = 0; i < io_test->num_threads; i++)
53 io_completed += io_test->io_completed[i];
55 iops = io_completed/io_test->time;
56 mbps = iops * io_test->size / (1024*1024);
58 printf("Threads: %2d Size: %6d %5s Time: %3d IO/s: %7ju MB/s: %4ju\n",
59 io_test->num_threads, io_test->size,
60 io_test->opc == NVME_OPC_READ ? "READ" : "WRITE",
61 io_test->time, (uintmax_t)iops, (uintmax_t)mbps);
64 for (i = 0; i < io_test->num_threads; i++)
65 printf("\t%3d: %8ju IO/s\n", i,
66 (uintmax_t)io_test->io_completed[i]/io_test->time);
72 fprintf(stderr, "usage:\n");
73 fprintf(stderr, PERFTEST_USAGE);
78 perftest(int argc, char *argv[])
80 struct nvme_io_test io_test;
84 u_long ioctl_cmd = NVME_IO_TEST;
85 bool nflag, oflag, sflag, tflag;
88 nflag = oflag = sflag = tflag = false;
90 memset(&io_test, 0, sizeof(io_test));
92 while ((ch = getopt(argc, argv, "f:i:n:o:ps:t:")) != -1) {
95 if (!strcmp(optarg, "refthread"))
96 io_test.flags |= NVME_TEST_FLAG_REFTHREAD;
99 if (!strcmp(optarg, "bio") ||
100 !strcmp(optarg, "wait"))
101 ioctl_cmd = NVME_BIO_TEST;
102 else if (!strcmp(optarg, "io") ||
103 !strcmp(optarg, "intr"))
104 ioctl_cmd = NVME_IO_TEST;
108 io_test.num_threads = strtoul(optarg, &p, 0);
109 if (p != NULL && *p != '\0') {
111 "\"%s\" not valid number of threads.\n",
114 } else if (io_test.num_threads == 0 ||
115 io_test.num_threads > 128) {
117 "\"%s\" not valid number of threads.\n",
124 if (!strcmp(optarg, "read") || !strcmp(optarg, "READ"))
125 io_test.opc = NVME_OPC_READ;
126 else if (!strcmp(optarg, "write") ||
127 !strcmp(optarg, "WRITE"))
128 io_test.opc = NVME_OPC_WRITE;
130 fprintf(stderr, "\"%s\" not valid opcode.\n",
140 io_test.size = strtoul(optarg, &p, 0);
141 if (p == NULL || *p == '\0' || toupper(*p) == 'B') {
143 } else if (toupper(*p) == 'K') {
144 io_test.size *= 1024;
145 } else if (toupper(*p) == 'M') {
146 io_test.size *= 1024 * 1024;
148 fprintf(stderr, "\"%s\" not valid size.\n",
155 io_test.time = strtoul(optarg, &p, 0);
156 if (p != NULL && *p != '\0') {
158 "\"%s\" not valid time duration.\n",
166 if (!nflag || !oflag || !sflag || !tflag || optind >= argc)
169 open_dev(argv[optind], &fd, 1, 1);
170 if (ioctl(fd, ioctl_cmd, &io_test) < 0)
171 err(1, "ioctl NVME_IO_TEST failed");
174 print_perftest(&io_test, perthread);