linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: bridge: Slightly optimize 'find_portno()'
@ 2021-11-14 19:02 Christophe JAILLET
  2021-11-15 12:35 ` Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe JAILLET @ 2021-11-14 19:02 UTC (permalink / raw)
  To: roopa, nikolay, davem, kuba
  Cc: bridge, netdev, linux-kernel, kernel-janitors, Christophe JAILLET

The 'inuse' bitmap is local to this function. So we can use the
non-atomic '__set_bit()' to save a few cycles.

While at it, also remove some useless {}.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 net/bridge/br_if.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index c1183fef1f21..64b2d4fb50f5 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -397,10 +397,10 @@ static int find_portno(struct net_bridge *br)
 	if (!inuse)
 		return -ENOMEM;
 
-	set_bit(0, inuse);	/* zero is reserved */
-	list_for_each_entry(p, &br->port_list, list) {
-		set_bit(p->port_no, inuse);
-	}
+	__set_bit(0, inuse);	/* zero is reserved */
+	list_for_each_entry(p, &br->port_list, list)
+		__set_bit(p->port_no, inuse);
+
 	index = find_first_zero_bit(inuse, BR_MAX_PORTS);
 	bitmap_free(inuse);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: bridge: Slightly optimize 'find_portno()'
  2021-11-14 19:02 [PATCH] net: bridge: Slightly optimize 'find_portno()' Christophe JAILLET
@ 2021-11-15 12:35 ` Dan Carpenter
  2021-11-15 18:35   ` Christophe JAILLET
  2021-11-15 12:57 ` Nikolay Aleksandrov
  2021-11-15 14:10 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2021-11-15 12:35 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: roopa, nikolay, davem, kuba, bridge, netdev, linux-kernel,
	kernel-janitors

On Sun, Nov 14, 2021 at 08:02:35PM +0100, Christophe JAILLET wrote:
> The 'inuse' bitmap is local to this function. So we can use the
> non-atomic '__set_bit()' to save a few cycles.
> 
> While at it, also remove some useless {}.

I like the {} and tend to add it in new code.  There isn't a rule about
this one way or the other.

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: bridge: Slightly optimize 'find_portno()'
  2021-11-14 19:02 [PATCH] net: bridge: Slightly optimize 'find_portno()' Christophe JAILLET
  2021-11-15 12:35 ` Dan Carpenter
@ 2021-11-15 12:57 ` Nikolay Aleksandrov
  2021-11-15 14:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Nikolay Aleksandrov @ 2021-11-15 12:57 UTC (permalink / raw)
  To: Christophe JAILLET, roopa, davem, kuba
  Cc: bridge, netdev, linux-kernel, kernel-janitors

On 14/11/2021 21:02, Christophe JAILLET wrote:
> The 'inuse' bitmap is local to this function. So we can use the
> non-atomic '__set_bit()' to save a few cycles.
> 
> While at it, also remove some useless {}.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  net/bridge/br_if.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index c1183fef1f21..64b2d4fb50f5 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -397,10 +397,10 @@ static int find_portno(struct net_bridge *br)
>  	if (!inuse)
>  		return -ENOMEM;
>  
> -	set_bit(0, inuse);	/* zero is reserved */
> -	list_for_each_entry(p, &br->port_list, list) {
> -		set_bit(p->port_no, inuse);
> -	}
> +	__set_bit(0, inuse);	/* zero is reserved */
> +	list_for_each_entry(p, &br->port_list, list)
> +		__set_bit(p->port_no, inuse);
> +
>  	index = find_first_zero_bit(inuse, BR_MAX_PORTS);
>  	bitmap_free(inuse);
>  
> 

This should be targeted at net-next.
The patch itself looks ok, TBH it's a slow path so speed
doesn't really matter but it's a straight-forward change.

Acked-by: Nikolay Aleksandrov <nikolay@nvidia.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: bridge: Slightly optimize 'find_portno()'
  2021-11-14 19:02 [PATCH] net: bridge: Slightly optimize 'find_portno()' Christophe JAILLET
  2021-11-15 12:35 ` Dan Carpenter
  2021-11-15 12:57 ` Nikolay Aleksandrov
