netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] etherdevice: Optimize is_broadcast_ether_addr
@ 2024-06-13  7:34 Qingfang Deng
  2024-06-14  0:05 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Qingfang Deng @ 2024-06-13  7:34 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel
  Cc: Joe Perches, Qingfang Deng

From: Qingfang Deng <qingfang.deng@siflower.com.cn>

Like is_zero_ether_addr, is_broadcast_ether_addr can also be optimized
by using a 32-bit load if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set.
Sign extension is used to populate the upper 16-bit of the 16-bit load.

Signed-off-by: Qingfang Deng <qingfang.deng@siflower.com.cn>
---
 include/linux/etherdevice.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 2ad1ffa4ccb9..23b9cc5e299d 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -174,9 +174,14 @@ static inline bool is_local_ether_addr(const u8 *addr)
  */
 static inline bool is_broadcast_ether_addr(const u8 *addr)
 {
+#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
+	return (*(const s32 *)(addr + 0) &
+		*(const s16 *)(addr + 4)) == (s32)0xffffffff;
+#else
 	return (*(const u16 *)(addr + 0) &
 		*(const u16 *)(addr + 2) &
 		*(const u16 *)(addr + 4)) == 0xffff;
+#endif
 }
 
 /**
-- 
2.34.1


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

* Re: [PATCH net-next] etherdevice: Optimize is_broadcast_ether_addr
  2024-06-13  7:34 [PATCH net-next] etherdevice: Optimize is_broadcast_ether_addr Qingfang Deng
@ 2024-06-14  0:05 ` Jakub Kicinski
  2024-06-18  6:47   ` Qingfang Deng
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2024-06-14  0:05 UTC (permalink / raw)
  To: Qingfang Deng
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, netdev, linux-kernel,
	Joe Perches, Qingfang Deng

On Thu, 13 Jun 2024 15:34:41 +0800 Qingfang Deng wrote:
> Like is_zero_ether_addr, is_broadcast_ether_addr can also be optimized
> by using a 32-bit load if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set.
> Sign extension is used to populate the upper 16-bit of the 16-bit load.

Can you provide more context on why it's beneficial. I mean, there's a
lot of code in the kernel one could micro-optimize...

Show us the assembly, cycle counts, where it's used on fast paths...
-- 
pw-bot: cr

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

* Re: [PATCH net-next] etherdevice: Optimize is_broadcast_ether_addr
  2024-06-14  0:05 ` Jakub Kicinski
@ 2024-06-18  6:47   ` Qingfang Deng
  0 siblings, 0 replies; 3+ messages in thread
From: Qingfang Deng @ 2024-06-18  6:47 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, netdev, linux-kernel,
	Joe Perches, Qingfang Deng

Hi Jakub,

On Fri, Jun 14, 2024 at 8:05 AM Jakub Kicinski <kuba@kernel.org> wrote:
> Can you provide more context on why it's beneficial. I mean, there's a
> lot of code in the kernel one could micro-optimize...
>
> Show us the assembly, cycle counts, where it's used on fast paths...

is_broadcast_ether_addr is used in bridge forwarding fast paths
(br_dev_xmit, br_multicast_flood, br_handle_frame_finish), and often
in combination with is_multicast_ether_addr.
Since commit d54385ce68cd ("etherdev: Process is_multicast_ether_addr
at same size as other operations"), is_multicast_ether_addr already
does a 32-bit load. We can avoid duplicate loads by applying the same
approach to is_broadcast_ether_addr and save a few instructions.
Tested with x86_64, aarch64 and RISC-V compilers.

> --
> pw-bot: cr

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

end of thread, other threads:[~2024-06-18  6:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13  7:34 [PATCH net-next] etherdevice: Optimize is_broadcast_ether_addr Qingfang Deng
2024-06-14  0:05 ` Jakub Kicinski
2024-06-18  6:47   ` Qingfang Deng

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).