Message ID | 20230922093842.2646157-2-haowenchao2@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5440498vqi; Fri, 22 Sep 2023 02:49:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2VHz7y1MQGQFZddu2Rg8hMxNHskk1bQzG/l5N00fBRIlBUf2kJb6754Ym8oKalxxBOUL+ X-Received: by 2002:a05:6a20:6a11:b0:132:cd2d:16fd with SMTP id p17-20020a056a206a1100b00132cd2d16fdmr9502198pzk.38.1695376169225; Fri, 22 Sep 2023 02:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695376169; cv=none; d=google.com; s=arc-20160816; b=Tn1f5c8ZQl+DYAcfWn2+cC6u6NX5uDPGkoqaYk+AtTuEmmPbSe13455wX2nZSWfA2S mKwB7qmvRteSsbGuXQNzGtenBWIxFCk7Q++aXHEwBxDGHHtIwfH8AZyLox8pr+ykaMuU +MlnGg4XQa+beX57XyXL4pRqYYFTpNJi4vXRmTolvvgjgu7S50CrEZrZlSWr18hcOtUe TQcOYsloVIghT1nNuSYg6IYfvZV19OU76Pzj2hp32XBKhPNw64jAuYplqa8u8RZIAVHk Y6dc5+iGTZcMBTu26xO7PTMU59xL8GPUd8yPav7uE7hHXvFb4Ivlc5c8SctsHCnYaAP4 6YpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ttfCiqrtQHlqJ8AdqUYWOySmUrbqqrxCW0hA43VPY5w=; fh=czI/RuS43lIcejQG7heSpqlilKbUywFjC/3GVjzlias=; b=Selk1kvtXySydsbtPcMBV2tYnDl3uEtD3y3FTPWbqeM+GS8ruoHchd4qx4KCKi/Ri2 ZBC/DlJUcQ9m5u6t3/qjF2IiV07MTejZPOAUl6NSO49/CvjYmO+K7GhTBqlmhEK3UzEF dUH/HJhYJLIWOFVxqWKVWW6gDMdasAP/8tZTJq3NPX3/I/l8yf4UifHTkkIevl3FP2AJ 1lD/puXMzuOwX/T+mW/wlFx276U1lvwqcMgpCykrnRcy58/bbuDMeIU7/vKFQDhFYPvi kdSvA3n4R9EQg94OOKY9VL6ONPmSMue4+u10hqTp7SUTFbOLkcU4mEPGHIkW3+rFEu4e X3Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id nl14-20020a17090b384e00b0026b7f68f386si6435357pjb.73.2023.09.22.02.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:49:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4AD948342191; Fri, 22 Sep 2023 02:39:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233280AbjIVJjT (ORCPT <rfc822;chrisfriedt@gmail.com> + 30 others); Fri, 22 Sep 2023 05:39:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233253AbjIVJjO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 22 Sep 2023 05:39:14 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53C51A1; Fri, 22 Sep 2023 02:39:07 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RsRxP42zKz15NSB; Fri, 22 Sep 2023 17:36:57 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 22 Sep 2023 17:39:05 +0800 From: Wenchao Hao <haowenchao2@huawei.com> To: "James E . J . Bottomley" <jejb@linux.ibm.com>, "Martin K . Petersen" <martin.petersen@oracle.com>, <open-iscsi@googlegroups.com>, <linux-scsi@vger.kernel.org> CC: <linux-kernel@vger.kernel.org>, <louhongxiang@huawei.com>, Wenchao Hao <haowenchao2@huawei.com> Subject: [PATCH 1/2] scsi: core: cleanup scsi_dev_queue_ready() Date: Fri, 22 Sep 2023 17:38:41 +0800 Message-ID: <20230922093842.2646157-2-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230922093842.2646157-1-haowenchao2@huawei.com> References: <20230922093842.2646157-1-haowenchao2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 22 Sep 2023 02:39:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777730762141371748 X-GMAIL-MSGID: 1777730762141371748 |
Series |
cleanup patch
|
|
Commit Message
Wenchao Hao
Sept. 22, 2023, 9:38 a.m. UTC
This is just a cleanup for scsi_dev_queue_ready() to avoid
redundant goto and if statement, it did not change the origin
logic.
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
---
drivers/scsi/scsi_lib.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
Comments
On 2023/09/22 2:38, Wenchao Hao wrote: > This is just a cleanup for scsi_dev_queue_ready() to avoid > redundant goto and if statement, it did not change the origin > logic. > > Signed-off-by: Wenchao Hao <haowenchao2@huawei.com> > --- > drivers/scsi/scsi_lib.c | 35 ++++++++++++++++++----------------- > 1 file changed, 18 insertions(+), 17 deletions(-) > > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c > index ca5eb058d5c7..f3e388127dbd 100644 > --- a/drivers/scsi/scsi_lib.c > +++ b/drivers/scsi/scsi_lib.c > @@ -1254,28 +1254,29 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, > int token; > > token = sbitmap_get(&sdev->budget_map); > - if (atomic_read(&sdev->device_blocked)) { > - if (token < 0) > - goto out; > + if (token < 0) > + return -1; This is changing how this function works... > > - if (scsi_device_busy(sdev) > 1) > - goto out_dec; > + /* > + * device_blocked is not set at mostly time, so check it first > + * and return token when it is not set. > + */ > + if (!atomic_read(&sdev->device_blocked)) > + return token; ...because you reversed the tests order. > > - /* > - * unblock after device_blocked iterates to zero > - */ > - if (atomic_dec_return(&sdev->device_blocked) > 0) > - goto out_dec; > - SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, > - "unblocking device at zero depth\n")); > + /* > + * unblock after device_blocked iterates to zero > + */ > + if (scsi_device_busy(sdev) > 1 || > + atomic_dec_return(&sdev->device_blocked) > 0) { And here too, you are changing how the function works. The atomic_dec may not be done if the first condition is true. > + sbitmap_put(&sdev->budget_map, token); > + return -1; > } > > + SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, > + "unblocking device at zero depth\n")); > + > return token; > -out_dec: > - if (token >= 0) > - sbitmap_put(&sdev->budget_map, token); > -out: > - return -1; > } > > /*
On 2023/9/22 20:50, Damien Le Moal wrote: > On 2023/09/22 2:38, Wenchao Hao wrote: >> This is just a cleanup for scsi_dev_queue_ready() to avoid >> redundant goto and if statement, it did not change the origin >> logic. >> >> Signed-off-by: Wenchao Hao <haowenchao2@huawei.com> >> --- >> drivers/scsi/scsi_lib.c | 35 ++++++++++++++++++----------------- >> 1 file changed, 18 insertions(+), 17 deletions(-) >> >> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c >> index ca5eb058d5c7..f3e388127dbd 100644 >> --- a/drivers/scsi/scsi_lib.c >> +++ b/drivers/scsi/scsi_lib.c >> @@ -1254,28 +1254,29 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, >> int token; >> >> token = sbitmap_get(&sdev->budget_map); >> - if (atomic_read(&sdev->device_blocked)) { >> - if (token < 0) >> - goto out; >> + if (token < 0) >> + return -1; > > This is changing how this function works... > I don't think so... The origin function flow: static inline int scsi_dev_queue_ready(struct request_queue *q, struct scsi_device *sdev) { ... token = sbitmap_get(&sdev->budget_map); if (atomic_read(&sdev->device_blocked)) { if (token < 0) goto out; } return token; out: return -1 } If the token is less than 0, it would always return -1. So we can found it's not necessary to check token after atomic_read(). >> >> - if (scsi_device_busy(sdev) > 1) >> - goto out_dec; >> + /* >> + * device_blocked is not set at mostly time, so check it first >> + * and return token when it is not set. >> + */ >> + if (!atomic_read(&sdev->device_blocked)) >> + return token; > > ...because you reversed the tests order. As explained in comment, the device_blocked is not set at mostly time, so when it's not set, just return the token. >> >> - /* >> - * unblock after device_blocked iterates to zero >> - */ >> - if (atomic_dec_return(&sdev->device_blocked) > 0) >> - goto out_dec; >> - SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, >> - "unblocking device at zero depth\n")); >> + /* >> + * unblock after device_blocked iterates to zero >> + */ >> + if (scsi_device_busy(sdev) > 1 || >> + atomic_dec_return(&sdev->device_blocked) > 0) { > > And here too, you are changing how the function works. The atomic_dec may not be > done if the first condition is true. > the origin flow would not call atomic_dec_return() too when condition "scsi_device_busy(sdev) > 1" is true like following: static inline int scsi_dev_queue_ready(struct request_queue *q, struct scsi_device *sdev) { ... if (atomic_read(&sdev->device_blocked)) { if (scsi_device_busy(sdev) > 1) goto out_dec; /* * unblock after device_blocked iterates to zero */ if (atomic_dec_return(&sdev->device_blocked) > 0) goto out_dec; SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, "unblocking device at zero depth\n")); } return token; out_dec: if (token >= 0) sbitmap_put(&sdev->budget_map, token); out: return -1; } Here is the function before and after my change: The old function: static inline int scsi_dev_queue_ready(struct request_queue *q, struct scsi_device *sdev) { int token; token = sbitmap_get(&sdev->budget_map); if (token < 0) return -1; /* * device_blocked is not set at mostly time, so check it first * and return token when it is not set. */ if (!atomic_read(&sdev->device_blocked)) return token; /* * unblock after device_blocked iterates to zero */ if (scsi_device_busy(sdev) > 1 || atomic_dec_return(&sdev->device_blocked) > 0) { sbitmap_put(&sdev->budget_map, token); return -1; } SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, "unblocking device at zero depth\n")); return token; } Function after my change: static inline int scsi_dev_queue_ready(struct request_queue *q, struct scsi_device *sdev) { int token; token = sbitmap_get(&sdev->budget_map); if (token < 0) return -1; /* * device_blocked is not set at mostly time, so check it first * and return token when it is not set. */ if (!atomic_read(&sdev->device_blocked)) return token; /* * unblock after device_blocked iterates to zero */ if (scsi_device_busy(sdev) > 1 || atomic_dec_return(&sdev->device_blocked) > 0) { sbitmap_put(&sdev->budget_map, token); return -1; } SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, "unblocking device at zero depth\n")); return token; } I think it looks more clear and readable than before. >> + sbitmap_put(&sdev->budget_map, token); >> + return -1; >> } >> >> + SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, >> + "unblocking device at zero depth\n")); >> + >> return token; >> -out_dec: >> - if (token >= 0) >> - sbitmap_put(&sdev->budget_map, token); >> -out: >> - return -1; >> } >> >> /* >
On 2023/9/24 14:27, Wenchao Hao wrote: > On 2023/9/22 20:50, Damien Le Moal wrote: >> On 2023/09/22 2:38, Wenchao Hao wrote: >>> This is just a cleanup for scsi_dev_queue_ready() to avoid >>> redundant goto and if statement, it did not change the origin >>> logic. >>> >>> Signed-off-by: Wenchao Hao <haowenchao2@huawei.com> >>> --- >>> drivers/scsi/scsi_lib.c | 35 ++++++++++++++++++----------------- >>> 1 file changed, 18 insertions(+), 17 deletions(-) >>> >>> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c >>> index ca5eb058d5c7..f3e388127dbd 100644 >>> --- a/drivers/scsi/scsi_lib.c >>> +++ b/drivers/scsi/scsi_lib.c >>> @@ -1254,28 +1254,29 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, >>> int token; >>> token = sbitmap_get(&sdev->budget_map); >>> - if (atomic_read(&sdev->device_blocked)) { >>> - if (token < 0) >>> - goto out; >>> + if (token < 0) >>> + return -1; >> >> This is changing how this function works... >> > > I don't think so... > The origin function flow: > > static inline int scsi_dev_queue_ready(struct request_queue *q, > struct scsi_device *sdev) > { > ... > token = sbitmap_get(&sdev->budget_map); > if (atomic_read(&sdev->device_blocked)) { > if (token < 0) > goto out; > } > return token; > out: > return -1 > } > > If the token is less than 0, it would always return -1. So we can found > it's not necessary to check token after atomic_read(). > >>> - if (scsi_device_busy(sdev) > 1) >>> - goto out_dec; >>> + /* >>> + * device_blocked is not set at mostly time, so check it first >>> + * and return token when it is not set. >>> + */ >>> + if (!atomic_read(&sdev->device_blocked)) >>> + return token; >> >> ...because you reversed the tests order. > > As explained in comment, the device_blocked is not set at mostly time, > so when it's not set, just return the token. > >>> - /* >>> - * unblock after device_blocked iterates to zero >>> - */ >>> - if (atomic_dec_return(&sdev->device_blocked) > 0) >>> - goto out_dec; >>> - SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, >>> - "unblocking device at zero depth\n")); >>> + /* >>> + * unblock after device_blocked iterates to zero >>> + */ >>> + if (scsi_device_busy(sdev) > 1 || >>> + atomic_dec_return(&sdev->device_blocked) > 0) { >> >> And here too, you are changing how the function works. The atomic_dec may not be >> done if the first condition is true. >> > > the origin flow would not call atomic_dec_return() too when condition > "scsi_device_busy(sdev) > 1" is true like following: > > static inline int scsi_dev_queue_ready(struct request_queue *q, > struct scsi_device *sdev) > { > ... > if (atomic_read(&sdev->device_blocked)) { > if (scsi_device_busy(sdev) > 1) > goto out_dec; > > /* > * unblock after device_blocked iterates to zero > */ > if (atomic_dec_return(&sdev->device_blocked) > 0) > goto out_dec; > SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, > "unblocking device at zero depth\n")); > } > return token; > out_dec: > if (token >= 0) > sbitmap_put(&sdev->budget_map, token); > out: > return -1; > } > > Here is the function before and after my change: > > The old function: > static inline int scsi_dev_queue_ready(struct request_queue *q, > struct scsi_device *sdev) > { > int token; > > token = sbitmap_get(&sdev->budget_map); > if (token < 0) > return -1; > > /* > * device_blocked is not set at mostly time, so check it first > * and return token when it is not set. > */ > if (!atomic_read(&sdev->device_blocked)) > return token; > > /* > * unblock after device_blocked iterates to zero > */ > if (scsi_device_busy(sdev) > 1 || > atomic_dec_return(&sdev->device_blocked) > 0) { > sbitmap_put(&sdev->budget_map, token); > return -1; > } > > SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, > "unblocking device at zero depth\n")); > > return token; > } > Sorry, I paste wrong for old function, the old function is: static inline int scsi_dev_queue_ready(struct request_queue *q, struct scsi_device *sdev) { int token; token = sbitmap_get(&sdev->budget_map); if (atomic_read(&sdev->device_blocked)) { if (token < 0) goto out; if (scsi_device_busy(sdev) > 1) goto out_dec; /* * unblock after device_blocked iterates to zero */ if (atomic_dec_return(&sdev->device_blocked) > 0) goto out_dec; SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, "unblocking device at zero depth\n")); } return token; out_dec: if (token >= 0) sbitmap_put(&sdev->budget_map, token); out: return -1; }
On 2023/9/24 14:27, Wenchao Hao wrote: > On 2023/9/22 20:50, Damien Le Moal wrote: >> On 2023/09/22 2:38, Wenchao Hao wrote: >>> This is just a cleanup for scsi_dev_queue_ready() to avoid >>> redundant goto and if statement, it did not change the origin >>> logic. >>> >>> Signed-off-by: Wenchao Hao <haowenchao2@huawei.com> >>> --- >>> drivers/scsi/scsi_lib.c | 35 ++++++++++++++++++----------------- >>> 1 file changed, 18 insertions(+), 17 deletions(-) >>> >>> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c >>> index ca5eb058d5c7..f3e388127dbd 100644 >>> --- a/drivers/scsi/scsi_lib.c >>> +++ b/drivers/scsi/scsi_lib.c >>> @@ -1254,28 +1254,29 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, >>> int token; >>> token = sbitmap_get(&sdev->budget_map); >>> - if (atomic_read(&sdev->device_blocked)) { >>> - if (token < 0) >>> - goto out; >>> + if (token < 0) >>> + return -1; >> >> This is changing how this function works... >> > > I don't think so... > The origin function flow: > > static inline int scsi_dev_queue_ready(struct request_queue *q, > struct scsi_device *sdev) > { > ... > token = sbitmap_get(&sdev->budget_map); > if (atomic_read(&sdev->device_blocked)) { > if (token < 0) > goto out; > } > return token; > out: > return -1 > } > > If the token is less than 0, it would always return -1. So we can found > it's not necessary to check token after atomic_read(). > >>> - if (scsi_device_busy(sdev) > 1) >>> - goto out_dec; >>> + /* >>> + * device_blocked is not set at mostly time, so check it first >>> + * and return token when it is not set. >>> + */ >>> + if (!atomic_read(&sdev->device_blocked)) >>> + return token; >> >> ...because you reversed the tests order. > > As explained in comment, the device_blocked is not set at mostly time, > so when it's not set, just return the token. > Friendly ping...
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ca5eb058d5c7..f3e388127dbd 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1254,28 +1254,29 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, int token; token = sbitmap_get(&sdev->budget_map); - if (atomic_read(&sdev->device_blocked)) { - if (token < 0) - goto out; + if (token < 0) + return -1; - if (scsi_device_busy(sdev) > 1) - goto out_dec; + /* + * device_blocked is not set at mostly time, so check it first + * and return token when it is not set. + */ + if (!atomic_read(&sdev->device_blocked)) + return token; - /* - * unblock after device_blocked iterates to zero - */ - if (atomic_dec_return(&sdev->device_blocked) > 0) - goto out_dec; - SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, - "unblocking device at zero depth\n")); + /* + * unblock after device_blocked iterates to zero + */ + if (scsi_device_busy(sdev) > 1 || + atomic_dec_return(&sdev->device_blocked) > 0) { + sbitmap_put(&sdev->budget_map, token); + return -1; } + SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, + "unblocking device at zero depth\n")); + return token; -out_dec: - if (token >= 0) - sbitmap_put(&sdev->budget_map, token); -out: - return -1; } /*