]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Added latency measurements to submit_io commands
authorStephen Bates <stephen.bates@pmcs.com>
Mon, 9 Feb 2015 15:58:58 +0000 (15:58 +0000)
committerStephen Bates <stephen.bates@pmcs.com>
Mon, 9 Feb 2015 16:00:29 +0000 (16:00 +0000)
Added a --latency (it) option to display the latency of a submit_io
IOCTL command. The results are displayed in micro-seconds.

Documentation/nvme-read.1
Documentation/nvme-read.txt
Documentation/nvme-write.1
Documentation/nvme-write.txt
nvme.c

index abbb03be1bdbd082ddff2d6051e43bae849f4575..b4a8b91eeaab41a0bc7d37684d5b5403f38d68ec 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: nvme-compare
 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
 .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      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=<appmask> | \-m <appmask>]
                         [\-\-app\-tag=<apptag> | \-a <apptag>]
                         [\-\-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\&.
index f380c162ec4058f85b594a6527f4e770e2b56086..934263589e554d941b293aeab43e39c16ee6f095 100644 (file)
@@ -17,6 +17,7 @@ SYNOPSIS
                        [--app-tag-mask=<appmask> | -m <appmask>]
                        [--app-tag=<apptag> | -a <apptag>]
                        [--limited-retry | -l]
+                       [--latency | -t]
                        [--force-unit-access | -f]
 
 DESCRIPTION
@@ -31,6 +32,10 @@ OPTIONS
 -s <slba>::
        Start block.
 
+--latency::
+-t::
+       Print out the latency the IOCTL took (in us).
+
 EXAMPLES
 --------
 No examples yet.
index 728b8f09cbb760a762e4c12aa01f6e90a24d5589..535568709d94959c55aa33e92353518c15528f48 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: nvme-compare
 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
 .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\"      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=<appmask> | \-m <appmask>]
                         [\-\-app\-tag=<apptag> | \-a <apptag>]
                         [\-\-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\&.
index 14533f990833d70ae6a65b8407ae4819de2cc18a..98ccd92f24ff644a37514d31d1c9a5cb1bddc5d3 100644 (file)
@@ -17,6 +17,7 @@ SYNOPSIS
                        [--app-tag-mask=<appmask> | -m <appmask>]
                        [--app-tag=<apptag> | -a <apptag>]
                        [--limited-retry | -l]
+                       [--latency | -t]
                        [--force-unit-access | -f]
 
 DESCRIPTION
@@ -31,6 +32,10 @@ OPTIONS
 -s <slba>::
        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 c0eb43f39449ae6db48aff71b6e85993ec416aef..8197b164e0d26c0c379019c5bbc6894ae758822c 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -40,6 +40,7 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 
 #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)