io_uring: Add 'write_mode' option for optional cmds
authorMinwoo Im <minwoo.im@samsung.com>
Tue, 28 May 2024 08:02:22 +0000 (17:02 +0900)
committerMinwoo Im <minwoo.im@samsung.com>
Fri, 31 May 2024 21:02:42 +0000 (06:02 +0900)
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 <minwoo.im@samsung.com>
HOWTO.rst
engines/io_uring.c
engines/nvme.c
engines/nvme.h
fio.1

index 0b39a89231fc099d4c7e5bcac1fcd4667db15b6f..33a6ad93a42d51b9be00999cb973bc11f5c2b43b 100644 (file)
--- 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:
index 05ce27ebcf2ab1123513932bbe84a0811a6fd19b..cf8cf289e355082c6c75705df029525633ede391 100644 (file)
@@ -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);
index 7b73c806af449f05dc5a062e485a76e095056a8e..72934c8b1d9172bb1f9e4c19e8fa5e0e1c151a2c 100644 (file)
@@ -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);
index 2db9eb86ddcc8b4d7c59bb29c2dafa5336cb9198..bc2370b8d2a2c11f764a4ce01b80f1a2a3f5ca5d 100644 (file)
@@ -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 9a965cb0903f4337de4c37d5f86a1fb80e29087f..2649529b1bc011611886658f8f71ce8fbc5f53ca 100644 (file)
--- 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: