linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG.
@ 2009-09-10 23:54 David Daney
  2009-09-10 23:56 ` [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h David Daney
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: David Daney @ 2009-09-10 23:54 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	Ingo Molnar, Mike Frysinger, Ivan Kokshaysky, uclinux-dist-devel,
	Thomas Gleixner, Richard Henderson, Haavard Skinnemoen,
	linux-parisc, ralf, Kyle McMartin, linux-alpha,
	Martin Schwidefsky, linux390, Koichi Yasutake

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

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

* [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h
  2009-09-10 23:54 [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG David Daney
@ 2009-09-10 23:56 ` David Daney
  2009-09-11  0:14   ` Richard Henderson
  2009-09-11 14:32   ` Michael Buesch
  2009-09-10 23:56 ` [PATCH 07/10] powerpc: Convert BUG() to use unreachable() David Daney
  2009-09-24  3:37 ` [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG Benjamin Herrenschmidt
  2 siblings, 2 replies; 9+ messages in thread
From: David Daney @ 2009-09-10 23:56 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	David Daney, Ingo Molnar, Mike Frysinger, Ivan Kokshaysky,
	uclinux-dist-devel, Thomas Gleixner, Richard Henderson,
	Haavard Skinnemoen, linux-parisc, linux-kernel, ralf,
	Kyle McMartin, linux-alpha, Martin Schwidefsky, linux390,
	Koichi Yasutake

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 <ddaney@caviumnetworks.com>
CC: Thomas Gleixner <tglx@linutronix.de>
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 <schwidefsky@de.ibm.com>
CC: Heiko Carstens <heiko.carstens@de.ibm.com>
CC: linux390@de.ibm.com
CC: linux-s390@vger.kernel.org
CC: David Howells <dhowells@redhat.com>
CC: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
CC: linux-am33-list@redhat.com
CC: Kyle McMartin <kyle@mcmartin.ca>
CC: Helge Deller <deller@gmx.de>
CC: linux-parisc@vger.kernel.org
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
CC: linuxppc-dev@ozlabs.org
CC: Richard Henderson <rth@twiddle.net>
CC: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
CC: linux-alpha@vger.kernel.org
CC: Haavard Skinnemoen <hskinnemoen@atmel.com>
CC: Mike Frysinger <vapier@gentoo.org>
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(-)

diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
index 450fa59..ab3af40 100644
--- a/include/linux/compiler-gcc4.h
+++ b/include/linux/compiler-gcc4.h
@@ -36,4 +36,18 @@
    the kernel context */
 #define __cold			__attribute__((__cold__))
 
+
+#if __GNUC_MINOR__ >= 5
+/*
+ * Mark a position in code as unreachable.  This can be used to
+ * suppress control flow warnings after asm blocks that transfer
+ * control elsewhere.
+ *
+ * Early snapshots of gcc 4.5 don't support this and we can't detect
+ * this in the preprocessor, but we can live with this because they're
+ * unreleased.  Really, we need to have autoconf for the kernel.
+ */
+#define unreachable() __builtin_unreachable()
+#endif
+
 #endif
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 04fb513..7efd73f 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -144,6 +144,11 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 # define barrier() __memory_barrier()
 #endif
 
+/* Unreachable code */
+#ifndef unreachable
+# define unreachable() do { for (;;) ; } while (0)
+#endif
+
 #ifndef RELOC_HIDE
 # define RELOC_HIDE(ptr, off)					\
   ({ unsigned long __ptr;					\
-- 
1.6.2.5

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

* [PATCH 07/10] powerpc: Convert BUG() to use unreachable()
  2009-09-10 23:54 [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG David Daney
  2009-09-10 23:56 ` [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h David Daney
@ 2009-09-10 23:56 ` David Daney
  2009-09-24  3:37 ` [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG Benjamin Herrenschmidt
  2 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2009-09-10 23:56 UTC (permalink / raw)
  To: torvalds, akpm; +Cc: linuxppc-dev, Paul Mackerras, linux-kernel, David Daney

Use the new unreachable() macro instead of for(;;);

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
CC: linuxppc-dev@ozlabs.org
---
 arch/powerpc/include/asm/bug.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index 64e1fdc..2c15212 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -68,7 +68,7 @@
 		_EMIT_BUG_ENTRY					\
 		: : "i" (__FILE__), "i" (__LINE__),		\
 		    "i" (0), "i"  (sizeof(struct bug_entry)));	\
-	for(;;) ;						\
+	unreachable();						\
 } while (0)
 
 #define BUG_ON(x) do {						\
-- 
1.6.2.5

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

* Re: [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h
  2009-09-10 23:56 ` [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h David Daney
@ 2009-09-11  0:14   ` Richard Henderson
  2009-09-11 14:32   ` Michael Buesch
  1 sibling, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2009-09-11  0:14 UTC (permalink / raw)
  To: David Daney
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	Ingo Molnar, Mike Frysinger, Ivan Kokshaysky, uclinux-dist-devel,
	Thomas Gleixner, Haavard Skinnemoen, linux-parisc, linux-kernel,
	ralf, Kyle McMartin, linux-alpha, Martin Schwidefsky, linux390,
	akpm, Koichi Yasutake, torvalds

On 09/10/2009 04:56 PM, David Daney wrote:
> +#ifndef unreachable
> +# define unreachable() do { for (;;) ; } while (0)
> +#endif

#define unreachable() do { } while (1)


r~

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

* Re: [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h
  2009-09-10 23:56 ` [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h David Daney
  2009-09-11  0:14   ` Richard Henderson
@ 2009-09-11 14:32   ` Michael Buesch
  2009-09-11 15:58     ` David Daney
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Buesch @ 2009-09-11 14:32 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	David Daney, Ingo Molnar, Mike Frysinger, Ivan Kokshaysky,
	linux390, Thomas Gleixner, Richard Henderson, Haavard Skinnemoen,
	linux-parisc, linux-kernel, ralf, Kyle McMartin, linux-alpha,
	Martin Schwidefsky, uclinux-dist-devel, akpm, Koichi Yasutake,
	torvalds

On Friday 11 September 2009 01:56:42 David Daney wrote:
> +/* Unreachable code */
> +#ifndef unreachable
> +# define unreachable() do { for (;;) ; } while (0)
> +#endif

# define unreachable() do { } while (1)

? :)

-- 
Greetings, Michael.

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

* Re: [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h
  2009-09-11 14:32   ` Michael Buesch
@ 2009-09-11 15:58     ` David Daney
  2009-09-12  7:22       ` Geert Uytterhoeven
  0 siblings, 1 reply; 9+ messages in thread
From: David Daney @ 2009-09-11 15:58 UTC (permalink / raw)
  To: Michael Buesch
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	Ingo Molnar, Mike Frysinger, Ivan Kokshaysky, linux390,
	Thomas Gleixner, Richard Henderson, Haavard Skinnemoen,
	linux-parisc, torvalds, linux-kernel, ralf, Kyle McMartin,
	linux-alpha, Martin Schwidefsky, uclinux-dist-devel, akpm,
	Koichi Yasutake, linuxppc-dev

Michael Buesch wrote:
> On Friday 11 September 2009 01:56:42 David Daney wrote:
>> +/* 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.

Thanks,
David Daney

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

* Re: [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h
  2009-09-11 15:58     ` David Daney
@ 2009-09-12  7:22       ` Geert Uytterhoeven
  2009-09-14 15:40         ` David Daney
  0 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2009-09-12  7:22 UTC (permalink / raw)
  To: David Daney
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	Ingo Molnar, Mike Frysinger, Ivan Kokshaysky, linux390,
	Thomas Gleixner, Richard Henderson, Haavard Skinnemoen,
	linux-parisc, torvalds, linux-kernel, ralf, Kyle McMartin,
	linux-alpha, Martin Schwidefsky, uclinux-dist-devel, akpm,
	Koichi Yasutake, linuxppc-dev

On Fri, Sep 11, 2009 at 17:58, David Daney<ddaney@caviumnetworks.com> wrote=
:
> Michael Buesch wrote:
>>
>> On Friday 11 September 2009 01:56:42 David Daney wrote:
>>>
>>> +/* 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

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

* Re: [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h
  2009-09-12  7:22       ` Geert Uytterhoeven
@ 2009-09-14 15:40         ` David Daney
  0 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2009-09-14 15:40 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	Ingo Molnar, Mike Frysinger, Ivan Kokshaysky, linux390,
	Thomas Gleixner, Richard Henderson, Haavard Skinnemoen,
	linux-parisc, torvalds, linux-kernel, ralf, Kyle McMartin,
	linux-alpha, Martin Schwidefsky, uclinux-dist-devel, akpm,
	Koichi Yasutake, linuxppc-dev

Geert Uytterhoeven wrote:
> On Fri, Sep 11, 2009 at 17:58, David Daney<ddaney@caviumnetworks.com> wrote:
>> Michael Buesch wrote:
>>> On Friday 11 September 2009 01:56:42 David Daney wrote:
>>>> +/* 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

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

* Re: [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG.
  2009-09-10 23:54 [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG David Daney
  2009-09-10 23:56 ` [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h David Daney
  2009-09-10 23:56 ` [PATCH 07/10] powerpc: Convert BUG() to use unreachable() David Daney
@ 2009-09-24  3:37 ` Benjamin Herrenschmidt
  2 siblings, 0 replies; 9+ messages in thread
From: Benjamin Herrenschmidt @ 2009-09-24  3:37 UTC (permalink / raw)
  To: David Daney
  Cc: linux-mips, Heiko Carstens, linuxppc-dev, Paul Mackerras,
	H. Peter Anvin, linux-s390, linux-am33-list, Helge Deller, x86,
	Ingo Molnar, Mike Frysinger, Ivan Kokshaysky, uclinux-dist-devel,
	Thomas Gleixner, Richard Henderson, Haavard Skinnemoen,
	linux-parisc, ralf, Kyle McMartin, linux-alpha,
	Martin Schwidefsky, linux390, Andrew Morton, Koichi Yasutake,
	Linus Torvalds

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>

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

end of thread, other threads:[~2009-09-24  3:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-10 23:54 [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG David Daney
2009-09-10 23:56 ` [PATCH 01/10] Add support for GCC-4.5's __builtin_unreachable() to compiler.h David Daney
2009-09-11  0:14   ` Richard Henderson
2009-09-11 14:32   ` Michael Buesch
2009-09-11 15:58     ` David Daney
2009-09-12  7:22       ` Geert Uytterhoeven
2009-09-14 15:40         ` David Daney
2009-09-10 23:56 ` [PATCH 07/10] powerpc: Convert BUG() to use unreachable() David Daney
2009-09-24  3:37 ` [PATCH 00/10] Add support for GCC's __builtin_unreachable() and use it in BUG Benjamin Herrenschmidt

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