Setting up a gem5 container

Wed 22 April 2015 | tags: Tools

Linux containers (LXC) are a relatively new feature in Linux. From what I gather, they allow you to create a sandboxed environment to run applications. Containers are somewhere between processes and a full virtual machine. They allow you to use and link to any libraries or applications you need, but they don't cost the same high overheads as full virtualization.

For gem5, I've been told by some people (mostly Mike Swift) that I should look at containers and Docker to see if it would be something useful for the gem5 community. So, in this post, I walk through what it took to set up a container for gem5.

<I WANT AN INSET OR SOMETHING> After I completed the post, I came back to this section to evaluate whether the work I put into creating a gem5 container was worth it.

In a word: "no".

I don't see the use case for the gem5 container that I just created. Maybe it's that I don't understand what containers are, or how to distribute them. The way I see it, I have just created a useful tool for myself, but it's not much use to the community as a whole. Next, I'm going to try to develop a gem5 Docker application. Maybe that will be more useful.

Install and configure lxc in Ubuntu

The first step is to install lxc, obviously. For the most part, I followed the documentation from the Linux Containers .

In Ubuntu it was as simple as:

> sudo apt-get install lxc

Next, I needed to set up user-mode unprivileged containers for my primary user (jason). First, I found my userid from /etc/subuid


Then, I added my username as an allowed user of the virtual ethernet device by adding the following line to /etc/lxc/lxc-usernet

jason veth lxcbr0 10

Then, as specified in the getting started page, I created the ~/.config/lxc directory and copied /etc/lxc/default.conf to ~/.config/lxc/default.conf. Finally, I added the following lines to that file. Note that I copied the nubers from /etc/subuid.

lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536

Finally, I needed to add one more line to ~/.config/lxc/default.conf. From what I can tell, there is a bug with my version of Ubuntu and AppArmor, though the pages I found describing the issue were not very clear. I saw the following error when I initially tried to start my container with lxc-start -n my-container -F:

lxc-start: lsm/apparmor.c: apparmor_process_label_set: 169 If you really want to start this container, set
lxc-start: lsm/apparmor.c: apparmor_process_label_set: 170 lxc.aa_allow_incomplete = 1
lxc-start: lsm/apparmor.c: apparmor_process_label_set: 171 in your container configuration file

To solve this problem, I added the follwing to ~/.config/lxc/default.conf.

lxc.aa_allow_incomplete = 1

Now, I was ready to create a new container for gem5.

Creating a container

You can use the following command to create a container based on the images from

> lxc-create -t download -n gem5-container

You will be shown a number of distributions, versions, and architecture options. I chose Ubuntu, trusty, and amd64.

Distribution: ubuntu
Release: trusty
Architecture: amd64

Now, you can start and log into the container with:

> lxc-start -n gem5-container -d
> lxc-attach -n gem5-container

Installing gem5 dependencies

The next step is installing of the dependencies for gem5. The current dependencies can be found on the gem5 website.

You can execute the following apt-get command to get all of gem5's dependencies:

> apt-get install build-essential gdb python-dev scons swig zlib1g-dev m4 libprotobuf-dev python-protobuf protobuf-compiler libgoogle-perftools-dev
> apt-get --no-install-recommends install mercurial

Finishing up

Next, I created a gem5 user, with the username gem5 and password gem5. This will allow us to keep gem5 relatively sandboxed when building and running.

> useradd gem5
> passwd gem5

Before downloading gem5, let's checkpoint our current state so we can come back to it in the future for a clean gem5-free system. First, we have to halt the container by using the halt command

> halt

After this, we are dumped back out to the host-system's terminal. Now we can clone the container with the following command:

> lxc-clone gem5-container gem5-depends

And restart the container:

> lxc-start -n gem5-container -d
> lxc-attach -n gem5-container

Downloading and building gem5

Now, let's change to the gem5 user and install and build gem5. We'll put gem5 in /opt/gem5.

> mkdir /opt/gem5
> chmod a+rw gem5
> su gem5
> cd /opt

After creating the directory, we can clone gem5!

> hg clone clone gem5
> cd gem5

When you list the directory you should see the following from the gem5 repository:

build_opts  configs  COPYING  ext  LICENSE  README  SConstruct        src  system  tests  util

Now, we can build gem5.

scons build/X86/gem5.opt

You will be asked to install the style hook the first time you build gem5. Just press enter and the style hook will automatically be added to you .hg/hgrc file.

You're missing the gem5 style hook, which automatically checks your code
against the gem5 style rules on hg commit and qrefresh commands.  This
script will now install the hook in your .hg/hgrc file.
Press enter to continue, or ctrl-c to abort:

Now we have a full, sandboxed, development environment for gem5! We can use this to build and make changes to gem5 without affecting the system we are running on.

Comments !