* [PATCH] Make gcc -align options .config-settable
@ 2004-10-01 19:26 Denis Vlasenko
2004-10-01 22:17 ` Andrew Morton
2004-10-04 18:38 ` Bill Davidsen
0 siblings, 2 replies; 13+ messages in thread
From: Denis Vlasenko @ 2004-10-01 19:26 UTC (permalink / raw)
To: Andrew Morton, Sam Ravnborg; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 195 bytes --]
Resend.
With all alignment options set to 1 (minimum alignment),
I've got 5% smaller vmlinux compared to one built with
default code alignment.
Rediffed against 2.6.9-rc3.
Please apply.
--
vda
[-- Attachment #2: align269r3.patch --]
[-- Type: text/x-diff, Size: 2812 bytes --]
diff -urp linux-2.6.9-rc3.src/Makefile linux-2.6.9-rc3_align.src/Makefile
--- linux-2.6.9-rc3.src/Makefile Fri Oct 1 21:29:57 2004
+++ linux-2.6.9-rc3_align.src/Makefile Fri Oct 1 21:45:20 2004
@@ -334,6 +334,8 @@ LDFLAGS_MODULE = -r
CFLAGS_KERNEL =
AFLAGS_KERNEL =
+GCC_VERSION = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
+
NOSTDINC_FLAGS = -nostdinc -iwithprefix include
# Use LINUXINCLUDE when you must reference the include/ directory.
@@ -484,6 +486,22 @@ ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
CFLAGS += -Os
else
CFLAGS += -O2
+endif
+
+GCC3 = $(shell if [ $(GCC_VERSION) -ge 0300 ] ; then echo "1"; else echo "0"; fi ;)
+ifeq ($(GCC3),1)
+ifneq ($(CONFIG_CC_ALIGN_FUNCTIONS),0)
+CFLAGS += -falign-functions=$(CONFIG_CC_ALIGN_FUNCTIONS)
+endif
+ifneq ($(CONFIG_CC_ALIGN_LABELS),0)
+CFLAGS += -falign-labels=$(CONFIG_CC_ALIGN_LABELS)
+endif
+ifneq ($(CONFIG_CC_ALIGN_LOOPS),0)
+CFLAGS += -falign-loops=$(CONFIG_CC_ALIGN_LOOPS)
+endif
+ifneq ($(CONFIG_CC_ALIGN_JUMPS),0)
+CFLAGS += -falign-jumps=$(CONFIG_CC_ALIGN_JUMPS)
+endif
endif
ifndef CONFIG_FRAME_POINTER
diff -urp linux-2.6.9-rc3.src/init/Kconfig linux-2.6.9-rc3_align.src/init/Kconfig
--- linux-2.6.9-rc3.src/init/Kconfig Fri Oct 1 21:30:19 2004
+++ linux-2.6.9-rc3_align.src/init/Kconfig Fri Oct 1 21:45:20 2004
@@ -303,6 +303,43 @@ config SHMEM
option replaces shmem and tmpfs with the much simpler ramfs code,
which may be appropriate on small systems without swap.
+config CC_ALIGN_FUNCTIONS
+ int "Function alignment"
+ default 0
+ help
+ Align the start of functions to the next power-of-two greater than n,
+ skipping up to n bytes. For instance, 32 aligns functions
+ to the next 32-byte boundary, but 24 would align to the next
+ 32-byte boundary only if this can be done by skipping 23 bytes or less.
+ Zero means use compiler's default.
+
+config CC_ALIGN_LABELS
+ int "Label alignment"
+ default 0
+ help
+ Align all branch targets to a power-of-two boundary, skipping
+ up to n bytes like ALIGN_FUNCTIONS. This option can easily
+ make code slower, because it must insert dummy operations for
+ when the branch target is reached in the usual flow of the code.
+ Zero means use compiler's default.
+
+config CC_ALIGN_LOOPS
+ int "Loop alignment"
+ default 0
+ help
+ Align loops to a power-of-two boundary, skipping up to n bytes.
+ Zero means use compiler's default.
+
+config CC_ALIGN_JUMPS
+ int "Jump alignment"
+ default 0
+ help
+ Align branch targets to a power-of-two boundary, for branch
+ targets where the targets can only be reached by jumping,
+ skipping up to n bytes like ALIGN_FUNCTIONS. In this case,
+ no dummy operations need be executed.
+ Zero means use compiler's default.
+
endmenu # General setup
config TINY_SHMEM
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-01 19:26 [PATCH] Make gcc -align options .config-settable Denis Vlasenko
@ 2004-10-01 22:17 ` Andrew Morton
2004-10-04 22:04 ` Sam Ravnborg
` (2 more replies)
2004-10-04 18:38 ` Bill Davidsen
1 sibling, 3 replies; 13+ messages in thread
From: Andrew Morton @ 2004-10-01 22:17 UTC (permalink / raw)
To: Denis Vlasenko; +Cc: sam, linux-kernel
Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> wrote:
>
> With all alignment options set to 1 (minimum alignment),
> I've got 5% smaller vmlinux compared to one built with
> default code alignment.
>
Sam, can you process this one?
>
>
> +GCC_VERSION = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
It bugs me that we're evaluating the same thing down in arch/i386/Makefile.
Perhaps we should evaluate GCC_VERSION once only, as some top-level kbuild
thing. So everyone can assume that it's present and correct?
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH] Make gcc -align options .config-settable
2004-10-01 22:17 ` Andrew Morton
@ 2004-10-04 22:04 ` Sam Ravnborg
2004-10-08 5:03 ` Keith Owens
2004-10-17 0:38 ` Sam Ravnborg
2 siblings, 0 replies; 13+ messages in thread
From: Sam Ravnborg @ 2004-10-04 22:04 UTC (permalink / raw)
To: Andrew Morton; +Cc: Denis Vlasenko, sam, linux-kernel
On Fri, Oct 01, 2004 at 03:17:51PM -0700, Andrew Morton wrote:
> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> wrote:
> >
> > With all alignment options set to 1 (minimum alignment),
> > I've got 5% smaller vmlinux compared to one built with
> > default code alignment.
> >
>
> Sam, can you process this one?
I will do so in a week or so.
Travelling (and busy) these days.
Sam
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-01 22:17 ` Andrew Morton
2004-10-04 22:04 ` Sam Ravnborg
@ 2004-10-08 5:03 ` Keith Owens
2004-10-17 0:38 ` Sam Ravnborg
2 siblings, 0 replies; 13+ messages in thread
From: Keith Owens @ 2004-10-08 5:03 UTC (permalink / raw)
To: Andrew Morton; +Cc: Denis Vlasenko, sam, linux-kernel
On Fri, 1 Oct 2004 15:17:51 -0700,
Andrew Morton <akpm@osdl.org> wrote:
>Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> wrote:
>>
>> With all alignment options set to 1 (minimum alignment),
>> I've got 5% smaller vmlinux compared to one built with
>> default code alignment.
>>
>
>Sam, can you process this one?
>
>>
>>
>> +GCC_VERSION = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
>
>It bugs me that we're evaluating the same thing down in arch/i386/Makefile.
> Perhaps we should evaluate GCC_VERSION once only, as some top-level kbuild
>thing. So everyone can assume that it's present and correct?
Using '=' is wrong here, it will evaluate the complete expression every
time GCC_VERSION is tested. It should be ':='. The only time '='
should be used in a Makefile is when delayed evaluation is really
required, e.g. for strings that are the target of $(call).
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-01 22:17 ` Andrew Morton
2004-10-04 22:04 ` Sam Ravnborg
2004-10-08 5:03 ` Keith Owens
@ 2004-10-17 0:38 ` Sam Ravnborg
2 siblings, 0 replies; 13+ messages in thread
From: Sam Ravnborg @ 2004-10-17 0:38 UTC (permalink / raw)
To: Andrew Morton; +Cc: Denis Vlasenko, sam, linux-kernel
On Fri, Oct 01, 2004 at 03:17:51PM -0700, Andrew Morton wrote:
> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> wrote:
> >
> > With all alignment options set to 1 (minimum alignment),
> > I've got 5% smaller vmlinux compared to one built with
> > default code alignment.
> >
>
> Sam, can you process this one?
>
> >
> >
> > +GCC_VERSION = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
>
> It bugs me that we're evaluating the same thing down in arch/i386/Makefile.
> Perhaps we should evaluate GCC_VERSION once only, as some top-level kbuild
> thing. So everyone can assume that it's present and correct?
Started looking into this.
gcc does not document what happens if -falign-functions=x is specified more than
once. It works but I have not checked the effect.
It will occur for some CPU's
Sam
Current patch to top-level Makefile looks like this.
===== Makefile 1.542 vs edited =====
--- 1.542/Makefile 2004-10-17 02:00:48 +02:00
+++ edited/Makefile 2004-10-17 02:29:56 +02:00
@@ -295,6 +295,11 @@
cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
+# cc-option-align
+# Prefix align with either -falign or -malign
+cc-option-align = $(subst -functions=0,,\
+ $(call cc-option,-falign-functions=0,-malign-functions=0))
+
# cc-version
# Usage gcc-ver := $(call cc-version $(CC))
cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
@@ -497,6 +502,13 @@
else
CFLAGS += -O2
endif
+
+#Add aling options in CONFIG_CC_ not equal to 0
+add-align = $(if $(filter-out 0,$($(1))),$(cc-option-align)$(2)=$($(1)))
+CFLAGS += $(call add-align,CONFIG_CC_ALIGN_FUNCTIONS,-functions)
+CFLAGS += $(call add-align,CONFIG_CC_ALIGN_LABELS,-labels)
+CFLAGS += $(call add-align,CONFIG_CC_ALIGN_LOOPS,-loops)
+CFLAGS += $(call add-align,CONFIG_CC_ALIGN_JUMPS,-jumps)
ifdef CONFIG_FRAME_POINTER
CFLAGS += -fno-omit-frame-pointer
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-01 19:26 [PATCH] Make gcc -align options .config-settable Denis Vlasenko
2004-10-01 22:17 ` Andrew Morton
@ 2004-10-04 18:38 ` Bill Davidsen
1 sibling, 0 replies; 13+ messages in thread
From: Bill Davidsen @ 2004-10-04 18:38 UTC (permalink / raw)
To: Denis Vlasenko; +Cc: Andrew Morton, Sam Ravnborg, linux-kernel
Denis Vlasenko wrote:
> Resend.
>
> With all alignment options set to 1 (minimum alignment),
> I've got 5% smaller vmlinux compared to one built with
> default code alignment.
It would be interesting to know if this is better WRT cache usage than
alignment which ensures that loops fit within the minimum number of
cache lines. That's not quite the same thing as starting on a cache line
in all cases.
This may be of interest to embedded builds.
--
-bill davidsen (davidsen@tmr.com)
"The secret to procrastination is to put things off until the
last possible moment - but no longer" -me
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <2KBq9-2S1-15@gated-at.bofh.it>]
* Re: [PATCH] Make gcc -align options .config-settable
[not found] <2KBq9-2S1-15@gated-at.bofh.it>
@ 2004-10-08 12:20 ` Andi Kleen
2004-10-08 17:10 ` Denis Vlasenko
0 siblings, 1 reply; 13+ messages in thread
From: Andi Kleen @ 2004-10-08 12:20 UTC (permalink / raw)
To: Denis Vlasenko; +Cc: linux-kernel
Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> writes:
> Resend.
>
> With all alignment options set to 1 (minimum alignment),
> I've got 5% smaller vmlinux compared to one built with
> default code alignment.
>
> Rediffed against 2.6.9-rc3.
> Please apply.
I agree with the basic idea (the big alignments also always annoy
me when I look at disassembly), but I think your CONFIG options
are far too complicated. I don't think anybody will go as far as
to tune loops vs function calls.
I would just do a single CONFIG_NO_ALIGNMENTS that sets everything to
1, that should be enough.
-Andi
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH] Make gcc -align options .config-settable
2004-10-08 12:20 ` Andi Kleen
@ 2004-10-08 17:10 ` Denis Vlasenko
2004-10-08 14:30 ` Grzegorz Kulewski
2004-10-08 15:42 ` Andi Kleen
0 siblings, 2 replies; 13+ messages in thread
From: Denis Vlasenko @ 2004-10-08 17:10 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel
On Friday 08 October 2004 12:20, Andi Kleen wrote:
> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> writes:
> > Resend.
> >
> > With all alignment options set to 1 (minimum alignment),
> > I've got 5% smaller vmlinux compared to one built with
> > default code alignment.
> >
> > Rediffed against 2.6.9-rc3.
> > Please apply.
>
> I agree with the basic idea (the big alignments also always annoy
> me when I look at disassembly), but I think your CONFIG options
> are far too complicated. I don't think anybody will go as far as
> to tune loops vs function calls.
>
> I would just do a single CONFIG_NO_ALIGNMENTS that sets everything to
> 1, that should be enough.
For me, yes, but there are people which are slightly less obsessed
with code size than me.
They might want to say "try to align to 16 bytes if
it costs less than 5 bytes" etc.
Also bencmarking people may do little research on real usefulness of
various kinds of alignment.
--
vda
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-08 17:10 ` Denis Vlasenko
@ 2004-10-08 14:30 ` Grzegorz Kulewski
2004-10-08 20:42 ` Denis Vlasenko
2004-10-08 15:42 ` Andi Kleen
1 sibling, 1 reply; 13+ messages in thread
From: Grzegorz Kulewski @ 2004-10-08 14:30 UTC (permalink / raw)
To: Denis Vlasenko; +Cc: Andi Kleen, linux-kernel
On Fri, 8 Oct 2004, Denis Vlasenko wrote:
> On Friday 08 October 2004 12:20, Andi Kleen wrote:
>> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> writes:
>>> Resend.
>>>
>>> With all alignment options set to 1 (minimum alignment),
>>> I've got 5% smaller vmlinux compared to one built with
>>> default code alignment.
>>>
>>> Rediffed against 2.6.9-rc3.
>>> Please apply.
>>
>> I agree with the basic idea (the big alignments also always annoy
>> me when I look at disassembly), but I think your CONFIG options
>> are far too complicated. I don't think anybody will go as far as
>> to tune loops vs function calls.
>>
>> I would just do a single CONFIG_NO_ALIGNMENTS that sets everything to
>> 1, that should be enough.
>
> For me, yes, but there are people which are slightly less obsessed
> with code size than me.
>
> They might want to say "try to align to 16 bytes if
> it costs less than 5 bytes" etc.
>
> Also bencmarking people may do little research on real usefulness of
> various kinds of alignment.
I think that removing aligns completly will be very bad. I am Gentoo user
and I set my user space CFLAGS for all system to -falign-loops
-fno-align-<everything else>. I did not tested it in depth, but my simple
tests show that unaligning loops is a very bad idea. Unaligning functions
is safer since small and fast functions should be always inlined.
Thanks,
Grzegorz Kulewski
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-08 14:30 ` Grzegorz Kulewski
@ 2004-10-08 20:42 ` Denis Vlasenko
2004-10-08 21:30 ` Grzegorz Kulewski
0 siblings, 1 reply; 13+ messages in thread
From: Denis Vlasenko @ 2004-10-08 20:42 UTC (permalink / raw)
To: Grzegorz Kulewski; +Cc: Andi Kleen, linux-kernel
On Friday 08 October 2004 17:30, Grzegorz Kulewski wrote:
> > Also bencmarking people may do little research on real usefulness of
> > various kinds of alignment.
>
> I think that removing aligns completly will be very bad. I am Gentoo user
> and I set my user space CFLAGS for all system to -falign-loops
> -fno-align-<everything else>. I did not tested it in depth, but my simple
> tests show that unaligning loops is a very bad idea. Unaligning functions
That depends on how often that loop runs. 90% of code runs only
10% of time. I think ultimately we want to mark other 10% of code with:
int __hotpath often_called_func()
{
...
}
Rest of code is to be optimized for size.
> is safer since small and fast functions should be always inlined.
Concept of alignment does not apply to inlined functions at all.
--
vda
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH] Make gcc -align options .config-settable
2004-10-08 20:42 ` Denis Vlasenko
@ 2004-10-08 21:30 ` Grzegorz Kulewski
0 siblings, 0 replies; 13+ messages in thread
From: Grzegorz Kulewski @ 2004-10-08 21:30 UTC (permalink / raw)
To: Denis Vlasenko; +Cc: Andi Kleen, linux-kernel
On Fri, 8 Oct 2004, Denis Vlasenko wrote:
> On Friday 08 October 2004 17:30, Grzegorz Kulewski wrote:
>>> Also bencmarking people may do little research on real usefulness of
>>> various kinds of alignment.
>>
>> I think that removing aligns completly will be very bad. I am Gentoo user
>> and I set my user space CFLAGS for all system to -falign-loops
>> -fno-align-<everything else>. I did not tested it in depth, but my simple
>> tests show that unaligning loops is a very bad idea. Unaligning functions
>
> That depends on how often that loop runs. 90% of code runs only
> 10% of time. I think ultimately we want to mark other 10% of code with:
Well, loops should probably always be aligned because aligning them will
not make the code significantly larger (I think, I did not mensure it),
but it will make the code significantly faster, and more friendly to
processor's cache.
>> is safer since small and fast functions should be always inlined.
>
> Concept of alignment does not apply to inlined functions at all.
That is my point. It is safe not to align functions because fast and often
called ones will be inlined and will not be slowed down by lack of
alignment.
Thanks,
Grzegorz Kulewski
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-08 17:10 ` Denis Vlasenko
2004-10-08 14:30 ` Grzegorz Kulewski
@ 2004-10-08 15:42 ` Andi Kleen
2004-10-08 20:46 ` Denis Vlasenko
1 sibling, 1 reply; 13+ messages in thread
From: Andi Kleen @ 2004-10-08 15:42 UTC (permalink / raw)
To: Denis Vlasenko; +Cc: linux-kernel
On Fri, Oct 08, 2004 at 05:10:58PM +0000, Denis Vlasenko wrote:
> On Friday 08 October 2004 12:20, Andi Kleen wrote:
> > Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> writes:
> > > Resend.
> > >
> > > With all alignment options set to 1 (minimum alignment),
> > > I've got 5% smaller vmlinux compared to one built with
> > > default code alignment.
> > >
> > > Rediffed against 2.6.9-rc3.
> > > Please apply.
> >
> > I agree with the basic idea (the big alignments also always annoy
> > me when I look at disassembly), but I think your CONFIG options
> > are far too complicated. I don't think anybody will go as far as
> > to tune loops vs function calls.
> >
> > I would just do a single CONFIG_NO_ALIGNMENTS that sets everything to
> > 1, that should be enough.
>
> For me, yes, but there are people which are slightly less obsessed
> with code size than me.
>
> They might want to say "try to align to 16 bytes if
> it costs less than 5 bytes" etc.
If they want to go down to that low level they can as well edit
the Makefiles. But we already have far too many configs and
adding new ones for obscure compiler options is not a good idea.
Also we don't normally add stuff "just in case", but only when
people actually use it.
-Andi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Make gcc -align options .config-settable
2004-10-08 15:42 ` Andi Kleen
@ 2004-10-08 20:46 ` Denis Vlasenko
0 siblings, 0 replies; 13+ messages in thread
From: Denis Vlasenko @ 2004-10-08 20:46 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel
> > > I would just do a single CONFIG_NO_ALIGNMENTS that sets everything to
> > > 1, that should be enough.
> >
> > For me, yes, but there are people which are slightly less obsessed
> > with code size than me.
> >
> > They might want to say "try to align to 16 bytes if
> > it costs less than 5 bytes" etc.
>
> If they want to go down to that low level they can as well edit
> the Makefiles. But we already have far too many configs and
> adding new ones for obscure compiler options is not a good idea.
>
> Also we don't normally add stuff "just in case", but only when
> people actually use it.
I have a suspicion that if I had submitted CONFIG_NO_ALIGNMENTS
patch instead, there would be comments from another crowd,
about it being too coarse.
Look at the post of Grzegorz Kulewski.
Anyway, I don't have strong preference. I just want to be at least
able to disable code alignment completely.
--
vda
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2004-10-16 22:38 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-01 19:26 [PATCH] Make gcc -align options .config-settable Denis Vlasenko
2004-10-01 22:17 ` Andrew Morton
2004-10-04 22:04 ` Sam Ravnborg
2004-10-08 5:03 ` Keith Owens
2004-10-17 0:38 ` Sam Ravnborg
2004-10-04 18:38 ` Bill Davidsen
[not found] <2KBq9-2S1-15@gated-at.bofh.it>
2004-10-08 12:20 ` Andi Kleen
2004-10-08 17:10 ` Denis Vlasenko
2004-10-08 14:30 ` Grzegorz Kulewski
2004-10-08 20:42 ` Denis Vlasenko
2004-10-08 21:30 ` Grzegorz Kulewski
2004-10-08 15:42 ` Andi Kleen
2004-10-08 20:46 ` Denis Vlasenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox