This chapter covers the details of how to set up a gem5 developmment environment and build gem5.
Todo
Add a pointer to the gem5 docker image. In fact, we may want to have a docker image for each section.
See gem5 requirements for more details.
On Ubuntu, you can install all of the required dependencies with the following command. The requirements are detailed below.
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev python-dev python
You may need to use environment variables to point to a non-default version of gcc.
On Ubuntu, you can install a development environment with
sudo apt-get install build-essential
gem5 uses SCons as its build environment. SCons is like make on steroids and uses Python scripts for all aspects of the build process. This allows for a very flexible (if slow) build system.
To get SCons on Ubuntu use
sudo apt-get install scons
gem5 relies on the Python development libraries. To install these on Ubuntu use
sudo apt-get install python-dev
“Protocol buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data.” In gem5, the protobuf library is used for trace generation and playback. protobuf is not a required package, unless you plan on using it for trace generation and playback.
sudo apt-get install libprotobuf-dev python-protobuf protobuf-compiler libgoogle-perftools-dev
Change directories to where you want to download the gem5 source. Then, to clone the repository, use the git clone command.
git clone https://gem5.googlesource.com/public/gem5
You can now change directories to gem5 which contains all of the gem5 code.
Let’s start by building a basic Arm system. Currently, you must compile gem5 separately for every ISA that you want to simulate. Additionally, if using Introduction to Ruby, you have to have separate compilations for every cache coherence protocol.
To build gem5, we will use SCons. SCons uses the SConstruct file (gem5/SConstruct) to set up a number of variables and then uses the SConscript file in every subdirectory to find and compile all of the gem5 source.
SCons automatically creates a gem5/build directory when first executed. In this directory you’ll find the files generated by SCons, the compiler, etc. There will be a separate directory for each set of options (ISA and cache coherence protocol) that you use to compile gem5.
There are a number of default compilations options in the build_opts directory. These files specify the parameters passed to SCons when initially building gem5. We’ll use the ARM defaults and specify that we want to compile all of the CPU models. You can look at the file build_opts/ARM to see the default values for the Scons options. You can also specify these options on the command line to override any default.
scons build/ARM/gem5.opt -j9
The main argument passed to SCons is what you want to build, build/ARM/gem5.opt. In this case, we are building gem5.opt (an optimized binary with debug symbols). We want to build gem5 in the directory build/ARM. Since this directory currently doesn’t exist, SCons will look in build_opts to find the default parameters for ARM. (Note: I’m using -j9 here to execute the build on 9 of my 8 cores on my machine. You should choose an appropriate number for your machine, usually cores+1.)
The output should look something like below:
Checking for C header file Python.h... yes
Checking for C library pthread... yes
Checking for C library dl... yes
Checking for C library util... yes
Checking for C library m... yes
Checking for C library python2.7... yes
Checking for accept(0,0,0) in C++ library None... yes
Checking for zlibVersion() in C++ library z... yes
Checking for GOOGLE_PROTOBUF_VERIFY_VERSION in C++ library protobuf... yes
Checking for clock_nanosleep(0,0,NULL,NULL) in C library None... yes
Checking for timer_create(CLOCK_MONOTONIC, NULL, NULL) in C library None... no
Checking for timer_create(CLOCK_MONOTONIC, NULL, NULL) in C library rt... yes
Checking for C library tcmalloc... yes
Checking for backtrace_symbols_fd((void*)0, 0, 0) in C library None... yes
Checking for C header file fenv.h... yes
Checking for C header file linux/kvm.h... yes
Checking size of struct kvm_xsave ... yes
Checking for member exclude_host in struct perf_event_attr...yes
Building in /local.chinook/gem5/gem5-tutorial/gem5/build/ARM
Variables file /local.chinook/gem5/gem5-tutorial/gem5/build/variables/ARM not found,
using defaults in /local.chinook/gem5/gem5-tutorial/gem5/build_opts/ARM
scons: done reading SConscript files.
scons: Building targets ...
[ISA DESC] ARM/arch/arm/isa/main.isa -> generated/inc.d
[NEW DEPS] ARM/arch/arm/generated/inc.d -> arm-deps
[ENVIRONS] arm-deps -> arm-environs
[ CXX] ARM/sim/main.cc -> .o
....
.... <lots of output>
....
[ SHCXX] nomali/lib/mali_midgard.cc -> .os
[ SHCXX] nomali/lib/mali_t6xx.cc -> .os
[ SHCXX] nomali/lib/mali_t7xx.cc -> .os
[ AR] -> drampower/libdrampower.a
[ SHCXX] nomali/lib/addrspace.cc -> .os
[ SHCXX] nomali/lib/mmu.cc -> .os
[ RANLIB] -> drampower/libdrampower.a
[ SHCXX] nomali/lib/nomali_api.cc -> .os
[ AR] -> nomali/libnomali.a
[ RANLIB] -> nomali/libnomali.a
[ CXX] ARM/base/date.cc -> .o
[ LINK] -> ARM/gem5.opt
scons: done building targets.
When compilation is finished you should have a working gem5 executable at build/ARM/gem5.opt. The compilation can take a very long time, often 15 minutes or more, especially if you are compiling on a remote file system like AFS or NFS.
Error: gcc version 4.8 or newer required.
Installed version: 4.4.7
Update your environment variables to point to the right gcc version, or install a more up to date version of gcc. See Requirements for gem5.
If you use a non-default version of Python, (e.g., version 2.7 when 2.5 is your default), there may be problems when using SCons to build gem5. RHEL6 version of SCons uses a hardcoded location for Python, which causes the issue. gem5 often builds successfully in this case, but may not be able to run. Below is one possible error you may see when you run gem5.
Traceback (most recent call last):
File "........../gem5-stable/src/python/importer.py", line 93, in <module>
sys.meta_path.append(importer)
TypeError: 'dict' object is not callable
To fix this, you can force SCons to use your environment’s Python version by running python `which scons` build/ARM/gem5.opt instead of scons build/ARM/gem5.opt. More information on this can be found on the gem5 wiki about non-default Python locations: Using a non-default Python installation.
If the M4 macro processor isn’t installed you’ll see an error similar to this:
...
Checking for member exclude_host in struct perf_event_attr...yes
Error: Can't find version of M4 macro processor. Please install M4 and try again.
Just installing the M4 macro package may not solve this issue. You may nee to also install all of the autoconf tools. On Ubuntu, you can use the following command.
sudo apt-get install automake