2007-10-25 18:33:47

by Mike Lothian

[permalink] [raw]
Subject: Possibility of adding -march=native to x86

Hi

I was wondering if it was possible to add -march=native support to the
processor options of the new x86 architecture if gcc 4.2 or greater is being
used.

I'm not suggesting this should be a default at all, merely an extra option
similar to selecting P4, Athlon or even -Os.

I've manually tried this flag at home with no ill effects.

Mike


2007-10-25 18:50:05

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, Oct 25, 2007 at 07:33:35PM +0100, Michael Lothian wrote:
> Hi
>
> I was wondering if it was possible to add -march=native support to the
> processor options of the new x86 architecture if gcc 4.2 or greater is being
> used.
>
> I'm not suggesting this should be a default at all, merely an extra option
> similar to selecting P4, Athlon or even -Os.
>
> I've manually tried this flag at home with no ill effects.

Selecting your CPU in the kernel configuration has more effects than
just setting the gcc flag, so it wouldn't gain you anything since you
anyway have to choose the correct CPU.

> Mike

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-10-25 19:10:12

by Mike Lothian

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

Actually I changed the Makefile.cpu and changed the -march to native
which did slightly change the size of the kernel (slightly larger I
think)

So what else does that option change?

Mike

On 25/10/2007, Adrian Bunk <[email protected]> wrote:
> On Thu, Oct 25, 2007 at 07:33:35PM +0100, Michael Lothian wrote:
> > Hi
> >
> > I was wondering if it was possible to add -march=native support to the
> > processor options of the new x86 architecture if gcc 4.2 or greater is being
> > used.
> >
> > I'm not suggesting this should be a default at all, merely an extra option
> > similar to selecting P4, Athlon or even -Os.
> >
> > I've manually tried this flag at home with no ill effects.
>
> Selecting your CPU in the kernel configuration has more effects than
> just setting the gcc flag, so it wouldn't gain you anything since you
> anyway have to choose the correct CPU.
>
> > Mike
>
> cu
> Adrian
>
> --
>
> "Is there not promise of rain?" Ling Tan asked suddenly out
> of the darkness. There had been need of rain for many days.
> "Only a promise," Lao Er said.
> Pearl S. Buck - Dragon Seed
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2007-10-25 19:17:06

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, Oct 25, 2007 at 08:09:56PM +0100, Michael Lothian wrote:
> Actually I changed the Makefile.cpu and changed the -march to native
> which did slightly change the size of the kernel (slightly larger I
> think)
>
> So what else does that option change?

Look at arch/i386/Kconfig.cpu

> Mike

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-10-25 19:33:04

by Mike Lothian

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On 25/10/2007, Adrian Bunk <[email protected]> wrote:
> On Thu, Oct 25, 2007 at 08:09:56PM +0100, Michael Lothian wrote:
> > Actually I changed the Makefile.cpu and changed the -march to native
> > which did slightly change the size of the kernel (slightly larger I
> > think)
> >
> > So what else does that option change?
>
> Look at arch/i386/Kconfig.cpu
>

Can you be a bit more specific?

2007-10-25 19:50:00

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, Oct 25, 2007 at 08:32:51PM +0100, Michael Lothian wrote:
> On 25/10/2007, Adrian Bunk <[email protected]> wrote:
> > On Thu, Oct 25, 2007 at 08:09:56PM +0100, Michael Lothian wrote:
> > > Actually I changed the Makefile.cpu and changed the -march to native
> > > which did slightly change the size of the kernel (slightly larger I
> > > think)
> > >
> > > So what else does that option change?
> >
> > Look at arch/i386/Kconfig.cpu
> >
>
> Can you be a bit more specific?

Let's make an example:

Consider you want to compile a kernel for your P4.

The MPENTIUM4 option does not only set -march=pentium4, it also enables
several other options in arch/i386/Kconfig.cpu resulting in better
performance.

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-10-25 20:12:55

by Mike Lothian

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

> The MPENTIUM4 option does not only set -march=pentium4, it also enables
> several other options in arch/i386/Kconfig.cpu resulting in better
> performance.

