Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to resolve -march=pentium4 stability issues.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
gubbs
n00b
n00b


Joined: 28 Feb 2003
Posts: 35

PostPosted: Mon May 05, 2003 3:53 pm    Post subject: How to resolve -march=pentium4 stability issues. Reply with quote

Hi, just before I start .. This was not my idea. Infodragon (rreich) came up with this after a week or so of pretty extensive testing on his new p4 3ghz box.

He's a busy chap so I'm posting on his behalf.

Section 1 - Instability

If you search around these forums for posts regarding gcc 3.2.2 and the -march=pentium4 flag you will find plenty of hear say and buffer overflows. :) It is a well documented issue with gcc 3.2.2 that this flag does result in some adverse affects. Its a fact that if you compile your whole system in this way you will experience problems.

This is (according to us obviously) chiefly because of glibc being unstable with the -march=pentium4 flag. Infodragon discovered this through trial and error, he's a software engineer and so I trust him if he says he's compiled the whole system 50, 000 times on 5-6 sets of CFLAGS and narrowed it down to glibc and certain flag combos.

Section 2 - The Fix (as we see it)

One you have installed your system or are experiencing some issues with an already problematic install having used -march=pentium4 on everything you can sort things out without having to use -march=pentium3 (which we all agree as p4 users is way too much of a peformance compromise).

Emerge glibc with these flags CFLAGS="-march=pentium3 -mcpu=pentium4 -O2 -pipe -mmmx -msse -msse2 -mfpmath=sse -fforce-addr -fomit-frame-pointer -funroll-loops -frerun-loop-opt -frerun-cse-after-loop -falign-functions=4 -fexpensive-optimizations" in your make.conf.

Obviously these are pretty aggressive, they do work fine, but you will probably want to change them in some way. The only really important part is -march=pentium3 -mcpu=pentium4 that will result in a stable but mildly p4 optimized glibc. HOWEVER, we tried all sorts of CFLAGS combos and variations and ONLY reccommend those we have pasted here. If you use other sets of flags and start to burn, thats not US. Its you. :P

The rest of your system can now be compiled CFLAGS="-march=pentium4 -O2 -pipe -mmmx -msse -msse2 -mfpmath=sse -fforce-addr -fomit-frame-pointer -funroll-loops -frerun-loop-opt -frerun-cse-after-loop -falign-functions=4 -fexpensive-optimizations"
for maximum uber-geek p4 optimization.

Right now portage is a nasty fecker and wont let you compile glibc, then emerge world -eup without recompiling glibc with the new (and dogey for glibc) flags. So kerframil wrote this little script that you can run to rebuild everything EXCEPT glibc. Good eh? Just open up glibcscript.sh and paste in:

for p in `emerge -eup world | grep -v "glibc" | egrep -o " [a-z\-].+\/[^\-]+" | egrep -o "[^ ]+"`; do emerge ${p}; done

......... and save it.

Now you should consult your /var/cache/edb/world file to comment out anything you dont want to rebuild (i.e. stuff you know is already optimized to the hilt or just dont want to sit around waiting for - altho this is kinda not the point but KDE does take a looong time and you may be happy with -march=pentium3 peformance).

Now run the script as root and sit back and relax while your whole system gets recompiled against the SAFE and STABLE glibc for maximum (as it presently is capable) p4 peformance.

NOTE: A lot of 'important' ebuilds contain instructions to strip CFLAGS and go with a safe proven set ie. to swap -march=pentium4 for -march=pentium3 and/or to include debugging etc. Xfree ebuilds all do this. So you will still need to have a look into these ebuilds to make sure you are using the p4 opts! I personally edit the xfree ebuid to use -march=pentium4 get rid of debugging and to strip symbols the normal way and it works fine with the CFLAGS I posted above. Fine and FAST! :)

Cheers.

Gubbs.

PS: Infodragon and myself (Gubbs) have been running our systems compiled in this fashion for a couple of weeks now. So far we've not experienced any adverse problems and have thoroughly enjoyed having uber fast bins! :) That said .. We're both nuts. So use the information above with your own discretion to avoid excessive flood. 8O
Back to top
View user's profile Send private message
rojaro
l33t
l33t


Joined: 06 May 2002
Posts: 732

PostPosted: Mon May 05, 2003 9:20 pm    Post subject: Reply with quote

