From b7e96716f39540a51664fdef173182389df72f05 Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Fri, 19 Jun 2020 20:26:20 +0900 Subject: [PATCH] Add latency check for zone-append Signed-off-by: Steven Seungcheol Lee Co-authored-by: Klaus Jensen --- nvme.c | 3 +-- nvme.h | 4 ++++ plugins/zns/zns.c | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/nvme.c b/nvme.c index 0b3e421..98c6c87 100644 --- a/nvme.c +++ b/nvme.c @@ -47,7 +47,6 @@ #include #include #include -#include #include "common.h" #include "nvme-print.h" @@ -3918,7 +3917,7 @@ ret: return nvme_status_to_errno(err, false); } -static unsigned long long elapsed_utime(struct timeval start_time, +unsigned long long elapsed_utime(struct timeval start_time, struct timeval end_time) { unsigned long long err = (end_time.tv_sec - start_time.tv_sec) * 1000000 + diff --git a/nvme.h b/nvme.h index 361191b..ffc3fbd 100644 --- a/nvme.h +++ b/nvme.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "plugin.h" #include "util/json.h" @@ -110,4 +111,7 @@ char *nvme_get_ctrl_attr(char *path, const char *attr); void *nvme_alloc(size_t len, bool *huge); void nvme_free(void *p, bool huge); + +unsigned long long elapsed_utime(struct timeval start_time, + struct timeval end_time); #endif /* _NVME_H */ diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 164446e..7a6da79 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -630,12 +630,14 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin const char *lbatm = "logical block application tag mask (for end to end PI)"; const char *metadata_size = "size of metadata in bytes"; const char *data_size = "size of data in bytes"; + const char *latency = "output latency statistics"; int err = -1, fd, dfd = STDIN_FILENO, mfd = STDIN_FILENO; unsigned int lba_size, meta_size; void *buf = NULL, *mbuf = NULL; __u16 nblocks, control = 0; __u64 result; + struct timeval start_time, end_time; struct nvme_id_ns ns; @@ -652,6 +654,7 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin __u16 lbat; __u16 lbatm; __u8 prinfo; + int latency; }; struct config cfg = { @@ -659,9 +662,9 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin OPT_ARGS(opts) = { OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_SUFFIX("zslba", 's', &cfg.zslba, zslba), - OPT_SUFFIX("data-size", 'z', &cfg.data_size, data_size), - OPT_SUFFIX("metadata-size", 'y', &cfg.metadata_size, metadata_size), + OPT_SUFFIX("zslba", 's', &cfg.zslba, zslba), + OPT_SUFFIX("data-size", 'z', &cfg.data_size, data_size), + OPT_SUFFIX("metadata-size", 'y', &cfg.metadata_size, metadata_size), OPT_FILE("data", 'd', &cfg.data, data), OPT_FILE("metadata", 'M', &cfg.metadata, metadata), OPT_FLAG("limited-retry", 'l', &cfg.limited_retry, limited_retry), @@ -670,6 +673,7 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin OPT_SHRT("app-tag-mask", 'm', &cfg.lbatm, lbatm), OPT_SHRT("app-tag", 'a', &cfg.lbat, lbat), OPT_BYTE("prinfo", 'p', &cfg.prinfo, prinfo), + OPT_FLAG("latency", 't', &cfg.latency, latency), OPT_END() }; @@ -774,10 +778,16 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin if (cfg.fua) control |= NVME_RW_FUA; + gettimeofday(&start_time, NULL); err = nvme_zns_append(fd, cfg.namespace_id, cfg.zslba, nblocks, control, cfg.ref_tag, cfg.lbat, cfg.lbatm, cfg.data_size, buf, cfg.metadata_size, mbuf, &result); + gettimeofday(&end_time, NULL); + if (cfg.latency) + printf(" latency: zone append: %llu us\n", + elapsed_utime(start_time, end_time)); + if (!err) printf("Success appended data to LBA %"PRIx64"\n", (uint64_t)result); else -- 2.49.0