git: 86990decd77e - stable/13 - nvme: count number of ignored interrupts

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Fri, 21 Jan 2022 02:26:53 UTC
The branch stable/13 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=86990decd77efbf36ba99d951b4f17688a939bdf

commit 86990decd77efbf36ba99d951b4f17688a939bdf
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-09-29 03:13:11 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-01-21 02:07:30 +0000

    nvme: count number of ignored interrupts
    
    Count the number of times we're asked to process completions, but that
    we ignore because the state of the qpair isn't in RECOVERY_NONE.
    
    Sponsored by:           Netflix
    Reviewed by:            mav, chuck
    Differential Revision:  https://reviews.freebsd.org/D32212
    
    (cherry picked from commit 587aa25525e54ea775298c402acd7a647f9838fb)
---
 sys/dev/nvme/nvme_private.h |  1 +
 sys/dev/nvme/nvme_qpair.c   |  5 ++++-
 sys/dev/nvme/nvme_sysctl.c  | 24 ++++++++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h
index 02cecaf03a97..b00130910a82 100644
--- a/sys/dev/nvme/nvme_private.h
+++ b/sys/dev/nvme/nvme_private.h
@@ -195,6 +195,7 @@ struct nvme_qpair {
 	int64_t			num_intr_handler_calls;
 	int64_t			num_retries;
 	int64_t			num_failures;
+	int64_t			num_ignored;
 
 	struct nvme_command	*cmd;
 	struct nvme_completion	*cpl;
diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c
index 827054efd48e..788322092f88 100644
--- a/sys/dev/nvme/nvme_qpair.c
+++ b/sys/dev/nvme/nvme_qpair.c
@@ -544,8 +544,10 @@ nvme_qpair_process_completions(struct nvme_qpair *qpair)
 	 * as soon as initialization is complete and we start sending commands
 	 * to the device.
 	 */
-	if (qpair->recovery_state != RECOVERY_NONE)
+	if (qpair->recovery_state != RECOVERY_NONE) {
+		qpair->num_ignored++;
 		return (false);
+	}
 
 	/*
 	 * Sanity check initialization. After we reset the hardware, the phase
@@ -746,6 +748,7 @@ nvme_qpair_construct(struct nvme_qpair *qpair,
 	qpair->num_intr_handler_calls = 0;
 	qpair->num_retries = 0;
 	qpair->num_failures = 0;
+	qpair->num_ignored = 0;
 	qpair->cmd = (struct nvme_command *)queuemem;
 	qpair->cpl = (struct nvme_completion *)(queuemem + cmdsz);
 	prpmem = (uint8_t *)(queuemem + cmdsz + cplsz);
diff --git a/sys/dev/nvme/nvme_sysctl.c b/sys/dev/nvme/nvme_sysctl.c
index 1f1e1ce4a628..4367a21861b3 100644
--- a/sys/dev/nvme/nvme_sysctl.c
+++ b/sys/dev/nvme/nvme_sysctl.c
@@ -164,6 +164,7 @@ nvme_qpair_reset_stats(struct nvme_qpair *qpair)
 	qpair->num_intr_handler_calls = 1;
 	qpair->num_retries = 0;
 	qpair->num_failures = 0;
+	qpair->num_ignored = 0;
 }
 
 static int
@@ -226,6 +227,21 @@ nvme_sysctl_num_failures(SYSCTL_HANDLER_ARGS)
 	return (sysctl_handle_64(oidp, &num_failures, 0, req));
 }
 
+static int
+nvme_sysctl_num_ignored(SYSCTL_HANDLER_ARGS)
+{
+	struct nvme_controller 	*ctrlr = arg1;
+	int64_t			num_ignored = 0;
+	int			i;
+
+	num_ignored = ctrlr->adminq.num_ignored;
+
+	for (i = 0; i < ctrlr->num_io_queues; i++)
+		num_ignored += ctrlr->ioq[i].num_ignored;
+
+	return (sysctl_handle_64(oidp, &num_ignored, 0, req));
+}
+
 static int
 nvme_sysctl_reset_stats(SYSCTL_HANDLER_ARGS)
 {
@@ -281,6 +297,9 @@ nvme_sysctl_initialize_queue(struct nvme_qpair *qpair,
 	SYSCTL_ADD_QUAD(ctrlr_ctx, que_list, OID_AUTO, "num_failures",
 	    CTLFLAG_RD, &qpair->num_failures,
 	    "Number of commands ending in failure after all retries");
+	SYSCTL_ADD_QUAD(ctrlr_ctx, que_list, OID_AUTO, "num_ignored",
+	    CTLFLAG_RD, &qpair->num_ignored,
+	    "Number of interrupts posted, but were administratively ignored");
 
 	SYSCTL_ADD_PROC(ctrlr_ctx, que_list, OID_AUTO,
 	    "dump_debug", CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
@@ -344,6 +363,11 @@ nvme_sysctl_initialize_ctrlr(struct nvme_controller *ctrlr)
 	    ctrlr, 0, nvme_sysctl_num_failures, "IU",
 	    "Number of commands ending in failure after all retries");
 
+	SYSCTL_ADD_PROC(ctrlr_ctx, ctrlr_list, OID_AUTO,
+	    "num_ignored", CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
+	    ctrlr, 0, nvme_sysctl_num_ignored, "IU",
+	    "Number of interrupts ignored administratively");
+
 	SYSCTL_ADD_PROC(ctrlr_ctx, ctrlr_list, OID_AUTO,
 	    "reset_stats", CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE, ctrlr,
 	    0, nvme_sysctl_reset_stats, "IU", "Reset statistics to zero");