Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
GCC optimization
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
markan
n00b
n00b


Joined: 11 Aug 2013
Posts: 20

PostPosted: Thu Oct 10, 2013 10:54 am    Post subject: GCC optimization Reply with quote

i wnat to try compile every packages separatelly, gentoo handbook says that this is only way to get maximum performance
but im not sure how to choose cflags for each package
i supose that using -O2, -Os or -O3 is just a default way becouse those is collection of many optimization flags so for max performance i need combine flags from -O2 and -O3 and many more...

so what i want to know is:
is there any formula or principe which can tell me what flags are best for each program or i need try to compile it with different flags and than test with benchmark
how i can know for example which flags are best for xorg ?
Back to top
View user's profile Send private message
nemectic
Apprentice
Apprentice


Joined: 20 Aug 2004
Posts: 182

PostPosted: Thu Oct 10, 2013 1:25 pm    Post subject: Reply with quote

Generally, just use:

Code:
-march=native


That will pick optimizations based on your processor.

Unless you really know what you're doing, it's a bad idea to start messing with CFLAGS too much, you'll just end up causing problems.

Code:
gcc -march=native -E -v - </dev/null 2>&1 | grep cc1


That will list all the flags -march=native turns on for you.
Back to top
View user's profile Send private message
Yamakuzure
Advocate
Advocate


Joined: 21 Jun 2006
Posts: 2280
Location: Adendorf, Germany

PostPosted: Thu Oct 10, 2013 3:01 pm    Post subject: Reply with quote

Please see
http://wiki.gentoo.org/wiki/CFLAGS
and if you do not want to use "-march=native" pleae see
http://wiki.gentoo.org/wiki/Safe_CFLAGS
_________________
Important German:
  1. "Aha" - German reaction to pretend that you are really interested while giving no f*ck.
  2. "Tja" - German reaction to the apocalypse, nuclear war, an alien invasion or no bread in the house.
Back to top
View user's profile Send private message
markan
n00b
n00b


Joined: 11 Aug 2013
Posts: 20

PostPosted: Thu Oct 10, 2013 6:08 pm    Post subject: Reply with quote

thanks for replaying
iw read this links but this is not what im looking for
i dont talk about architecture optimization
architecture opt will optimize program for my proc, so like handbook says every program is deiferend and will reqie some specifical optimization
-O2 is default its just save but its not optimized becouse optimization and stabillity cant go together
-O2, even -O3 will just optimize program little bit how it can be optimized to stay stable
becouse GCC doesnt know what our system will look like, it can do general specification for maximum optimization
and we cant optimize program max with -O2, we must know how one program will use memory and proc to supose best optimization for it
and thats my question. How i can know that ?
firefox will be max optimized if i choose -Os for it becouse its big but with adding some flags from -O2 and even -O3 too, and optimize it in /portage.env to be able other deps will not be optimized with this flags becouse they requied another flags for max optimization, they are different apps, smaller so i can try with -O3 but with removing some dangerous flags from it.
-O3 is general flag with many flags inside...just some of them (not all) are dangerous for just on application (not all)

how i can shoose what combinations are best for each app?
Back to top
View user's profile Send private message
nemectic
Apprentice
Apprentice


Joined: 20 Aug 2004
Posts: 182

PostPosted: Thu Oct 10, 2013 6:25 pm    Post subject: Reply with quote

Research, trial & error, the links posted above are a good starting point.

Most people don't mess around with CFLAGS too much because it's easy to mess up your system and improvements are generally negligible.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Thu Oct 10, 2013 6:36 pm    Post subject: Reply with quote

Just use -O2 -march=native. That's what everyone does...

Also there may be some useflags (mmx sse etc.) you might want to set in order to get optimal support for your CPU in some programs. ffmpeg has a bunch of those flags.
Back to top
View user's profile Send private message
markan
n00b
n00b


Joined: 11 Aug 2013
Posts: 20

PostPosted: Thu Oct 10, 2013 9:40 pm    Post subject: Reply with quote

Code:
The CFLAGS and CXXFLAGS variables define the optimization flags for the gcc C and C++ compiler respectively. [b]Although we define those generally here, you will only have maximum performance if you optimize these flags for each program separately[/b]. The reason for this is because every program is different


Thats from Gentoo handbook 2004.2
I like that handbook so much, that was true gentoo with stage 1 tarball.
Im a newbie gentoo user (use it for couple of mounts) but i can release that -march=naitive and -O2 will not optimize my system how it can be optimized, it will just make its stable with default optimization which work on every gentoo system in the world same. if i think like that i can use genkernel becouse it is optimized with default optimization like -O2 is...
we dont want generical genkernel, so why will we want use generical -O2 ?

People thing thats no big difference in optimization. It is. People also use stage 3 and dont believe there is defference:

Code:
Starting from a stage1 allows you to have total control over the optimization settings and optional build-time functionality that is initially enabled on your system


Thats form handbook 2004.2 too
And i was try stage 1 and im 100% sure that my gentoo is 30% faster and optimized than it was with stage 3.
And i thing it will be 30% faster too if i build every part of it with different cflags like this handbook says. Without included globaly flag like -O2 or -Os, just with combining specific flags from -O2 and -Os or -O3, depends on program and make some -Ox flag wich is mutated from all -O
But i have problem, becouse description for flags on GCC page are general and only programers can understand it... so i need something to start which can learn me how to optimize it best i can for specific application

