Skip to contentSkip to conversation

mips: bug: add unlikely() to BUG_ON()

PATCH In review Igor Stoppa 2 participants 3 messages Sep 7, 2018 – Sep 10, 2018 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mips: bug: add unlikely() to BUG_ON()

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

---
 arch/mips/include/asm/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/bug.h +1 -1
index 745dc160a069..02101b54aec2 100644
@@ -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
 
Signature · 1 line
2.17.1
#1 lore raw

Hi Igor,

arch/mips/include/asm/bug.h static inline void __BUG_ON(unsigned long condition) · line 37

Quoted 13 lines · Igor Stoppa
arch/mips/include/asm/bug.h +1 -1
index 745dc160a069..02101b54aec2 100644
@@ -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

#2 lore raw

Hi Paul,

Quoted 7 lines · Paul Burton

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.

Quoted 5 lines

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