old-www/LDP/LG/issue88/piszcz.html

260 lines
9.1 KiB
HTML

<!--startcut ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>Optimizing GCC LG #88</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="okopnik.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue88/piszcz.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="pramode.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
<!--endcut ============================================================-->
<TABLE BORDER><TR><TD WIDTH="200">
<A HREF="http://www.linuxgazette.com/">
<IMG ALT="LINUX GAZETTE" SRC="../gx/2002/lglogo_200x41.png"
WIDTH="200" HEIGHT="41" border="0"></A>
<BR CLEAR="all">
<SMALL>...<I>making Linux just a little more fun!</I></SMALL>
</TD><TD WIDTH="380">
<CENTER>
<BIG><BIG><STRONG><FONT COLOR="maroon">Optimizing GCC</FONT></STRONG></BIG></BIG>
<BR>
<STRONG>By <A HREF="../authors/piszcz.html">Justin Piszcz</A></STRONG>
</CENTER>
</TD></TR>
</TABLE>
<P>
<!-- END header -->
I have a Pentium 3 866MHZ CPU. After reading the
<A HREF="http://freshmeat.net/articles/view/730/">freshmeat article on
optimizing GCC</A> a few days ago, it got me thinking.
So I posed the following question:
How much faster would gcc compile the kernel if gcc itself was optimized?
I chose to benchmark kernel compilation times, because I think it is a good
benchmark, and many other people also use it to benchmark system performance.
Also, at one point or another, most Linux users will have to take the step and
compile the kernel, so I thought I'd benchmark something that is useful and
something that people have a general idea of how long it takes to compile without
optimizations.
So my test is comprised of the following:
<OL>
<LI> Run 10 kernel compilations and calculate the average time.
<UL>
<LI> Regular GCC build.
<LI> Optimized GCC build.
</UL>
<LI> The kernel in question is the latest stable Linux kernel.
<UL>
<LI> At this time, 2.4.20 remains the latest stable Linux kernel.
</UL>
<LI> The GCC used with this test is the latest stable gcc.
<UL>
<LI> At this time, 3.2.2 remains the lastest stable gcc.
</UL>
</OL>
<P>
With an non-optimized compiler, (configure;make;make install)<BR>
Average of 10 'make bzImage':<BR>
TIME: 12.42 minutes (762 seconds)
<P>
With an optimized compiler,
I specifically used:
<PRE>
-O3 -pipe -fomit-frame-pointer -funroll-loops -march=pentium3 -mcpu=pentium3
-mfpmath=sse -mmmx -msse
</PRE>
In case you are wondering how to do this, it is in the FAQ of the gcc tarball.
The following line is what I used:
<PRE>
./configure ; make BOOT_CFLAGS="optimization flags" bootstrap ; make install
</PRE>
Average of 10 'make bzImage'<BR>
TIME: 9.31 minutes (571 seconds)
<P>
I compile almost everything I run on my Linux box.
I use a package manager called
<A HREF="http://relink.sourceforge.net/">relink</A> to manage
all of my installed packages.
<P>
Optimizing the compiler alone:
offers a speed increase of: 33% (or 3:11 minutes, 191 seconds faster).
This may not seem like a lot, but for compiling big programs, it will significantly
reduce compile time making those QT &amp; Mozilla builds that much faster :)
The actual test consisted of this:
<PRE>
cd /usr/src/Linux
for i in `seq 1 10`
do
make dep
make clean
/usr/bin/time make bzImage 2&gt;&gt; /home/war/log
done
</PRE>
In case you're wondering about the time elapsed per build and how much
the CPU was utilized, here they are:
<PRE>
No Optimization (Standard GCC-3.2.2):
720.88user 34.54system 12:43.97elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
719.06user 35.69system 12:42.09elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
719.14user 34.37system 12:39.64elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
720.52user 36.42system 12:46.68elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
721.07user 33.86system 12:41.59elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
718.95user 35.65system 12:41.31elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
721.83user 36.26system 12:51.54elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
720.29user 34.18system 12:40.63elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
719.14user 34.80system 12:39.19elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
721.16user 33.88system 12:41.93elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
Optimized Compiler (GCC-3.2.2 w/ "-O3 -pipe -fomit-frame-pointer -funroll-loops
-march=pentium3 -mcpu=pentium3 -mfpmath=sse -mmmx -msse")
532.09user 33.62system 9:32.76elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
531.57user 32.92system 9:29.25elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
532.99user 33.12system 9:31.18elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
532.58user 33.16system 9:30.57elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
533.18user 32.96system 9:31.34elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
534.01user 32.21system 9:32.50elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
532.59user 33.41system 9:31.56elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
532.76user 33.68system 9:32.01elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
534.19user 32.54system 9:31.92elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
534.11user 32.76system 9:32.40elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
</PRE>
Note:
I realize some of the optimizations, most specifically (-fomit-frame-pointer) may
not be a good optimization feature, especially for debugging. However, my
goal is to increase compiler performance and not worry about debugging.
<!-- *** BEGIN author bio *** -->
<P>&nbsp;
<P>
<!-- *** BEGIN bio *** -->
<!-- P>
<img ALIGN="LEFT" ALT="[BIO]" SRC="../gx/2002/note.png">
<em>
I am currently in my final year for my A.S. in Computer Science at a
local community college. I then plan on transferring to another college
for a B.S. in Computer Science. I have been using UNIX on and off since
1989. I grew up around Macintosh computers. In 1996 however, I became
frusturated with Macs and how unstable they were. So in December, 1996
I installed LinuxPPC R3, this is when I began using Linux daily. This
distrubution came with kernel 2.1.24, and kde 0.2 I believe, but I
primarily used the CLI because xpmac and gnome/kde was not quite
complete yet. Then, in 1998 I built a good x86 box and now use Red Hat
for my desktop machine and Slackware for my Linux router/server. I have
been using Linux every day since then.
</em>
<br CLEAR="all" -->
<!-- *** END bio *** -->
<!-- *** END author bio *** -->
<!-- *** BEGIN copyright *** -->
<hr>
<CENTER><SMALL><STRONG>
Copyright &copy; 2003, Justin Piszcz.
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 88 of <i>Linux Gazette</i>, March 2003
</STRONG></SMALL></CENTER>
<!-- *** END copyright *** -->
<HR>
<!--startcut ==========================================================-->
<CENTER>
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="okopnik.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue88/piszcz.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="pramode.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>
<!--endcut ============================================================-->