public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam-uyr5N9Q2VtJg9hUCZPvPmw@public.gmane.org>
To: Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Cc: Adrian Bunk <bunk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Linus Torvalds
	<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	linux arch <linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>,
	David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
Subject: Re: [PATCH] prepare kconfig inline optimization for all architectures
Date: Sun, 27 Apr 2008 20:31:31 +0200	[thread overview]
Message-ID: <20080427183131.GA26937@uranus.ravnborg.org> (raw)
In-Reply-To: <20080427181411.GA31667-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>

On Sun, Apr 27, 2008 at 02:14:12PM -0400, Christoph Hellwig wrote:
> On Sun, Apr 27, 2008 at 08:09:57PM +0200, Sam Ravnborg wrote:
> > With the config option we pass the inline hint to gcc (if enabled).
> > So with the config option we have the possibility to pass a _hint_ to
> > gcc about inlining.
> > 
> > Before the config option there were no difference between
> > static int alwyas_inline foo() {}
> > and
> > static int inline foo() {}
> > 
> > With the config option we now have a situation where they actually
> > differ as they should do (assuming gcc > 4.x).
> 
> As Linus mentioned the hint doesn't make any sense because gcc will
> get it wrong anyway.  In fact when you look at kernel code it tends
> to inline the everything and the kitchensink as long as there's just
> one caller and this bloat the stack but doesn't inline where it needs
> to.  Better don't try to mess with that and do it explicit.

The tendency is that gcc inline *more than we whish* - not less.
Which is why we have noinline - to cover the cases where we do not
want stuff inlined.

What the patch in question does is to make a difference
between always_inle and inline.
Previously they were the same. With the patch applied and
with a gcc > 4.0 inline is now a hint.

Did you actually read the patch?

> 
> > So you say that it is safe to assume all places where we really need
> > always_inline are annotedted such - and we do not need a simple
> > config option that the user can uncheck.
> 
> I don't say it is that, it certainly isn't on powerpc and probably most
> other architectures right now, because only x86 got the fixup so far.
> But making it a user-visible option instead of an architecture opt
> in/out selection doesn't make any sense.
If you read the patch you will see that the architectures that
want to enable this has to do an explicit HAVE_CC_INLINE_HINT
so powerpc is not impacted by this until they request it.
Exactly the reason why this was not widely enabled in the
first place (but implemnted in a too x86 specific way).


Updated patch below. I btw. renamed the option to say this is
about a INLINE_HINT.

	Sam

diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 49590f8..9645a6f 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -68,6 +68,7 @@ config SPARC
 	default y
 	select HAVE_IDE
 	select HAVE_OPROFILE
+	select HAVE_CC_INLINE_HINT
 
 # Identify this as a Sparc32 build
 config SPARC32
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index 8acc5cc..3c8ba36 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -9,6 +9,7 @@ config SPARC
 	bool
 	default y
 	select HAVE_OPROFILE
+	select HAVE_CC_INLINE_HINT
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
 
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2fadf79..48e352b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -20,6 +20,7 @@ config X86
 	def_bool y
 	select HAVE_IDE
 	select HAVE_OPROFILE
+	select HAVE_CC_INLINE_HINT
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
 	select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
@@ -142,9 +143,6 @@ config AUDIT_ARCH
 config ARCH_SUPPORTS_AOUT
 	def_bool y
 
-config ARCH_SUPPORTS_OPTIMIZED_INLINING
-	def_bool y
-
 # Use the generic interrupt handling code in kernel/irq/:
 config GENERIC_HARDIRQS
 	bool
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 5b1979a..23956ea 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -258,15 +258,3 @@ config CPA_DEBUG
 
 endmenu
 
-config OPTIMIZE_INLINING
-	bool "Allow gcc to uninline functions marked 'inline'"
-	default y
-	help
-	  This option determines if the kernel forces gcc to inline the functions
-	  developers have marked 'inline'. Doing so takes away freedom from gcc to
-	  do what it thinks is best, which is desirable for the gcc 3.x series of
-	  compilers. The gcc 4.x series have a rewritten inlining algorithm and
-	  disabling this option will generate a smaller kernel there. Hopefully
-	  this algorithm is so good that allowing gcc4 to make the decision can
-	  become the default in the future, until then this option is there to
-	  test gcc for this.
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index b2fd754..e49fade 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -31,8 +31,7 @@
 /*
  * Force always-inline if the user requests it so via the .config:
  */