any reason for not modifying the glibc ebuild to contain the CFLAGS? that way you wont have to edit the world file and you also won't need the mentioned script ...
i also just read in the weekly news that there is a gcc 3.3 ebuild ... any experiences with that on the same topic?
_________________
A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
Back to top
View user's profile Send private message
jesterspet
Apprentice
Apprentice


Joined: 05 Feb 2003
Posts: 215
Location: Atlanta

PostPosted: Wed May 07, 2003 3:53 am    Post subject: Reply with quote

I must pipe up and say that I can vouch for the glibc stability issue. I had posted before asking someone to verify my findings, but I think that request got lost in the mix.

I had originally compiled my system with:
Code:

CFLAGS="-s -march=pentium4 -mmmx -msse -msse2 -Os -fomit-frame-pointer -pipe -fexpensive-optimizations -fpic -frerun-cse-after-loop -frerun-loop-opt -foptimize-register-move -masm=intel"


and had some strange stability issues and compilation issues. After chasing all of those issue around, I managed to narrow most of my issues down to glibc problems (corruption. version conflicts, etc), and GCC issues with the '-march=pentium4' flag. So I did as was suggested and backed it down to '-march=pentium3' and specified '-mcpu=pentium4' and all of my problems went away.

I have since added to my CFLAGS to really get down to brass tacks but that is a whole different story.
_________________
(X) Yes! I am a brain damaged lemur on crack, and would like to buy your software package for $499.95
Back to top
View user's profile Send private message
floam
Veteran
Veteran


Joined: 27 Oct 2002
Posts: 1067
Location: Vancouver, WA USA

PostPosted: Wed May 07, 2003 4:19 am    Post subject: Reply with quote

or switch to gcc 3.3 :)
https://forums.gentoo.org/viewtopic.php?t=50679
Back to top
View user's profile Send private message
kilimanjaro
n00b
n00b


Joined: 29 Jan 2003
Posts: 37
Location: Jakarta

PostPosted: Wed May 07, 2003 7:53 am    Post subject: Reply with quote

how do you set the CFLAGS when you emerge xfree so it doesnt default itself to march=pentium3 ? anyone ?
Back to top
View user's profile Send private message
antipop
Tux's lil' helper
Tux's lil' helper


Joined: 04 Oct 2002
Posts: 84

PostPosted: Wed May 07, 2003 10:49 am    Post subject: Reply with quote

kilimanjaro wrote:
how do you set the CFLAGS when you emerge xfree so it doesnt default itself to march=pentium3 ? anyone ?

Just edit the ebuild.

Code:
               # Should fix bug #4189.  gcc-3.x have problems with -march=pentium4
                # and -march=athlon-tbird
                replace-flags "-march=pentium4" "-march=pentium3"
                replace-flags "-march=athlon-tbird" "-march=athlon"


Find that piece of code and comment out where pentium4 is changed to pentium3.
To ease finding those lines, the line number is ~270.
Back to top
View user's profile Send private message
TeddY-T
n00b
n00b


Joined: 08 May 2003
Posts: 10
Location: Australia

PostPosted: Sat May 10, 2003 9:32 am    Post subject: Reply with quote

I have just started using the below use flags as you have specified.

Code:

CFLAGS="-march=pentium4 -O2 -pipe -mmmx -msse -msse2 -mfpmath=sse -fforce-addr -fomit-frame-pointer -funroll-loops -frerun-loop-opt -frerun-cse-after-loop -falign-functions=4 -fexpensive-optimizations"


I haven't had anything as yet to beseline the performance of these cfflags, so my question is basically if people find this to be fairly optimized or not.

I have also spoke to some people on irc in #gentoo about that certain flags are repeating, I quickly did some research on gcc I have found this to true. They have also told me there are better way to optmize the cflags for a P4. I guess I'm just trying to start a little debate on the use of these cflags.
Back to top
View user's profile Send private message
Beetle B.
Guru
Guru


Joined: 01 Mar 2003
Posts: 517

PostPosted: Tue May 20, 2003 11:08 pm    Post subject: Reply with quote

I tried the information in the first post and everything is running smoothly. :D

Some "important" ebuilds intentionally replace pentium4 with pentium3 for CFLAGS. I did a search to see what I could find and came up with only:

xfree-4.3.0-r2
mozilla-1.2.1-r5
recode-3.6

There were other ebuilds where pentium4 was replaced with i686 or something other than pentium3. I'm assuming that those were not related to the gcc bug (anyone know different?).

