From: Stephen Bates Date: Mon, 9 Feb 2015 15:58:58 +0000 (+0000) Subject: Added latency measurements to submit_io commands X-Git-Tag: v0.1~68 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=e9f2be14f1d2657feefae2d3f257f183b3ee5019;p=users%2Fsagi%2Fnvme-cli.git Added latency measurements to submit_io commands Added a --latency (it) option to display the latency of a submit_io IOCTL command. The results are displayed in micro-seconds. --- diff --git a/Documentation/nvme-read.1 b/Documentation/nvme-read.1 index abbb03be..b4a8b91e 100644 --- a/Documentation/nvme-read.1 +++ b/Documentation/nvme-read.1 @@ -2,12 +2,12 @@ .\" Title: nvme-compare .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 02/04/2015 +.\" Date: 02/09/2015 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "NVME\-COMPARE" "1" "02/04/2015" "\ \&" "\ \&" +.TH "NVME\-COMPARE" "1" "02/09/2015" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -41,6 +41,7 @@ nvme-read \- Send an NVMe Read command, provide results [\-\-app\-tag\-mask= | \-m ] [\-\-app\-tag= | \-a ] [\-\-limited\-retry | \-l] + [\-\-latency | \-t] [\-\-force\-unit\-access | \-f] .fi .SH "DESCRIPTION" @@ -52,6 +53,11 @@ The Read command reads the logical blocks specified by the command from the medi .RS 4 Start block\&. .RE +.PP +\-\-latency, \-t +.RS 4 +Print out the latency the IOCTL took (in us)\&. +.RE .SH "EXAMPLES" .sp No examples yet\&. diff --git a/Documentation/nvme-read.txt b/Documentation/nvme-read.txt index f380c162..93426358 100644 --- a/Documentation/nvme-read.txt +++ b/Documentation/nvme-read.txt @@ -17,6 +17,7 @@ SYNOPSIS [--app-tag-mask= | -m ] [--app-tag= | -a ] [--limited-retry | -l] + [--latency | -t] [--force-unit-access | -f] DESCRIPTION @@ -31,6 +32,10 @@ OPTIONS -s :: Start block. +--latency:: +-t:: + Print out the latency the IOCTL took (in us). + EXAMPLES -------- No examples yet. diff --git a/Documentation/nvme-write.1 b/Documentation/nvme-write.1 index 728b8f09..53556870 100644 --- a/Documentation/nvme-write.1 +++ b/Documentation/nvme-write.1 @@ -2,12 +2,12 @@ .\" Title: nvme-compare .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 02/04/2015 +.\" Date: 02/09/2015 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "NVME\-COMPARE" "1" "02/04/2015" "\ \&" "\ \&" +.TH "NVME\-COMPARE" "1" "02/09/2015" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -41,6 +41,7 @@ nvme-write \- Send an NVMe write command, provide results [\-\-app\-tag\-mask= | \-m ] [\-\-app\-tag= | \-a ] [\-\-limited\-retry | \-l] + [\-\-latency | \-t] [\-\-force\-unit\-access | \-f] .fi .SH "DESCRIPTION" @@ -52,6 +53,11 @@ The Write command writes the logical blocks specified by the command to the medi .RS 4 Start block\&. .RE +.PP +\-\-latency, \-t +.RS 4 +Print out the latency the IOCTL took (in us)\&. +.RE .SH "EXAMPLES" .sp No examples yet\&. diff --git a/Documentation/nvme-write.txt b/Documentation/nvme-write.txt index 14533f99..98ccd92f 100644 --- a/Documentation/nvme-write.txt +++ b/Documentation/nvme-write.txt @@ -17,6 +17,7 @@ SYNOPSIS [--app-tag-mask= | -m ] [--app-tag= | -a ] [--limited-retry | -l] + [--latency | -t] [--force-unit-access | -f] DESCRIPTION @@ -31,6 +32,10 @@ OPTIONS -s :: Start block. +--latency:: +-t:: + Print out the latency the IOCTL took (in us). + EXAMPLES -------- No examples yet. diff --git a/nvme.c b/nvme.c index c0eb43f3..8197b164 100644 --- a/nvme.c +++ b/nvme.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "linux/nvme.h" @@ -110,6 +111,14 @@ struct command commands[] = { #undef ENTRY }; +static unsigned long long elapsed_utime(struct timeval start_time, + struct timeval end_time) +{ + unsigned long long ret = (end_time.tv_sec - start_time.tv_sec)*1000000 + + (end_time.tv_usec - start_time.tv_usec); + return ret; +} + static void open_dev(const char *dev) { int err; @@ -1751,9 +1760,10 @@ static int resv_report(int argc, char **argv) static int submit_io(int opcode, char *command, int argc, char **argv) { struct nvme_user_io io; + struct timeval start_time, end_time; void *buffer; int err, opt, dfd = opcode & 1 ? STDIN_FILENO : STDOUT_FILENO, - show = 0, dry_run = 0, long_index = 0; + show = 0, dry_run = 0, long_index = 0, latency = 0; unsigned int data_size = 0; __u8 prinfo = 0; @@ -1771,11 +1781,12 @@ static int submit_io(int opcode, char *command, int argc, char **argv) {"force-unit-access", no_argument, 0, 'f'}, {"show-command", no_argument, 0, 'v'}, {"dry-run", no_argument, 0, 'w'}, + {"latency", no_argument, 0, 't'}, { 0, 0, 0, 0} }; memset(&io, 0, sizeof(io)); - while ((opt = getopt_long(argc, (char **)argv, "p:s:c:z:r:d:m:a:lfvw", opts, + while ((opt = getopt_long(argc, (char **)argv, "p:s:c:z:r:d:m:a:lfvwt", opts, &long_index)) != -1) { switch(opt) { case 's': get_long(optarg, &io.slba); break; @@ -1808,6 +1819,7 @@ static int submit_io(int opcode, char *command, int argc, char **argv) break; case 'v': show = 1; break; case 'w': dry_run = 1; break; + case 't': latency = 1; break; default: return EINVAL; } @@ -1844,7 +1856,12 @@ static int submit_io(int opcode, char *command, int argc, char **argv) goto free_and_return; } + gettimeofday(&start_time, NULL); err = ioctl(fd, NVME_IOCTL_SUBMIT_IO, &io); + gettimeofday(&end_time, NULL); + if (latency) + fprintf(stdout, " latency: %s: %llu us\n", + command, elapsed_utime(start_time, end_time)); if (err < 0) perror("ioctl"); else if (err)