* [PATCH net-next] fib: use __fls() on non null argument
@ 2012-08-07 13:30 Eric Dumazet
2012-08-07 20:05 ` Ben Hutchings
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2012-08-07 13:30 UTC (permalink / raw)
To: David Miller; +Cc: netdev
From: Eric Dumazet <edumazet@google.com>
__fls(x) is a bit faster than fls(x), granted we know x is non null.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/fib_trie.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index f0cdb30..0bb20c4 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1550,7 +1550,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
* state.directly.
*/
if (pref_mismatch) {
- int mp = KEYLENGTH - fls(pref_mismatch);
+ int mp = KEYLENGTH - __fls(pref_mismatch);
if (tkey_extract_bits(cn->key, mp, cn->pos - mp) != 0)
goto backtrace;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] fib: use __fls() on non null argument
2012-08-07 13:30 [PATCH net-next] fib: use __fls() on non null argument Eric Dumazet
@ 2012-08-07 20:05 ` Ben Hutchings
2012-08-07 20:45 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2012-08-07 20:05 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, netdev
On Tue, 2012-08-07 at 15:30 +0200, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> __fls(x) is a bit faster than fls(x), granted we know x is non null.
And it doesn't have the +1 bias, so this change is not correct.
Ben.
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
> net/ipv4/fib_trie.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
> index f0cdb30..0bb20c4 100644
> --- a/net/ipv4/fib_trie.c
> +++ b/net/ipv4/fib_trie.c
> @@ -1550,7 +1550,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
> * state.directly.
> */
> if (pref_mismatch) {
> - int mp = KEYLENGTH - fls(pref_mismatch);
> + int mp = KEYLENGTH - __fls(pref_mismatch);
>
> if (tkey_extract_bits(cn->key, mp, cn->pos - mp) != 0)
> goto backtrace;
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] fib: use __fls() on non null argument
2012-08-07 20:05 ` Ben Hutchings
@ 2012-08-07 20:45 ` Eric Dumazet
2012-08-07 23:27 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2012-08-07 20:45 UTC (permalink / raw)
To: Ben Hutchings; +Cc: David Miller, netdev
From: Eric Dumazet <edumazet@google.com>
On Tue, 2012-08-07 at 21:05 +0100, Ben Hutchings wrote:
> On Tue, 2012-08-07 at 15:30 +0200, Eric Dumazet wrote:
> > From: Eric Dumazet <edumazet@google.com>
> >
> > __fls(x) is a bit faster than fls(x), granted we know x is non null.
>
> And it doesn't have the +1 bias, so this change is not correct.
Good catch, I wonder why my routing was still working...
[PATCH v2 net-next] fib: use __fls() on non null argument
__fls(x) is a bit faster than fls(x), granted we know x is non null.
As Ben Hutchings pointed out, fls(x) = __fls(x) + 1
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Ben Hutchings <bhutchings@solarflare.com>
---
net/ipv4/fib_trie.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index f0cdb30..f84a0e9 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1550,7 +1550,8 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
* state.directly.
*/
if (pref_mismatch) {
- int mp = KEYLENGTH - fls(pref_mismatch);
+ /* fls(x) = __fls(x) + 1 */
+ int mp = KEYLENGTH - __fls(pref_mismatch) - 1;
if (tkey_extract_bits(cn->key, mp, cn->pos - mp) != 0)
goto backtrace;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] fib: use __fls() on non null argument
2012-08-07 20:45 ` Eric Dumazet
@ 2012-08-07 23:27 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2012-08-07 23:27 UTC (permalink / raw)
To: eric.dumazet; +Cc: bhutchings, netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 07 Aug 2012 22:45:47 +0200
> [PATCH v2 net-next] fib: use __fls() on non null argument
>
> __fls(x) is a bit faster than fls(x), granted we know x is non null.
>
> As Ben Hutchings pointed out, fls(x) = __fls(x) + 1
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Ben Hutchings <bhutchings@solarflare.com>
Applied.
This is, btw, the most expensive part of fib_trie on sparc64 since we
really don't have a universal way to do this in a hardware instruction
and therefore we end up with the branch-heavy software implementation :-/
So if anyone can come up with a way to eliminate this fls() entirely,
you will be my hero.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-07 23:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-07 13:30 [PATCH net-next] fib: use __fls() on non null argument Eric Dumazet
2012-08-07 20:05 ` Ben Hutchings
2012-08-07 20:45 ` Eric Dumazet
2012-08-07 23:27 ` 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).