nvme: use hw qid in trace events
authorKeith Busch <keith.busch@intel.com>
Fri, 29 Jun 2018 22:50:01 +0000 (16:50 -0600)
committerChristoph Hellwig <hch@lst.de>
Mon, 23 Jul 2018 07:35:19 +0000 (09:35 +0200)
We can not match a command to its completion based on the command
id alone. We need the submitting queue identifier to pair with the
completion, so this patch adds that to the trace buffer.

This patch is also collapsing the admin and IO submission traces into a
single one so we don't need to duplicate this and creating unnecessary
code branches: we know if the command is an admin vs IO based on the qid.

And since we're here, the patch fixes code formatting in the area.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
[hch: move the qid helper to nvme.h and made it an inline function]
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/nvme/host/trace.h

index e541fe268bcfbc1d6284dcc55691a0d231495ca3..e77e6418a21cb3f04d89e9f957ff14bb1ec3aae3 100644 (file)
@@ -652,10 +652,7 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
        }
 
        cmd->common.command_id = req->tag;
-       if (ns)
-               trace_nvme_setup_nvm_cmd(req->q->id, cmd);
-       else
-               trace_nvme_setup_admin_cmd(cmd);
+       trace_nvme_setup_cmd(req, cmd);
        return ret;
 }
 EXPORT_SYMBOL_GPL(nvme_setup_cmd);
index f2249387b60d709271f2d5c3edd93ffb9e35d299..4ad0c8ad2a2747120494dcc7f5a37ae3a6ba8e5a 100644 (file)
@@ -120,6 +120,13 @@ static inline struct nvme_request *nvme_req(struct request *req)
        return blk_mq_rq_to_pdu(req);
 }
 