Btw i dont like why gentoo developers doesnt support stage 1 anymore, with stage 3 gentoo is not gentoo it same like arch: install base and compile if you want or install binarys for your needs, only difference is that gentoo have kernel compilation and 100 times better package management but stage 1 is another story it is LFS with best package management system in linux
i think developers must support stage 1 again so people will not talking anymore thats no performance difference between gentoo and arch, on the other hand nobodie today use pentium 4 so stage 1 isnt long time process
it will be nice to see updated stage 1 tarball like alternative handbook page list, last is from 2005 and it only can make problems
Back to top
View user's profile Send private message
nemectic
Apprentice
Apprentice


Joined: 20 Aug 2004
Posts: 182

PostPosted: Thu Oct 10, 2013 10:58 pm    Post subject: Reply with quote

Well it seems you know what you want, so you could try starting here.
Back to top
View user's profile Send private message
markan
n00b
n00b


Joined: 11 Aug 2013
Posts: 20

PostPosted: Fri Oct 11, 2013 2:29 am    Post subject: Reply with quote

thats link is just about why to use gentoo instead of debian, nothing about gcc optimization
but thanks its great links... i will save it to give someone when he will ask me why to use gentoo
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Fri Oct 11, 2013 3:30 am    Post subject: Reply with quote

markan wrote:
And i was try stage 1 and im 100% sure that my gentoo is 30% faster and optimized than it was with stage 3.

I am 100% sure your guess is more than 500% wrong. What can be achieved with not specifically hardware-related cflags and without special code is in the domain of 0-1% speed. Hardware-related flags as set by -march=native -O2 may be a different story, but even they do not give much more except for some special multimedia libraries (which usually add the supported hardware features anyway unless you explicitly forbid it.)
Moreover, apparently you missed that after the first recompile there is no difference at all whether you started from stage1 or stage3.
Quote:
But i have problem, becouse description for flags on GCC page are general and only programers can understand it...

You must be a programmer to understand which effect a change has on various parts of a given project you want to optimize. Otherwise you can only do trial-and-error (compile with various CFLAGS and do reliable benchmarks. With emphasis on reliable, e.g. on a library to make sure to call and weight all functions in the way you need it later on.)
Quote:
i will save it to give someone when he will ask me why to use gentoo

It seems that you use gentoo for the wrong reasons. Perhaps you did not read carefully enough to get that all of the reasons in the link are meant as an irony? You should really read it, understanding that almost the opposite is the real truth!
Back to top
View user's profile Send private message
markan
n00b
n00b


Joined: 11 Aug 2013
Posts: 20

PostPosted: Fri Oct 11, 2013 5:10 am    Post subject: Reply with quote

mv wrote:

I am 100% sure your guess is more than 500% wrong.


its not, after i was build stage 2 i feel big performance difference than stage 3

mv wrote:
Moreover, apparently you missed that after the first recompile there is no difference at all whether you started from stage1 or stage3.


dont know if gcc, binutils, linux-headers will be build with updating
even if they will, this is stage 2 which i can do with -e system and i will miss next gentoo gift presents in handbook 2004.2
Quote:
Stage1 Pros and Cons
+ Allows you to have total control over the optimization settings and optional build-time functionality that is initially enabled on your system

Quote:
Stage2 Pros and Cons
- You cannot tweak as much as with a stage1


and finally i will have more unessessery deps for base system with -e system or updating, that cant be what stage 1 is

Quote:

It seems that you use gentoo for the wrong reasons. Perhaps you did not read carefully enough to get that all of the reasons in the link are meant as an irony? You should really read it, understanding that almost the opposite is the real truth!


gentoo was imagine for users be able optimize it for max performance or for other specific needs

even kernel..
people told me on irc i dont need experiment with all kernel config options... and i was have kernel 4 mb without initramfs..
i was study every option there and put size to 2,4mb without initramfs ant that new kernel runs and works 10% faster, so it was worth
its just 1,6mb nothing, but effects are big, gcc flags can make same effects for all aps but not with default like -O2

...firefox is one of the fastes browser becouse developers was rebuilding it hundreds times with different flags and test with benchmark on different systems to see results..
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Fri Oct 11, 2013 6:50 am    Post subject: Reply with quote

If you want to set things per-package, see package.env in man portage.

But please don't point out stuff from 2004 handbook: it really has no relevance. If you do an -e system on install from stage3, and then do things like xorg-server after you've got your machine rebooting, everything will be built afresh. As it will in general, since everything gets recompiled on upgrade, but I quite like doing -e system personally, so don't think I'm trying to discourage your approach. In fact, it's what update --toolchain is all about (though it's still got rough edges.)
Back to top
View user's profile Send private message
markan
n00b
n00b


Joined: 11 Aug 2013
Posts: 20

PostPosted: Fri Oct 11, 2013 8:44 am    Post subject: Reply with quote

steveL wrote:
If you want to set things per-package, see package.env in man portage.

But please don't point out stuff from 2004 handbook: it really has no relevance. If you do an -e system on install from stage3, and then do things like xorg-server after you've got your machine rebooting, everything will be built afresh. As it will in general, since everything gets recompiled on upgrade, but I quite like doing -e system personally, so don't think I'm trying to discourage your approach. In fact, it's what update --toolchain is all about (though it's still got rough edges.)


i cant agree with that
-e system will not do the job right or it can if we manually look through all system deps and unmerge it separtelly, becouse "emerge -e system" on the first installation before compiling kernel well be 77 packages and 130 deps. with useflags we will be able to remove just 5 deps...
and there will be 125 deps left which we cant remove with gentoolkit or emerge
with stage 1 we can build 77 needed system packages and just several from 130 deps (emerge -e system --nodeps -is stage 1 )
this are default deps putted here by developers becouse they make it to support every needs and usage, they cant know what each of us will need
there is stage 1 for that needs , its same as removing default profile flags and configurations, build your own profile instead of using general one provided by default
and it is LFS with best system in linux world called "portage"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum