From patchwork Mon Aug 6 04:51:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Gilbert X-Patchwork-Id: 10556483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EB99174A for ; Mon, 6 Aug 2018 04:51:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A47328FFB for ; Mon, 6 Aug 2018 04:51:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E5EA29006; Mon, 6 Aug 2018 04:51:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3F3528FFE for ; Mon, 6 Aug 2018 04:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726942AbeHFG6q (ORCPT ); Mon, 6 Aug 2018 02:58:46 -0400 Received: from smtp.infotech.no ([82.134.31.41]:35032 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbeHFG6o (ORCPT ); Mon, 6 Aug 2018 02:58:44 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id 07817204247; Mon, 6 Aug 2018 06:51:27 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.6.6 (20110518) (Debian) at infotech.no Received: from smtp.infotech.no ([127.0.0.1]) by localhost (smtp.infotech.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8vytXK1Q9OGm; Mon, 6 Aug 2018 06:51:25 +0200 (CEST) Received: from xtwo70.bingwo.ca (host-45-58-245-67.dyn.295.ca [45.58.245.67]) by smtp.infotech.no (Postfix) with ESMTPA id 7B16E20423B; Mon, 6 Aug 2018 06:51:23 +0200 (CEST) From: Douglas Gilbert To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, hare@suse.de, bart.vanassche@wdc.com, jthumshirn@suse.de Subject: [RFC PATCH 4/5] streamline some logical operations Date: Mon, 6 Aug 2018 00:51:14 -0400 Message-Id: <20180806045115.7725-5-dgilbert@interlog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180806045115.7725-1-dgilbert@interlog.com> References: <20180806045115.7725-1-dgilbert@interlog.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Re-arrange some logic to lessen the number of checks. With logical ANDs put the least likely first, with logical ORs put the most likely first. Also add conditional hints on the assumed fastpath. Signed-off-by: Douglas Gilbert --- drivers/scsi/sd.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 9f047fd3c92d..05014054e357 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1171,9 +1171,9 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) fua = (rq->cmd_flags & REQ_FUA) ? 0x8 : 0; dix = scsi_prot_sg_count(cmd); - dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); + dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type); - if (write && dix) + if (dix && write) sd_dif_prepare(cmd); if (dif || dix) @@ -1181,19 +1181,27 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) else protect = 0; - if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { + if (unlikely(protect && + sdkp->protection_type == T10_PI_TYPE2_PROTECTION)) ret = sd_setup_read_write_32_cmnd(cmd, write, lba, nr_blocks, protect | fua); - } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { + else if (sdp->use_16_for_rw) ret = sd_setup_read_write_16_cmnd(cmd, write, lba, nr_blocks, protect | fua); - } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || sdp->use_10_for_rw - || protect) { - ret = sd_setup_read_write_10_cmnd(cmd, write, lba, nr_blocks, - protect | fua); - } else { - ret = sd_setup_read_write_6_cmnd(cmd, write, lba, nr_blocks, - protect | fua); + else if (likely(nr_blocks < 0x100)) { + if (sdp->use_10_for_rw || (lba > 0x1fffff) || protect) + ret = sd_setup_read_write_10_cmnd(cmd, write, lba, + nr_blocks, protect | fua); + else + ret = sd_setup_read_write_6_cmnd(cmd, write, lba, + nr_blocks, protect | fua); + } else { /* not already done and nr_blocks > 0xff */ + if (unlikely(nr_blocks > 0xffff)) + ret = sd_setup_read_write_16_cmnd(cmd, write, lba, + nr_blocks, protect | fua); + else + ret = sd_setup_read_write_10_cmnd(cmd, write, lba, + nr_blocks, protect | fua); } if (ret != BLKPREP_OK) @@ -1976,7 +1984,6 @@ static int sd_done(struct scsi_cmnd *SCpnt) struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk); struct request *req = SCpnt->request; int sense_valid = 0; - int sense_deferred = 0; /* * Assumption that REQ_OP_READ and REQ_OP_WRITE are 0 and 1 is @@ -2030,16 +2037,14 @@ static int sd_done(struct scsi_cmnd *SCpnt) } } - if (result) { + if (unlikely(result)) { sense_valid = scsi_command_normalize_sense(SCpnt, &sshdr); - if (sense_valid) - sense_deferred = scsi_sense_is_deferred(&sshdr); + if (driver_byte(result) == DRIVER_SENSE || + (sense_valid && (!scsi_sense_is_deferred(&sshdr)))) + good_bytes = sd_done_sense(SCpnt, good_bytes, &sshdr); } - sdkp->medium_access_timed_out = 0; - if (unlikely(driver_byte(result) == DRIVER_SENSE || - (sense_valid && !sense_deferred))) - good_bytes = sd_done_sense(SCpnt, good_bytes, &sshdr); + sdkp->medium_access_timed_out = 0; if (sd_is_zoned(sdkp)) sd_zbc_complete(SCpnt, good_bytes, &sshdr);