linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mips: bug: add unlikely() to BUG_ON()
@ 2018-09-07 18:03 Igor Stoppa
  2018-09-07 22:02 ` Paul Burton
  0 siblings, 1 reply; 3+ messages in thread
From: Igor Stoppa @ 2018-09-07 18:03 UTC (permalink / raw)
  To: David Daney
  Cc: igor.stoppa, Igor Stoppa, Ralf Baechle, Paul Burton, James Hogan,
	linux-mips, linux-kernel

Add a hint to the compiler that probably it won't be necessary to BUG()

Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
Cc: David Daney <ddaney@caviumnetworks.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paul.burton@mips.com>
Cc: James Hogan <jhogan@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
---
 arch/mips/include/asm/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mips: bug: add unlikely() to BUG_ON()
  2018-09-07 18:03 [PATCH] mips: bug: add unlikely() to BUG_ON() Igor Stoppa
@ 2018-09-07 22:02 ` Paul Burton
  2018-09-10  9:45   ` Igor Stoppa
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Burton @ 2018-09-07 22:02 UTC (permalink / raw)
  To: Igor Stoppa
  Cc: David Daney, Igor Stoppa, Ralf Baechle, James Hogan, linux-mips,
	linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mips: bug: add unlikely() to BUG_ON()
  2018-09-07 22:02 ` Paul Burton
@ 2018-09-10  9:45   ` Igor Stoppa
  0 siblings, 0 replies; 3+ messages in thread
From: Igor Stoppa @ 2018-09-10  9:45 UTC (permalink / raw)
  To: Paul Burton
  Cc: David Daney, Igor Stoppa, Ralf Baechle, James Hogan, linux-mips,
	linux-kernel

Hi Paul,

On 08/09/18 01:02, Paul Burton wrote:

> 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.

Thank you for the explanation. Please discard this patch.

--
igor

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-10  9:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-07 18:03 [PATCH] mips: bug: add unlikely() to BUG_ON() Igor Stoppa
2018-09-07 22:02 ` Paul Burton
2018-09-10  9:45   ` Igor Stoppa

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).