+static inline u16 nvme_req_qid(struct request *req)
+{
+       if (!req->rq_disk)
+               return 0;
+       return blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(req)) + 1;
+}
+
 /* The below value is the specific amount of delay needed before checking
  * readiness in case of the PCI_DEVICE(0x1c58, 0x0003), which needs the
  * NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was
index 01390f0e167105413401ffb484b0533a3cd23e5d..e6362677447d6347ef7545101c164068d910f49f 100644 (file)
                nvme_admin_opcode_name(nvme_admin_security_recv),       \
                nvme_admin_opcode_name(nvme_admin_sanitize_nvm))
 
-const char *nvme_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
-                                      u8 *cdw10);
-#define __parse_nvme_admin_cmd(opcode, cdw10) \
-       nvme_trace_parse_admin_cmd(p, opcode, cdw10)
-
 #define nvme_opcode_name(opcode)       { opcode, #opcode }
-#define show_opcode_name(val)                                  \
+#define show_nvm_opcode_name(val)                              \
        __print_symbolic(val,                                   \
                nvme_opcode_name(nvme_cmd_flush),               \
                nvme_opcode_name(nvme_cmd_write),               \
@@ -70,83 +65,66 @@ const char *nvme_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
                nvme_opcode_name(nvme_cmd_resv_acquire),        \
                nvme_opcode_name(nvme_cmd_resv_release))
 
-const char *nvme_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode,
-                                    u8 *cdw10);
-#define __parse_nvme_cmd(opcode, cdw10) \
-       nvme_trace_parse_nvm_cmd(p, opcode, cdw10)
+#define show_opcode_name(qid, opcode)                                  \
+       (qid ? show_nvm_opcode_name(opcode) : show_admin_opcode_name(opcode))
 
-TRACE_EVENT(nvme_setup_admin_cmd,
-           TP_PROTO(struct nvme_command *cmd),
-           TP_ARGS(cmd),
-           TP_STRUCT__entry(
-                   __field(u8, opcode)
-                   __field(u8, flags)
-                   __field(u16, cid)
-                   __field(u64, metadata)
-                   __array(u8, cdw10, 24)
-           ),
-           TP_fast_assign(
-                   __entry->opcode = cmd->common.opcode;
-                   __entry->flags = cmd->common.flags;
-                   __entry->cid = cmd->common.command_id;
-                   __entry->metadata = le64_to_cpu(cmd->common.metadata);
-                   memcpy(__entry->cdw10, cmd->common.cdw10,
-                          sizeof(__entry->cdw10));
-           ),
-           TP_printk(" cmdid=%u, flags=0x%x, meta=0x%llx, cmd=(%s %s)",
-                     __entry->cid, __entry->flags, __entry->metadata,
-                     show_admin_opcode_name(__entry->opcode),
-                     __parse_nvme_admin_cmd(__entry->opcode, __entry->cdw10))
-);
+const char *nvme_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
+               u8 *cdw10);
+const char *nvme_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode,
+               u8 *cdw10);
 
+#define parse_nvme_cmd(qid, opcode, cdw10)                     \
+       (qid ?                                                  \
+        nvme_trace_parse_nvm_cmd(p, opcode, cdw10) :           \
+        nvme_trace_parse_admin_cmd(p, opcode, cdw10))
 
-TRACE_EVENT(nvme_setup_nvm_cmd,
-           TP_PROTO(int qid, struct nvme_command *cmd),
-           TP_ARGS(qid, cmd),
+TRACE_EVENT(nvme_setup_cmd,
+           TP_PROTO(struct request *req, struct nvme_command *cmd),
+           TP_ARGS(req, cmd),
            TP_STRUCT__entry(
-                   __field(int, qid)
-                   __field(u8, opcode)
-                   __field(u8, flags)
-                   __field(u16, cid)
-                   __field(u32, nsid)
-                   __field(u64, metadata)
-                   __array(u8, cdw10, 24)
+               __field(int, qid)
+               __field(u8, opcode)
+               __field(u8, flags)
+               __field(u16, cid)
+               __field(u32, nsid)
+               __field(u64, metadata)
+               __array(u8, cdw10, 24)
            ),
            TP_fast_assign(
-                   __entry->qid = qid;
-                   __entry->opcode = cmd->common.opcode;
-                   __entry->flags = cmd->common.flags;
-                   __entry->cid = cmd->common.command_id;
-                   __entry->nsid = le32_to_cpu(cmd->common.nsid);
-                   __entry->metadata = le64_to_cpu(cmd->common.metadata);
-                   memcpy(__entry->cdw10, cmd->common.cdw10,
-                          sizeof(__entry->cdw10));
+               __entry->qid = nvme_req_qid(req);
+               __entry->opcode = cmd->common.opcode;
+               __entry->flags = cmd->common.flags;
+               __entry->cid = cmd->common.command_id;
+               __entry->nsid = le32_to_cpu(cmd->common.nsid);
+               __entry->metadata = le64_to_cpu(cmd->common.metadata);
+               memcpy(__entry->cdw10, cmd->common.cdw10,
+                      sizeof(__entry->cdw10));
            ),
-           TP_printk("qid=%d, nsid=%u, cmdid=%u, flags=0x%x, meta=0x%llx, cmd=(%s %s)",
-                     __entry->qid, __entry->nsid, __entry->cid,
+           TP_printk("qid=%d, cmdid=%u, nsid=%u, flags=0x%x, meta=0x%llx, cmd=(%s %s)",
+                     __entry->qid, __entry->cid, __entry->nsid,
                      __entry->flags, __entry->metadata,
-                     show_opcode_name(__entry->opcode),
-                     __parse_nvme_cmd(__entry->opcode, __entry->cdw10))
+                     show_opcode_name(__entry->qid, __entry->opcode),
+                     parse_nvme_cmd(__entry->qid, __entry->opcode, __entry->cdw10))
 );
 
 TRACE_EVENT(nvme_complete_rq,
            TP_PROTO(struct request *req),
            TP_ARGS(req),
            TP_STRUCT__entry(
-                   __field(int, qid)
-                   __field(int, cid)
-                   __field(u64, result)
-                   __field(u8, retries)
-                   __field(u8, flags)
-                   __field(u16, status)
+               __field(int, qid)
+               __field(int, cid)
+               __field(u64, result)
+               __field(u8, retries)
+               __field(u8, flags)
+               __field(u16, status)
            ),
            TP_fast_assign(
-                   __entry->qid = req->q->id;
-                   __entry->cid = req->tag;
-                   __entry->result = le64_to_cpu(nvme_req(req)->result.u64);
-                   __entry->retries = nvme_req(req)->retries;
-                   __entry->flags = nvme_req(req)->flags;
-                   __entry->status = nvme_req(req)->status;
+               __entry->qid = nvme_req_qid(req);
+               __entry->cid = req->tag;
+               __entry->result = le64_to_cpu(nvme_req(req)->result.u64);
+               __entry->retries = nvme_req(req)->retries;
+               __entry->flags = nvme_req(req)->flags;
+               __entry->status = nvme_req(req)->status;
            ),
            TP_printk("qid=%d, cmdid=%u, res=%llu, retries=%u, flags=0x%x, status=%u",
                      __entry->qid, __entry->cid, __entry->result,