From patchwork Wed Mar 7 03:21:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Gilbert X-Patchwork-Id: 10263335 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07F2760247 for ; Wed, 7 Mar 2018 03:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2F642947E for ; Wed, 7 Mar 2018 03:21:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1C2A29483; Wed, 7 Mar 2018 03:21:48 +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=-6.9 required=2.0 tests=BAYES_00,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 922682947E for ; Wed, 7 Mar 2018 03:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753996AbeCGDVr (ORCPT ); Tue, 6 Mar 2018 22:21:47 -0500 Received: from smtp.infotech.no ([82.134.31.41]:56321 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933055AbeCGDVq (ORCPT ); Tue, 6 Mar 2018 22:21:46 -0500 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id E2F872041D7; Wed, 7 Mar 2018 04:21:43 +0100 (CET) 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 F9X3U3vth2yB; Wed, 7 Mar 2018 04:21:42 +0100 (CET) Received: from xtwo70.bingwo.ca (host-184-164-15-239.dyn.295.ca [184.164.15.239]) by smtp.infotech.no (Postfix) with ESMTPA id 52CF5204247; Wed, 7 Mar 2018 04:21:41 +0100 (CET) From: Douglas Gilbert To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, jejb@linux.vnet.ibm.com, hare@suse.de, bart.vanassche@wdc.com, jthumshirn@suse.de Subject: [PATCH 4/5] scsi_io_completion: conditional hints on fastpath Date: Tue, 6 Mar 2018 22:21:33 -0500 Message-Id: <20180307032134.18978-5-dgilbert@interlog.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180307032134.18978-1-dgilbert@interlog.com> References: <20180307032134.18978-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 ChangeLog: - add likely() and unlikely() hints to conditionals on or near the fastpath - fix a comment in scsi_io_completion_action() Signed-off-by: Douglas Gilbert Reviewed-by: Johannes Thumshirn --- drivers/scsi/scsi_lib.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8d2d12a69508..23e59281bd02 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -818,7 +818,7 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result) unsigned long wait_for = (cmd->allowed + 1) * req->timeout; struct scsi_sense_hdr sshdr; bool sense_valid_and_current = false; - blk_status_t blk_stat; /* enum, BLK_STS_OK is 0 */ + blk_status_t blk_stat; /* u8, BLK_STS_OK is only 0 */ /* sense not about current command is termed: deferred */ if (scsi_command_normalize_sense(cmd, &sshdr) && @@ -1009,7 +1009,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) struct request *req = cmd->request; blk_status_t blk_stat = BLK_STS_OK; /* u8: BLK_STS_OK is only 0 */ - if (result) { + if (unlikely(result)) { blk_stat = scsi_io_completion_nz_result(cmd, result); if (blk_stat == BLK_STS_OK) result = 0; @@ -1017,14 +1017,14 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) blk_stat = BLK_STS_OK; } - if (blk_rq_is_passthrough(req)) { + if (unlikely(blk_rq_is_passthrough(req))) { /* * __scsi_error_from_host_byte may have reset the host_byte */ scsi_req(req)->result = cmd->result; scsi_req(req)->resid_len = scsi_get_resid(cmd); - if (scsi_bidi_cmnd(cmd)) { + if (unlikely(scsi_bidi_cmnd(cmd))) { /* * Bidi commands Must be complete as a whole, * both sides at once. @@ -1037,7 +1037,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) } } - /* no bidi support for !blk_rq_is_passthrough yet */ + /* no bidi support yet, other than in pass-through */ BUG_ON(blk_bidi_rq(req)); SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, cmd, @@ -1049,15 +1049,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) * handle. Failed, zero length commands always need to drop down * to retry code. Fast path should return in this block. */ - if (blk_rq_bytes(req) > 0 || blk_stat == BLK_STS_OK) { - if (!scsi_end_request(req, blk_stat, good_bytes, 0)) - return; /* no bytes remaining */ + if (likely(blk_rq_bytes(req) > 0 || blk_stat == BLK_STS_OK)) { + if (likely(!scsi_end_request(req, blk_stat, good_bytes, 0))) + return; /* no bytes remaining */ } - /* - * Kill remainder if no retrys. - */ - if (blk_stat && scsi_noretry_cmd(cmd)) { + /* Kill remainder if no retrys */ + if (unlikely(blk_stat && scsi_noretry_cmd(cmd))) { if (scsi_end_request(req, blk_stat, blk_rq_bytes(req), 0)) BUG(); return; @@ -1067,14 +1065,14 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) * If there had been no error, but we have leftover bytes in the * requeues just queue the command up again. */ - if (result == 0) { + if (likely(result == 0)) { /* * Unprep the request and put it back at the head of the * queue. A new command will be prepared and issued. * This block is the same as case ACTION_REPREP in * scsi_io_completion_action() above. */ - if (q->mq_ops) + if (likely(q->mq_ops)) scsi_mq_requeue_cmd(cmd); else { scsi_release_buffers(cmd);