From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Cc: martin.petersen@oracle.com, bostroesser@gmail.com,
kanie@linux.alibaba.com
Subject: [PATCH 1/2] scsi: add scsi_done_direct() helper
Date: Tue, 8 Feb 2022 14:37:06 +0800 [thread overview]
Message-ID: <20220208063707.4781-1-xiaoguang.wang@linux.alibaba.com> (raw)
For scsi commands that are known to be completed in non-interrupt
context, scsi_done_direct() calling blk_mq_complete_request_direct()
can be used to completes commands directly instead deferring it
to softirq, which can give throughput improvement.
Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
---
drivers/scsi/scsi_lib.c | 32 +++++++++++++++++++++++++++-----
include/scsi/scsi_cmnd.h | 1 +
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 0a70aa763a96..c37879f46eaf 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1625,26 +1625,48 @@ static blk_status_t scsi_prepare_cmd(struct request *req)
return scsi_cmd_to_driver(cmd)->init_command(cmd);
}
-void scsi_done(struct scsi_cmnd *cmd)
+static bool __scsi_done(struct scsi_cmnd *cmd)
{
switch (cmd->submitter) {
case SUBMITTED_BY_BLOCK_LAYER:
- break;
+ return false;
case SUBMITTED_BY_SCSI_ERROR_HANDLER:
- return scsi_eh_done(cmd);
+ scsi_eh_done(cmd);
+ return true;
case SUBMITTED_BY_SCSI_RESET_IOCTL:
- return;
+ return true;
}
if (unlikely(blk_should_fake_timeout(scsi_cmd_to_rq(cmd)->q)))
- return;
+ return true;
if (unlikely(test_and_set_bit(SCMD_STATE_COMPLETE, &cmd->state)))
+ return true;
+ return false;
+}
+
+void scsi_done(struct scsi_cmnd *cmd)
+{
+ if (__scsi_done(cmd))
return;
+
trace_scsi_dispatch_cmd_done(cmd);
blk_mq_complete_request(scsi_cmd_to_rq(cmd));
}
EXPORT_SYMBOL(scsi_done);
+/* Complete cmds directly, useful in preemptible instead of an interrupt. */
+void scsi_done_direct(struct scsi_cmnd *cmd)
+{
+ struct request *rq = scsi_cmd_to_rq(cmd);
+
+ if (__scsi_done(cmd))
+ return;
+
+ trace_scsi_dispatch_cmd_done(cmd);
+ blk_mq_complete_request_direct(rq, rq->q->mq_ops->complete);
+}
+EXPORT_SYMBOL(scsi_done_direct);
+
static void scsi_mq_put_budget(struct request_queue *q, int budget_token)
{
struct scsi_device *sdev = q->queuedata;
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 6794d7322cbd..ff1c4b51f7ae 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -168,6 +168,7 @@ static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
}
void scsi_done(struct scsi_cmnd *cmd);
+void scsi_done_direct(struct scsi_cmnd *cmd);
extern void scsi_finish_command(struct scsi_cmnd *cmd);
--
2.14.4.44.g2045bb6
next reply other threads:[~2022-02-08 6:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 6:37 Xiaoguang Wang [this message]
2022-02-08 6:37 ` [PATCH 2/2] scsi: target: tcm_loop: use scsi_done_direct() Xiaoguang Wang
2022-02-11 21:49 ` [PATCH 1/2] scsi: add scsi_done_direct() helper Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220208063707.4781-1-xiaoguang.wang@linux.alibaba.com \
--to=xiaoguang.wang@linux.alibaba.com \
--cc=bostroesser@gmail.com \
--cc=kanie@linux.alibaba.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox