On Wed, Jun 26, 2019 at 11:24:32AM +0200, Peter Zijlstra wrote:
> That is, would something like this:
> 
> diff --git a/arch/x86/include/asm/jump_label.h 
> b/arch/x86/include/asm/jump_label.h
> index 06c3cc22a058..1761b1e76ddc 100644
> --- a/arch/x86/include/asm/jump_label.h
> +++ b/arch/x86/include/asm/jump_label.h
> @@ -32,7 +32,7 @@ static __always_inline bool arch_static_branch(struct 
> static_key *key, bool bran
>               : :  "i" (key), "i" (branch) : : l_yes);
>  
>       return false;
> -l_yes:
> +l_yes: __attribute__((cold));
>       return true;
>  }
>  
> @@ -49,7 +49,7 @@ static __always_inline bool arch_static_branch_jump(struct 
> static_key *key, bool
>               : :  "i" (key), "i" (branch) : : l_yes);
>  
>       return false;
> -l_yes:
> +l_yes: __attribute__((hot));
>       return true;
>  }
>  
> Help LLVM?

No, that's broken. What we do is the likely() and unlikely() hints in
static_branch_{,un}likely():

#define static_branch_likely(x)                                                 
\
({                                                                              
\
        bool branch;                                                            
\
        if (__builtin_types_compatible_p(typeof(*x), struct static_key_true))   
\
                branch = !arch_static_branch(&(x)->key, true);                  
\
        else if (__builtin_types_compatible_p(typeof(*x), struct 
static_key_false)) \
                branch = !arch_static_branch_jump(&(x)->key, true);             
\
        else                                                                    
\
                branch = ____wrong_branch_error();                              
\
        likely(branch);                                                         
\
})

#define static_branch_unlikely(x)                                               
\
({                                                                              
\
        bool branch;                                                            
\
        if (__builtin_types_compatible_p(typeof(*x), struct static_key_true))   
\
                branch = arch_static_branch_jump(&(x)->key, false);             
\
        else if (__builtin_types_compatible_p(typeof(*x), struct 
static_key_false)) \
                branch = arch_static_branch(&(x)->key, false);                  
\
        else                                                                    
\
                branch = ____wrong_branch_error();                              
\
        unlikely(branch);                                                       
\
})

That should convey out-of-line vs in-line 'hint'. And clearly that's
broken for LLVM.

Reply via email to