* PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
@ 2012-06-23 16:06 H.J. Lu
2012-06-23 16:13 ` Andi Kleen
2012-06-24 3:13 ` [tip:x86/build] x86-64, gcc: Use -mpreferred-stack-boundary= 3 " tip-bot for H.J. Lu
0 siblings, 2 replies; 8+ messages in thread
From: H.J. Lu @ 2012-06-23 16:06 UTC (permalink / raw)
To: LKML, Andi Kleen, H. Peter Anvin
[-- Attachment #1: Type: text/plain, Size: 460 bytes --]
Hi,
-mpreferred-stack-boundary=3 can be used on x86-64 with GCC 4.8.0:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
I backported it to hjl/x32/gcc-4_7-branch branch at
http://gcc.gnu.org/git/?p=gcc.git;a=summary
http://gcc.gnu.org/git/?p=gcc.git;a=commit;h=96828b1f869a31e3a1227afa420b8f28e71
e006c
This patch uses -mpreferred-stack-boundary=3 on x86-64 if it is supported.
I have been running 3.4 kernel compiled with this option for weeks.
H.J.
[-- Attachment #2: 0001-Use-mpreferred-stack-boundary-3-if-supported.patch --]
[-- Type: application/octet-stream, Size: 884 bytes --]
From 5e067376e73fe3bf86b71c2560e03c5d35a7b537 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 29 May 2012 14:31:23 -0700
Subject: [PATCH] Use -mpreferred-stack-boundary=3 if supported
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
arch/x86/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 94e91e4..cd4a4f7 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -49,6 +49,9 @@ else
KBUILD_AFLAGS += -m64
KBUILD_CFLAGS += -m64
+ # Use -mpreferred-stack-boundary=3 if supported.
+ KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
+
# FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
--
1.7.10.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
2012-06-23 16:06 PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported H.J. Lu
@ 2012-06-23 16:13 ` Andi Kleen
2012-06-23 16:17 ` H. Peter Anvin
2012-06-24 3:13 ` [tip:x86/build] x86-64, gcc: Use -mpreferred-stack-boundary= 3 " tip-bot for H.J. Lu
1 sibling, 1 reply; 8+ messages in thread
From: Andi Kleen @ 2012-06-23 16:13 UTC (permalink / raw)
To: H.J. Lu; +Cc: LKML, Andi Kleen, H. Peter Anvin
> This patch uses -mpreferred-stack-boundary=3 on x86-64 if it is supported.
> I have been running 3.4 kernel compiled with this option for weeks.
But why?
All the SSE code in the kernel should adjust manually. And the other
code doesn't need it.
Besides the entry points do not guarantee alignment.
For the kernel it would be probably more useful to have a attribute
per function that forces alignment.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
2012-06-23 16:13 ` Andi Kleen
@ 2012-06-23 16:17 ` H. Peter Anvin
2012-06-23 16:49 ` H.J. Lu
2012-06-23 19:27 ` Andi Kleen
0 siblings, 2 replies; 8+ messages in thread
From: H. Peter Anvin @ 2012-06-23 16:17 UTC (permalink / raw)
To: Andi Kleen, H.J. Lu; +Cc: LKML
To keep gcc from paddong the stack to maintain a nonexistent alignment.
Andi Kleen <andi@firstfloor.org> wrote:
>> This patch uses -mpreferred-stack-boundary=3 on x86-64 if it is
>supported.
>> I have been running 3.4 kernel compiled with this option for weeks.
>
>But why?
>
>All the SSE code in the kernel should adjust manually. And the other
>code doesn't need it.
>
>Besides the entry points do not guarantee alignment.
>
>For the kernel it would be probably more useful to have a attribute
>per function that forces alignment.
>
>-Andi
>--
>ak@linux.intel.com -- Speaking for myself only.
--
Sent from my mobile phone. Please excuse brevity and lack of formatting.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
2012-06-23 16:17 ` H. Peter Anvin
@ 2012-06-23 16:49 ` H.J. Lu
2012-06-23 22:57 ` Randy Dunlap
2012-06-23 19:27 ` Andi Kleen
1 sibling, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2012-06-23 16:49 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Andi Kleen, LKML
On Sat, Jun 23, 2012 at 9:17 AM, H. Peter Anvin <hpa@zytor.com> wrote:
> To keep gcc from paddong the stack to maintain a nonexistent alignment.
>
> Andi Kleen <andi@firstfloor.org> wrote:
>
>>> This patch uses -mpreferred-stack-boundary=3 on x86-64 if it is
>>supported.
>>> I have been running 3.4 kernel compiled with this option for weeks.
>>
>>But why?
>>
>>All the SSE code in the kernel should adjust manually. And the other
>>code doesn't need it.
>>
>>Besides the entry points do not guarantee alignment.
>>
>>For the kernel it would be probably more useful to have a attribute
>>per function that forces alignment.
There was an attempt from you to do it in 2007:
http://lkml.indiana.edu/hypermail/linux/kernel/0708.2/2604.html
http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01697.html
But the gcc patch was never checked in.
--
H.J.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
2012-06-23 16:17 ` H. Peter Anvin
2012-06-23 16:49 ` H.J. Lu
@ 2012-06-23 19:27 ` Andi Kleen
2012-06-23 19:45 ` H. Peter Anvin
1 sibling, 1 reply; 8+ messages in thread
From: Andi Kleen @ 2012-06-23 19:27 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Andi Kleen, H.J. Lu, LKML
On Sat, Jun 23, 2012 at 09:17:06AM -0700, H. Peter Anvin wrote:
> To keep gcc from paddong the stack to maintain a nonexistent alignment.
Ah ok. 3 instead of 4.
I thought i had done that a long time ago, but now it somehow
only seems to be there for 32bit.
Makes sense.
-Andi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
2012-06-23 19:27 ` Andi Kleen
@ 2012-06-23 19:45 ` H. Peter Anvin
0 siblings, 0 replies; 8+ messages in thread
From: H. Peter Anvin @ 2012-06-23 19:45 UTC (permalink / raw)
To: Andi Kleen; +Cc: H.J. Lu, LKML
Yes, it didn't work on 64 bits until now.
Andi Kleen <andi@firstfloor.org> wrote:
>On Sat, Jun 23, 2012 at 09:17:06AM -0700, H. Peter Anvin wrote:
>> To keep gcc from paddong the stack to maintain a nonexistent
>alignment.
>
>
>Ah ok. 3 instead of 4.
>
>I thought i had done that a long time ago, but now it somehow
>only seems to be there for 32bit.
>
>Makes sense.
>
>-Andi
--
Sent from my mobile phone. Please excuse brevity and lack of formatting.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported
2012-06-23 16:49 ` H.J. Lu
@ 2012-06-23 22:57 ` Randy Dunlap
0 siblings, 0 replies; 8+ messages in thread
From: Randy Dunlap @ 2012-06-23 22:57 UTC (permalink / raw)
To: H.J. Lu; +Cc: H. Peter Anvin, Andi Kleen, LKML
On 06/23/2012 09:49 AM, H.J. Lu wrote:
> On Sat, Jun 23, 2012 at 9:17 AM, H. Peter Anvin <hpa@zytor.com> wrote:
>> To keep gcc from paddong the stack to maintain a nonexistent alignment.
>>
>> Andi Kleen <andi@firstfloor.org> wrote:
>>
>>>> This patch uses -mpreferred-stack-boundary=3 on x86-64 if it is
>>> supported.
>>>> I have been running 3.4 kernel compiled with this option for weeks.
>>>
>>> But why?
>>>
>>> All the SSE code in the kernel should adjust manually. And the other
>>> code doesn't need it.
>>>
>>> Besides the entry points do not guarantee alignment.
>>>
>>> For the kernel it would be probably more useful to have a attribute
>>> per function that forces alignment.
>
> There was an attempt from you to do it in 2007:
>
> http://lkml.indiana.edu/hypermail/linux/kernel/0708.2/2604.html
> http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01697.html
>
> But the gcc patch was never checked in.
>
>
Some (most) of this explanation needs to be in the patch description.
--
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* [tip:x86/build] x86-64, gcc: Use -mpreferred-stack-boundary= 3 if supported
2012-06-23 16:06 PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported H.J. Lu
2012-06-23 16:13 ` Andi Kleen
@ 2012-06-24 3:13 ` tip-bot for H.J. Lu
1 sibling, 0 replies; 8+ messages in thread
From: tip-bot for H.J. Lu @ 2012-06-24 3:13 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hjl.tools
Commit-ID: d9b0cde91c60da0ed5f92cdc3ac878142e6b5f27
Gitweb: http://git.kernel.org/tip/d9b0cde91c60da0ed5f92cdc3ac878142e6b5f27
Author: H.J. Lu <hjl.tools@gmail.com>
AuthorDate: Tue, 29 May 2012 14:31:23 -0700
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Sat, 23 Jun 2012 19:25:22 -0700
x86-64, gcc: Use -mpreferred-stack-boundary=3 if supported
On x86-64, the standard ABI requires alignment to 16 bytes. However,
this is not actually necessary in the kernel (we don't do SSE except
in very controlled ways); and furthermore, the standard kernel entry
on x86-64 actually leaves the stack on an odd 8-byte boundary, which
means that gcc will generate extra instructions to keep the stack
*mis*aligned!
gcc 4.8 adds an -mpreferred-stack-boundary=3 option to override this
and lets us save some stack space and a handful of instructions.
Note that this causes us to pass -mno-sse twice; this is redundant,
but necessary since the cc-option test will fail unless -mno-sse is
passed on the same command line.
[ hpa: rewrote the patch description ]
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Link: http://lkml.kernel.org/r/CAMe9rOqPfy3JcZRLaUeCjBe9BVY-P6e0uaSbMi5hvS-6WwQueg@mail.gmail.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/Makefile | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 1f25214..b0c5276 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -49,6 +49,9 @@ else
KBUILD_AFLAGS += -m64
KBUILD_CFLAGS += -m64
+ # Use -mpreferred-stack-boundary=3 if supported.
+ KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
+
# FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-06-24 3:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-23 16:06 PATCH] Use -mpreferred-stack-boundary=3 on x86-64 if supported H.J. Lu
2012-06-23 16:13 ` Andi Kleen
2012-06-23 16:17 ` H. Peter Anvin
2012-06-23 16:49 ` H.J. Lu
2012-06-23 22:57 ` Randy Dunlap
2012-06-23 19:27 ` Andi Kleen
2012-06-23 19:45 ` H. Peter Anvin
2012-06-24 3:13 ` [tip:x86/build] x86-64, gcc: Use -mpreferred-stack-boundary= 3 " tip-bot for H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox