Re: [PATCH] mips: bug: add unlikely() to BUG_ON()

From: Paul Burton
Date: Fri Sep 07 2018 - 18:02:19 EST


Hi Igor,

On Fri, Sep 07, 2018 at 09:03:02PM +0300, Igor Stoppa wrote:
> diff --git a/arch/mips/include/asm/bug.h b/arch/mips/include/asm/bug.h
> index 745dc160a069..02101b54aec2 100644
> --- a/arch/mips/include/asm/bug.h
> +++ b/arch/mips/include/asm/bug.h
> @@ -31,7 +31,7 @@ static inline void __BUG_ON(unsigned long condition)
> : : "r" (condition), "i" (BRK_BUG));
> }
>
> -#define BUG_ON(C) __BUG_ON((unsigned long)(C))
> +#define BUG_ON(C) __BUG_ON(unlikely((unsigned long)(C)))
>
> #define HAVE_ARCH_BUG_ON
>

I'm not sure this will actually do anything.

__BUG_ON() doesn't use the value of its condition argument for regular
control flow unless it's compile-time constant anyway, in which case
unlikely() should be redundant because the compiler knows the value
already.

If the condition isn't compile-time constant then we just emit a tne
(trap-if-not-equal) instruction using inline asm. That will generate an
exception if the value is non-zero at runtime. I don't see how adding
unlikely() is going to help the compiler do anything differently with
that.

Thanks,
Paul