Category Archives: Programming

General thoughts on programming

DistCC on OSX for Mozilla Builds

I have gotten Mozilla to build using DistCC on Mac. Luckily, everything you need is already installed with XCode. If you can build Mozilla in the machine, you should be good to build using DistCC. DistCC is a wrapper for the compiler which distributes portions of the build process to other machines. Some things which can’t be done in a distributed way like linking are done on the machine in the driver’s seat. In DistCC you have one client and many servers. I found this confusing at first, because I was thinking of the computer driving the build as serving jobs for clients, but in fact, it is the client which is using ‘compile servers’.

This is actually a very simple thing to set up, once you know what you are doing. For this blog post, I tested using two of our school macs. I have spain (142.204.133.122) as a build server and canada (142.204.133.7) as a client. On all the server machines I have started the DistCC daemon by running distccd --daemon. It is possible to run this with only allowing jobs from specified IPs but this is easier. Make sure that port 3632 is reachable by your servers as that is where the jobs are sent and results received. On the client machine (in this case canada) I need to configure distcc to make use of the build servers. With the included version of DistCC on Leopard, you have to specify this using an exported environmental variable. I used export DISTCC_HOSTS='localhost 142.204.133.122' in the shell I ran the build from. Next you are going to need to wrap the compilers to make use of DistCC. I have done this by overriding the default C and C++ compilers in my .mozconfig file (below) with the CC and CXX environment variable in my make flags. You will want to specify a job count (-j6 in this instance) to make use of DistCC. It is hard to pick a good number, but it should definitely be greater than the number of total processor cores and some say an extra two for good measure.

canada:~ jhford$ cat ~/.mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj
ac_add_options --enable-application=browser
mk_add_options MOZ_MAKE_FLAGS="CC='distcc /usr/bin/gcc' CXX='distcc /usr/bin/g++' -j6"

When you start your build with make -f client.mk build you will be able to monitor the status of your distribution using the also included distccmon-text. An important thing to note, which caused me much grief, is that this program is run on the DistCC client (the driver). This program will give you a nice little bit of output like this:

This shows you which jobs are going to which machines. Another thing that indicates that distcc is working is the g++ build steps, which should now look like this (greatly abridged) example:

distcc /usr/bin/g++ -o nsMorkHistoryImporter.o -c -I../../../../dist/include/system_wrappers -include /Users/jhford/mozilla-central/config/gcc_hidden.h -DXPCOM_TRANSLATE_NSGM_ENTRY_POINT=1 -DMOZILLA_INTERNAL_API -D_IMPL_NS_COM -DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_COM_OBSOLETE -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET -DIMPL_XREAPI -DIMPL_NS_NET -DIMPL_THEBES -DZLIB_INTERNAL -DOSTYPE=\"Darwin9.6.0\" -DOSARCH=Darwin

As far as results go: with an iMac that has 1GB of memory as client I got these times for the DistCC with a Mac Mini as a server (-j6):
real 20m41.704s
user 22m5.748s
sys 5m22.026s

With 12 jobs (-j12) I got:
real 19m54.374s
user 20m39.539s
sys 5m20.019s

And with just the single iMac with 1GB (-j4):
real 20m25.626s
user 27m3.408s
sys 4m22.820s

I watched the output of the distccmon-text and noticed that only about half of the files get distributed, with the other half being done on localhost. I am thinking that it would be good to test this with a more powerful machine as the client and more servers, but as this is right now, there is nearly zero benefit to this configuration.

My thoughts on Fedora

I wouldn’t normally write this, but someone asked me what my thoughts are regarding Fedora and Ubuntu on IRC. A bit of background: I started using RHL 5.2 and stuck with it until Fedora Core 1 was out. I strongly disliked FC1 and moved to SuSE(9.1) and later Ubuntu. I used Ubuntu for a long time (5.04 until 8.04) then went back to Fedora in a big way (F8-F11Alpha, CentOS).

I guess what I love about Fedora is that it uses the latest versions of software because. Patches are either pushed upstream or killed. This means that the software is distributed as the authors intended. This also means that Fedora is a team player, Fedora gives back to the developers and respects the upstream developer’s judgement. This is important to me, especially as highlighted by the Debian OpenSSL kerfuffle. It is also interesting to note that much of the software used by Linux distributions was written by Fedora contributors.

Another thing is forward thinking. Fedora doesn’t worry about what we have now, Fedora is working on the future. This means that occasionally certain functionality is broken in a new version but in the long run the situation is improved. An example of this is the Plymouth boot screen application. It requires a relatively new feature (KMS, Kernel Mode Setting) to work properly. This doesn’t work with closed source drivers but it is definitely the way to go.

A post on the Ubuntu Brainstorm by ajjeckmans seems to sum up my thoughts of how ubuntu works in respect to their use of open source software “I support the idea but I do think that it should only be considered after Fedora has done all the dirty work of getting it to work at all :) ”. While this only be one user, it occurs in a setting that if anything, encourages this behaviour. This post highlights everything I dislike about ubuntu.

