diff mbox series

[v2,7/7] Remove an atomic instruction from the hot path

Message ID 20190116005003.230678-8-bvanassche@acm.org (mailing list archive)
State Mainlined
Commit cd464d838041b3a69464c0dd3938c1f912487bd3
Headers show
Series sd patches for kernel v5.1 | expand

Commit Message

Bart Van Assche Jan. 16, 2019, 12:50 a.m. UTC
From scsi_init_command(), a function called by scsi_mq_prep_fn():

	/* zero out the cmd, except for the embedded scsi_request */
	memset((char *)cmd + sizeof(cmd->req), 0,
		sizeof(*cmd) - sizeof(cmd->req) + dev->host->hostt->cmd_size);

In other words, scsi_mq_prep_fn() clears scsi_cmnd.flags. Hence move
the clear_bit() call into the else branch, the only branch in which
this code is necessary.

See also commit f1342709d18a ("scsi: Do not rely on blk-mq for double
completions").

Cc: Keith Busch <keith.busch@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Keith Busch Jan. 16, 2019, 1:10 a.m. UTC | #1
On Tue, Jan 15, 2019 at 04:50:03PM -0800, Bart Van Assche wrote:
> From scsi_init_command(), a function called by scsi_mq_prep_fn():
> 
> 	/* zero out the cmd, except for the embedded scsi_request */
> 	memset((char *)cmd + sizeof(cmd->req), 0,
> 		sizeof(*cmd) - sizeof(cmd->req) + dev->host->hostt->cmd_size);
> 
> In other words, scsi_mq_prep_fn() clears scsi_cmnd.flags. Hence move
> the clear_bit() call into the else branch, the only branch in which
> this code is necessary.

Right, good call. You can even safely use "cmd->state = 0" in this
path instead of clear_bit(), but last time there were objections to
it looking inconsistent with the completion+timeout paths that use it
atomicly. Anyway,

Reviewed-by: Keith Busch <keith.busch@intel.com>
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index b13cc9288ba0..00cd365fb7d2 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1712,13 +1712,13 @@  static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
 	if (!scsi_host_queue_ready(q, shost, sdev))
 		goto out_dec_target_busy;
 
-	clear_bit(SCMD_STATE_COMPLETE, &cmd->state);
 	if (!(req->rq_flags & RQF_DONTPREP)) {
 		ret = scsi_mq_prep_fn(req);
 		if (ret != BLK_STS_OK)
 			goto out_dec_host_busy;
 		req->rq_flags |= RQF_DONTPREP;
 	} else {
+		clear_bit(SCMD_STATE_COMPLETE, &cmd->state);
 		blk_mq_start_request(req);
 	}