-#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
-    !defined(CONFIG_OPTIMIZE_INLINING) && (__GNUC__ >= 4)
+#if !(defined(CONFIG_HAVE_CC_INLINE_HINT) && (__GNUC__ >= 4))
 # define inline		inline		__attribute__((always_inline))
 # define __inline__	__inline__	__attribute__((always_inline))
 # define __inline	__inline	__attribute__((always_inline))
diff --git a/init/Kconfig b/init/Kconfig
index ba3a389..3568647 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -508,6 +508,13 @@ config CC_OPTIMIZE_FOR_SIZE
 
 	  If unsure, say N.
 
+# archs shall "select HAVE_CC_INLINE_HINT"
+# to avoid forcing all function annotated inline
+# to be inline.
+# Note: This is only enforced for gcc > 4.0
+config HAVE_CC_INLINE_HINT
+	def_bool n
+
 config SYSCTL
 	bool
 

WARNING: multiple messages have this Message-ID (diff)
From: Sam Ravnborg <sam@ravnborg.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Adrian Bunk <bunk@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux arch <linux-arch@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
	David Miller <davem@davemloft.net>
Subject: Re: [PATCH] prepare kconfig inline optimization for all architectures
Date: Sun, 27 Apr 2008 20:31:31 +0200	[thread overview]
Message-ID: <20080427183131.GA26937@uranus.ravnborg.org> (raw)
Message-ID: <20080427183131.qZrYO-KemCmbQjDTflPshnr5LlXaUpPwxl6hobvabq4@z> (raw)
In-Reply-To: <20080427181411.GA31667@infradead.org>

On Sun, Apr 27, 2008 at 02:14:12PM -0400, Christoph Hellwig wrote:
> On Sun, Apr 27, 2008 at 08:09:57PM +0200, Sam Ravnborg wrote:
> > With the config option we pass the inline hint to gcc (if enabled).
> > So with the config option we have the possibility to pass a _hint_ to
> > gcc about inlining.
> > 
> > Before the config option there were no difference between
> > static int alwyas_inline foo() {}
> > and
> > static int inline foo() {}
> > 
> > With the config option we now have a situation where they actually
> > differ as they should do (assuming gcc > 4.x).
> 
> As Linus mentioned the hint doesn't make any sense because gcc will
> get it wrong anyway.  In fact when you look at kernel code it tends
> to inline the everything and the kitchensink as long as there's just
> one caller and this bloat the stack but doesn't inline where it needs
> to.  Better don't try to mess with that and do it explicit.

The tendency is that gcc inline *more than we whish* - not less.
Which is why we have noinline - to cover the cases where we do not
want stuff inlined.

What the patch in question does is to make a difference
between always_inle and inline.
Previously they were the same. With the patch applied and
with a gcc > 4.0 inline is now a hint.

Did you actually read the patch?

> 
> > So you say that it is safe to assume all places where we really need
> > always_inline are annotedted such - and we do not need a simple
> > config option that the user can uncheck.
> 
> I don't say it is that, it certainly isn't on powerpc and probably most
> other architectures right now, because only x86 got the fixup so far.
> But making it a user-visible option instead of an architecture opt
> in/out selection doesn't make any sense.
If you read the patch you will see that the architectures that
want to enable this has to do an explicit HAVE_CC_INLINE_HINT
so powerpc is not impacted by this until they request it.
Exactly the reason why this was not widely enabled in the
first place (but implemnted in a too x86 specific way).


Updated patch below. I btw. renamed the option to say this is
about a INLINE_HINT.

	Sam

diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 49590f8..9645a6f 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -68,6 +68,7 @@ config SPARC
 	default y
 	select HAVE_IDE
 	select HAVE_OPROFILE
+	select HAVE_CC_INLINE_HINT
 
 # Identify this as a Sparc32 build
 config SPARC32
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index 8acc5cc..3c8ba36 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -9,6 +9,7 @@ config SPARC
 	bool
 	default y
 	select HAVE_OPROFILE