I also like that Fedora is purely Free and Open Source. Like being agile, this annoys some people, but I feel that this is probably the key differentiation between Fedora and ubuntu. Fedora will not bend on its promise to be free and freely distributable. ubuntu used to have this promise, but seemed to loose its focus when they started including proprietary drivers and even encourages their use with the ‘Hardware Drivers’ application. Again, they are becoming less worried about Open Source as if memory serves me correctly, it used to be called ‘Restricted Drivers’. This transforms proprietary software from “scary, don’t use this” to “par for the course”. This is highly indicative of the chant I seem to hear from the ubuntu ecosystem: “Make it work for me now! I don’t care how, I don’t care about helping out, I don’t care about the people who wrote this”. Maybe that is just my own cynicism.

Credit where credit is due though, ubuntu does put together a very polished and easy to use product. It is simply an amazing use of open source software, but it isn’t for me.

btw, the straw that broke the camels back: Alsa 1.0.16. Ubuntu 8.04 didn’t have it and Fedora 8 did. Without this version of Alsa, my desktop soundcard didn’t work at all and my laptop didn’t mute with headphones. Every time I look at Linux operating systems, I am thankful for this. I am also especially thankful for Red Hat’s support of an awesome project!

First Core i7 Mozilla build. It was quick!


I finally got my desktop back together with a shiny new Intel Core i7 920, 6GB of DDR3. I haven’t overclocked anything yet and my entire build tree and operating system is on one 7200RPM drive. This thing is really fast for builds! I just built Firefox in less than 5 minutes. I did make -s -j16 -f client.mk clean then time make -s -j16 -f client.mk build and got the following output.
real 4m50.217s
user 2m44.854s
sys 0m55.450s

I used this as my mozconfig:
#John Ford's MozConfig file

ac_add_options --enable-application=browser
ac_add_options --disable-tests
ac_add_options --enable-official-branding

mk_add_options MOZ_CO_PROJECT=browser
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@

I should have done a build before I went to the new hardware as a comparison, but my old hardware is essentially the same as liberia and china over at CDOT.

Grokzilla – Code indexing revisited

I finally decided to write a script to automate setting up OpenGrok for Mozilla’s Mercurial Repository. This script creates a new repository the first time it is run then updates it on subsequent runs. The output of all programs is logged to files to aid in debugging. To set this script up on a local machine you will need to have a Java Application Server, such as JBoss or Tomcat and all related dependancies (Java), Exuberant Ctags, bash, OpenGrok and Mercurial. The details of this script are posted on my Wiki page for it and I can be reached on Mozilla’s IRC in #seneca as John64 if you need a little help with it.

I’d like to take this further if it is seen as valuable to the Mozilla community. Currently, OpenGrok considers all top level directories to be a project within it’s code. I can change this to be whatever needed. I have a sample instance running at http://142.204.133.36:8080/grokzilla/ but that might be up or down depending on many things. It is very possible for me to theme the web application and if there is interest in setting up this for community use I am willing to work on that. Should I file a bug on Mozilla’s Bugzilla to track this? I don’t know.

Testing the gold linker on Mozilla

I decided it is time to do something that isn’t Fedora or JBoss related. I noticed that Dave Humphrey would like to test the new Gold linker included in binutils with Firefox.

I used kvm test this.
I launched kvm with sudo qemu-kvm -hda gold-tests -cdrom F10-Snap2-i686-Live.iso -boot d -smp 2 -m 3500. I installed the required software to build Firefox then make 2 additional copies of the hard disk image, giving me three in total. One as backup, one for regular ld and one for gold. I compiled binutils from source without using RPM because this is a one off test system which I don’t care about breaking. If I was going to continue using this system I would have modified the package descriptor for binutils to enable gold.

The Following packages were installed to facilitate compilation:

  • groupinstall “Development Tools”
  • gtk2-devel
  • libXt-devel
  • freetype-devel
  • dbus-glib-devel
  • alsa-lib-devel
  • curl-devel
  • ORBit2-devel

According to this news list post when you compile binutils you either get the regular linker or the gold linker. To do this you specify --enable-gold when running ./configure. I am going to install binutils using both to test both with the same version of binutils. I will start from my clean image each time.

Since the version of binutils in my installation is different to my tarball, i used the –version option to verify that it installed successfully. As suggested in the original contributions page, I will export LD=gold as an environmental variable, but only on the vm with gold for obvious reasons. I am compiling firefox with the default options from the tarball as ./configure --prefix=/home/jhford --enable-application=browser; time make -j8 -s > ~/mozbuildtime; make install. I also bumped my -smp flag to 4 to match my host and to ensure I get the best possible performance out of my vms.

Here is the time for a non-gold build.

real 9m3.720s
user 4m28.562s
sys 11m1.834s

And the times for a gold build I aliased ld to ‘ld –threads –thread-count 4′ for these runs as well as exporting LD=gold.

real 8m41.445s
user 4m18.749s
sys 10m45.263s

Initially, I was getting that gold was cutting my builds in half, but it turns out I accidentally did make with j4 instead of j8. I found that consistently, gold builds were faster but not by a substantial enough amount to justify having to manually enable it in your package manager of choice.