Running gem5

From gem5
Jump to: navigation, search


The gem5 command line has four parts, the gem5 binary, options for the binary, a simulation script, and options for the script. The options that are passed to the gem5 binary and those passed to the script are handled separately, so be sure any options you use are being passed to the right component.

% <gem5 binary> [gem5 options] <simulation script> [script options]

gem5 Options

Running gem5 with the "-h" flag prints a help message that includes all of the supported simulator options. Here's a snippet:

% build/ALPHA/gem5.debug -h
  gem5.debug [gem5 options] [script options]

 Copyright (c) 2001-2008 The Regents of The University of Michigan All Rights
gem5 is copyrighted software; use the --copyright option for details.

--version               show program's version number and exit
--help, -h              show this help message and exit
--build-info, -B        Show build information
--copyright, -C         Show full copyright information
--readme, -R            Show the readme
--outdir=DIR, -d DIR    Set the output directory to DIR [Default: m5out]
--redirect-stdout, -r   Redirect stdout (& stderr, without -e) to file
--redirect-stderr, -e   Redirect stderr to file
--stdout-file=FILE      Filename for -r redirection [Default: simout]
--stderr-file=FILE      Filename for -e redirection [Default: simerr]
--interactive, -i       Invoke the interactive interpreter after running the
--pdb                   Invoke the python debugger before running the script
--path=PATH[:PATH], -p PATH[:PATH]
                        Prepend PATH to the system path when invoking the
--quiet, -q             Reduce verbosity

The default options that gem5 uses to run can be set by creating an ~/.m5/ file and placing options that you are interested in there. For example, if you would like to always redirect standard error and out to a file you could add: options.stdout_file=simout to

Script Options

The script section of the command line begins with a path to your script file and includes any options that you'd like to pass to that script. Most Example scripts allow you to pass a '-h' or '--help' flag to the script to see script specific options. An example is as follows:

gem5 compiled Apr  2 2011 00:57:11
gem5 started Apr  3 2011 21:16:02
gem5 executing on zooks
command line: build/ALPHA/gem5.opt configs/example/ -h
Usage: [options]

  -h, --help            show this help message and exit
  -c CMD, --cmd=CMD     The binary to run in syscall emulation mode.
  -o OPTIONS, --options=OPTIONS
                        The options to pass to the binary, use " " around the
                        entire string
  -i INPUT, --input=INPUT
                        Read stdin from a file.
  --output=OUTPUT       Redirect stdout to a file.
  --errout=ERROUT       Redirect stderr to a file.
  -d, --detailed        
  -t, --timing          
  -n NUM_CPUS, --num-cpus=NUM_CPUS

The script file documentation page (Configuration / Simulation Scripts) describes how to write your own simulation scripts, and the Options section explains how to add your own command line options. The simulation scripts that are most commonly used are and These scripts are present in configs/examples directory. is meant for simulation using the system call emulation mode, while is for full-system simulations. In most cases, it should be possible to use either of these two scripts without any modifications. Understanding how these two scripts work can help you decide on what modifications are required for your particular case.

System Call Emulation (SE) Mode

In this mode, one only needs to specify the binary file to be simulated. This binary file should be statically compiled since the simulator does not dynamically linked executables. configs/examples/ is used for configuring and running simulations in this mode. What follows is probably the simplest example of how to use The binary file to simulated is specified with option -c.

$ ./build/ALPHA/gem5.opt ./configs/example/ -c ./tests/test-progs/hello/bin/alpha/linux/hello 
gem5 Simulator System.
gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Mar  2 2014 00:06:39
gem5 started Mar  4 2014 10:52:10
gem5 executing on $
command line: ./build/ALPHA/gem5.opt ./configs/example/ -c ./tests/test-progs/hello/bin/alpha/linux/hello
Global frequency set at 1000000000000 ticks per second
0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000
info: Entering event queue @ 0.  Starting simulation...
info: Increasing stack size by one page.
Hello world!
Exiting @ tick 3233000 because target called exit()

Specifying Command-Line Arguments

In order to pass command line arguments to a binary you can use --options="arg1 arg2 ..." to specify them as a script option in your simulation command.

Full System (FS) Mode

This mode simulates a complete system which provides an operating system based simulation environment. For full system mode, you can use the file configs/example/ for configuration and simulation. Sensible default values have been set for the options that this script uses. We provide examples for ALPHA and ARM based full system simulations.

Example video showing gem5 full system simulation for ARM. Host system is x86 64bit Ubuntu 12.04. Video resolution can be set to 1080

