* [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
@ 2013-12-06 8:18 Joe Perches
2013-12-06 10:10 ` Antonio Quartulli
2013-12-06 20:39 ` David Miller
0 siblings, 2 replies; 9+ messages in thread
From: Joe Perches @ 2013-12-06 8:18 UTC (permalink / raw)
To: Marek Lindner, Simon Wunderlich, Antonio Quartulli
Cc: netdev, b.a.t.m.a.n, David S. Miller, linux-kernel
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
}
/**
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
2013-12-06 8:18 [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
@ 2013-12-06 10:10 ` Antonio Quartulli
2013-12-06 20:39 ` David Miller
1 sibling, 0 replies; 9+ messages in thread
From: Antonio Quartulli @ 2013-12-06 10:10 UTC (permalink / raw)
To: Joe Perches, Marek Lindner, Simon Wunderlich
Cc: netdev, b.a.t.m.a.n, David S. Miller, linux-kernel
-----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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQIcBAEBCAAGBQJSoaKXAAoJEEKTMo6mOh1VMjoP/3GqGy0TQG1yXRzbrzAbbklJ
8Oa6DHQd2pSN/cJkR501JYwSUnCGh3m7eh7qc1HZYrEIgxIrJDLHWSqBL3FPtgap
gQ92BBQG/pd38ZmmWSeZob44bEMEGAn00B1kgFx+Xb4YW4bP2rDAlvPxjjaqjT3U
tBNbNYxUTBY2JMftI7WwEOwMWgLPVoHR1PhAbBTpbXMXCRrGp/vXN1xXam1xIDNx
kahFmHA1Dc91dwr8ev4bcUjfGO2tXkQOEoqKRkwc1SEzuKTjgJNDxdbFNqG6vMAm
k/aXhMvf3DOUkaCeslRQIkwefbKmzN69c1x2ND7S8mLEMIKyBuhKUFcf6PebD9SK
Dc+KdwIx0lsaS2vGqOt6mUSie1KfY8QNAc74eF6XjDhKyJynYXe6S3L40uT4eLXR
8fwGClJmyYVIiYD65NOtiIx6C2uHFchjDpXjlz0X8N9oQ2Azr4e2RMTGkkoihvOh
94r1dmAaBrnRiAu6AkImhgN+lWgLglHWD5trmmRCxNEJf0iW+x9ZaR4yAQFDUP3k
mrk5AN8JuRZkOeY5QK4AIZ0bFUh8tKW6JaNb8VHQGsLqjhAB/HPS6VljyRgMalyQ
c/kLlEOIIZ9dsjMwKMgyoJ9bMtTYUTxrriKz12mQbx8mWvm4CMFEQglljQiuTyvh
J+UsjAHs/ffW59JIGCfB
=8xL7
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
2013-12-06 8:18 [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
2013-12-06 10:10 ` Antonio Quartulli
@ 2013-12-06 20:39 ` David Miller
2013-12-06 21:17 ` Joe Perches
1 sibling, 1 reply; 9+ messages in thread
From: David Miller @ 2013-12-06 20:39 UTC (permalink / raw)
To: joe; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
2013-12-06 20:39 ` David Miller
@ 2013-12-06 21:17 ` Joe Perches
2013-12-06 21:38 ` David Miller
0 siblings, 1 reply; 9+ messages in thread
From: Joe Perches @ 2013-12-06 21:17 UTC (permalink / raw)
To: David Miller; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
2013-12-06 21:17 ` Joe Perches
@ 2013-12-06 21:38 ` David Miller
2013-12-06 22:21 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned Joe Perches
0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2013-12-06 21:38 UTC (permalink / raw)
To: joe; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned
2013-12-06 21:38 ` David Miller
@ 2013-12-06 22:21 ` Joe Perches
2013-12-06 22:39 ` [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
2013-12-10 1:58 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned David Miller
0 siblings, 2 replies; 9+ messages in thread
From: Joe Perches @ 2013-12-06 22:21 UTC (permalink / raw)
To: David Miller; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
2013-12-06 22:21 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned Joe Perches
@ 2013-12-06 22:39 ` Joe Perches
2013-12-10 1:58 ` David Miller
2013-12-10 1:58 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned David Miller
1 sibling, 1 reply; 9+ messages in thread
From: Joe Perches @ 2013-12-06 22:39 UTC (permalink / raw)
To: David Miller; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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);
}
/**
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned
2013-12-06 22:21 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned Joe Perches
2013-12-06 22:39 ` [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
@ 2013-12-10 1:58 ` David Miller
1 sibling, 0 replies; 9+ messages in thread
From: David Miller @ 2013-12-10 1:58 UTC (permalink / raw)
To: joe; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth
2013-12-06 22:39 ` [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
@ 2013-12-10 1:58 ` David Miller
0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2013-12-10 1:58 UTC (permalink / raw)
To: joe; +Cc: mareklindner, netdev, b.a.t.m.a.n, linux-kernel, antonio
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-12-10 1:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-06 8:18 [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
2013-12-06 10:10 ` Antonio Quartulli
2013-12-06 20:39 ` David Miller
2013-12-06 21:17 ` Joe Perches
2013-12-06 21:38 ` David Miller
2013-12-06 22:21 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned Joe Perches
2013-12-06 22:39 ` [B.A.T.M.A.N.] [PATCH -next] batadv: Slight optimization of batadv_compare_eth Joe Perches
2013-12-10 1:58 ` David Miller
2013-12-10 1:58 ` [B.A.T.M.A.N.] [PATCH -next] etherdevice: Add ether_addr_equal_unaligned David Miller
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).