Thread (4 messages) flat view 4 messages, 3 authors, 2011-01-28

Re: [PATCH 2/7] PowerPC: add unlikely() to BUG_ON()

From: David Daney <hidden>
Date: 2011-01-27 17:57:41
Also in: lkml

Why not also CC the PPC maintainers as well?  I am not certain, but I 
think they may be reached at:

linuxppc-dev@lists.ozlabs.org


On 01/27/2011 04:12 AM, Coly Li wrote:
quoted hunk
Current BUG_ON() arch/powerpc/include/asm/bug.h does not use unlikely(),
in order to get better branch predict result, source code may have to call
BUG_ON() with unlikely() explicitly. This is not a suggested method
to use BUG_ON().

This patch adds unlikely() inside BUG_ON implementation on PPC
code, callers can use BUG_ON without explicit unlikely() now.

I don't have any PPC hardware to compile and test this fix, any feedback
of this patch is welcome.

Signed-off-by: Coly Li<redacted>
Cc: Jeremy Fitzhardinge<redacted>
Cc: David Daney<redacted>
Cc: Wang Cong<redacted>
Cc: Yong Zhang<redacted>
diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index 065c590..10889a6 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -2,6 +2,7 @@
  #define _ASM_POWERPC_BUG_H
  #ifdef __KERNEL__

+#include<linux/compiler.h>
  #include<asm/asm-compat.h>

  /*
@@ -71,7 +72,7 @@
  	unreachable();						\
  } while (0)

-#define BUG_ON(x) do {						\
+#define __BUG_ON(x) do {					\
  	if (__builtin_constant_p(x)) {				\
  		if (x)						\
  			BUG();					\
@@ -85,6 +86,8 @@
  	}							\
  } while (0)

+#define BUG_ON(x) __BUG_ON(unlikely(x))
+
This is the same type of frobbing you were trying to do to MIPS.

I will let the powerpc maintainers weigh in on it, but my opinion is 
that, as with MIPS, BUG_ON() is expanded to a single machine 
instruction, and this unlikely() business will not change the generated 
code in any useful way.  It is thus gratuitous code churn and 
complexification.

David Daney
  #define __WARN_TAINT(taint) do {				\
  	__asm__ __volatile__(					\
  		"1:	twi 31,0,0\n"				\
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help