From: David Daney <hidden> Date: 2009-09-11 00:10:56
Starting with version 4.5, GCC has a new built-in function called
__builtin_unreachable(). The function tells the compiler that control
flow will never reach that point. Currently we trick the compiler by
putting in for(;;); but this has the disadvantage that extra code is
emitted for an endless loop. For an i386 kernel using
__builtin_unreachable() results in an allyesconfig that is nearly 4000
bytes smaller.
This patch set adds support to compiler.h creating a
new macro usable in the kernel called unreachable(). If the compiler
lacks __builtin_unreachable(), it just expands to for(;;).
The x86 and MIPS patches I actually tested with a GCC-4.5 snapshot.
Lacking the ability to test the rest of the architectures, I just did
what seemed right without even trying to compile the kernel.
01/10 adds the compiler.h support, the rest of the patches retrofit
the various architecture BUG macros to use it instead of for(;;) or
while(1) loops.
I will reply with the 10 patches.
The architecture specific patches I will send to a smaller set of
people.
David Daney (10):
Add support for GCC-4.5's __builtin_unreachable() to compiler.h
x86: Convert BUG() to use unreachable()
MIPS: Convert BUG() to use unreachable()
s390: Convert BUG() to use unreachable()
mn10300: Convert BUG() to use unreachable()
parisc: Convert BUG() to use unreachable()
powerpc: Convert BUG() to use unreachable()
alpha: Convert BUG() to use unreachable()
avr32: Convert BUG() to use unreachable()
blackfin: Convert BUG() to use unreachable()
arch/alpha/include/asm/bug.h | 2 +-
arch/avr32/include/asm/bug.h | 2 +-
arch/blackfin/include/asm/bug.h | 2 +-
arch/mips/include/asm/bug.h | 4 +---
arch/mn10300/include/asm/bug.h | 3 ++-
arch/parisc/include/asm/bug.h | 4 ++--
arch/powerpc/include/asm/bug.h | 2 +-
arch/s390/include/asm/bug.h | 2 +-
arch/x86/include/asm/bug.h | 4 ++--
include/linux/compiler-gcc4.h | 14 ++++++++++++++
include/linux/compiler.h | 5 +++++
11 files changed, 31 insertions(+), 13 deletions(-)
From: David Daney <hidden> Date: 2009-09-10 23:57:44
Use the new unreachable() macro instead of for(;;);
Signed-off-by: David Daney <redacted>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <redacted>
CC: linuxppc-dev@ozlabs.org
---
arch/powerpc/include/asm/bug.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
From: David Daney <hidden> Date: 2009-09-10 23:58:31
Starting with version 4.5, GCC has a new built-in function
__builtin_unreachable() that can be used in places like the kernel's
BUG() where inline assembly is used to transfer control flow. This
eliminated the need for an endless loop in these places.
The patch adds a new macro 'unreachable()' that will expand to either
__builtin_unreachable() or an endless loop depending on the compiler
version.
Signed-off-by: David Daney <redacted>
CC: Thomas Gleixner <redacted>
CC: Ingo Molnar <mingo@redhat.com>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: x86@kernel.org
CC: ralf@linux-mips.org
CC: linux-mips@linux-mips.org
CC: Martin Schwidefsky <redacted>
CC: Heiko Carstens <redacted>
CC: linux390@de.ibm.com
CC: linux-s390@vger.kernel.org
CC: David Howells <dhowells@redhat.com>
CC: Koichi Yasutake <redacted>
CC: linux-am33-list@redhat.com
CC: Kyle McMartin <redacted>
CC: Helge Deller <deller@gmx.de>
CC: linux-parisc@vger.kernel.org
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <redacted>
CC: linuxppc-dev@ozlabs.org
CC: Richard Henderson <redacted>
CC: Ivan Kokshaysky <redacted>
CC: linux-alpha@vger.kernel.org
CC: Haavard Skinnemoen <redacted>
CC: Mike Frysinger <redacted>
CC: uclinux-dist-devel@blackfin.uclinux.org
---
include/linux/compiler-gcc4.h | 14 ++++++++++++++
include/linux/compiler.h | 5 +++++
2 files changed, 19 insertions(+), 0 deletions(-)
On Fri, Sep 11, 2009 at 17:58, David Daney[off-list ref] wrote=
:
Michael Buesch wrote:
quoted
On Friday 11 September 2009 01:56:42 David Daney wrote:
quoted
+/* Unreachable code */
+#ifndef unreachable
+# define unreachable() do { for (;;) ; } while (0)
+#endif
# define unreachable() do { } while (1)
? :)
Clearly I was not thinking clearly when I wrote that part. =C2=A0RTH note=
d the
same thing. =C2=A0I will fix it.
However, people are so used to seeing the `do { } while (0)' idiom,
that they might miss
there's a `1' here, not a `0'.
So perhaps it's better to use plain `for (;;)' for infinite loops?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k=
.org
In personal conversations with technical people, I call myself a hacker. Bu=
t
when I'm talking to journalists I just say "programmer" or something like t=
hat.
-- Linus Torvalds
From: David Daney <hidden> Date: 2009-09-14 15:40:34
Geert Uytterhoeven wrote:
On Fri, Sep 11, 2009 at 17:58, David Daney[off-list ref] wrote:
quoted
Michael Buesch wrote:
quoted
On Friday 11 September 2009 01:56:42 David Daney wrote:
quoted
+/* Unreachable code */
+#ifndef unreachable
+# define unreachable() do { for (;;) ; } while (0)
+#endif
# define unreachable() do { } while (1)
? :)
Clearly I was not thinking clearly when I wrote that part. RTH noted the
same thing. I will fix it.
However, people are so used to seeing the `do { } while (0)' idiom,
that they might miss
there's a `1' here, not a `0'.
So perhaps it's better to use plain `for (;;)' for infinite loops?
I don't think so. The only valid token that can follow 'do { } while
(1)' is ';', any statement may follow 'for (;;)', so there is a greater
possibility to silently screw things up with the for(;;) form.
David Daney
From: Benjamin Herrenschmidt <benh@kernel.crashing.org> Date: 2009-09-24 03:44:44
On Thu, 2009-09-10 at 16:54 -0700, David Daney wrote:
Starting with version 4.5, GCC has a new built-in function called
__builtin_unreachable(). The function tells the compiler that control
flow will never reach that point. Currently we trick the compiler by
putting in for(;;); but this has the disadvantage that extra code is
emitted for an endless loop. For an i386 kernel using
__builtin_unreachable() results in an allyesconfig that is nearly 4000
bytes smaller.
For the powerpc part:
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>