View Full Version : Optimizations
Weinter
November 20th, 2008, 09:25
Is it safe to use -O3 on /etc/make.conf?
Any other Optimizations that is great on AMD Processors?
vermaden
November 20th, 2008, 10:32
For some apps like mplayer -O3 can do good things, for most of the apps -O3 even will slow them down in many cases.
lme@
November 20th, 2008, 10:36
Please don't use build optimizations in make.conf. The standard compile options are already chosen wisely.
Weinter
November 20th, 2008, 10:40
Please don't use build optimizations in make.conf. The standard compile options are already chosen wisely.
I don't understand why can you elaborate ? Thanks :e
Also why not processor optimizations
lme@
November 20th, 2008, 10:44
Because when you use optimizations you can get very subtle problems and you'll never find out where the problems come from.
Apart from that you probably won't get any support from the FreeBSD devs until you re-compiled everything with the standard compile options.
Mel_Flynn
November 20th, 2008, 17:23
And ports that can safely be compiled with optimizations, will have a config option for it, either via the OPTIONS dialog or WITH_OPTIMIZED_CFLAGS tunable.
kamikaze
November 20th, 2008, 17:37
I did a lot of benchmarking and I have to say, it doesn't make sense to optimize beyond the default FreeBSD CFLAGS. The only thing that makes sense is setting CPUTYPE properly. Applications where more optimizations make sense (e.g. multimedia applications) normally offer additional optimizations as recommended by the developers through the options framework.
graudeejs
November 20th, 2008, 17:42
Make this sticky!!! i assure you, many will ask this question.
Weinter
November 21st, 2008, 05:45
This is my make.conf so far everything works
CPUTYPE?= k8
CFLAGS+= -O2 -pipe
COPTFLAGS+= -O2 -pipe
MAKEOPTS+= -j3
graudeejs
November 21st, 2008, 05:58
why does ppl, like writing default flags to make.conf?
Like it speeds things up?
I have tried Gentoo linux to many times, to tell you this:
Forget about it. It just ain't worth.
not to mention, that your flags didn't improve anything at all
Weinter
November 21st, 2008, 06:44
why does ppl, like writing default flags to make.conf?
Like it speeds things up?
I have tried Gentoo linux to many times, to tell you this:
Forget about it. It just ain't worth.
not to mention, that your flags didn't improve anything at all
You mean it doesn't?!!
I thought these were documented in GCC?
Mel_Flynn
November 21st, 2008, 07:24
This isn't very smart:
CPUTYPE?= k8
CFLAGS+= -O2 -pipe
COPTFLAGS+= -O2 -pipe
MAKEOPTS+= -j3
From /usr/share/mk/sys.mk:
.if defined(%POSIX)
CC ?= c89
CFLAGS ?= -O
.else
CC ?= cc
CFLAGS ?= -O2 -fno-strict-aliasing -pipe
.endif
So, CFLAGS is overridden by you:
-O2 without -fno-strict-aliasing is NOT supported on FreeBSD and will cause programs to miscompile or misbehave.
The only compiler flag that makes sense to put in /etc/make.conf is:
CXXFLAGS+=-Wno-deprecated
As this gets rid of useless warnings about char to string conversions in c++ code.
COPTFLAGS is used by the kernel, as seen in /usr/src/sys/conf/kern.pre.mk. Nowhere else. Unless you're a kernel hacker who knows what he's doing, stay away from it. Here's how it's set up:
.if ${CC} == "icc"
COPTFLAGS?= -O
.else
. if defined(DEBUG)
_MINUS_O= -O
. else
_MINUS_O= -O2
. endif
. if ${MACHINE_ARCH} == "amd64"
COPTFLAGS?=-O2 -frename-registers -pipe
. else
COPTFLAGS?=${_MINUS_O} -pipe
. endif
. if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
COPTFLAGS+= -fno-strict-aliasing
. endif
.endif
.if !defined(NO_CPU_COPTFLAGS)
. if ${CC} == "icc"
COPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
. else
COPTFLAGS+= ${_CPUCFLAGS}
. endif
.endif
fender0107401
November 21st, 2008, 08:56
This is my make.conf so far everything works
CPUTYPE?= k8
CFLAGS+= -O2 -pipe
COPTFLAGS+= -O2 -pipe
MAKEOPTS+= -j3
Gentoo or FreeBSD?
fender0107401
November 21st, 2008, 09:12
Hi all,
This is my /etc/make.conf file, maybe anyone can give me some suggestion, the compilation flag always confuse me.
################################################## ##############################
# cpu type
CPUTYPE=nocona
# ports compilation flag
CFLAGS= -O2 -fno-strict-aliasing -pipe
CXXFLAGS+= -fconserve-space
# shell
MAKE_SHELL=sh
# kernle compilation flag
COPTFLAGS= -O2 -pipe
# kernel config
KERNCONF=MYKERNEL
# install command
INSTALL=install -C
# do not build modules with the kernel
NO_MODULES=true
# avoid compiling profiled libraries
NO_PROFILE=true
################################################## ##############################
# for update
SUP_UPDATE=true
SUP= /usr/bin/csup
SUPFLAGS= -g -L 2
SUPHOST= cvsup5.cn.FreeBSD.org
SUPFILE= /usr/share/examples/cvsup/standard-supfile
PORTSSUPFILE= /usr/share/examples/cvsup/ports-supfile
################################################## ##############################
# do not update documentation
NO_DOCUPDATE=true
################################################## ##############################
# for gui application
WITH_GTK2=yes
################################################## ##############################
# set server for distfiles
#MASTER_SITE_OVERRIDE?=http://ports.hshh.org/${DIST_SUBDIR}/
#MASTER_SITE_OVERRIDE?=http://ports.cn.freebsd.org/${DIST_SUBDIR}/
################################################## ##############################
# for ccache
.if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj*)) && !defined(NOCCACHE)
CC=/usr/local/libexec/ccache/world-cc
CXX=/usr/local/libexec/ccache/world-c++
.endif
# about ccache for "make buildworld"
# NOCCACHE=true
################################################## ##############################
# added by use.perl 2008-08-22 20:04:44
PERL_VER=5.8.8
PERL_VERSION=5.8.8
################################################## ##############################
Weinter
November 21st, 2008, 09:56
This isn't very smart:
From /usr/share/mk/sys.mk:
.if defined(%POSIX)
CC ?= c89
CFLAGS ?= -O
.else
CC ?= cc
CFLAGS ?= -O2 -fno-strict-aliasing -pipe
.endif
So, CFLAGS is overridden by you:
-O2 without -fno-strict-aliasing is NOT supported on FreeBSD and will cause programs to miscompile or misbehave.
The only compiler flag that makes sense to put in /etc/make.conf is:
CXXFLAGS+=-Wno-deprecated
As this gets rid of useless warnings about char to string conversions in c++ code.
COPTFLAGS is used by the kernel, as seen in /usr/src/sys/conf/kern.pre.mk. Nowhere else. Unless you're a kernel hacker who knows what he's doing, stay away from it. Here's how it's set up:
.if ${CC} == "icc"
COPTFLAGS?= -O
.else
. if defined(DEBUG)
_MINUS_O= -O
. else
_MINUS_O= -O2
. endif
. if ${MACHINE_ARCH} == "amd64"
COPTFLAGS?=-O2 -frename-registers -pipe
. else
COPTFLAGS?=${_MINUS_O} -pipe
. endif
. if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
COPTFLAGS+= -fno-strict-aliasing
. endif
.endif
.if !defined(NO_CPU_COPTFLAGS)
. if ${CC} == "icc"
COPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
. else
COPTFLAGS+= ${_CPUCFLAGS}
. endif
.endif
But i used += which adds to the compilation options not overwrite it?!
kamikaze
November 21st, 2008, 11:01
Is this a contest in displaying the most nonsensical make.conf lines?
Seriously just set CPUTYPE?=<mycpu> and select OPTIMIZED_CFLAGS when an options dialogue offers it and you've done everything that makes sense.
vermaden
November 21st, 2008, 11:05
I use that /etc/make.conf:
http://toya.net.pl/~vermaden/text/make.conf
Mel_Flynn
November 21st, 2008, 11:10
But i used += which adds to the compilation options not overwrite it?!
You're right. No idea why you'd do that as it simply doubles flags already there. Makes compilation slightly slower as the argument list of the compile command grows.
CPUTYPE is the only one that makes sense, but it has the drawback that if you backup and restore your machine to another machine with different cpu type (because your machine went kaput), you will have to recompile everything or hit signal 4 a lot.
Any programmer knows that the best thing to speed up your program is to upgrade your hardware. The rest is marginal in comparison.
oliverh
November 21st, 2008, 13:04
CPUTYPE can be of some help in terms of 3-5%, but it can be a problem too (had some with Pentium4 some years ago). Most of the time the bottleneck lies in different areas and it yields no miracles as some people believe.
s-tlk
November 21st, 2008, 14:26
I'm programming numerical software and optimize them. I can tell you we got a lot of trouble with different kinds of optimizations. You have to know what the program is doing and what the flags are doing with the program when you set them. There are some 'global' flags which increase in most cases the performance, but most of the flags are for a special purpose. The worst thing what could happen, when you are using aggressive optimizations is, that the program misscalculates. And I believe I must not tell you that this can cause weird results, which are extremly difficult to locate, especially by sensitve parts of the system like kernel, base system...
So, switch on brain, before switching on optimization flags. ;)
The best rise in performance you can get, besides buying new hardware, is to design your programs well and perhaps use a specific compiler. For example the Intel fortran compiler is much faster then gfortran.
Maurovale
November 27th, 2008, 23:02
Is this a contest in displaying the most nonsensical make.conf lines?
Seriously just set CPUTYPE?=<mycpu> and select OPTIMIZED_CFLAGS when an options dialogue offers it and you've done everything that makes sense.
This is everything I put in my make.conf, I do not recommend put any other thing in where, sooner or later you will have problems...
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.