git: f022d47f2faa - stable/13 - nvme: Reduce traffic to the doorbell register

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

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

commit f022d47f2faa2d4f24be4920645dab8b6f87dd3c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-10-14 14:44:37 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-01-21 02:07:31 +0000

    nvme: Reduce traffic to the doorbell register
    
    Reduce traffic to doorbell register when processing multiple completion
    events at once. Only write it at the end of the loop after we've
    processed everything (assuming we found at least one completion,
    even if that completion wasn't valid).
    
    Sponsored by:           Netflix
    Reviewed by:            mav
    Differential Revision:  https://reviews.freebsd.org/D32470
    
    (cherry picked from commit 2ec165e3f065217ae8d54a2a8235fe1f219805ea)
---
 sys/dev/nvme/nvme_qpair.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c
index 6669eeee6613..54718492ff09 100644
--- a/sys/dev/nvme/nvme_qpair.c
+++ b/sys/dev/nvme/nvme_qpair.c
@@ -629,10 +629,10 @@ nvme_qpair_process_completions(struct nvme_qpair *qpair)
 		else
 			tr = NULL;
 
+		done++;
 		if (tr != NULL) {
 			nvme_qpair_complete_tracker(tr, &cpl, ERROR_PRINT_ALL);
 			qpair->sq_head = cpl.sqhd;
-			done++;
 		} else if (!in_panic) {
 			/*
 			 * A missing tracker is normally an error.  However, a
@@ -664,10 +664,13 @@ nvme_qpair_process_completions(struct nvme_qpair *qpair)
 			atomic_store_rel_int(&qpair->cq_head, 0);	/* 2 */
 			qpair->phase = !qpair->phase;			/* 3 */
 		}
+	}
 
+	if (done != 0) {
 		bus_space_write_4(qpair->ctrlr->bus_tag, qpair->ctrlr->bus_handle,
 		    qpair->cq_hdbl_off, qpair->cq_head);
 	}
+
 	return (done != 0);
 }