+	select HAVE_CC_INLINE_HINT
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
 
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2fadf79..48e352b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -20,6 +20,7 @@ config X86
 	def_bool y
 	select HAVE_IDE
 	select HAVE_OPROFILE
+	select HAVE_CC_INLINE_HINT
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
 	select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
@@ -142,9 +143,6 @@ config AUDIT_ARCH
 config ARCH_SUPPORTS_AOUT
 	def_bool y
 
-config ARCH_SUPPORTS_OPTIMIZED_INLINING
-	def_bool y
-
 # Use the generic interrupt handling code in kernel/irq/:
 config GENERIC_HARDIRQS
 	bool
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 5b1979a..23956ea 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -258,15 +258,3 @@ config CPA_DEBUG
 
 endmenu
 
-config OPTIMIZE_INLINING
-	bool "Allow gcc to uninline functions marked 'inline'"
-	default y
-	help
-	  This option determines if the kernel forces gcc to inline the functions
-	  developers have marked 'inline'. Doing so takes away freedom from gcc to
-	  do what it thinks is best, which is desirable for the gcc 3.x series of
-	  compilers. The gcc 4.x series have a rewritten inlining algorithm and
-	  disabling this option will generate a smaller kernel there. Hopefully
-	  this algorithm is so good that allowing gcc4 to make the decision can
-	  become the default in the future, until then this option is there to
-	  test gcc for this.
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index b2fd754..e49fade 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -31,8 +31,7 @@
 /*
  * Force always-inline if the user requests it so via the .config:
  */
-#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
-    !defined(CONFIG_OPTIMIZE_INLINING) && (__GNUC__ >= 4)
+#if !(defined(CONFIG_HAVE_CC_INLINE_HINT) && (__GNUC__ >= 4))
 # define inline		inline		__attribute__((always_inline))
 # define __inline__	__inline__	__attribute__((always_inline))
 # define __inline	__inline	__attribute__((always_inline))
diff --git a/init/Kconfig b/init/Kconfig
index ba3a389..3568647 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -508,6 +508,13 @@ config CC_OPTIMIZE_FOR_SIZE
 
 	  If unsure, say N.
 
+# archs shall "select HAVE_CC_INLINE_HINT"
+# to avoid forcing all function annotated inline
+# to be inline.
+# Note: This is only enforced for gcc > 4.0
+config HAVE_CC_INLINE_HINT
+	def_bool n
+
 config SYSCTL
 	bool
 

  parent reply	other threads:[~2008-04-27 18:31 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-27 10:51 [PATCH] prepare kconfig inline optimization for all architectures Sam Ravnborg
2008-04-27 10:51 ` Sam Ravnborg
     [not found] ` <20080427105100.GA14795-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org>
2008-04-27 11:31   ` Adrian Bunk
2008-04-27 11:31     ` Adrian Bunk
     [not found]     ` <20080427113158.GY2252-Aar9JVdAhcRoA3hw4S0G5QR5/fbUUdgG@public.gmane.org>
2008-04-27 11:56       ` Sam Ravnborg
2008-04-27 11:56         ` Sam Ravnborg
     [not found]         ` <20080427115603.GA23493-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org>
2008-04-27 12:36           ` Ingo Molnar
2008-04-27 12:36             ` Ingo Molnar
     [not found]             ` <20080427123642.GA28005-X9Un+BFzKDI@public.gmane.org>
2008-04-27 12:49               ` Ingo Molnar
2008-04-27 12:49                 ` Ingo Molnar
2008-04-27 17:06       ` Linus Torvalds
2008-04-27 17:06         ` Linus Torvalds
     [not found]         ` <alpine.LFD.1.10.0804271002360.2896-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-27 17:22           ` Adrian Bunk
2008-04-27 17:22             ` Adrian Bunk
     [not found]             ` <20080427172235.GA2252-Aar9JVdAhcRoA3hw4S0G5QR5/fbUUdgG@public.gmane.org>
2008-04-27 17:32               ` Linus Torvalds
2008-04-27 17:32                 ` Linus Torvalds
     [not found]                 ` <alpine.LFD.1.10.0804271029130.2896-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-27 17:47                   ` Adrian Bunk
2008-04-27 17:47                     ` Adrian Bunk
     [not found]                     ` <20080427174714.GB2252-Aar9JVdAhcRoA3hw4S0G5QR5/fbUUdgG@public.gmane.org>
2008-04-27 18:00                       ` Christoph Hellwig
2008-04-27 18:00                         ` Christoph Hellwig
     [not found]                         ` <20080427180007.GB28483-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2008-04-27 18:09                           ` Sam Ravnborg
2008-04-27 18:09                             ` Sam Ravnborg
     [not found]                             ` <20080427180957.GA25964-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org>
2008-04-27 18:14                               ` Christoph Hellwig
2008-04-27 18:14                                 ` Christoph Hellwig
     [not found]                                 ` <20080427181411.GA31667-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2008-04-27 18:24                                   ` Linus Torvalds
2008-04-27 18:24                                     ` Linus Torvalds
     [not found]                                     ` <alpine.LFD.1.10.0804271118500.2896-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-27 18:32                                       ` Christoph Hellwig
2008-04-27 18:32                                         ` Christoph Hellwig
2008-04-27 19:36                                       ` Ingo Molnar
2008-04-27 19:36                                         ` Ingo Molnar
     [not found]                                         ` <20080427193627.GA32654-X9Un+BFzKDI@public.gmane.org>
2008-04-27 19:49                                           ` Adrian Bunk
2008-04-27 19:49                                             ` Adrian Bunk
2008-04-27 23:26                                       ` Arjan van de Ven
2008-04-27 23:26                                         ` Arjan van de Ven
     [not found]                                         ` <20080427162606.3dd82c0c-NIQFrBLA1CpScpXdPBN83iCwEArCW2h5@public.gmane.org>
2008-04-27 23:36                                           ` Linus Torvalds
2008-04-27 23:36                                             ` Linus Torvalds
     [not found]                                             ` <alpine.LFD.1.10.0804271634490.3119-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-27 23:41                                               ` Ingo Molnar
2008-04-27 23:41                                                 ` Ingo Molnar
2008-04-27 18:31                                   ` Sam Ravnborg [this message]
2008-04-27 18:31                                     ` Sam Ravnborg
     [not found]                                     ` <20080427183131.GA26937-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org>
2008-04-27 18:36                                       ` Christoph Hellwig
2008-04-27 18:36                                         ` Christoph Hellwig
2008-04-27 18:11                       ` Linus Torvalds
2008-04-27 18:11                         ` Linus Torvalds
     [not found]                         ` <alpine.LFD.1.10.0804271053300.2896-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-27 18:25                           ` Christoph Hellwig
2008-04-27 18:25                             ` Christoph Hellwig
     [not found]                             ` <20080427182544.GA23828-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2008-04-27 18:30                               ` Linus Torvalds
2008-04-27 18:30                                 ` Linus Torvalds
2008-04-27 18:41                           ` Adrian Bunk
2008-04-27 18:41                             ` Adrian Bunk
     [not found]                             ` <20080427184106.GD2252-Aar9JVdAhcRoA3hw4S0G5QR5/fbUUdgG@public.gmane.org>
2008-04-27 18:57                               ` Linus Torvalds
2008-04-27 18:57                                 ` Linus Torvalds
2008-04-27 20:51                       ` Mike Galbraith
2008-04-27 20:51                         ` Mike Galbraith
2008-04-27 17:57                   ` Christoph Hellwig
2008-04-27 17:57                     ` Christoph Hellwig
2008-04-27 17:40               ` Matthew Wilcox
2008-04-27 17:40                 ` Matthew Wilcox
     [not found]                 ` <20080427174055.GS14990-6jwH94ZQLHl74goWV3ctuw@public.gmane.org>
2008-04-27 17:59                   ` Adrian Bunk
2008-04-27 17:59                     ` Adrian Bunk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080427183131.GA26937@uranus.ravnborg.org \
    --to=sam-uyr5n9q2vtjg9huczpvpmw@public.gmane.org \
    --cc=bunk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mingo-X9Un+BFzKDI@public.gmane.org \
    --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox