Case Study Build Time Optimization 3
Case Study Build Time Optimization 3
Build-Time Optimization
1. Introduction
This document describes the project undertaken by PalC Networks for the build-time optimization of a
source-code base involving the combination of multiple versions of kernel-source code-bases, 3rd party
system libraries, NOS-code and Software Development Kit of Broadcom ASICs.
The overall requirements can be categorized into the following four divisions and the subsequent sections
explain in detail about the same.
A wrapper shell-script was developed on top of the existing linux makefile, which makes use of the starting
system timestamp, ending timestamp for each sub-module component compilation, takes the difference,
which denotes the overall time taken for that particular module. The captured timing information was
then sent to a server and represented in a graphical form with appropriate filters to narrow down the
displayed information.
The environment used for the project has the following set of specifications:
root@Ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.6 LTS
Release: 14.04
Codename: trusty
Overall flow for the instrumentation and profiling part of the execution has been captured in the below
mentioned flow diagram:
2
Build-Time Optimization
Implementation
The top-level shell script which prepares the environment for parallel compilation has been explained in
the below section. This script reads the contents from a config.sh file which will have the parameters such
as source-code path in the host-machine, number of CPUs, number of master-slave docker containers,
RAM for each container etc.
The overall process is summarized in the below diagram. Prepare-build-debian.sh is the in-house script,
3
Build-Time Optimization
which comes along with the source-code and sets up all the basic packages required to build the source
code. The end product of the project had the container with prepare-build script integrated onto it and
submitted to a private repository itself, which was then used to setup distCC and build the source-code.
1. The source-code file comes to the preprocessor, which makes the content substitution of the
corresponding #include header files and expands the macros.
2. The preprocessed files come to the compiler and are converted to the specific object file.
3. The linker links all the object files together and provides static libraries, forms the final
executable program.
4
Build-Time Optimization
So theoretically, the program consists of multiple translation units (*.c, *.cpp) which can be pre-processed
or compiled independently from each other. In addition, each translation unit does not have any
information about the other unit and only during the third stage; linker is going to link the different object
files. When using a standard approach, a new file will get to the compiler for preprocessing and compiling.
As each translation unit is self-sufficient, then a good way of speeding up is to parallelize phase 1 and 2
(above mentioned translation phases), processing simultaneously N files at a time. The below mentioned
approach related to parallel compilation exploits that.
Distcc is a program to distribute builds of C, C++, Objective C or Objective C++ code across several
machines on a network to speed up building. It should always generate the same results as a local build,
is simple to install and use, and is usually much faster than a local compile. Further, one can use it together
with native Arch build tools such as makepkg. In the distcc, the nodes take the role of either master or
slave. The master is the computer, which initiates the compilation, and the slave accepts compilation
requests sent by the master. One can setup multiple slave systems or just a single one.
Implementation:
● Distcc needs to be called in place of the compiler. We can export CC=distcc for the compilers we
want to replace with it.
● Slave-Node Configuration
● Each client/slave node needs to run the distcc daemon and needs to allow connections
from the master host on the distcc port (3632). The daemon can be started manually at
boot time by adding it system service.
5
Build-Time Optimization
One of the most powerful features of Conan is that it can manage per-compiled binaries for packages. To
define a package, referenced by its name, version, user and channel, a package recipe is needed. Such a
package recipe is a conanfile.py python script that defines how the package is built from sources, what
the final binary artifacts are, the package dependencies, etc.
The Conan installation and Conan client configuration are done on the host/build machine and the built
binaries are uploaded to the Jfrog artifactory. The developer instead of rebuilding the object-files/binaries
from the scratch can fetch these from the Jfrog artifactory during the next build-time.
A pictorial representation of the overall workflow has been depicted below:
6
Build-Time Optimization
2. GLOSSARY
NOS Network Operating System