Message ID | c94fb1b4dcd9a04eff08cf9ba2444c348477e554.1682023416.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp612233vqo; Thu, 20 Apr 2023 14:00:56 -0700 (PDT) X-Google-Smtp-Source: AKy350b3PyNVcWNQipkIC6BUXZo44BQHa8EKwawFw3Mh/fX7ahkhmYitUYtnD8pqPCRsS3aQfxpa X-Received: by 2002:a05:6a20:548c:b0:ef:88c8:90ec with SMTP id i12-20020a056a20548c00b000ef88c890ecmr4370845pzk.10.1682024455815; Thu, 20 Apr 2023 14:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682024455; cv=none; d=google.com; s=arc-20160816; b=WwNU2GRf2Zwv5Rf0Qv1FyJrS7U3CM/rGzGLbeic47ltMbVOCiP+nXSxL7QSOatX6mg PIylNXGA+J5D9//7eIBcTvzibsdlR1aq0FxezBB+nWNr37vERWu1T6tXQXaC26O5/1M+ z4+eeHhEFT0pBtzXIUgAQbpqOXbH4yoArxK1ftXpwgoqnlaTG3j7LLDVR85TDG9nqrEn kMz3CsM6otTYUgWEK/YizQ1Z4YrM//wbLBibB8Uqv6By1qgcMV10qi+beZXNwVOK63fH FhEX3vt8aDw1QzbKTXr2hwMibVwKXKxcREe8u3Elr0cKqrZhINd2uZbVFFeUChNcQghS GGTA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=a/xPA7tF/CGArRsFpwm1r+BaXbXOHoj1SyeyiFZc7Ow=; b=piFJ0E9qyRPNJPaw0b4F3Ynnhmttix2ZL9wxhoWRGqXhTA0CsfTRcjKrghvu78UOBZ EAvSvZi0Uw2ZTA4sQqQCE92Ag0URZov8WWncNr9RMVTz4RUhw8jVujxx6ZqedXUXfA3Q 2PLrSnscivywPCLYU/+dLu1x1AIIpoTUhkjok+LNQB+/SLP770pZ6apgc+RCCTZtLrlW SdAsl0TTEGioXsHBA2HrFn5AZcypGVk6vAz+JF4jpDyOa1JvnrXmttyRRPrlIRFK8B77 a3cCKAvdEB9fLvkDRt+A1CBeuFR55qtcXF+gUu71TABSp2q2H6Q36iokigQ+ZHiJF0dx GEqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=OaSdxjWr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a65430d000000b0051f265b549dsi2451881pgq.346.2023.04.20.14.00.42; Thu, 20 Apr 2023 14:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=OaSdxjWr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232410AbjDTUo2 (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Thu, 20 Apr 2023 16:44:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjDTUoT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Apr 2023 16:44:19 -0400 Received: from smtp.smtpout.orange.fr (smtp-22.smtpout.orange.fr [80.12.242.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C7035AA for <linux-kernel@vger.kernel.org>; Thu, 20 Apr 2023 13:44:16 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id pb8WpIj6fkuIhpb8WpSgq7; Thu, 20 Apr 2023 22:44:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1682023455; bh=a/xPA7tF/CGArRsFpwm1r+BaXbXOHoj1SyeyiFZc7Ow=; h=From:To:Cc:Subject:Date; b=OaSdxjWr68FBxCGG8hbo0vS4DKWX0NNIIIEp/bdFq016Hd/w9DvX0ITh2xvM6xYmn gQ2YqFCBgq+RkCNDXDw5QAzjNhtvsqz85OGRYL4bxraJQYQPUI8BQAx5gbVk0rPbu+ wpQNSRjfbb2fjFnRt+rieHruLqwCM68p3WVnbGAmoG/a3ltWiUydNj0ZvvcE7b2URg 0Y6/zAlrTmgabtK2VMYp6wonj3EJAkQRHowrg81Q3aU+ZGmXmZ7EbDrNGJUCX8wriV j0zCaVEy/fEPz5JVyLK2ru0tQWG2umnvVUEUuLEm5YAzRcxyzMxoaHuHlnmMjjN3oP FoDhnmwNLH7fA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 20 Apr 2023 22:44:15 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Florian Fainelli <f.fainelli@gmail.com>, Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, netdev@vger.kernel.org Subject: [PATCH net-next] net: dsa: b53: Slightly optimize b53_arl_read() Date: Thu, 20 Apr 2023 22:44:10 +0200 Message-Id: <c94fb1b4dcd9a04eff08cf9ba2444c348477e554.1682023416.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763730476137349880?= X-GMAIL-MSGID: =?utf-8?q?1763730476137349880?= |
Series |
[net-next] net: dsa: b53: Slightly optimize b53_arl_read()
|
|
Commit Message
Christophe JAILLET
April 20, 2023, 8:44 p.m. UTC
When the 'free_bins' bitmap is cleared, it is better to use its full
maximum size instead of only the needed size.
This lets the compiler optimize it because the size is now known at compile
time. B53_ARLTBL_MAX_BIN_ENTRIES is small (i.e. currently 4), so a call to
memset() is saved.
Also, as 'free_bins' is local to the function, the non-atomic __set_bit()
can also safely be used here.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/net/dsa/b53/b53_common.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On 4/20/2023 1:44 PM, Christophe JAILLET wrote: > When the 'free_bins' bitmap is cleared, it is better to use its full > maximum size instead of only the needed size. > This lets the compiler optimize it because the size is now known at compile > time. B53_ARLTBL_MAX_BIN_ENTRIES is small (i.e. currently 4), so a call to > memset() is saved. > > Also, as 'free_bins' is local to the function, the non-atomic __set_bit() > can also safely be used here. > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > drivers/net/dsa/b53/b53_common.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c > index 3464ce5e7470..8c55fe0e0747 100644 > --- a/drivers/net/dsa/b53/b53_common.c > +++ b/drivers/net/dsa/b53/b53_common.c > @@ -1627,7 +1627,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, > if (ret) > return ret; > > - bitmap_zero(free_bins, dev->num_arl_bins); > + bitmap_zero(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES); That one I am not a big fan, as the number of ARL bins is a function of the switch model, and this illustrates it well. > > /* Read the bins */ > for (i = 0; i < dev->num_arl_bins; i++) { > @@ -1641,7 +1641,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, > b53_arl_to_entry(ent, mac_vid, fwd_entry); > > if (!(fwd_entry & ARLTBL_VALID)) { > - set_bit(i, free_bins); > + __set_bit(i, free_bins); I would be keen on taking that hunk but keep the other as-is. Does that work for you? -- Florian
Le 21/04/2023 à 02:40, Florian Fainelli a écrit : > > > On 4/20/2023 1:44 PM, Christophe JAILLET wrote: >> When the 'free_bins' bitmap is cleared, it is better to use its full >> maximum size instead of only the needed size. >> This lets the compiler optimize it because the size is now known at >> compile >> time. B53_ARLTBL_MAX_BIN_ENTRIES is small (i.e. currently 4), so a >> call to >> memset() is saved. >> >> Also, as 'free_bins' is local to the function, the non-atomic __set_bit() >> can also safely be used here. >> >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> >> --- >> drivers/net/dsa/b53/b53_common.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/net/dsa/b53/b53_common.c >> b/drivers/net/dsa/b53/b53_common.c >> index 3464ce5e7470..8c55fe0e0747 100644 >> --- a/drivers/net/dsa/b53/b53_common.c >> +++ b/drivers/net/dsa/b53/b53_common.c >> @@ -1627,7 +1627,7 @@ static int b53_arl_read(struct b53_device *dev, >> u64 mac, >> if (ret) >> return ret; >> - bitmap_zero(free_bins, dev->num_arl_bins); >> + bitmap_zero(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES); > > That one I am not a big fan, as the number of ARL bins is a function of > the switch model, and this illustrates it well. Ok, up to you to take or not what looks the better solution. From my point of view, the "for (i = 0; i < dev->num_arl_bins" below illustrates it better. Maybe, another approach to save the memset() call would be remove the bitmap_zero() call, and declare 'free_bins' as: DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES) = { }; (this syntax is already used in b53_configure_vlan()) The compiler should still be able to optimize the initialisation and this wouldn't, IMHO, introduce confusion about the intent. Let me know if you prefer to leave this hunk as-is, or if this other alternative pleases you. CJ > >> /* Read the bins */ >> for (i = 0; i < dev->num_arl_bins; i++) { >> @@ -1641,7 +1641,7 @@ static int b53_arl_read(struct b53_device *dev, >> u64 mac, >> b53_arl_to_entry(ent, mac_vid, fwd_entry); >> if (!(fwd_entry & ARLTBL_VALID)) { >> - set_bit(i, free_bins); >> + __set_bit(i, free_bins); > > I would be keen on taking that hunk but keep the other as-is. Does that > work for you? > -- > Florian >
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 3464ce5e7470..8c55fe0e0747 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -1627,7 +1627,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, if (ret) return ret; - bitmap_zero(free_bins, dev->num_arl_bins); + bitmap_zero(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES); /* Read the bins */ for (i = 0; i < dev->num_arl_bins; i++) { @@ -1641,7 +1641,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, b53_arl_to_entry(ent, mac_vid, fwd_entry); if (!(fwd_entry & ARLTBL_VALID)) { - set_bit(i, free_bins); + __set_bit(i, free_bins); continue; } if ((mac_vid & ARLTBL_MAC_MASK) != mac)