diff mbox series

[net-next] etherdevice: Optimize is_broadcast_ether_addr

Message ID 20240613073441.781919-1-dqfext@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] etherdevice: Optimize is_broadcast_ether_addr | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3719 this patch: 3719
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 940 this patch: 940
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3924 this patch: 3924
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 17 this patch: 17
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-13--18-00 (tests: 647)

Commit Message

Qingfang Deng June 13, 2024, 7:34 a.m. UTC
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(+)

Comments

Jakub Kicinski June 14, 2024, 12:05 a.m. UTC | #1
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...
Qingfang Deng June 18, 2024, 6:47 a.m. UTC | #2
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
diff mbox series

Patch

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
 }
 
 /**