Booting Linux

We'll assume that you've already built an ALPHA version of the gem5 simulator, and downloaded and installed the full-system binary and disk image files. Then you can run the configuration file in the gem5/configs/examples directory. For example:

% build/ALPHA/gem5.debug -d /tmp/output configs/example/
gem5 Simulator System

Copyright (c) 2001-2006
The Regents of The University of Michigan
All Rights Reserved

gem5 compiled Aug 16 2006 18:51:57
gem5 started Wed Aug 16 21:53:38 2006
gem5 executing on zeep
command line: ./build/ALPHA/gem5.debug configs/example/
      0: Real-time clock set to Sun Jan  1 00:00:00 2006
Listening for console connection on port 3456
0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000
warn: Entering event queue @ 0.  Starting simulation...
<...simulation continues...>

Basic Operation

By default, the script boots Linux and starts a shell on the system console. To keep console traffic separate from simulator input and output, this simulated console is associated with a TCP port. To interact with the console, you must connect to the port using a program such as telnet, for example:

 % telnet localhost 3456

Telnet's echo behavior doesn't work well with gem5, so if you are using the console regularly, you probably want to use M5term instead of telnet. By default gem5 will try to use port 3456, as in the example above. However, if that port is already in use, it will increment the port number until it finds a free one. The actual port number used is printed in the gem5 output.

In addition to loading a Linux kernel, gem5 mounts one or more disk images for its filesystems. At least one disk image must be mounted as the root filesystem. Any application binaries that you want to run must be present on these disk images. To begin running benchmarks without requiring an interactive shell session, gem5 can load .rcS files that replace the normal Linux boot scripts to directly execute from after booting the OS. These .rcS files can be used to configure ethernet interfaces, execute special gem5 instructions, or begin executing a binary on the disk image. The pointers for the linux binary, disk images, and .rcS files are all set in the simulation script. (To see how these files work, see Configuration / Simulation Scripts.) Examples: Going into / of root filesystem and typing ls will show:

  benchmarks  etc     lib         mnt      sbin  usr
  bin         floppy  lost+found  modules  sys   var
  dev         home    man         proc     tmp   z

Snippet of an .rcS file:

echo -n "setting up network..."
/sbin/ifconfig eth0 txqueuelen 1000
/sbin/ifconfig lo
echo -n "running surge client..."
/bin/bash -c "cd /benchmarks/surge && ./Surge 2 100 1 5.
echo -n "halting machine"
m5 exit


The m5term program allows the user to connect to the simulated console interface that full-system gem5 provides. Simply change into the util/term directory and build m5term:

	% cd gem5/util/term 
	% make
	gcc  -o m5term term.c
	% make install
	sudo install -o root -m 555 m5term /usr/local/bin

The usage of m5term is:

	./m5term <host> <port>

	<host> is the host that is running gem5

	<port> is the console port to connect to. gem5 defaults to
	using port 3456, but if the port is used, it will try the next
	higher port until it finds one available.

	If there are multiple systems running within one simulation,
	there will be a console for each one.  (The first system's
	console will be on 3456 and the second on 3457 for example)

	m5term uses '~' as an escape character.  If you enter
	the escape character followed by a '.', the m5term program
	will exit.

m5term can be used to interactively work with the simulator, though users must often set various terminal settings to get things to work

A slightly shortened example of m5term in action:

	% m5term localhost 3456
	==== m5 slave console: Console 0 ====
	M5 console
	Got Configuration 127 
	memsize 8000000 pages 4000 
	First free page after ROM 0xFFFFFC0000018000
	HWRPB 0xFFFFFC0000018000 l1pt 0xFFFFFC0000040000 l2pt 0xFFFFFC0000042000 l3pt_rpb 0xFFFFFC0000044000 l3pt_kernel 0xFFFFFC0000048000 l2reserv 0xFFFFFC0000046000
	CPU Clock at 2000 MHz IntrClockFrequency=1024 
	Booting with 1 processor(s) 
	VFS: Mounted root (ext2 filesystem) readonly.
	Freeing unused kernel memory: 480k freed
	init started:  BusyBox v1.00-rc2 (2004.11.18-16:22+0000) multi-call binary

	PTXdist-0.7.0 (2004-11-18T11:23:40-0500)

	mounting filesystems...
	EXT2-fs warning: checktime reached, running e2fsck is recommended
	loading script...
	Script from M5 readfile is empty, starting bash shell...
	# ls
	benchmarks  etc         lib         mnt         sbin        usr
	bin         floppy      lost+found  modules     sys         var
	dev         home        man         proc        tmp         z

