Speed Builds Using Compiler Cache

From odroid US
Jump to: navigation, search

A package named ccache can speed up builds. It is easy to use. Get more information here: http://ccache.samba.org/manual.html

# install the c compiler cache
# as root
apt-get install ccache
# add symlinks so ccache can invoke the compiler
# /usr/local/bin is usually in the path before /usr/bin, so that is where we put the symlinks 
cd /usr/local/bin
# The CROSS_COMPILE environment variable should be empty for odroid native builds, it could be something like
# arm-none-linux-gnueabi- for cross-building on a host.
ln -s $(which ccache)  $(echo $CROSS_COMPILE)gcc
ln -s $(which ccache)  $(echo $CROSS_COMPILE)g++
ln -s $(which ccache)  $(echo $CROSS_COMPILE)cpp
ln -s $(which ccache)  $(echo $CROSS_COMPILE)c++

Setup environment variables. You may want to add these to your .bashrc file so they are applied for each new shell

export CCACHE_DIR=/home/$USER/.ccache
export CCACHE_HASHDIR=$CCACHE_DIR


To test it, build the kernel. You need to be set up with kernel source and prerequisites first: (link to tutorial)

cd /usr/src/linux
# clear the ccache
ccache -c
# start clean
make clean
#
time make -j8

After about 45 minutes, the native build is complete, using SD Card. An eMMC build completed after about 17 minutes.

# clean the object files
make clean
# time the build again
time make -j8

Now the clean re-build takes 2 minutes 15 seconds on (eMMC)

Check the ccache statistics:

root@odroidu2-1:/usr/src/linux# ccache -s    
cache directory                     /root/.ccache
cache hit (direct)                  2554
cache hit (preprocessed)               3
cache miss                             0
called for link                       11
called for preprocessing               2
unsupported source language           62
no input file                         68
files in cache                      7709
cache size                         316.4 Mbytes
max cache size                       1.0 Gbytes
root@odroidu2-1:/usr/src/linux# 


Kernel Build Time Comparisons

using odroidu2_ubuntu-defconfig and linux-3.0.57 (ed's kernel)

Processor	    : Odroid-U2
Memory		    : 2GiB
Operating System    : Debian Wheezy

SD-Card Clean cache, clean build 45m15s
SD-Card cached, clean build [re-test this]

NFS-mounted root file system, Clean cache, clean build: 25m48s
NFS-mounted root file system, Cached, clean build: 5m17s

eMMC Clean cache, clean build 17m14s
eMMC cached, clean build 2m10s

This data is for cross-building on x86_64 Linux host CodeSourcery (2011.09-64) toolchain.

Processor	: 4x Intel(R) Core(TM)2 Quad CPU    Q9550  @ 2.83GHz
Memory		: 8177MB (2393MB used)
Operating System		: Linux Mint 13 Maya
Using solid-state drive for source code and ccache directory (CCACHE_DIR)

SSD Clean cache, clean build 5m25s
SSD cached, clean build 0m33s

This data is for cross-building on x86_64 Linux host Linaro toolchain: arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.7-2012.10-20121022 - Linaro GCC 2012.10) 4.7.3 20121001 (prerelease)

Processor	: 4x Intel(R) Core(TM)2 Quad CPU    Q9550  @ 2.83GHz
Memory		: 8177MB (2393MB used)
Operating System		: Linux Mint 13 Maya
Using solid-state drive for source code and ccache directory (CCACHE_DIR)

SSD Clean cache, clean build 8m49s
SSD cached, clean build 0m39s

This data is for building a snapshot kernel, 3.0.61 with Linaro 2013.01 toochain

Processor       : Intel Core™ i7 CPU Q 740 @ 1.73GHz 
Memory          : 8GB RAM and SSD.

Clean Build: 13m