From 87a4903f6cf07d3c16f292aea74c1cb42b924439 Mon Sep 17 00:00:00 2001 From: Minwoo Im Date: Tue, 28 May 2024 17:02:22 +0900 Subject: [PATCH] io_uring: Add 'write_mode' option for optional cmds Add a new option 'write_mode' to support additional optional Write command family such as Write Uncorrectable and Write Zeroes in NVMe. Since we have io_uring_cmd ioengine where we can define the actual opcode of the command, this option will be used to test NVMe device with various combination of Write command types. 'write_mode' option can be given either 'write', 'uncor', 'zeroes' or 'verify'. 'write' is for normal Write command which is by default, 'uncor' is for Write Uncorrectable, 'zeroes' for Write Zeroes and 'verify' for Verify command This should be used with DDIR_WRITE ddir. This patch updates command's opcode in fio_ioring_init() to avoid branches in the I/O hottest path giving opcode value to the fio_nvme_uring_cmd_prep() as an argument. Signed-off-by: Minwoo Im --- HOWTO.rst | 16 ++++++++++++ engines/io_uring.c | 64 +++++++++++++++++++++++++++++++++++++++++++++- engines/nvme.c | 4 +-- engines/nvme.h | 5 +++- fio.1 | 20 +++++++++++++++ 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/HOWTO.rst b/HOWTO.rst index 0b39a89231..33a6ad93a4 100644 --- a/HOWTO.rst +++ b/HOWTO.rst @@ -2857,6 +2857,22 @@ with the caveat that when used on the command line, they must come after the With writefua option set to 1, write operations include the force unit access (fua) flag. Default is 0. +.. option:: write_mode=str : [io_uring_cmd] + + Specifies the type of write operation. Defaults to 'write'. + + **write** + Use Write commands for write operations + + **uncor** + Use Write Uncorrectable commands for write opreations + + **zeroes** + Use Write Zeroes commands for write operations + + **verify** + Use Verify commands for write operations + .. option:: sg_write_mode=str : [sg] Specify the type of write commands to issue. This option can take ten values: diff --git a/engines/io_uring.c b/engines/io_uring.c index 05ce27ebcf..cf8cf289e3 100644 --- a/engines/io_uring.c +++ b/engines/io_uring.c @@ -34,6 +34,13 @@ enum uring_cmd_type { FIO_URING_CMD_NVME = 1, }; +enum uring_cmd_write_mode { + FIO_URING_CMD_WMODE_WRITE = 1, + FIO_URING_CMD_WMODE_UNCOR, + FIO_URING_CMD_WMODE_ZEROES, + FIO_URING_CMD_WMODE_VERIFY, +}; + struct io_sq_ring { unsigned *head; unsigned *tail; @@ -83,6 +90,7 @@ struct ioring_data { struct nvme_dsm *dsm; uint32_t cdw12_flags[DDIR_RWDIR_CNT]; + uint8_t write_opcode; }; struct ioring_options { @@ -90,6 +98,7 @@ struct ioring_options { unsigned int hipri; unsigned int readfua; unsigned int writefua; + unsigned int write_mode; struct cmdprio_options cmdprio_options; unsigned int fixedbufs; unsigned int registerfiles; @@ -158,6 +167,34 @@ static struct fio_option options[] = { .category = FIO_OPT_C_ENGINE, .group = FIO_OPT_G_IOURING, }, + { + .name = "write_mode", + .lname = "Additional Write commands support (Write Uncorrectable, Write Zeores)", + .type = FIO_OPT_STR, + .off1 = offsetof(struct ioring_options, write_mode), + .help = "Issue Write Uncorrectable or Zeroes command instaed of Write command", + .def = "write", + .posval = { + { .ival = "write", + .oval = FIO_URING_CMD_WMODE_WRITE, + .help = "Issue Write commands for write operations" + }, + { .ival = "uncor", + .oval = FIO_URING_CMD_WMODE_UNCOR, + .help = "Issue Write Uncorrectable commands for write operations" + }, + { .ival = "zeroes", + .oval = FIO_URING_CMD_WMODE_ZEROES, + .help = "Issue Write Zeroes commands for write operations" + }, + { .ival = "verify", + .oval = FIO_URING_CMD_WMODE_VERIFY, + .help = "Issue Verify commands for write operations" + }, + }, + .category = FIO_OPT_C_ENGINE, + .group = FIO_OPT_G_IOURING, + }, { .name = "fixedbufs", .lname = "Fixed (pre-mapped) IO buffers", @@ -455,7 +492,7 @@ static int fio_ioring_cmd_prep(struct thread_data *td, struct io_u *io_u) return fio_nvme_uring_cmd_prep(cmd, io_u, o->nonvectored ? NULL : &ld->iovecs[io_u->index], - dsm, ld->cdw12_flags[io_u->ddir]); + dsm, ld->write_opcode, ld->cdw12_flags[io_u->ddir]); } static struct io_u *fio_ioring_event(struct thread_data *td, int event) @@ -1243,6 +1280,23 @@ static int fio_ioring_init(struct thread_data *td) } if (!strcmp(td->io_ops->name, "io_uring_cmd")) { + if (td_write(td)) { + switch (o->write_mode) { + case FIO_URING_CMD_WMODE_UNCOR: + ld->write_opcode = nvme_cmd_write_uncor; + break; + case FIO_URING_CMD_WMODE_ZEROES: + ld->write_opcode = nvme_cmd_write_zeroes; + break; + case FIO_URING_CMD_WMODE_VERIFY: + ld->write_opcode = nvme_cmd_verify; + break; + default: + ld->write_opcode = nvme_cmd_write; + break; + } + } + if (o->readfua) ld->cdw12_flags[DDIR_READ] = 1 << 30; if (o->writefua) @@ -1371,6 +1425,14 @@ static int fio_ioring_cmd_open_file(struct thread_data *td, struct fio_file *f) td_verror(td, EINVAL, "fio_ioring_cmd_open_file"); return 1; } + + if (o->write_mode != FIO_URING_CMD_WMODE_WRITE && + !td_write(td)) { + log_err("%s: 'readwrite=|rw=' has no write\n", + f->file_name); + td_verror(td, EINVAL, "fio_ioring_cmd_open_file"); + return 1; + } } if (!ld || !o->registerfiles) return generic_open_file(td, f); diff --git a/engines/nvme.c b/engines/nvme.c index 7b73c806af..72934c8b1d 100644 --- a/engines/nvme.c +++ b/engines/nvme.c @@ -363,7 +363,7 @@ void fio_nvme_uring_cmd_trim_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u, int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u, struct iovec *iov, struct nvme_dsm *dsm, - unsigned int cdw12_flags) + uint8_t write_opcode, unsigned int cdw12_flags) { struct nvme_data *data = FILE_ENG_DATA(io_u->file); __u64 slba; @@ -376,7 +376,7 @@ int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u, cmd->opcode = nvme_cmd_read; break; case DDIR_WRITE: - cmd->opcode = nvme_cmd_write; + cmd->opcode = write_opcode; break; case DDIR_TRIM: fio_nvme_uring_cmd_trim_prep(cmd, io_u, dsm); diff --git a/engines/nvme.h b/engines/nvme.h index 2db9eb86dd..bc2370b8d2 100644 --- a/engines/nvme.h +++ b/engines/nvme.h @@ -75,7 +75,10 @@ enum nvme_admin_opcode { enum nvme_io_opcode { nvme_cmd_write = 0x01, nvme_cmd_read = 0x02, + nvme_cmd_write_uncor = 0x04, + nvme_cmd_write_zeroes = 0x08, nvme_cmd_dsm = 0x09, + nvme_cmd_verify = 0x0c, nvme_cmd_io_mgmt_recv = 0x12, nvme_zns_cmd_mgmt_send = 0x79, nvme_zns_cmd_mgmt_recv = 0x7a, @@ -427,7 +430,7 @@ int fio_nvme_get_info(struct fio_file *f, __u64 *nlba, __u32 pi_act, int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u, struct iovec *iov, struct nvme_dsm *dsm, - unsigned int cdw12_flags); + uint8_t write_opcode, unsigned int cdw12_flags); void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u, struct nvme_cmd_ext_io_opts *opts); diff --git a/fio.1 b/fio.1 index 9a965cb090..2649529b1b 100644 --- a/fio.1 +++ b/fio.1 @@ -2640,6 +2640,26 @@ unit access (fua) flag. Default: 0. With writefua option set to 1, write operations include the force unit access (fua) flag. Default: 0. .TP +.BI (io_uring_cmd)write_mode \fR=\fPstr +Specifies the type of write operation. Defaults to 'write'. +.RS +.RS +.TP +.B write +Use Write commands for write operations +.TP +.B uncor +Use Write Uncorrectable commands for write opreations +.TP +.B zeroes +Use Write Zeroes commands for write operations +.TP +.B verify +Use Verify commands for write operations +.TP +.RE +.RE +.TP .BI (sg)sg_write_mode \fR=\fPstr Specify the type of write commands to issue. This option can take multiple values: