Here I am gonna shows some cool flags to optimize your compiled applications for linux in faqs form.
Why compile applications?
To harvest all power of your cpu you need to compile your own package. Binaries distributed by applications like apache , mplayer , mysql, e.t.c. are not optimized for your cpu.
I have generally written here only safe configurations.
Run the command
cat /proc/cpuinfo
open /etc/make.conf
Scroll down to this:
Cflags :
march options
If you don't what is your cpu. Then use this
CFLAGS="-march=native
GCC will try to use flags appropriate for you.
If your are using core2duo or above then use this:
CFLAGS="-march=core2
Os options
O ( O for orange not 0 zero)
They vary from 0 , O1 , O2 , O3 , Os
I recommend using 02 . It determine the level of optimization. Using higher might break codes So they are not recommended. Using O = no optimization. 0s = 02 optimization with smaller binaries.
cat /proc/cpuinfo | grep flag
This command print additional flags available for use as C flags or CXX flags ( in layman terms c & c++). If you don't give out | grep flag it will print whole info about your cpu. Flags are switches for optimizing your gcc compiled codes.
Some of the flags you can use from among them are :
-msse, -msse2, -msse3, -msse4 , -mssse3,-mmmx, -m3dnow
pni= sse3
I have put -m as it should be . So now your Cflags
CFLAGS="-march=core2 -O2 -pipe -msse -msse2 -msse3 -mssse3 -mmmx"
( depending upon your arch)
-fomit-frame-pointer & -pipe
Former decreases the code size & latter increases the speed of compiling.
So now your Cflags should loook like this:
CFLAGS="-march=core2 -O2 -pipe -msse -msse2 -msse3 -mssse3 -mmmx -fomit-frame-pointer"
CXX flags
They are same as Cflags.
CXXFLAGS="${CFLAGS}"
Scroll down to
MAKEOPTS options:
They are -j2 , -j3 ,.... They should be one more than your total number of cores. If you have core2duo then
MAKEOPTS="-j3"
If you have icore 7 use this ( as it has 8 cores considering 4 virtuals + 4 real)
MAKEOPTS="-j7"
Next time we are gonna compile something. Bye.
PS: Don't plagiarize.
For more reference see GCC manual.



LinkBack URL
About LinkBacks
Reply With Quote