@ 2021-11-15 14:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-15 14:10 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: roopa, nikolay, davem, kuba, bridge, netdev, linux-kernel,
	kernel-janitors

Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Sun, 14 Nov 2021 20:02:35 +0100 you wrote:
> The 'inuse' bitmap is local to this function. So we can use the
> non-atomic '__set_bit()' to save a few cycles.
> 
> While at it, also remove some useless {}.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> [...]

Here is the summary with links:
  - net: bridge: Slightly optimize 'find_portno()'
    https://git.kernel.org/netdev/net-next/c/cc0be1ad686f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: bridge: Slightly optimize 'find_portno()'
  2021-11-15 12:35 ` Dan Carpenter
@ 2021-11-15 18:35   ` Christophe JAILLET
  2021-11-16  8:32     ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2021-11-15 18:35 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: roopa, nikolay, davem, kuba, bridge, netdev, linux-kernel,
	kernel-janitors

Le 15/11/2021 à 13:35, Dan Carpenter a écrit :
> On Sun, Nov 14, 2021 at 08:02:35PM +0100, Christophe JAILLET wrote:
>> The 'inuse' bitmap is local to this function. So we can use the
>> non-atomic '__set_bit()' to save a few cycles.
>>
>> While at it, also remove some useless {}.
> 
> I like the {} and tend to add it in new code.  There isn't a rule about
> this one way or the other.
> 
> regards,
> dan carpenter
> 
> 
> 

Hi Dan,

- checkpatch prefers the style without {}
- Usually, greg k-h and Joe Perches give feed-back that extra {} should 
be removed.
- in https://www.kernel.org/doc/html/v5.13/process/coding-style.html, 
after "Rationale: K&R":
    "Do not unnecessarily use braces where a single statement will do."


My own preference is to have {}. It is the standard used on another 
project I work on (i.e. httpd) and it helps when you add some code (it 
avoids unexpected behavior if you forget to add some missing {})

My understanding is that on the HUGE code base of Linux, emphasis is put 
on saving some lines of code, reducing the length of lines and avoiding 
the need to read some extra char.
I'm also fine with it.

CJ

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: bridge: Slightly optimize 'find_portno()'
  2021-11-15 18:35   ` Christophe JAILLET
@ 2021-11-16  8:32     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-11-16  8:32 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: roopa, nikolay, davem, kuba, bridge, netdev, linux-kernel,
	kernel-janitors

On Mon, Nov 15, 2021 at 07:35:48PM +0100, Christophe JAILLET wrote:
> Le 15/11/2021 à 13:35, Dan Carpenter a écrit :
> > On Sun, Nov 14, 2021 at 08:02:35PM +0100, Christophe JAILLET wrote:
> > > The 'inuse' bitmap is local to this function. So we can use the
> > > non-atomic '__set_bit()' to save a few cycles.
> > > 
> > > While at it, also remove some useless {}.
> > 
> > I like the {} and tend to add it in new code.  There isn't a rule about
> > this one way or the other.
> > 

[ heavily snipped ]

> 
> - checkpatch prefers the style without {}

Not for these.

> - Usually, greg k-h and Joe Perches give feed-back that extra {} should be
> removed.

I can't find any reference to that.

> - in https://www.kernel.org/doc/html/v5.13/process/coding-style.html, after
> "Rationale: K&R":
>    "Do not unnecessarily use braces where a single statement will do."

There are exceptions for readability.  For example, mutiline indents
get it whether they need or not.  Do while statements get braces.

Quite a lot of people don't use braces for list_for_each() unless it's
required, definitely, but I think it's allowable.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-16  8:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-14 19:02 [PATCH] net: bridge: Slightly optimize 'find_portno()' Christophe JAILLET
2021-11-15 12:35 ` Dan Carpenter
2021-11-15 18:35   ` Christophe JAILLET
2021-11-16  8:32     ` Dan Carpenter
2021-11-15 12:57 ` Nikolay Aleksandrov
2021-11-15 14:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).