[29/34] net: smc: fix opencoded find_and_set_bit() in smc_wr_tx_get_free_slot_index()
Message ID | 20231118155105.25678-30-yury.norov@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1242669vqn; Sat, 18 Nov 2023 07:56:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEK8JTBfwCJgG7VJI5aybp79kbOKhd4vyKsXgzHk+dnlbRYz14tTVXiYolUbRl5fBHzAgbI X-Received: by 2002:a05:6a20:a11a:b0:188:1282:4f5f with SMTP id q26-20020a056a20a11a00b0018812824f5fmr2170877pzk.54.1700323018658; Sat, 18 Nov 2023 07:56:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700323018; cv=none; d=google.com; s=arc-20160816; b=ieCmQ9yZmfDVuv649kxvMy5mPWj7tb3eLw9ckxsvSVt/5hx9nFoEhiQqAY4wjTAye/ yTp0BRamck45jJrEXuGOMLet292RmnUw3hOBcLPJv9ewO1yKcFaudHqyTYEQFX5xhstS ttbiTft2lk4+cJxxzV+RhZhfC73dJ7OgcN7UmRrQ237RpZse0hJiQiFXyGmDWxnb4JN/ wU5a6IY46Amc/ewxYx7ax9XUp2rPPgPVKnv0CNftJH/RdHt2mOxEZKkCIfXgXv69+kJH kLPlWfN/O7ccmdJxy/lNlJ0YDLRD5F0M8AnoWMgwf/+DSfdlv7SS8skWbnluWUs7jWFL vxEg== 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 :dkim-signature; bh=FRJAi9fqLnpZBQBfWveY0fRnarAyBBO44GyImL+GpQw=; fh=NDbNaXA2hK0c5MfpGj9WKM2VAZappZ1nAgV0cz2V4IE=; b=Q+1XvZbDmNnyjnbELVEZzxZOYdl+xqO7xb7XnohVjr7jPnZOxS3P7XmvdyDTJcpIFY TFPusP+thIljaYtBUgxgPDOLqNR12uTQ6qQw/v+8dYIvegb8fWpMiar9ekbHSQvR3PD5 3q06qumgd2+vxaUgYy7YiOlVUO/Tg66vq9zclzzZvyl0+729Ea4E3kaSLN7DZNf0mYMT 1TbwsGmwZO+isUzNwxmtRGSfbNnb0bw+Hn9c+nd1PFY18ZBEpPApZ07rOaVHewuPclzh fOdi3yj49XP79DoqyPM8Upus8Ca037/Pdk0wA9AnsqI93Pt5e77U+PGrik2uKW4ytKiw xGmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="IT8+IBr/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z2-20020a056a00240200b006be0278445esi4527159pfh.138.2023.11.18.07.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:56:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="IT8+IBr/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A2CFF8087B5A; Sat, 18 Nov 2023 07:56:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbjKRPyl (ORCPT <rfc822;jaysivo@gmail.com> + 29 others); Sat, 18 Nov 2023 10:54:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbjKRPxf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 18 Nov 2023 10:53:35 -0500 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27F821FF3; Sat, 18 Nov 2023 07:51:54 -0800 (PST) Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-da3b4b7c6bdso2917083276.2; Sat, 18 Nov 2023 07:51:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700322712; x=1700927512; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FRJAi9fqLnpZBQBfWveY0fRnarAyBBO44GyImL+GpQw=; b=IT8+IBr/GjwsHiuzp7JbGVGoUMD6y1ZMGmXhJaeFaN9TrOcyttSLuKo4qdu1SmXbcG VgMptIT0UAnXXPkr+htmJdWc8gttbfZJkgEawCYNoL3m1PmHFpTdb/1VYtDUa07e+tWc YjIfSHyIXopdgUYFRwTlxcaaOtQKI762QKvW8zdhLUU+jOHItUV2D9HlB/xKYgi2d27J Tx+DKwf0B/ilLwI6vSXqzgjVkD61+aQRmW9T+9xlfrfdXzy9qxHVkFY/cat075drS2di /foAu1lF96mWe7J41kM2yRloUptbCXY6fjPpShM53bkrQJ+krv3IFOWamSUUxClDXG39 4i5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700322712; x=1700927512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FRJAi9fqLnpZBQBfWveY0fRnarAyBBO44GyImL+GpQw=; b=mDBnc/xl3/t16XUHfApkuAktgGMjkyxeKEp9vBN0+hxNFXHTqEHzokNr9YK+VsAsKF FTOEo88in//BEuOU0B3wE8a0L9+6hYJj6TTNznIDk6yy2RaI95MssBIIKBq3Pd0NqI2z wDmH0xpka0HJQ8tgr3kdtTHoi8X0k4U4itbl1aEUWeTU4MKfRPQx3L6BrlEsMVUilQOE aw9m9jzk/Ciy6b3vDILc+FOIFiXzC2zN4SUIe+v+grOfQSWlrcugQQI22Xikx7qyYfVd L+leu3AqRb6r2KsJ0iU0Hv0PYJOwZQ/KjYo7Cnn9/kSZ+yzld/NPLvH/drU8h4DrTGA+ KPSQ== X-Gm-Message-State: AOJu0Yy+Fkdbs3cozq22sc2AkHohJpbMBiASZs2x7WLhVxu9P0cdIjUm 8J08UJJ4YcruDo/4vry5oWqTLuzICP1NQ/lp X-Received: by 2002:a05:6902:212:b0:d9a:d7a5:e445 with SMTP id j18-20020a056902021200b00d9ad7a5e445mr2342423ybs.49.1700322711961; Sat, 18 Nov 2023 07:51:51 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:48a9:bd4c:868d:dc97]) by smtp.gmail.com with ESMTPSA id e62-20020a25a3c4000000b00da10d9e96cesm1006690ybi.35.2023.11.18.07.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:51:51 -0800 (PST) From: Yury Norov <yury.norov@gmail.com> To: linux-kernel@vger.kernel.org, Karsten Graul <kgraul@linux.ibm.com>, Wenjia Zhang <wenjia@linux.ibm.com>, Jan Karcher <jaka@linux.ibm.com>, "D. Wythe" <alibuda@linux.alibaba.com>, Tony Lu <tonylu@linux.alibaba.com>, Wen Gu <guwen@linux.alibaba.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-s390@vger.kernel.org, netdev@vger.kernel.org Cc: Yury Norov <yury.norov@gmail.com>, Jan Kara <jack@suse.cz>, Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>, Matthew Wilcox <willy@infradead.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>, Alexey Klimov <klimov.linux@gmail.com> Subject: [PATCH 29/34] net: smc: fix opencoded find_and_set_bit() in smc_wr_tx_get_free_slot_index() Date: Sat, 18 Nov 2023 07:51:00 -0800 Message-Id: <20231118155105.25678-30-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231118155105.25678-1-yury.norov@gmail.com> References: <20231118155105.25678-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Sat, 18 Nov 2023 07:56:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782917909240746674 X-GMAIL-MSGID: 1782917909240746674 |
Series |
biops: add atomig find_bit() operations
|
|
Commit Message
Yury Norov
Nov. 18, 2023, 3:51 p.m. UTC
The function opencodes find_and_set_bit() with a for_each() loop. Fix
it, and make the whole function a simple almost one-liner.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
net/smc/smc_wr.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
Comments
On 18.11.23 16:51, Yury Norov wrote: > The function opencodes find_and_set_bit() with a for_each() loop. Fix > it, and make the whole function a simple almost one-liner. > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > --- > net/smc/smc_wr.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c > index 0021065a600a..b6f0cfc52788 100644 > --- a/net/smc/smc_wr.c > +++ b/net/smc/smc_wr.c > @@ -170,15 +170,11 @@ void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context) > > static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx) > { > - *idx = link->wr_tx_cnt; > if (!smc_link_sendable(link)) > return -ENOLINK; > - for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { > - if (!test_and_set_bit(*idx, link->wr_tx_mask)) > - return 0; > - } > - *idx = link->wr_tx_cnt; > - return -EBUSY; > + > + *idx = find_and_set_bit(link->wr_tx_mask, link->wr_tx_cnt); > + return *idx < link->wr_tx_cnt ? 0 : -EBUSY; > } > > /** My understanding is that you can omit the lines with > - *idx = link->wr_tx_cnt; because they only apply to the error paths and you checked that the calling function does not use the idx variable in the error cases. Do I understand this correct? If so the removal of these 2 lines is not related to your change of using find_and_set_bit(), do I understand that correctly? If so, it may be worth mentioning that in the commit message.
The prefix tag and subject imply that it is a bugfix. I think, first, it should be a new feature with net-next tag. Also please use net/smc as prefix. Thanks, Tony Lu On Sat, Nov 18, 2023 at 07:51:00AM -0800, Yury Norov wrote: > The function opencodes find_and_set_bit() with a for_each() loop. Fix > it, and make the whole function a simple almost one-liner. > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > --- > net/smc/smc_wr.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c > index 0021065a600a..b6f0cfc52788 100644 > --- a/net/smc/smc_wr.c > +++ b/net/smc/smc_wr.c > @@ -170,15 +170,11 @@ void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context) > > static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx) > { > - *idx = link->wr_tx_cnt; > if (!smc_link_sendable(link)) > return -ENOLINK; > - for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { > - if (!test_and_set_bit(*idx, link->wr_tx_mask)) > - return 0; > - } > - *idx = link->wr_tx_cnt; > - return -EBUSY; > + > + *idx = find_and_set_bit(link->wr_tx_mask, link->wr_tx_cnt); > + return *idx < link->wr_tx_cnt ? 0 : -EBUSY; > } > > /** > -- > 2.39.2
On Mon, Nov 20, 2023 at 09:43:54AM +0100, Alexandra Winter wrote: > > > On 18.11.23 16:51, Yury Norov wrote: > > The function opencodes find_and_set_bit() with a for_each() loop. Fix > > it, and make the whole function a simple almost one-liner. > > > > Signed-off-by: Yury Norov <yury.norov@gmail.com> > > --- > > net/smc/smc_wr.c | 10 +++------- > > 1 file changed, 3 insertions(+), 7 deletions(-) > > > > diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c > > index 0021065a600a..b6f0cfc52788 100644 > > --- a/net/smc/smc_wr.c > > +++ b/net/smc/smc_wr.c > > @@ -170,15 +170,11 @@ void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context) > > > > static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx) > > { > > - *idx = link->wr_tx_cnt; > > if (!smc_link_sendable(link)) > > return -ENOLINK; > > - for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { > > - if (!test_and_set_bit(*idx, link->wr_tx_mask)) > > - return 0; > > - } > > - *idx = link->wr_tx_cnt; > > - return -EBUSY; > > + > > + *idx = find_and_set_bit(link->wr_tx_mask, link->wr_tx_cnt); > > + return *idx < link->wr_tx_cnt ? 0 : -EBUSY; > > } > > > > /** > > > My understanding is that you can omit the lines with > > - *idx = link->wr_tx_cnt; > because they only apply to the error paths and you checked that the calling function > does not use the idx variable in the error cases. Do I understand this correct? > > If so the removal of these 2 lines is not related to your change of using find_and_set_bit(), > do I understand that correctly? > > If so, it may be worth mentioning that in the commit message. I'll add: If find_and_set_bit() doesn't acquire a bit, it returns ->wr_tx_cnt, and so explicit initialization of *idx with the same value is unneeded. Makes sense?
On 21.11.23 14:41, Yury Norov wrote: > On Mon, Nov 20, 2023 at 09:43:54AM +0100, Alexandra Winter wrote: >> >> >> On 18.11.23 16:51, Yury Norov wrote: >>> The function opencodes find_and_set_bit() with a for_each() loop. Fix >>> it, and make the whole function a simple almost one-liner. >>> >>> Signed-off-by: Yury Norov <yury.norov@gmail.com> >>> --- >>> net/smc/smc_wr.c | 10 +++------- >>> 1 file changed, 3 insertions(+), 7 deletions(-) >>> >>> diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c >>> index 0021065a600a..b6f0cfc52788 100644 >>> --- a/net/smc/smc_wr.c >>> +++ b/net/smc/smc_wr.c >>> @@ -170,15 +170,11 @@ void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context) >>> >>> static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx) >>> { >>> - *idx = link->wr_tx_cnt; >>> if (!smc_link_sendable(link)) >>> return -ENOLINK; >>> - for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { >>> - if (!test_and_set_bit(*idx, link->wr_tx_mask)) >>> - return 0; >>> - } >>> - *idx = link->wr_tx_cnt; >>> - return -EBUSY; >>> + >>> + *idx = find_and_set_bit(link->wr_tx_mask, link->wr_tx_cnt); >>> + return *idx < link->wr_tx_cnt ? 0 : -EBUSY; >>> } >>> >>> /** >> >> >> My understanding is that you can omit the lines with >>> - *idx = link->wr_tx_cnt; >> because they only apply to the error paths and you checked that the calling function >> does not use the idx variable in the error cases. Do I understand this correct? >> >> If so the removal of these 2 lines is not related to your change of using find_and_set_bit(), >> do I understand that correctly? >> >> If so, it may be worth mentioning that in the commit message. > > I'll add: > > If find_and_set_bit() doesn't acquire a bit, it returns > ->wr_tx_cnt, and so explicit initialization of *idx with > the same value is unneeded. > > Makes sense? > Makes sense for the -EBUSY case, thank you. It does not explain that you also removed the line for the -ENOLINK case (which is ok, because the caller has also initialized it to link->wr_tx_cnt)
diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c index 0021065a600a..b6f0cfc52788 100644 --- a/net/smc/smc_wr.c +++ b/net/smc/smc_wr.c @@ -170,15 +170,11 @@ void smc_wr_tx_cq_handler(struct ib_cq *ib_cq, void *cq_context) static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx) { - *idx = link->wr_tx_cnt; if (!smc_link_sendable(link)) return -ENOLINK; - for_each_clear_bit(*idx, link->wr_tx_mask, link->wr_tx_cnt) { - if (!test_and_set_bit(*idx, link->wr_tx_mask)) - return 0; - } - *idx = link->wr_tx_cnt; - return -EBUSY; + + *idx = find_and_set_bit(link->wr_tx_mask, link->wr_tx_cnt); + return *idx < link->wr_tx_cnt ? 0 : -EBUSY; } /**