Full System Benchmarks

We have several full-system benchmarks already up and running. The binaries are available in the disk images you can obtain/download from us, and the .rcS files are in the gem5/configs/boot/ directory. To run any of them, you merely need to set the benchmark option to the name of the test you want to run. For example:

%./build/ALPHA/gem5.opt  configs/example/ -b NetperfMaerts 

To see a comprehensive list of all benchmarks available:

%./build/ALPHA/gem5.opt configs/examples/ -h 

Experimenting with DVFS

This is a quick hands-on tutorial to start a DVFS-enabled system where the Linux DVFS governors can change voltage and frequencies of the ongoing simulation. Right now, the driver and interface components live in ARM-specific parts of the Linux kernel / gem5, but there is no fundamental reason why this could not be ported to work on other architectures, too.

Quick Instructions

These instructions apply for a Ubuntu-based machine, but can be easily adapted / extended etc. for other use cases and systems.

  • Get gem5 with the proper changesets added
    • Anything after [1]
    hg clone
  • Build gem5
  • scons build/ARM/gem5.opt -j 8
  • Get a DVFS-enabled Linux kernel
    • From here: [2]
    • Anything after / including [3]
    git clone --depth 10 git://
  • Get a cross-compile tool chain
  • sudo apt-get install gcc-arm-linux-gnueabihf
  • Build the kernel
  • make ARCH=arm vexpress_gem5_dvfs_defconfig
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8
  • Check / select the right DTS / DTB file
  • ls arch/arm/boot/dts/vexpress-v2*dvfs*
  • Get / prepare a disk image
  • wget
    tar xvjf arm-system-2013-07.tar.bz2
  • Add DVFS points to the configuration
    • Enable and link the energy controller / DVFS handler
      patch -p1 << EOF
      diff --git a/configs/example/ b/configs/example/
      --- a/configs/example/
      +++ b/configs/example/
      @@ -106,7 +106,11 @@
           # Create a source clock for the CPUs and set the clock period
           test_sys.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
                                                    voltage_domain =
      -                                             test_sys.cpu_voltage_domain)
      +                                             test_sys.cpu_voltage_domain,
      +                                             domain_id = 0)
      + = test_sys.cpu_clk_domain
      +    test_sys.dvfs_handler.enable = 1
           if options.kernel is not None:
               test_sys.kernel = binary(options.kernel)
    • Can also change the clock frequencies here, or from command line
  • Start a simple test simulation
  • M5_PATH=$(pwd)/.. ./build/ARM/gem5.opt --debug-flags=DVFS,EnergyCtrl \
      --debug-file=dfvs_debug.log configs/example/ --cpu-type=AtomicSimpleCPU \
      -n 2 --machine-type=VExpress_EMM --kernel=../linux-linaro-tracking-gem5/vmlinux \
    vexpress-v2p-ca15-tc1-gem5_dvfs_2cpus.dtb \
      --disk-image=../disks/arm-ubuntu-natty-headless.img \
      --cpu-clock=\['1 GHz','750 MHz','500 MHz'\]
  • Test DVFS functionality
  • util/term/m5term 3456
    cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
    echo 750187 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

Futher Experiments

  • Set up different voltages for the operating points
    patch -p1 < EOF
    diff --git a/configs/example/ b/configs/example/
    --- a/configs/example/
    +++ b/configs/example/
    @@ -101,12 +101,16 @@
                 voltage_domain = test_sys.voltage_domain)
         # Create a CPU voltage domain
    -    test_sys.cpu_voltage_domain = VoltageDomain()
    +    test_sys.cpu_voltage_domain = VoltageDomain(voltage = ['1V','0.9V','0.8V'])
         # Create a source clock for the CPUs and set the clock period
         test_sys.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
                                                  voltage_domain =
    -                                             test_sys.cpu_voltage_domain)
    +                                             test_sys.cpu_voltage_domain,
    +                                             domain_id = 0)
    + = test_sys.cpu_clk_domain
    +    test_sys.dvfs_handler.enable = 1
         if options.kernel is not None:
             test_sys.kernel = binary(options.kernel)
  • Per-core DVFS
    • Set up separate clock (and voltage) domains per core
    • Separate clock domains need separate clusters in the device tree
      diff -u linux-linaro-tracking-gem5/arch/arm/boot/dts/\
    • Change the socket_id to have a separate socket per CPU core