How about an autodetect to set the right options here too using cpuid?

With a warning of course that the code produced will be specifically
for the native cpu that it's compiled on.

2007-10-25 20:20:32

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, Oct 25, 2007 at 09:12:45PM +0100, Michael Lothian wrote:
> > The MPENTIUM4 option does not only set -march=pentium4, it also enables
> > several other options in arch/i386/Kconfig.cpu resulting in better
> > performance.
>
> How about an autodetect to set the right options here too using cpuid?
>
> With a warning of course that the code produced will be specifically
> for the native cpu that it's compiled on.

If you don't know or can figure out yourself the CPU you have, you'd
better not compile your own kernel...

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-10-25 20:24:38

by Arjan van de Ven

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, 25 Oct 2007 22:20:31 +0200
Adrian Bunk <[email protected]> wrote:

> On Thu, Oct 25, 2007 at 09:12:45PM +0100, Michael Lothian wrote:
> > > The MPENTIUM4 option does not only set -march=pentium4, it also
> > > enables several other options in arch/i386/Kconfig.cpu resulting
> > > in better performance.
> >
> > How about an autodetect to set the right options here too using
> > cpuid?
> >
> > With a warning of course that the code produced will be specifically
> > for the native cpu that it's compiled on.
>
> If you don't know or can figure out yourself the CPU you have, you'd
> better not compile your own kernel...
>
... or if there is more than just one CPU type, you pick generic.


--
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings,
visit http://www.lesswatts.org

2007-10-25 20:41:52

by Gabriel C

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

Michael Lothian wrote:
>> The MPENTIUM4 option does not only set -march=pentium4, it also enables
>> several other options in arch/i386/Kconfig.cpu resulting in better
>> performance.
>
> How about an autodetect to set the right options here too using cpuid?
>
> With a warning of course that the code produced will be specifically
> for the native cpu that it's compiled on.

And kill off all Distro kernels right ? IMO to set that auto magically is bad.

Regards,

Gabriel

2007-10-25 21:30:26

by Mike Lothian

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On 25/10/2007, Gabriel C <[email protected]> wrote:
> Michael Lothian wrote:
> >> The MPENTIUM4 option does not only set -march=pentium4, it also enables
> >> several other options in arch/i386/Kconfig.cpu resulting in better
> >> performance.
> >
> > How about an autodetect to set the right options here too using cpuid?
> >
> > With a warning of course that the code produced will be specifically
> > for the native cpu that it's compiled on.
>
> And kill off all Distro kernels right ? IMO to set that auto magically is bad.
>
> Regards,
>
> Gabriel
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
Yes for something like a distro kernel it is bad but as I said before
this isn't what this is for.

Eventually it would be nice to to a make localkernel and for a
customised kernel to be build compiling in all pci / pci express
drivers into the kernel and all usb devices as modules.

Auto magically detecting the cpu would be part of that

I hate getting a new piece of kit and then have to figure out from
lspci which options need to be turned on and the the really iritation
part of finding the option in make menuconfig

Detecting the cpu and using march=native could be all part of that

Mike

2007-10-25 21:46:32

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, Oct 25, 2007 at 10:30:09PM +0100, Michael Lothian wrote:
> On 25/10/2007, Gabriel C <[email protected]> wrote:
> > Michael Lothian wrote:
> > >> The MPENTIUM4 option does not only set -march=pentium4, it also enables
> > >> several other options in arch/i386/Kconfig.cpu resulting in better
> > >> performance.
> > >
> > > How about an autodetect to set the right options here too using cpuid?
> > >
> > > With a warning of course that the code produced will be specifically
> > > for the native cpu that it's compiled on.
> >
> > And kill off all Distro kernels right ? IMO to set that auto magically is bad.
> >
> > Regards,
> >
> > Gabriel
> >
> Yes for something like a distro kernel it is bad but as I said before
> this isn't what this is for.
>
> Eventually it would be nice to to a make localkernel and for a
> customised kernel to be build compiling in all pci / pci express
> drivers into the kernel and all usb devices as modules.
>
> Auto magically detecting the cpu would be part of that
>
> I hate getting a new piece of kit and then have to figure out from
> lspci which options need to be turned on and the the really iritation
> part of finding the option in make menuconfig

