diff mbox series

[net-next] net: ethernet: Move eth_*_addr_base to global symbols

Message ID 20240409160720.154470-2-diogo.ivo@siemens.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: ethernet: Move eth_*_addr_base to global symbols | 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: 3799 this patch: 3799
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1047 this patch: 1047
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: 4014 this patch: 4014
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 39 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 31 this patch: 31
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-11--00-00 (tests: 959)

Commit Message

Diogo Ivo April 9, 2024, 4:07 p.m. UTC
Promote IPv4/6 and Ethernet reserved base addresses to global symbols
to avoid local copies being created when these addresses are referenced.

Signed-off-by: Diogo Ivo <diogo.ivo@siemens.com>
---
 include/linux/etherdevice.h | 10 +++-------
 net/ethernet/eth.c          | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 7 deletions(-)

Comments

Jakub Kicinski April 9, 2024, 9:58 p.m. UTC | #1
On Tue,  9 Apr 2024 17:07:18 +0100 Diogo Ivo wrote:
> Promote IPv4/6 and Ethernet reserved base addresses to global symbols
> to avoid local copies being created when these addresses are referenced.

Did someone bloat-o-meter this?
I agree it's odd but the values are tiny and I'd expect compiler 
to eliminate the dead instances.
I mean, the instances are literally smaller than a pointer we'll
need to refer to them, if they can be inlined..
Alexander Lobakin April 10, 2024, 11:48 a.m. UTC | #2
From: Jakub Kicinski <kuba@kernel.org>
Date: Tue, 9 Apr 2024 14:58:35 -0700

> On Tue,  9 Apr 2024 17:07:18 +0100 Diogo Ivo wrote:
>> Promote IPv4/6 and Ethernet reserved base addresses to global symbols
>> to avoid local copies being created when these addresses are referenced.
> 
> Did someone bloat-o-meter this?

bloat-o-meter would be good, right.

> I agree it's odd but the values are tiny and I'd expect compiler 
> to eliminate the dead instances.

The compiler won't copy the arrays to each file which includes
ethernet.h obviously.

> I mean, the instances are literally smaller than a pointer we'll
> need to refer to them, if they can be inlined..

The compilers are sometimes even able to inline extern consts. So,
without bloat-o-meter, I wouldn't assume anything at all :)

Thanks,
Olek
Alexander Lobakin April 10, 2024, 12:49 p.m. UTC | #3
From: Alexander Lobakin <aleksander.lobakin@intel.com>
Date: Wed, 10 Apr 2024 13:48:54 +0200

> From: Jakub Kicinski <kuba@kernel.org>
> Date: Tue, 9 Apr 2024 14:58:35 -0700
> 
>> On Tue,  9 Apr 2024 17:07:18 +0100 Diogo Ivo wrote:
>>> Promote IPv4/6 and Ethernet reserved base addresses to global symbols
>>> to avoid local copies being created when these addresses are referenced.
>>
>> Did someone bloat-o-meter this?
> 
> bloat-o-meter would be good, right.
> 
>> I agree it's odd but the values are tiny and I'd expect compiler 
>> to eliminate the dead instances.
> 
> The compiler won't copy the arrays to each file which includes
> ethernet.h obviously.
> 
>> I mean, the instances are literally smaller than a pointer we'll
>> need to refer to them, if they can be inlined..
> 
> The compilers are sometimes even able to inline extern consts. So,
> without bloat-o-meter, I wouldn't assume anything at all :)

Kuba is right, converting them to globals only hurts.

vmlinux before/after the patch:

text: add/remove: 0/0 grow/shrink: 2/0 up/down: 16/0 (16)
text: add/remove: 3/0 grow/shrink: 0/0 up/down: 18/0 (18)

Simple module which uses static inlines referencing these arrays:

text: add/remove: 0/0 grow/shrink: 4/0 up/down: 75/0 (75)

I'm sorry that I suggested this anti-improvement :z
Please reject this patch.

Thanks,
Olek
diff mbox series

Patch

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 8d6daf828427..6002dabca0f8 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -67,15 +67,11 @@  struct sk_buff *eth_gro_receive(struct list_head *head, struct sk_buff *skb);
 int eth_gro_complete(struct sk_buff *skb, int nhoff);
 
 /* Reserved Ethernet Addresses per IEEE 802.1Q */
-static const u8 eth_reserved_addr_base[ETH_ALEN] __aligned(2) =
-{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
+extern const u8 eth_reserved_addr_base[ETH_ALEN];
 #define eth_stp_addr eth_reserved_addr_base
 
-static const u8 eth_ipv4_mcast_addr_base[ETH_ALEN] __aligned(2) =
-{ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
-
-static const u8 eth_ipv6_mcast_addr_base[ETH_ALEN] __aligned(2) =
-{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 };
+extern const u8 eth_ipv4_mcast_addr_base[ETH_ALEN];
+extern const u8 eth_ipv6_mcast_addr_base[ETH_ALEN];
 
 /**
  * is_link_local_ether_addr - Determine if given Ethernet address is link-local
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 2edc8b796a4e..8141e5c7e4f3 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -63,6 +63,21 @@ 
 #include <linux/uaccess.h>
 #include <net/pkt_sched.h>
 
+const u8 eth_reserved_addr_base[ETH_ALEN] __aligned(2) = {
+	0x01, 0x80, 0xc2, 0x00, 0x00, 0x00
+};
+EXPORT_SYMBOL(eth_reserved_addr_base);
+
+const u8 eth_ipv4_mcast_addr_base[ETH_ALEN] __aligned(2) = {
+	0x01, 0x00, 0x5e, 0x00, 0x00, 0x00
+};
+EXPORT_SYMBOL(eth_ipv4_mcast_addr_base);
+
+const u8 eth_ipv6_mcast_addr_base[ETH_ALEN] __aligned(2) = {
+	0x33, 0x33, 0x00, 0x00, 0x00, 0x00
+};
+EXPORT_SYMBOL(eth_ipv6_mcast_addr_base);
+
 /**
  * eth_header - create the Ethernet header
  * @skb:	buffer to alter