2013-10-11 20:50:57

by Roel Kluin

[permalink] [raw]
Subject: [PATCH] jump_label: unlikely(x) > 0

untested, but wasn't this intended instead?
--------------
if (unlikely(x) > 0) doesn't seem to help branch prediction

Signed-off-by: Roel Kluin <[email protected]>
---
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index a507907..cf08540 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -132,14 +132,14 @@ static __always_inline void jump_label_init(void)

static __always_inline bool static_key_false(struct static_key *key)
{
- if (unlikely(atomic_read(&key->enabled)) > 0)
+ if (unlikely(atomic_read(&key->enabled) > 0))
return true;
return false;
}

static __always_inline bool static_key_true(struct static_key *key)
{
- if (likely(atomic_read(&key->enabled)) > 0)
+ if (likely(atomic_read(&key->enabled) > 0))
return true;
return false;
}


2013-10-11 20:57:09

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] jump_label: unlikely(x) > 0

On Fri, 11 Oct 2013 22:50:50 +0200 (CEST) Roel Kluin <[email protected]> wrote:

> untested, but wasn't this intended instead?
> --------------
> if (unlikely(x) > 0) doesn't seem to help branch prediction
>
> ...
>
> --- a/include/linux/jump_label.h
> +++ b/include/linux/jump_label.h
> @@ -132,14 +132,14 @@ static __always_inline void jump_label_init(void)
>
> static __always_inline bool static_key_false(struct static_key *key)
> {
> - if (unlikely(atomic_read(&key->enabled)) > 0)
> + if (unlikely(atomic_read(&key->enabled) > 0))
> return true;
> return false;
> }
>
> static __always_inline bool static_key_true(struct static_key *key)
> {
> - if (likely(atomic_read(&key->enabled)) > 0)
> + if (likely(atomic_read(&key->enabled) > 0))
> return true;
> return false;
> }

I'm sure this was intended instead ;) The patch doesn't seem to make
any difference in code generation with my gcc.

2013-10-15 16:53:43

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH] jump_label: unlikely(x) > 0

On 10/11/2013 01:57 PM, Andrew Morton wrote:
>
> I'm sure this was intended instead ;) The patch doesn't seem to make
> any difference in code generation with my gcc.
>

Which is odd, because doesn't unlikely() booleanize?

-hpa

2013-10-16 06:47:06

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH] jump_label: unlikely(x) > 0


* H. Peter Anvin <[email protected]> wrote:

> On 10/11/2013 01:57 PM, Andrew Morton wrote:
> >
> > I'm sure this was intended instead ;) The patch doesn't seem to make
> > any difference in code generation with my gcc.
> >
>
> Which is odd, because doesn't unlikely() booleanize?

It's supposed to:

include/linux/compiler.h:#define unlikely_notrace(x) __builtin_expect(!!(x), 0)

Thanks,

Ingo