march和mtune的区别

转自:  http://blog.openrays.org/blog-htm-do-showone-tid-364.html

给定gcc优化选项时经常要指定march和mtune。我以前都将它们赋为一样的值,例如pentium4.

今天仔细研究了一下它们的区别,原来还是有一些道道的。

首先是man gcc:

-mtune=name
      This option is very similar to the -mcpu= option, except that
      instead of specifying the actual target processor type, and hence
      restricting which instructions can be used, it specifies that GCC
      should tune the performance of the code as if the target were of
      the type specified in this option, but still choosing the instruc-
      tions that it will generate based on the cpu specified by a -mcpu=
      option.

上面是gcc3.2的manpage,现在mcpu已经不用了,一般都用march。望文生义,march指定的是当前cpu的架构,而mtune是真正作用于某一型号cpu的选项。

根据链接:
http://gentoo-wiki.com/Safe_Cflags
的解释,march是“紧约束”,mtune是“松约束”。mtune可以提供后向兼容性,也就是mtune=pentium-mmx编译出来的程序,在pentium4处理器上也是可以运行的。

因此,像-march=i686 -mtune=pentium4这样的优化选项编译出来的程序,是为奔腾4处理器优化过的,但是在任何i686上都可以运行。

我猜,如果指定了-march=pentium3,那么在奔腾4处理器上程序是不能运行的。

上面是自己根据别人的文档整理出来的一些说法,具体是不是这么回事没有试验过。若有错误的地方,还请大虾指正:-)


转自:http://www.raspberrypi.org/phpBB3/viewtopic.php?f=54&t=707&start=50
There are stage3-tarballs but I didn't yet create a stage4-image. I could create you a SD that contains just bootloader-stuff (kernel, GPU firmware on the FAT-partition) and the Gentoo-stage3 files on a 4GB-base if you want.
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  drivintin » Sat May 19, 2012 10:13 pm
All I can say is, THANK YOU!

I just got my Pi, and just now really getting started with building Gentoo for it. Having an image has saved me tons of time.

Did any of you have any luck with cross-compiling? I am trying to see how an entire laymen overlay will work, so really need a lot more umph then just running QEMU. I just started the armv6zk-hardfloat-linux-gnueabi crossdev build. Really hoping it works out.

Also the SD card I have is total pain. Have any of you tried usb flash storage? It says you can boot from usb drives, but seems like most are putting the kernel on the SD then loading root from USB.

I am sure I will have a ton more questions. Thank you guys for working on this so that I can have a jumpstart!
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  Morgaine » Sun May 20, 2012 1:46 am
I'm a long-term user of Gentoo on all my Intel machines, so I'll be keeping an eye on this forum. However, as CERN wrote, "emerge -DuN" is most definitely not the thing to run on this little board, nor the daily "emerge --sync". These are probably commands to send the SD card to an early grave, in addition to taking forever.

It's going to be interesting to find good ways to get the best aspects of Gentoo on the Pi without suffering its downsides. The prize will be a very streamlined distribution since all options that are considered bloat can be disabled.

No Pi here yet though, probably not until June.

Morgaine.
Intolerance is a failure of education. Education is predicated on tolerance of the uneducated.

Posts: 141
Joined: Mon Mar 12, 2012 1:13 am
by  jannis » Sun May 20, 2012 5:10 am
drivintin wrote:Did any of you have any luck with cross-compiling? I am trying to see how an entire laymen overlay will work, so really need a lot more umph then just running QEMU. I just started the armv6zk-hardfloat-linux-gnueabi crossdev build. Really hoping it works out.


Yes, cross-compiling works just as well as distcc. When building your toolchain with crossdev be sure to sync before ( https://bugs.gentoo.org/show_bug.cgi?id=415937) and use "armv6j-hardfloat-linux-gnueabi" as triplet.

drivintin wrote:Also the SD card I have is total pain. Have any of you tried usb flash storage? It says you can boot from usb drives, but seems like most are putting the kernel on the SD then loading root from USB.


Yep, running from SD is pain. I'm using a 2.5"-SATA-HDD with external (USB 2.0) enclosure. and true, the kernel is in the SD-card since you cannot boot w/o SD.
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  drivintin » Mon May 21, 2012 5:51 am
Ok, well here is where I sit.

I had Fedora on an SD card that was working. So I got a 32G flash drive that I am going to run Gentoo from. Expanded  disneysw image onto the usb drive, copied over the boot partition to the sd card, and modified the root to /dev/sda2. Problem is the kernel does find the USB stick, but doesn't seem to know to make it sda. I actually used the fedora kernel fine, except for the fact that it doesn't contain nfs, which i need to mount the compiling machine. 

So really, what I guess I am asking is:
disneysw Can I get your kernel .config so I can try building another one? also what special items do I need to boot the raspberry besides the kernel? I noticed there were other files in the boot partition, i just don't have them in front of me.
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  coRpTitan » Mon May 21, 2012 6:36 am
Hello guys,
I've successfully deployed Gentoo on my RaspberryPI - CHOST="armv6zk-hardfloat-linux-gnueabi" .
I just wanna ask, if you are running Gentoo on your RaspberryIP box, what values in /etc/make.conf ? I'm interested at values for GCC.

I'm using:
CODE:  SELECT ALL
CFLAGS="-O2 -pipe -mcpu=arm1176jzf-s -march=armv6zk -mfpu=vfp -mfloat-abi=hard"
CXXFLAGS="${CFLAGS}"
CHOST="armv6zk-hardfloat-linux-gnueabi"


I think this should be correct, unfortunately when I'm compiling every single package I'm getting this warning:

warning: switch -mcpu=arm1176jzf-s conflicts with -march= switch

According to  http://dev.gentoo.org/~armin76/arm/chost.xml arm1176jzf-s should be armv6zk .

Is anyone having such wired warning message? I guess this message is not any serious problem, as it won't terminate compilation process but it's wired.
Posts: 3
Joined: Mon May 21, 2012 12:49 am
by  drivintin » Mon May 21, 2012 6:44 am
Ok, got a new kernel out of the github and looks like everything is booting up and mounting fine. not the trick is getting it to compile.

And suggestions on how to link the nfs share from my crossdev enviroment into the running Pi enviroment? 

Thanks again guys.
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  jannis » Mon May 21, 2012 9:55 am
coRpTitan wrote:I think this should be correct, unfortunately when I'm compiling every single package I'm getting this warning:

warning: switch -mcpu=arm1176jzf-s conflicts with -march= switch


Just omit the march-switch. Check the resulting binaries with "readelf -A" and you'll see that the mcpu-switch sets the arch automatically.
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  drivintin » Mon May 21, 2012 2:15 pm
So on the crossdev machine I am getting

CODE:  SELECT ALL
!!! /usr/armv6zk-hardfloat-linux-gnueabi/etc/make.profile is not a symlink and will probably prevent most merges.
!!! It should point into a profile within /usr/portage/profiles/
!!! (You can safely ignore this message when syncing. It's harmless.)


Looking at the profiles I assume I would point to /usr/portage/profiles/arm/arm6zk 
Except that doesn't exist, only a arm6j, is that where I should point it?

Sorry for all the questions, just new to this side of Gentoo.
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  jannis » Mon May 21, 2012 2:26 pm
drivintin wrote:So on the crossdev machine I am getting

CODE:  SELECT ALL
!!! /usr/armv6zk-hardfloat-linux-gnueabi/etc/make.profile is not a symlink and will probably prevent most merges.


I told you here:  viewtopic.php?p=80903#p80903
that armv6j-hardfloat-linux-gnueabi is the right triplet
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  drivintin » Mon May 21, 2012 2:50 pm
jannis wrote:I told you here:  viewtopic.php?p=80903#p80903
that armv6j-hardfloat-linux-gnueabi is the right triplet


Sorry, I think I understand now. The triplet uses armv6j then you use the make.conf of 

CODE:  SELECT ALL
 CFLAGS="-O2 -pipe -mcpu=arm1176jzf-s  -mfpu=vfp -mfloat-abi=hard"
CXXFLAGS="${CFLAGS}"
CHOST="armv6j-hardfloat-linux-gnueabi"


to set the hardware float, and the correct cpu. Right, I hope?
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  jannis » Mon May 21, 2012 3:21 pm
Yep, that one looks right. Sorry if it was formulated a little harsh in the last post, I have a bit of a headache today. If you have kernel problems, here is one I compiled for someone on IRC:
http://rpi.kripserver.net/unofficial/

make.conf will be uploaded there in some minutes (need to connect and boot up my RPi).
*EDIT*: make.conf up:  http://rpi.kripserver.net/unofficial/make.conf
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  drivintin » Mon May 21, 2012 10:40 pm
jannis wrote:Yep, that one looks right. Sorry if it was formulated a little harsh in the last post, I have a bit of a headache today. If you have kernel problems, here is one I compiled for someone on IRC:
http://rpi.kripserver.net/unofficial/

make.conf will be uploaded there in some minutes (need to connect and boot up my RPi).
*EDIT*: make.conf up:  http://rpi.kripserver.net/unofficial/make.conf



Not a problem, got it up and running, having some packages crash, but I will have to take a look at it a bit later. Glad you posted that make, I had not even thought about making a remote portage, makes it soo much faster and easier just to use a network copy and keeping it synced up.
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  disneysw » Tue May 22, 2012 7:39 am
Subject: Gentoo Linux

drivintin wrote:Ok, well here is where I sit.

I had Fedora on an SD card that was working. So I got a 32G flash drive that I am going to run Gentoo from. Expanded  disneysw image onto the usb drive, copied over the boot partition to the sd card, and modified the root to /dev/sda2. Problem is the kernel does find the USB stick, but doesn't seem to know to make it sda. I actually used the fedora kernel fine, except for the fact that it doesn't contain nfs, which i need to mount the compiling machine. 

So really, what I guess I am asking is:
disneysw Can I get your kernel .config so I can try building another one? also what special items do I need to boot the raspberry besides the kernel? I noticed there were other files in the boot partition, i just don't have them in front of me.


(Sorry, been busy for the past few days trying to build firefox ~3 day compile and Java/Icedtea.)

You can get the .config from a running kernel by uncompressing /proc/config.gz

The kernel on my images is from the pi foundation. Initially I was going to build a stock kernel but a quick browse around github it became clear there a number of customisation were made to support the Pi and it would take time determine exactly what they were. I may revisit this in future.

BTW, given the compile times for some of the larger packages I for one am implementing a crosscompile system!
Posts: 14
Joined: Tue May 08, 2012 10:49 am
by  disneysw » Tue May 22, 2012 8:04 am
Subject: Gentoo Linux

And suggestions on how to link the nfs share from my crossdev enviroment into the running Pi enviroment? 

Thanks again guys.[/quote]

I'd suggest physically plugging your SD card/memorystick into your crosscompile system using a reader if necessary.

Then create an executable script file containing
#! /bin/bash
mkdir -p /mnt/gentoo
mount /dev/sdXXXX /mnt/gentoo
cp /etc/resolv.conf /mnt/gentoo/etc/
mount -t /proc none /mnt/gentoo/proc
mount -o bind /tmp /mnt/gentoo/tmp
mount -o bind /dev /mnt/gentoo/dev
mount -o bind /sys /mnt/gentoo/sys
chroot /mnt/gentoo /bin/bash

run the above script, to chroot into the filesystem on your memory card
run the commands

env-update
source /etc/profile

you should now be good to go!

The above is done from memory so there may be mistakes, if I remember when I get home I will post my 'script'.


The other alternative if you cant physically plug the root filesystem in is to start sshd on the Pi and use 'sshfs' to remotly mount it. Google sshfs & gentoo for more info.
Posts: 14
Joined: Tue May 08, 2012 10:49 am
by  jannis » Tue May 22, 2012 8:43 am
That way of cross-compiling won't work. You can't chroot into an ARM-system an a x86/x86_64 system because you cannot execute ARM-binaries on that host.
The way to go is to setup a cross-compiler on your x86/x86_64 system (easy with crossdev) and then use distcc for cross-compiling:
http://www.gentoo.org/doc/en/cross-compiling-distcc.xml

Just make sure that the RPi doesn't do any compilation (don't include 127.0.0.1 in /etc/distcc/hosts). Such a setup is working here. The only problem is memory-usage on linking (which is done on the emerging host, distcc off or on). One way around would be to use the gold linker on the RPi ( https://wiki.gentoo.org/wiki/Gold) but I've never tried it since I'm not going to install firefox or java on the Pi (or at least don't plan to do so)
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  disneysw » Tue May 22, 2012 12:57 pm
Sorry, your correct. I am planning on trying using qemu, but I have yet to test this method.
See  http://www.gentoo.org/proj/en/base/embe ... t=1&chap=5 


distcc would probably be a faster but I have had versioning issues with the in the past that put me off using it. To be fair that was a good number of years ago.
Posts: 14
Joined: Tue May 08, 2012 10:49 am
by  jannis » Tue May 22, 2012 1:48 pm
Yep, with binfmt_misc and qemu_user this might work. Keep us informed how things work out.

I remember having had versioning issues, too. That was back in the days where x86_64-machines helped x86-machines keep their system up-to-date. Just today I set-up the i686-toolchain again and distcc is working. I guess the "-S"-parameter (use stable versions for the cross-toolchain) helped a lot.
Posts: 55
Joined: Tue Jan 17, 2012 3:48 pm
by  drivintin » Tue May 22, 2012 3:30 pm
So what I did was actually use crossdev to build the cross compile system tree. Then I made that directory tree an nfs share, and planned on actually chroot'ing into the nfs share. I have gentoo running from a 32GB flash drive right now just fine. A also used the github kernel on an sd card fo the boot. I am running into several packages that won't build is the problem I am having right now. I haven't had a chance to dive in and see what the deal is, but hope to get to that over the next day.
Posts: 7
Joined: Sat May 19, 2012 10:08 pm
by  disneysw » Tue May 22, 2012 11:09 pm
Ok, so here is the last of the Gentoo stages that I plan to release. In total I have three raspberryPi images at different build stages. All of them are designed to reduce the amount of time it takes to get Gentoo up and running as a platform. It's up to you to customise the images for your own needs. 

The first is basically a bootable stage3 install and will fit on a 4GB card
http://com.legato-solutions.raspberrypi ... 13V1-1.zip

The second builds on that to add X11 in prep for a Window Manager - Use this if you want to build KDE, Gnome etc.. Requires an 8GB card
http://com.legato-solutions.raspberrypi ... GB.img.zip


The final adds xfce4 as a window manager - Requires an 8GB card 
http://com.legato-solutions.raspberrypi ... GB.img.zip

I'll probably create and release a bootable USB Live version of Gentoo containing distcc and crossdev to allow one or more PC's to assist the compile process as some of the larger packages could/will take days on a physical device.



README:

This zip contains a bootable Gentoo Linux image for the RaspberryPi
It was created by gmcclean at legato-solutions.com as a checkpoint during the build of a customised solution for an embedded application. 

The default username is 'pi' 
The default password 'raspberry'

You can 'sudo -s' to root or use sudo to run elevated commands or 
manually start a GUI by typing 'startxfce4' after logging in.

22 May 2012 Requires 8GB or larger card
Added xfce desktop GUI, ffmpeg, mplayer, vlc, distcc
Support for distcc is not fully enabled yet (It still compiles locally). I will probably create a live USB drive consisting of a minimal gentoo plus distcc and crosscompile to accelerate building for the raspberryPi
Added rpi-update from  https://github.com/Hexxeh/rpi-update to enable simple firmware updates
Things still to do - fix hardware video acceleration!!!!! Move /usr/portage to separate file system to reduce footprint
Available from  http://com.legato-solutions.raspberrypi ... GB.img.zip

15 May 2012 Requires 8GB or larger card
Added xorg-base as a prelude to building an X11 Window Manager. Personally going with xfce but you could build/use KDE, Gnome or something else. The choice is yours.......
Available from  http://com.legato-solutions.raspberrypi ... GB.img.zip


13 May 2012 - Base Gentoo install on RaspberryPi suitable for someone looking for a headless solution with minimal footprint and easily fits on a 4GB SD card. Available from 
https://s3-eu-west-1.amazonaws.com/com. ... 13V1-1.zip

(V1.1)
Fixed /etc/make.conf
Resolved issue that would have effected eth0

(V1.0)
Created ext4 filesystem with extra inodes
Installed Stage3
chroot into system
kernel and modules take from debian6-19-04-2012 image
Removed serial tty from /etc/inittab
Updated /etc/make.conf
Added nano, openntpd, sudo
Set /etc/locattime and /etc/timezone to Europe/London
Set uk keyboard in /etc/conf/keymaps
Updated /etc/conf.d/hwclock so avoid error when trying to read no-existent clock 
Created "pi" user with "raspberry" password
sudoers updated to give access to 'pi' account
Updated /etc/fstab
Posts: 14
Joined: Tue May 08, 2012 10:49 am
by  coRpTitan » Wed May 23, 2012 7:08 pm
jannis wrote:Just omit the march-switch. Check the resulting binaries with "readelf -A" and you'll see that the mcpu-switch sets the arch automatically.

I've did it, and here is output:
CODE:  SELECT ALL
raspberrypi ~ # readelf -A /usr/bin/mc
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM1176JZF-S"
  Tag_CPU_arch: v6KZ
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_HardFP_use: SP and DP
  Tag_ABI_VFP_args: VFP registers
  Tag_DIV_use: Not allowed
  Tag_Virtualization_use: TrustZone
raspberrypi ~ #
Notice that Tag_CPU_arch is v6 K Z

and according to official gcc documentation(  http://gcc.gnu.org/onlinedocs/gcc-4.5.3 ... RM-Options ) it should be: armv6 Z K .

So I guess it's wrongly in gcc documentation or in GCC itself, but I don't care, I've omitted "-march=" completely and warning is no more here.

BTW: Did anyone tried to deploy armv6 j-hardfloat-linux-gnueabi onto rpi and then change CHOST to armv6 zk-hardfloat-linux-gnueabi and recompile gcc?

I was getting error, when compiling it, I've tried to purge ccache cache, disabled distcc and result was still the same. After that I've used USE="vanilla" emerge -av gcc and it worked, so I guess Gentoo patchset is preventing it to compile. So if you will go through this, you can safe lot of testing if you will emerge vanilla gcc :]
Posts: 3
Joined: Mon May 21, 2012 12:49 am
by  mike632t » Wed May 23, 2012 9:58 pm
jannis wrote:There are stage3-tarballs but I didn't yet create a stage4-image. I could create you a SD that contains just bootloader-stuff (kernel, GPU firmware on the FAT-partition) and the Gentoo-stage3 files on a 4GB-base if you want.


That would be a great help - this will only be the second time I've tried a Gentoo install as I normally stick with Debian. (Yep you guessed it - the last time wasn't a huge success, but I've learn't a little more since then!)
Posts: 32
Joined: Sat May 19, 2012 7:56 pm
Location: UK
by  playmobot » Fri Jun 01, 2012 12:05 am
disneysw wrote:Ok, so here is the last of the Gentoo stages that I plan to release. In total I have three raspberryPi images at different build stages. All of them are designed to reduce the amount of time it takes to get Gentoo up and running as a platform. It's up to you to customise the images for your own needs. 

The first is basically a bootable stage3 install and will fit on a 4GB card
http://com.legato-solutions.raspberrypi ... 13V1-1.zip

The second builds on that to add X11 in prep for a Window Manager - Use this if you want to build KDE, Gnome etc.. Requires an 8GB card
http://com.legato-solutions.raspberrypi ... GB.img.zip


The final adds xfce4 as a window manager - Requires an 8GB card 
http://com.legato-solutions.raspberrypi ... GB.img.zip

I'll probably create and release a bootable USB Live version of Gentoo containing distcc and crossdev to allow one or more PC's to assist the compile process as some of the larger packages could/will take days on a physical device.



README:

This zip contains a bootable Gentoo Linux image for the RaspberryPi
It was created by gmcclean at legato-solutions.com as a checkpoint during the build of a customised solution for an embedded application. 

The default username is 'pi' 
The default password 'raspberry'

You can 'sudo -s' to root or use sudo to run elevated commands or 
manually start a GUI by typing 'startxfce4' after logging in.

22 May 2012 Requires 8GB or larger card
Added xfce desktop GUI, ffmpeg, mplayer, vlc, distcc
Support for distcc is not fully enabled yet (It still compiles locally). I will probably create a live USB drive consisting of a minimal gentoo plus distcc and crosscompile to accelerate building for the raspberryPi
Added rpi-update from  https://github.com/Hexxeh/rpi-update to enable simple firmware updates
Things still to do - fix hardware video acceleration!!!!! Move /usr/portage to separate file system to reduce footprint
Available from  http://com.legato-solutions.raspberrypi ... GB.img.zip

15 May 2012 Requires 8GB or larger card
Added xorg-base as a prelude to building an X11 Window Manager. Personally going with xfce but you could build/use KDE, Gnome or something else. The choice is yours.......
Available from  http://com.legato-solutions.raspberrypi ... GB.img.zip


13 May 2012 - Base Gentoo install on RaspberryPi suitable for someone looking for a headless solution with minimal footprint and easily fits on a 4GB SD card. Available from 
https://s3-eu-west-1.amazonaws.com/com. ... 13V1-1.zip

(V1.1)
Fixed /etc/make.conf
Resolved issue that would have effected eth0

(V1.0)
Created ext4 filesystem with extra inodes
Installed Stage3
chroot into system
kernel and modules take from debian6-19-04-2012 image
Removed serial tty from /etc/inittab
Updated /etc/make.conf
Added nano, openntpd, sudo
Set /etc/locattime and /etc/timezone to Europe/London
Set uk keyboard in /etc/conf/keymaps
Updated /etc/conf.d/hwclock so avoid error when trying to read no-existent clock 
Created "pi" user with "raspberry" password
sudoers updated to give access to 'pi' account
Updated /etc/fstab



Thanks for the great work would you be able to have a twm .img with rpi-update?
Posts: 12
Joined: Wed Aug 24, 2011 9:25 pm
by  disneysw » Fri Jun 01, 2012 1:13 pm

Thanks for the great work would you be able to have a twm .img with rpi-update?



np

The image created on 15 May 2012 ( http://com.legato-solutions.raspberrypi ... GB.img.zip) includes twm but not the firmware update app. However it only takes a few minutes to install it by going to Hexxeh’s blog ( http://hexxeh.net/?p=328117855) and following the instructions.
Posts: 14
Joined: Tue May 08, 2012 10:49 am
by  whitelabrat » Sun Jun 03, 2012 10:55 pm
Big thanks for your build images disneysw!

I've been able to add apache2, php, and mysql along with other odd and ends. Building midori right now.


你可能感兴趣的:(march和mtune的区别)