I compiled XFree 4.3 with pentium4 (commented out the replace line in the ebuild) and it works fine (note: I did this only today so I can't guarantee complete success - it may die later on).

I tried mozilla with pentium4 and it wouldn't install. I did -march=pentium3 -mcpu=pentium4 and it installed.

No idea what recode is...

Just thought I'd let you all know that Mozilla wouldn't compile with pentium4 (yes, I know it's been mentioned elsewhere, but I think most people read this thread to resolve the pentium4 problem...).

Hopefully, this will soon be a non-issue as it seems the latest gcc doesn't have this problem. I don't know if people have compiled Mozilla with it.
_________________
Beetle B.

Please update the table of equivalents.
A Firefox guide.
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Tue May 20, 2003 11:45 pm    Post subject: Reply with quote

I simply use this as my CFLAGS:

Code:
CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer -mno-sse2"


the original bug in glibc had to do with the sse2 instructions. so I just turn those off for now.

It's a pain to turn off sse2 for glibc, and that's the most important thing to turn them off for.
the glibc ebuild is quite picky about the cflags.

in /usr/portage/eclass/flag-o-matic.eclass, there is a line that looks like this:

Code:

# C[XX]FLAGS that we allow in strip-flags
ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"


I just added '-mno-sse2' to the list, then it allows the -mno-sse2 flag while building glibc until the next time you 'emerge rsync' :wink:
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Tue May 20, 2003 11:49 pm    Post subject: Reply with quote

here's the forum post where I read about the sse2 problems:

https://forums.gentoo.org/viewtopic.php?t=43373&highlight=sse2+pentium4
Back to top
View user's profile Send private message
Chris Finch
Tux's lil' helper
Tux's lil' helper


Joined: 10 Mar 2003
Posts: 106
Location: Darmstadt, Germany

PostPosted: Sun Jul 06, 2003 9:47 pm    Post subject: Reply with quote

One question:

If glibc manages to make gcc produce wrong instructions when tuned for pentium4, how can you be so sure that none of the other programs in portage can? Until anyone is able to explain that, I won't use the sse2 flag (or anything that implies it) for any program.
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Sun Jul 06, 2003 10:31 pm    Post subject: Reply with quote

I turn off all sse2 in my CFLAGS now (-mno-sse2). and yes, it does cause problems with all kinds of things. I saw weird problems in gnumeric & python both, I'm sure there are others too.

all this convinces me never to buy a pentium 4 system. This machine is a work computer the company bought. go AMD! :wink:
_________________
http://www.desertsol.com/~kevin/ppc
Back to top
View user's profile Send private message
Chris Finch
Tux's lil' helper
Tux's lil' helper


Joined: 10 Mar 2003
Posts: 106
Location: Darmstadt, Germany

PostPosted: Mon Jul 07, 2003 5:29 am    Post subject: Reply with quote

zojas: Yes, I was addressing those who suggest using -march=pentium4 for everything except glibc.

About the problem with python: I seem to remember that that problem occurs only if you compile glibc with -march=pentium4, regardless of how you compile python itself. I would not know of any example of pentium4 - breakage except for glibc. But that is not a proof that it never happens, either. Or does anyone know first hand that -march=pentium4 breaks other packages as well?

About AMD vs. Intel: I fail to see how a bug in gcc is an argument for either company.


ps:
while the gentoo forums definitely make a great part of gentoo's success, it can be a disadvantage sometimes when people try to help without having first hand experience. Particularly in the pentium4 threads I find it hard to distinguish those who have a solid backgroud from those who just repeat hearsay. This is a general observation, not targeted at anyone particularly. I do not exclude myself from this criticism, by the way.
Back to top
View user's profile Send private message
Chris Finch
Tux's lil' helper
Tux's lil' helper


Joined: 10 Mar 2003
Posts: 106
Location: Darmstadt, Germany

PostPosted: Mon Jul 07, 2003 12:04 pm    Post subject: Reply with quote

Gubbs wrote:
Emerge glibc with these flags CFLAGS="-march=pentium3 -mcpu=pentium4 -O2 -pipe -mmmx -msse -msse2 -mfpmath=sse -fforce-addr -fomit-frame-pointer -funroll-loops -frerun-loop-opt -frerun-cse-after-loop -falign-functions=4 -fexpensive-optimizations" in your make.conf.

If you have a look at the glibc ebuild and the flag-o-matic eclass you will find out that pretty much all of the fancy CFLAGs above are stripped out, anyway. I don't know if this was already the case at the time of writing, but it may be a good idea to edit the post.
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Mon Jul 07, 2003 4:17 pm    Post subject: Reply with quote

in the thread I posted above, you want to read the second post by vazagi. his post has the real info.

the gist is you need to hack the flag-o-matic.eclass file in /usr/portage/eclass directory to allow -mno-sse2. (just add it to the ALLOWED_FLAGS variable). then set your CFLAGS to

Code:

CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer -mno-sse2"


then 'emerge glibc' again. I then ran the python test which is also listed in that thread to see if python needed to be re-emerged, and I tested gnumeric too. (i don't remember if I had to re-emerge them or not, it's been a while).

I have done this, it fixed my problems, and I've had no issues since.

(don't forget, if you 'emerge rsync' it will overwrite your flag-o-matic.eclass file, but you only care when you are emerging glibc)
_________________
http://www.desertsol.com/~kevin/ppc
Back to top
View user's profile Send private message
Garbz
Apprentice
Apprentice


Joined: 02 Jul 2003
Posts: 260
Location: Brisbane, Australia

PostPosted: Wed Jul 09, 2003 2:34 am    Post subject: Reply with quote

I'd just like to say some of the experiences with the ever elusive stability with the pentium4 flag. Please note these are person experiences and by no means a professional oppinion! The flags represent what i have read, and my solutions are an act of desperation to get my system up and running.

When i installed my gentoo system on my home computer i have always been plagued with problems.

I started by leaving a very generous set of CFLAGS for bootstrap.sh I didn't do much at all in the way of optimisations and definatly not add the pentium4 flag.

After bootstrapping was done a quick gcc -v showed that i was running version 3.2.2.something, definatly not the version which was desirable considering all the problems. So a quick upgrade via emerge -u gcc. THis placed me with gcc-3.2.3 20030422. Apparently this version had none of the problems.
I then proceeded to install the system with these flags:
Code:

-march=pentium4 -mcpu=pentium4 -O3 -pipe -mmmx -msse -msse2 -mfpmath=sse,387 -ffast-math -fforce-addr -fomit-frame-pointer -funroll-loops -frerun-cse-after-loop -frerun-loop-opt -faligh-functions=4

Do not use these optimisations lightly keep reading why.

These optimisations are about as good as they get with my understanding of the gcc compiler (bearly anything just what i read that is), so i somehow think they are creating more problems than they solve.

After an unsucessfull emerge of system stopped at iputils i injected iputils and continued with the emerge. After system had finished i emerged iputils and low and behold it worked, so i'm not sure if my cflags caused whatever problem i had.

After a complete setup i wanted to emerge gnome and kde, so i did. Kde didn't do to well. No matter what i did i could not get arts-1.1.2 to install, so i simply left kde off the system. Gnome caused similar problems. This time in the Qt library.

Qt segfaulted during compile everytime so i eventually changed my cflags to the standard flags with march=pentium3 -O3 -pipe and then emerged Qt. It worked. So something must still be screwed with it. Note that the Python test in the other thread did not produce an overflow.

So personally i'm still confused with the issue. Considering the problems i had with compile i doubt my system is going to be very stable.

Can anybody give any aditional pointers, i'm not quite ready for gcc-3.3 and i'll only upgrade to it if i have to redo the entire system. It's a waste of a good weekend installing gentoo :?
I did make sure that glibc was not installed with the nazi flag despite already running gcc-3.2.3. Maybe these optimisations are just too strong but if they work they should provide an insanely fast system 8)

Also on the topic of Pentium4 vs Athlon, the gcc problem is definatly NOT an indication of which chip is better, Infact the line in make.conf file reads:
Code:
#ATHLON-4 will generate invalid SSE instructions; use 'athlon' instead.
#PENTIUM4 will generate invalid instructions; use pentium 3 instead.

For thoes who don't know what this means it means that the problem is GCC related and not processor related. Infact i believe that either the latest or the upcomming AMD processors have copied the sse2 instructions exactly to intel specifications meaning that Athlon and Pentium4 suffer from exactly the same problems.

And my personal oppinion: Pentium4s run with more stability than any athlon will ever, but let's not start a war in this thread, if u want to argue pm me :)


/EDIT: iputils problem is not related to pentium4 or the cflags. My p3m laptop had exactly the same problem :?
_________________
Every begining is another begining's end.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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