View previous topic :: View next topic |
Author |
Message |
soaringcondor Tux's lil' helper
Joined: 16 Dec 2003 Posts: 103
|
Posted: Sat Feb 07, 2004 12:33 am Post subject: Compile Optimization Questions |
|
|
I'm trying to go through and learn how to set up my CFLAGS to make gentoo optimize programs pretty well for my machine and purposes. I have a couple of questions. I have an AMD Athlon-XP 2800+ with GCC 3.2.3 and am running KDE as my desktop enviroment (more on this latter.) Having gone through a bunch of documentation I want to make sure what I know is correct.
1. Using "-march=athlon-xp" uses "-mcpu=athlon-xp" plus flags that the chip supports, like "-mmx -m3dnow -msse" so I don't need to add them.
2. If I use flags that are too aggressive, some programs won't compile well. Ideally, I'd like to get a set of flags that most things will work well on (so not too aggressive.)
3. Everyone seems to use at least -O2 with -O3 and -Os being different branches of that.
Anyways, I've read that since -Os optimizes for size, it will make KDE and X run better while -O3 will have it run a bit slower since it inlines the code making for a larger executable. Any opinions on this and the two sets of CFLAGS?
CFLAGS="-Os -march=athlon-xp -pipe -fomit-frame-pointer -ffast-math -ftracer"
CFLAGS="-O3 -march=athlon-xp -pipe -fomit-frame-pointer -fprefetch-loop-arrays -ffast-math -fforce-addr -falign-functions=4 -momit-leaf-frame-pointer -ftracer"
Any recomendations on which to use or how to improve it would be great. Also, should/can I upgrade to GCC 3.3.2 or 3.4? How would one go about doing that?
Is it wise to run "emerge -e world" and then walk away for a day?
Thanks,
Justin |
|
Back to top |
|
|
d99ma Tux's lil' helper
Joined: 21 Jul 2003 Posts: 148 Location: Lund, Sweden
|
Posted: Sat Feb 07, 2004 12:56 am Post subject: |
|
|
1. Correct
2. Sounds sane
Most people run O2 or O3, but Os is catching on, I'm using it cause I have a laptop with a slow hd, and I like it.
There are quite a few threads about CFLAGS around, check them for tips. Start with CFLAG Central.
GCC 3.3.2 is pretty safe to use, 3.4 will give you more trouble, but also more rewards. Compile times with 3.4 are a bit nicer than erlier gcc versions.
But I suggest you get a working system up with 3.2 or 3.3 before you start compiling packages with 3.4.
/Martin |
|
Back to top |
|
|
soaringcondor Tux's lil' helper
Joined: 16 Dec 2003 Posts: 103
|
Posted: Sat Feb 07, 2004 1:21 am Post subject: |
|
|
Okay - any idea on what CFLAGS to use or if I can emerge -e world safely?
EDIT: Can I just do this to upgrade GCC? What about bootstraping?
# ACCEPT_KEYWORDS="~x86" emerge gcc |
|
Back to top |
|
|
jesterspet Apprentice
Joined: 05 Feb 2003 Posts: 215 Location: Atlanta
|
Posted: Sat Feb 07, 2004 1:35 am Post subject: |
|
|
First the GCC question.
Yes, you should upgrade it first, and you only need to bootstrap upon initial installation, after that normal installations are more than sufficient. I have not seen any shows topping news on GCC 3.4 yet, so it should be safe to upgrade if your compiler is due for upgrading, then upgrading it before the rest of your packages is a must. The only exceptions to this rule would be Portage & Glibc.
- Portage because it contains all the high level instructions on how everything else should be compiled & installed.
- Glibc should always be upgrade before anything else (except portage) as it is the library that everything else will reference during compiling & when they run. Having the most current libs for your compile is really important.
- GCC is the third most important thing to upgrade before the rest of your system as ti has bug fixes & code optimizations & other goodies that you will most likely want to take advantage of.
If you read CFLAGS Central you should be able to see that:- Implied flags are not always implemented, so stating the ones you really want wont hurt.
- Not all flags work for all folks, it is a bit of trial & error until you find the ones that work for you.
- Reading that entire thread from start to finish, may cause sudden drowsiness, brain hemorrhaging, and bleeding from various bodily openings.
- Starting with small steps and implementing small changes will most likely be the best advice you get as this can become a religious debate quickly.
As far as running emerge -e world and walking away, that is a decision only you can make , but I have had problems with just emerge world, I only walk away if I know the packages I am upgrading are minor upgrades, otherwise I keep an eye on it. _________________ (X) Yes! I am a brain damaged lemur on crack, and would like to buy your software package for $499.95 |
|
Back to top |
|
|
soaringcondor Tux's lil' helper
Joined: 16 Dec 2003 Posts: 103
|
Posted: Sat Feb 07, 2004 1:48 am Post subject: |
|
|
Thank you very much for the response. I will go back through the GCC docs and more of the CFLAGS Central thread (you were right about the side effects )
Anyways, since my version of Portage and glibc are up-to-date under the x86 tree, should I emerge the ~x86 version of GCC or upgrade Portage and glibc to their respective ~x86 versions?
As far as having portage recompile everything with the new settings, is there any specific order things need to be recompiled in assuming I'm only really messing with portage and GCC settings? That way I can do it in chunks intead of the whole thing.
Thanks again
EDIT: Are there any flags I need to add to be able to prelink things? I couldn't find it in the guide. |
|
Back to top |
|
|
jesterspet Apprentice
Joined: 05 Feb 2003 Posts: 215 Location: Atlanta
|
Posted: Sat Feb 07, 2004 5:26 am Post subject: |
|
|
soaringcondor wrote: | should I emerge the ~x86 version of GCC or upgrade Portage and glibc to their respective ~x86 versions? |
Unless you want to take a shot at b0rking your entire system, never install the ~x86 version of glibc, or portage. these are two things you want to run stable & sure, all the time, every time. You can install the ~x86 version of GCC normally without many problems.
soaringcondor wrote: | As far as having portage recompile everything with the new settings, is there any specific order things need to be recompiled in assuming I'm only really messing with portage and GCC settings? That way I can do it in chunks intead of the whole thing.
Thanks again
EDIT: Are there any flags I need to add to be able to prelink things? I couldn't find it in the guide. |
-fPIC is the CFLAG you are looking for, and you have to compile glibc to support prelinking (the pic USE flag should be set), and there is no way you read the whole thread, as all the needed info about CFLAGS for the last few versions of GCC are contained within it.
As long as portage , glibc are let to their stable versions, you should not need to break up your emerge. Since you are using the -e flag I can only assume that you want to recompile everything, and not just the packages that have been updated since your last emerge world In this case, I suggest that you use a stable compiler for your emerge, and then after that is over you can install the GCC 3.4 & recompile whatever package that suits your fancy. If you try to install GCC 3.4 first, you will only revert back to GCC 3.2.3 when you do your emerge, and only a few packages will be compiled with the GCC 3.4 compiler. _________________ (X) Yes! I am a brain damaged lemur on crack, and would like to buy your software package for $499.95 |
|
Back to top |
|
|
soaringcondor Tux's lil' helper
Joined: 16 Dec 2003 Posts: 103
|
Posted: Sat Feb 07, 2004 5:53 am Post subject: |
|
|
No, I'm just using 3.2.3 now so I wanted to use 3.3.2 before I redid everything - no need to mess with 3.4 since I don't even see it in portage (probably available at breakmygentoo.net.)
Thanks for the help,
Justin |
|
Back to top |
|
|
soaringcondor Tux's lil' helper
Joined: 16 Dec 2003 Posts: 103
|
Posted: Sat Feb 07, 2004 7:18 am Post subject: |
|
|
Trying to decide which CFLAG set to use. I read through the thread and found a lot a great information that I missed before (mainly regarding setting things up to work the best for the Athlon XPs L1 cache) but am worried about my stability. Any ideas on what I should use?
# Pretty Safe Flags:
#CFLAGS="-mcpu=athlon-xp -O2 -finline-functions -pipe -fomit-frame-pointer -funroll-loops"
#
# Little more aggressive:
# CFLAGS="-mcpu=athlon-xp -O2 -finline-functions -pipe -fomit-frame-pointer -funroll-loops -ffast-math -fpic"
#
# Aggressive:
#CFLAGS="-mcpu=athlon-xp -O2 -finline-functions -pipe -fomit-frame-pointer -funroll-loops -ffast-math -fpic -fforce-addr -ftracer -fprefetch-loop-arrays"
#
# Really Aggressive for the Athlon XP:
#CFLAGS="-O2 -march=athlon-xp -pipe -finline-functions -falign-functions=16 -falign-loops=16 -falign-jumps=16 -falign-labels=1 -fomit-frame-pointer -fforce-addr -fpic -ffast-math -fforce-addr -ftracer -fprefetch-loop-arrays -funroll-loops"
EDIT: I give up - unless tweaking my CFLAGS exhaustively will yield a large (10% or so) increase can someone recomend a good, safe setting to be used on an athlon-xp? Perhaps as simple as:
CFLAGS="-02 -march=athlon-xp -finlin-functions -pipe -fomit-frame-pointers"
or are there a couple more that can be safely added for good proformance gains?
EDIT2: Should I stick -fPIC in my CFLAGS for use with prelinking or is there no need (since glibc compilies with it's own flags based on your USE flags.) |
|
Back to top |
|
|
soaringcondor Tux's lil' helper
Joined: 16 Dec 2003 Posts: 103
|
Posted: Sat Feb 07, 2004 6:44 pm Post subject: |
|
|
Using the following CFLAGS now and wanted to make sure it was an acceptable choice, if possible:
CFLAGS="-march=athlon-xp -O2 -finline-functions -pipe -fomit-frame-pointer -funroll-loops -ffast-math -fpic -fforce-addr -ftracer -fprefetch-loop-arrays" |
|
Back to top |
|
|
boudie n00b
Joined: 01 Feb 2004 Posts: 74 Location: nova scotia, canada
|
Posted: Sat Feb 07, 2004 7:09 pm Post subject: |
|
|
man gcc says:
-O2 turns on all optional optimizations except for
loop unrolling, function inlining, and register renaming. |
|
Back to top |
|
|
Otto[FIN] n00b
Joined: 25 Aug 2003 Posts: 22 Location: Espoo/Finland
|
Posted: Tue Feb 10, 2004 2:56 pm Post subject: |
|
|
Someone told me that you should specify both -mcpu and -march, because some packages strips away -march.
If no -mcpu then is present when -march is stripped, it use defaults.
But if you have -mcpu there, you at least get the optimizations.
This is only what I'm told, so don't know if true. But I don't think -mcpu will hurt to be there even if you have -march.
Otto |
|
Back to top |
|
|
|