From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org, akpm@linux-foundation.org,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 12/12] Force always inline for gcc 4.5 when optimizing for size
Date: Thu, 13 Oct 2011 16:08:52 -0700 [thread overview]
Message-ID: <1318547332-23155-12-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1318547332-23155-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
I found that gcc 4.5 didn't inline a lot of inlines with
CONFIG_OPTIMIZE_INLINING and CONFIG_CC_OPTIMIZE_FOR_SIZE. It was quite
common to have very small inlines to be out of line, or worse inline
statics in include files to be out of line with a copy for every file
using it too.
This is handily visible in a function graph trace for might_fault:
10) | might_fault() {
10) | _cond_resched() {
10) | should_resched() {
10) | need_resched() {
10) 0.063 us | test_ti_thread_flag();
10) 0.643 us | }
10) 1.238 us | }
10) 1.845 us | }
10) 2.438 us | }
Note all of these functions are very small and should be definitely
inlined in each other. In many cases even copy_from_user
ends up out of line now which is really bad!
If I switch to -O2 it is also not quite as bad, but since a lot
of people use -Os I was trying to fix it up.
So this patch forces inlining with gcc 4.5 with -Os.
Unfortunately it costs some code size with just this patch.
text data bss dec hex filename
11507035 1940276 1191936 14639247 df608f vmlinux-O2
10189858 1908124 1187840 13285822 cab9be vmlinux-Os-force
9808525 1940204 1187840 12936569 c56579 vmlinux-Os-orig
It turned out most of this was because of unnecessary inlines.
With a lot of inlines removed I now get:
11175824 1977200 1191936 14344960 dae300 vmlinux-inlines-removed-no-optimize
11642530 2018416 1191936 14852882 e2a312 vmlinux-master-no-optimize
11530439 2001264 1191936 14723639 e0aa37 vmlinux-master-optimize
which is significantly smaller.
I haven't tested earlier gcc 4.x versions, but they may need
the same treatment.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
include/linux/compiler-gcc.h | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 59e4028..e477a7c 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -44,9 +44,12 @@
/*
* Force always-inline if the user requests it so via the .config,
* or if gcc is too old:
+ * When optimizing for size on gcc 4.5 always force inlining too.
*/
#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
- !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
+ !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) || \
+ (defined(CONFIG_CC_OPTIMIZE_FOR_SIZE) && \
+ (__GNUC__ == 4 && __GNUC_MINOR__ == 5))
# define inline inline __attribute__((always_inline))
# define __inline__ __inline__ __attribute__((always_inline))
# define __inline __inline __attribute__((always_inline))
--
1.7.4.4
next prev parent reply other threads:[~2011-10-13 23:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-13 23:08 [PATCH 01/12] RADEON: Drop inlines from evergreen_cs.c / r600_cs.c Andi Kleen
2011-10-13 23:08 ` [PATCH 02/12] RADEON: Move r100_*_*reg out of line Andi Kleen
2011-10-13 23:08 ` [PATCH 03/12] RADEON: drop inlines in r600_blit.c Andi Kleen
2011-10-13 23:08 ` [PATCH 04/12] RADEON: Remove now unused functions in radeon driver Andi Kleen
2011-10-13 23:08 ` [PATCH 05/12] FB_ATY: Move register accesses out of line Andi Kleen
2011-10-13 23:08 ` [PATCH 06/12] RADEON: Remove more bogus inlines in the radeon driver Andi Kleen
2011-10-13 23:08 ` [PATCH 07/12] RADEON: Move more code out of line Andi Kleen
2011-10-13 23:08 ` [PATCH 08/12] X86: Move alloc_intr_gate " Andi Kleen
2011-10-13 23:08 ` [PATCH 09/12] Don't use inline node_page_state for sysfs output functions Andi Kleen
2011-10-13 23:08 ` [PATCH 10/12] REISERFS: reiserfs drop unnecessary inlines Andi Kleen
2011-10-13 23:08 ` [PATCH 11/12] i915: Move i915_read/write out of line Andi Kleen
2011-10-15 13:49 ` Daniel Vetter
2011-10-18 5:47 ` Ben Widawsky
2011-10-13 23:08 ` Andi Kleen [this message]
2011-10-18 8:59 ` [PATCH 01/12] RADEON: Drop inlines from evergreen_cs.c / r600_cs.c David Airlie
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=1318547332-23155-12-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.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
Powered by JetHome