Skip to content

Commit 648bf0a

Browse files
committed
nvme: move submit_io show-command and dry-run outputs into logging
Also latency output moved into logging as same. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent e1882cd commit 648bf0a

3 files changed

Lines changed: 52 additions & 32 deletions

File tree

nvme.c

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8009,15 +8009,13 @@ unsigned long long elapsed_utime(struct timeval start_time,
80098009

80108010
static int submit_io(int opcode, char *command, const char *desc, int argc, char **argv)
80118011
{
8012-
struct timeval start_time, end_time;
80138012
void *buffer;
80148013
_cleanup_free_ void *mbuffer = NULL;
80158014
int err = 0;
80168015
_cleanup_fd_ int dfd = -1, mfd = -1;
80178016
int flags, pi_size;
80188017
int mode = 0644;
80198018
__u16 control = 0, nblocks = 0;
8020-
__u32 dsmgmt = 0;
80218019
unsigned int logical_block_size = 0;
80228020
unsigned long long buffer_size = 0, mbuffer_size = 0;
80238021
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
@@ -8147,7 +8145,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
81478145
if (cfg.prinfo > 0xf)
81488146
return err;
81498147

8150-
dsmgmt = cfg.dsmgmt;
81518148
control |= (cfg.prinfo << 10);
81528149
if (cfg.limited_retry)
81538150
control |= NVME_IO_LR;
@@ -8161,7 +8158,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
81618158
return -EINVAL;
81628159
}
81638160
control |= cfg.dtype << 4;
8164-
dsmgmt |= ((__u32)cfg.dspec) << 16;
81658161
}
81668162

81678163
if (opcode & 1) {
@@ -8285,27 +8281,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82858281
}
82868282
}
82878283

8288-
if (cfg.show || nvme_cfg.dry_run) {
8289-
printf("opcode : %02x\n", opcode);
8290-
printf("nsid : %02x\n", cfg.namespace_id);
8291-
printf("flags : %02x\n", 0);
8292-
printf("control : %04x\n", control);
8293-
printf("nblocks : %04x\n", nblocks);
8294-
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)mbuffer);
8295-
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)buffer);
8296-
printf("slba : %"PRIx64"\n", (uint64_t)cfg.start_block);
8297-
printf("dsmgmt : %08x\n", dsmgmt);
8298-
printf("reftag : %"PRIx64"\n", (uint64_t)cfg.ref_tag);
8299-
printf("apptag : %04x\n", cfg.app_tag);
8300-
printf("appmask : %04x\n", cfg.app_tag_mask);
8301-
printf("storagetagcheck : %04x\n", cfg.storage_tag_check);
8302-
printf("storagetag : %"PRIx64"\n", (uint64_t)cfg.storage_tag);
8303-
printf("pif : %02x\n", pif);
8304-
printf("sts : %02x\n", sts);
8305-
}
8306-
if (nvme_cfg.dry_run)
8307-
return 0;
8308-
83098284
struct nvme_io_args args = {
83108285
.args_size = sizeof(args),
83118286
.fd = dev_fd(dev),
@@ -8329,16 +8304,13 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
83298304
.timeout = nvme_cfg.timeout,
83308305
.result = NULL,
83318306
};
8332-
gettimeofday(&start_time, NULL);
8333-
err = nvme_io(&args, opcode);
8334-
gettimeofday(&end_time, NULL);
8335-
if (cfg.latency)
8336-
printf(" latency: %s: %llu us\n", command, elapsed_utime(start_time, end_time));
8307+
8308+
err = nvme_submit_io(&args, opcode, cfg.show, cfg.latency);
83378309
if (err < 0) {
83388310
nvme_show_error("submit-io: %s", nvme_strerror(errno));
83398311
} else if (err) {
83408312
nvme_show_status(err);
8341-
} else {
8313+
} else if (!nvme_cfg.dry_run) {
83428314
if (!(opcode & 1) && write(dfd, (void *)buffer, buffer_size) < 0) {
83438315
nvme_show_error("write: %s: failed to write buffer to output file",
83448316
strerror(errno));

util/logging.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,51 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
150150

151151
return err;
152152
}
153+
154+
static void nvme_show_io_command(struct nvme_io_args *args, __u8 opcode)
155+
{
156+
__u32 dsmgmt = args->dsm;
157+
__u8 dtype = (args->control >> 4) & 0xf;
158+
159+
if (dtype)
160+
dsmgmt |= ((__u32)args->dspec) << 16;
161+
162+
printf("opcode : %02x\n", opcode);
163+
printf("nsid : %02x\n", args->nsid);
164+
printf("flags : %02x\n", 0);
165+
printf("control : %04x\n", args->control);
166+
printf("nblocks : %04x\n", args->nlb);
167+
printf("metadata : %"PRIx64"\n", (uint64_t)args->metadata);
168+
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)args->data);
169+
printf("slba : %"PRIx64"\n", (uint64_t)(uintptr_t)args->slba);
170+
printf("dsmgmt : %08x\n", dsmgmt);
171+
printf("reftag : %"PRIx64"\n", (uint64_t)args->reftag_u64);
172+
printf("apptag : %04x\n", args->apptag);
173+
printf("appmask : %04x\n", args->appmask);
174+
printf("storagetagcheck : %04x\n", args->control | NVME_IO_STC ? true : false);
175+
printf("storagetag : %"PRIx64"\n", (uint64_t)args->storage_tag);
176+
printf("pif : %02x\n", args->pif);
177+
printf("sts : %02x\n", args->sts);
178+
}
179+
180+
int nvme_submit_io(struct nvme_io_args *args, __u8 opcode, bool show, bool latency)
181+
{
182+
struct timeval start_time;
183+
struct timeval end_time;
184+
int err;
185+
186+
if (show || dry_run)
187+
nvme_show_io_command(args, opcode);
188+
189+
if (dry_run)
190+
return 0;
191+
192+
gettimeofday(&start_time, NULL);
193+
err = nvme_io(args, opcode);
194+
gettimeofday(&end_time, NULL);
195+
196+
if (latency)
197+
nvme_show_latency(start_time, end_time);
198+
199+
return err;
200+
}

util/logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ extern int log_level;
2121

2222
int map_log_level(int verbose, bool quiet);
2323
void set_dry_run(bool enable);
24-
24+
int nvme_submit_io(struct nvme_io_args *args, __u8 opcode, bool show, bool latency);
2525
#endif // DEBUG_H_

0 commit comments

Comments
 (0)