What exactly is irritating?
Please name the problems so that they can be fixed.

> Detecting the cpu and using march=native could be all part of that

You don't need march=native for this.

You have to set the right config option for your CPU and you
automatically get the right compiler options.

> Mike

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-10-25 22:04:52

by H. Peter Anvin

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

Adrian Bunk wrote:
>>>
>> Yes for something like a distro kernel it is bad but as I said before
>> this isn't what this is for.
>>
>> Eventually it would be nice to to a make localkernel and for a
>> customised kernel to be build compiling in all pci / pci express
>> drivers into the kernel and all usb devices as modules.
>>
>> Auto magically detecting the cpu would be part of that
>>
>> I hate getting a new piece of kit and then have to figure out from
>> lspci which options need to be turned on and the the really iritation
>> part of finding the option in make menuconfig
>
> What exactly is irritating?
> Please name the problems so that they can be fixed.
>
>> Detecting the cpu and using march=native could be all part of that
>
> You don't need march=native for this.
>
> You have to set the right config option for your CPU and you
> automatically get the right compiler options.
>

There was a long discussion years ago -- the infamous "Aunt Tillie"
thread -- about automatically configuring customized kernels for
specific hardware.

It's somewhat of an unusual thing to bother with these days, except for
people who develop and maintain the kernel.

-hpa

2007-10-25 22:43:20

by Mike Lothian

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

> What exactly is irritating?
> Please name the problems so that they can be fixed.
>
> > Detecting the cpu and using march=native could be all part of that
>
> You don't need march=native for this.
>
> You have to set the right config option for your CPU and you
> automatically get the right compiler options.

Well when doing a lspci here are some specific examples:



03:02.0 Multimedia controller: Philips Semiconductors SAA7146 (rev 01)

What modules would you think you'd need to compile to get this to work?

No it's not budget card os buget card ci even though the card its self
has no cam interface



00:14.2 Audio device: ATI Technologies Inc SB600 Azalia

Is there any indication from this piece of info that the intel hda
driver is required?



00:12.0 SATA controller: ATI Technologies Inc SB600 Non-Raid-5 SATA

This uses AHCI



As for the i2c and the hardware monitoring support well that's mostly guess work


Half the time it's easier doing a lsmod when booted on a livecd and
trying to figure out what options are required from the module names
which sometime can be just as tricky.

Why not auto detect the CPU the same way GCC does and automatically
set the correct CPU and then go the whole hog and let GCC use the
correct flags if it's new enough using native

I can't understand why you wouldn't find this useful when setting up a
customised kernel.

Maybe even having a make addnewhardware option to quickly add extra
devices to your config file.

Mike

2007-10-25 22:58:17

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Thu, Oct 25, 2007 at 11:42:47PM +0100, Michael Lothian wrote:
> > What exactly is irritating?
> > Please name the problems so that they can be fixed.
> >
> > > Detecting the cpu and using march=native could be all part of that
> >
> > You don't need march=native for this.
> >
> > You have to set the right config option for your CPU and you
> > automatically get the right compiler options.
>
> Well when doing a lspci here are some specific examples:
>
>
>
> 03:02.0 Multimedia controller: Philips Semiconductors SAA7146 (rev 01)
>
> What modules would you think you'd need to compile to get this to work?
>
> No it's not budget card os buget card ci even though the card its self
> has no cam interface
>
>
>
> 00:14.2 Audio device: ATI Technologies Inc SB600 Azalia
>
> Is there any indication from this piece of info that the intel hda
> driver is required?
>
>
>
> 00:12.0 SATA controller: ATI Technologies Inc SB600 Non-Raid-5 SATA
>
> This uses AHCI
>
>
>
> As for the i2c and the hardware monitoring support well that's mostly guess work
>
>
> Half the time it's easier doing a lsmod when booted on a livecd and
> trying to figure out what options are required from the module names
> which sometime can be just as tricky.

Sure, distributions already have solved this and you can use their
work.

> Why not auto detect the CPU the same way GCC does and automatically
> set the correct CPU and then go the whole hog and let GCC use the
> correct flags if it's new enough using native
>
> I can't understand why you wouldn't find this useful when setting up a
> customised kernel.
>
> Maybe even having a make addnewhardware option to quickly add extra
> devices to your config file.

Knowing your CPU is much easier to figure out than to figure out the
BIOS settings of your SATA controller that determine how to access it.

If you do not even know what CPU you have you should really not compile
your own kernel.

> Mike

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-10-25 22:58:48

by Mike Lothian

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

> > Half the time it's easier doing a lsmod when booted on a livecd and
> > trying to figure out what options are required from the module names
> > which sometime can be just as tricky.
>
> Sure, distributions already have solved this and you can use their
> work.

I like compiling my own kernel it's just a pain doing it the first
time on a new motherboard or when adding a new piece of hardware

> > Maybe even having a make addnewhardware option to quickly add extra
> > devices to your config file.
>
> Knowing your CPU is much easier to figure out than to figure out the
> BIOS settings of your SATA controller that determine how to access it.

So how do distro's figure out which driver to use? Isn't it a matter
of taking the pci-ids and selecting the correct driver?

> If you do not even know what CPU you have you should really not compile
> your own kernel.

It about ease of use, look at the new core2 architecture, if your gcc
is new enough there is a march=core2 else you use an older flag

Same with the new cell architecture you use cell if your using gcc 4.3
alpha or 930 if it's not that new.

What I'm saying is sometimes GCC or the Kernel is better at making
these decisions or at least make it easier

Mike

2007-10-26 09:16:40

by Thomas Gleixner

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86


On Thu, 25 Oct 2007, Michael Lothian wrote:

> Hi
>
> I was wondering if it was possible to add -march=native support to the
> processor options of the new x86 architecture if gcc 4.2 or greater is being
> used.
>
> I'm not suggesting this should be a default at all, merely an extra option
> similar to selecting P4, Athlon or even -Os.
>
> I've manually tried this flag at home with no ill effects.

It works for your specific setup, but it will kill distro compiles as
well as cross compiling.

tglx

2007-10-26 10:42:39

by Pádraig Brady

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

Adrian Bunk wrote:
> On Thu, Oct 25, 2007 at 09:12:45PM +0100, Michael Lothian wrote:
>>> The MPENTIUM4 option does not only set -march=pentium4, it also enables
>>> several other options in arch/i386/Kconfig.cpu resulting in better
>>> performance.
>> How about an autodetect to set the right options here too using cpuid?
>>
>> With a warning of course that the code produced will be specifically
>> for the native cpu that it's compiled on.
>
> If you don't know or can figure out yourself the CPU you have, you'd
> better not compile your own kernel...

There also is the added variable of what your version of gcc supports.
The kernel gcc options would have to be the highest common factor.
See also http://www.pixelbeat.org/scripts/gcccpuopt

Pádraig.

2007-10-26 11:45:01

by Adrian Bunk

[permalink] [raw]
Subject: Re: Possibility of adding -march=native to x86

On Fri, Oct 26, 2007 at 11:41:18AM +0100, Pádraig Brady wrote:
> Adrian Bunk wrote:
> > On Thu, Oct 25, 2007 at 09:12:45PM +0100, Michael Lothian wrote:
> >>> The MPENTIUM4 option does not only set -march=pentium4, it also enables
> >>> several other options in arch/i386/Kconfig.cpu resulting in better
> >>> performance.
> >> How about an autodetect to set the right options here too using cpuid?
> >>
> >> With a warning of course that the code produced will be specifically
> >> for the native cpu that it's compiled on.
> >
> > If you don't know or can figure out yourself the CPU you have, you'd
> > better not compile your own kernel...
>
> There also is the added variable of what your version of gcc supports.
> The kernel gcc options would have to be the highest common factor.
> See also http://www.pixelbeat.org/scripts/gcccpuopt

arch/i386/Makefile.cpu already does more or less the same.

> Pádraig.

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed