Use CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS to check if this function can be optimized by using the generic ether_addr_equal.
Remove the unnecessary ?: after the unoptimized memcmp.
Signed-off-by: Joe Perches joe@perches.com --- net/batman-adv/main.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index f94f287b..74a7a3f 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h @@ -266,7 +266,11 @@ static inline void batadv_dbg(int type __always_unused, */ static inline int batadv_compare_eth(const void *data1, const void *data2) { - return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) + return ether_addr_equal(data1, data2); +#else + return memcmp(data1, data2, ETH_ALEN) == 0; +#endif }
/**
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 06/12/13 09:18, Joe Perches wrote:
Use CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS to check if this function can be optimized by using the generic ether_addr_equal.
Remove the unnecessary ?: after the unoptimized memcmp.
Signed-off-by: Joe Perches joe@perches.com
Acked-by: Antonio Quartulli antonio@meshcoding.com
- -- Antonio Quartulli
From: Joe Perches joe@perches.com Date: Fri, 06 Dec 2013 00:18:10 -0800
@@ -266,7 +266,11 @@ static inline void batadv_dbg(int type __always_unused, */ static inline int batadv_compare_eth(const void *data1, const void *data2) {
- return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
- return ether_addr_equal(data1, data2);
+#else
- return memcmp(data1, data2, ETH_ALEN) == 0;
+#endif }
Let's not crap up implementations with these ifdefs.
What's the specific situation here? Is it that 'data1' and/or 'data2' my not be u16 aligned?
If so, make a function for that in linux/etherdevice.h and invoke it in such places. You can name it something like "ether_addr_equal_unaligned()" or similar.
Thanks.
On Fri, 2013-12-06 at 15:39 -0500, David Miller wrote:
From: Joe Perches joe@perches.com Date: Fri, 06 Dec 2013 00:18:10 -0800
@@ -266,7 +266,11 @@ static inline void batadv_dbg(int type __always_unused, */ static inline int batadv_compare_eth(const void *data1, const void *data2) {
- return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
- return ether_addr_equal(data1, data2);
+#else
- return memcmp(data1, data2, ETH_ALEN) == 0;
+#endif }
Let's not crap up implementations with these ifdefs.
What's the specific situation here? Is it that 'data1' and/or 'data2' my not be u16 aligned?
Yes.
If so, make a function for that in linux/etherdevice.h and invoke it in such places. You can name it something like "ether_addr_equal_unaligned()" or similar.
I'll resubmit if/after you apply the ether_addr_equal/compare_ether_addr removal.
cheers, Joe
From: Joe Perches joe@perches.com Date: Fri, 06 Dec 2013 13:17:01 -0800
On Fri, 2013-12-06 at 15:39 -0500, David Miller wrote:
If so, make a function for that in linux/etherdevice.h and invoke it in such places. You can name it something like "ether_addr_equal_unaligned()" or similar.
I'll resubmit if/after you apply the ether_addr_equal/compare_ether_addr removal.
Done.
Add a generic routine to test if possibly unaligned to u16 Ethernet addresses are equal.
If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set, this uses the slightly faster generic routine ether_addr_equal, otherwise this uses memcmp.
Signed-off-by: Joe Perches joe@perches.com --- include/linux/etherdevice.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 3526e81..eb36845 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -266,6 +266,24 @@ static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], }
/** + * ether_addr_equal_unaligned - Compare two not u16 aligned Ethernet addresses + * @addr1: Pointer to a six-byte array containing the Ethernet address + * @addr2: Pointer other six-byte array containing the Ethernet address + * + * Compare two Ethernet addresses, returns true if equal + * + * Please note: Use only when any Ethernet address may not be u16 aligned. + */ +static inline bool ether_addr_equal_unaligned(const u8 *addr1, const u8 *addr2) +{ +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) + return ether_addr_equal(addr1, addr2); +#else + return memcmp(addr1, addr2, ETH_ALEN) == 0; +#endif +} + +/** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure * @addr: Pointer to a six-byte array containing the Ethernet address
Use the newly added generic routine ether_addr_equal_unaligned to test if possibly unaligned to u16 Ethernet addresses are equal.
This slightly improves comparison time for systems with CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.
Signed-off-by: Joe Perches joe@perches.com --- net/batman-adv/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index f94f287b..322dd73 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h @@ -266,7 +266,7 @@ static inline void batadv_dbg(int type __always_unused, */ static inline int batadv_compare_eth(const void *data1, const void *data2) { - return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); + return ether_addr_equal_unaligned(data1, data2); }
/**
From: Joe Perches joe@perches.com Date: Fri, 06 Dec 2013 14:39:46 -0800
Use the newly added generic routine ether_addr_equal_unaligned to test if possibly unaligned to u16 Ethernet addresses are equal.
This slightly improves comparison time for systems with CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.
Signed-off-by: Joe Perches joe@perches.com
Applied.
From: Joe Perches joe@perches.com Date: Fri, 06 Dec 2013 14:21:01 -0800
Add a generic routine to test if possibly unaligned to u16 Ethernet addresses are equal.
If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set, this uses the slightly faster generic routine ether_addr_equal, otherwise this uses memcmp.
Signed-off-by: Joe Perches joe@perches.com
Applied.
b.a.t.m.a.n@lists.open-mesh.org