Difference between revisions of "Running gem5"

From gem5
Jump to: navigation, search
(Update kernel repo URL)
 
(49 intermediate revisions by 11 users not shown)
Line 1: Line 1:
The m5 command line has two parts: (1) the simulator section which includes the simulator executable and its options, and (2) the script section, which includes the script file and its options. The usage is:
+
__TOC__
 +
== Usage ==
 +
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.
  
 
<pre>
 
<pre>
% m5 [m5 options] <script.py> [script options]
+
% <gem5 binary> [gem5 options] <simulation script> [script options]
 
</pre>
 
</pre>
  
The m5 executable is any of the version you may have built (See [[Compiling M5]]) such as ALPHA_SE/m5.debug or m5.opt, and the [m5 options] part are all of the options that the simulator itself understands.  Running m5 with the "-h" flag prints a help message that includes all of the supported simulator options. Here's a snippet:
+
== gem5 Options ==
 +
Running gem5 with the "-h" flag prints a help message that includes all of the supported simulator options. Here's a snippet:
  
 
<pre>
 
<pre>
% build/ALPHA_SE/m5.debug -h
+
% build/ALPHA/gem5.debug -h
 
Usage
 
Usage
 
=====
 
=====
   m5.debug [m5 options] script.py [script options]
+
   gem5.debug [gem5 options] script.py [script options]
  
  Copyright (c) 2001-2006 The Regents of The University of Michigan All Rights
+
  Copyright (c) 2001-2008 The Regents of The University of Michigan All Rights
 
Reserved
 
Reserved
 +
gem5 is copyrighted software; use the --copyright option for details.
  
options
+
Options
 
=======
 
=======
 
--version              show program's version number and exit
 
--version              show program's version number and exit
 
--help, -h              show this help message and exit
 
--help, -h              show this help message and exit
--authors, -A          Show author information
+
--build-info, -B        Show build information
 
--copyright, -C        Show full copyright information
 
--copyright, -C        Show full copyright information
 
--readme, -R            Show the readme
 
--readme, -R            Show the readme
--release-notes, -N    Show the release notes
+
--outdir=DIR, -d DIR    Set the output directory to DIR [Default: m5out]
--outdir=DIR, -d DIR    Set the output directory to DIR [Default: .]
+
--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
 
--interactive, -i      Invoke the interactive interpreter after running the
 
                         script
 
                         script
Line 32: Line 39:
 
                         script
 
                         script
 
--quiet, -q            Reduce verbosity
 
--quiet, -q            Reduce verbosity
--verbose, -v          Increase verbosity
 
 
...
 
...
 
</pre>
 
</pre>
  
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. Since M5 runs the script in a way similar to python itself (i.e. it's similar to running "python myscript.py [ options ]"), you can pass your script options on the command line to make your script flexible. The script file documentation page ([[Simulation Scripts Explained]]) has details on how to write scripts for M5, and the [[Simulation Scripts Explained#Options|Options]] section of that page gives a bit of detail on how your scripts can have their own options.
+
The default options that gem5 uses to run can be set by creating an <code>~/.m5/options.py</code> 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: <code>options.stdout_file=simout</code> to <code>options.py</code>.
  
 +
== 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:
 +
<pre>
 +
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/se.py -h
 +
Usage: se.py [options]
 +
 +
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.
 +
  --ruby               
 +
  -d, --detailed       
 +
  -t, --timing         
 +
  --inorder           
 +
  -n NUM_CPUS, --num-cpus=NUM_CPUS
 +
  --caches             
 +
  --l2cache           
 +
  --fastmem           
 +
  --clock=CLOCK       
 +
  --num-dirs=NUM_DIRS 
 +
  --num-l2caches=NUM_L2CACHES
 +
  --l1d_size=L1D_SIZE 
 +
  --l1i_size=L1I_SIZE 
 +
  --l2_size=L2_SIZE     
 +
  --l1d_assoc=L1D_ASSOC
 +
  --l1i_assoc=L1I_ASSOC
 +
  --l2_assoc=L2_ASSOC 
 +
...
 +
</pre>
 +
 +
The script file documentation page ([[Configuration / Simulation Scripts]]) describes how to write your own simulation scripts, and the [[Configuration / Simulation Scripts#Options | Options]] section explains how to add your own command line options. The simulation scripts that are most commonly used are se.py and fs.py. These scripts are present in configs/examples directory. se.py is meant for simulation using the system call emulation mode, while fs.py 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 can be statically/dynamically linked.  configs/examples/se.py is used for configuring and running simulations in this mode. What follows is probably the simplest example of how to use se.py.  The binary file to simulated is specified with option '''-c'''.
 +
<pre>
 +
$ ./build/ALPHA/gem5.opt ./configs/example/se.py -c ./tests/test-progs/hello/bin/alpha/linux/hello
 +
gem5 Simulator System.  http://gem5.org
 +
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/se.py -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
 +
**** REAL SIMULATION ****
 +
info: Entering event queue @ 0.  Starting simulation...
 +
info: Increasing stack size by one page.
 +
Hello world!
 +
Exiting @ tick 3233000 because target called exit()
 +
</pre>
 +
 +
====Specifying Command-Line Arguments====
  
== Example configuration files ==
+
In order to pass command line arguments to a binary you can use <code>--options="arg1 arg2 ..."</code> to specify them as a script option in your simulation command.
In the <code> configs/examples </code> directory there are example scripts <code>fs.py</code> and <code>se.py</code> for running full system and syscall emulation benchmarks respectively. Each of these also takes a <code>--help</code> parameter and lists some parameters we think may be useful to get running quickly. Note the position of <code>--help</code> changes what help you get. <code>./build/ALPHA_SE/m5.opt --help</code> provides you help for M5 and <code>./build/ALPHA_SE/m5.opt configs/example/se.py --help</code> provides help on the <code>se.py</code> script. See [[Simulation Scripts Explained]] for more information. The sample scripts we distribute work for ALPHA, SPARC, and MIPS. However only ALPHA and SPARC are supported for full system simulation.
 
  
 +
== 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/fs.py 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.
  
==Simple SE binary==
+
{{#ev:youtube|gd_DtxQD5kc|400|center|Example video showing gem5 full system simulation for ARM. Host system is x86 64bit Ubuntu 12.04.  Video resolution can be set to 1080}}
==SPEC2k/2k6==
 
==m5threads==
 
==Booting Linux==
 
  
We'll assume that you've already [[Compiling M5|built]] an ALPHA_FS version of the M5 simulator, and [[Compiling_M5#Installing_full_system_files|downloaded and installed]] the full-system binary and disk image files.
+
=== Booting Linux ===
Then you can just run the fs.py configuration file in the m5/configs/examples directory. For example:
+
We'll assume that you've already [[Build System|built]] an ALPHA version of the gem5 simulator, and [[Introduction#Getting Additional Tools and Files|downloaded and installed]] the full-system binary and disk image files.
 +
Then you can run the fs.py configuration file in the gem5/configs/examples directory. For example:
 
<pre>
 
<pre>
% build/ALPHA_FS/m5.debug -d /tmp/output configs/example/fs.py
+
% build/ALPHA/gem5.debug -d /tmp/output configs/example/fs.py
M5 Simulator System
+
gem5 Simulator System
  
 
Copyright (c) 2001-2006
 
Copyright (c) 2001-2006
Line 59: Line 127:
  
  
M5 compiled Aug 16 2006 18:51:57
+
gem5 compiled Aug 16 2006 18:51:57
M5 started Wed Aug 16 21:53:38 2006
+
gem5 started Wed Aug 16 21:53:38 2006
M5 executing on zeep
+
gem5 executing on zeep
command line: ./build/ALPHA_FS/m5.debug configs/example/fs.py
+
command line: ./build/ALPHA/gem5.debug configs/example/fs.py
 
       0: system.tsunami.io.rtc: Real-time clock set to Sun Jan  1 00:00:00 2006
 
       0: system.tsunami.io.rtc: Real-time clock set to Sun Jan  1 00:00:00 2006
 
Listening for console connection on port 3456
 
Listening for console connection on port 3456
Line 70: Line 138:
 
</pre>
 
</pre>
  
===Basic Operation===
+
====Basic Operation====
  
 
By default, the fs.py 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 <code>telnet</code>, for example:
 
By default, the fs.py 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 <code>telnet</code>, for example:
Line 76: Line 144:
 
   % telnet localhost 3456
 
   % telnet localhost 3456
  
Telnet's echo behavior doesn't work well with m5, so if you are using the console regularly, you probably want to use [[M5term]] instead of telnet.  By default m5 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 m5 output.   
+
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, M5 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, M5 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 m5 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 [[Simulation Scripts Explained]].)
+
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:
 
Examples: Going into / of root filesystem and typing ls will show:
 
<pre>
 
<pre>
Line 97: Line 165:
 
</pre>
 
</pre>
  
===Full System Benchmarks===
+
====m5term====
 +
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:
 +
 
 +
<pre>
 +
% cd gem5/util/term
 +
% make
 +
gcc  -o m5term term.c
 +
% make install
 +
sudo install -o root -m 555 m5term /usr/local/bin
 +
</pre>
 +
 
 +
The usage of m5term is:
 +
<pre>
 +
./m5term <host> <port>
  
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 m5/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:
+
<host> is the host that is running gem5
  
<pre>%./build/ALPHA_FS/m5.opt  configs/example/fs.py -b NetperfMaerts </pre>
+
<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.
  
To see a comprehensive list of all benchmarks available:
+
If there are multiple systems running within one simulation,
<pre>%./build/ALPHA_FS/m5.opt configs/examples/fs.py -h </pre>
+
there will be a console for each one.  (The first system's
 +
console will be on 3456 and the second on 3457 for example)
  
== Restoring from a checkpoint ==
+
m5term uses '~' as an escape character.  If you enter
First of all, you need to create a checkpoint.
+
the escape character followed by a '.', the m5term program
After booting the M5 simulator, execute the following command (in the shell):
+
will exit.
<pre>
 
m5 checkpoint
 
 
</pre>
 
</pre>
which will create a new directory with the checkpoint, named 'cpt.TICKNUMBER'
+
m5term can be used to interactively work with the simulator, though users must often set various terminal settings to get things to work
  
With the new simulator (2.0 beta2), the restoring from a checkpoint can usually be easily done from the command line, e.g.:
+
A slightly shortened example of m5term in action:
 
<pre>
 
<pre>
build/ALPHA_FS/m5.debug configs/example/fs.py -r N
+
% m5term localhost 3456
OR
+
==== m5 slave console: Console 0 ====
build/ALPHA_FS/m5.debug configs/example/fs.py --checkpoint-restore=N
+
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
 +
#
 
</pre>
 
</pre>
The number N is integer that represents checkpoint number, when they are order lexically (i.e. by the ticknumber) - oldest tick has number 1, next checkpoint has number 2, etc.
+
 
==Switchover/Fastforwarding==
+
====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:
 +
 
 +
<pre>%./build/ALPHA/gem5.opt  configs/example/fs.py -b NetperfMaerts </pre>
 +
 
 +
To see a comprehensive list of all benchmarks available:
 +
<pre>%./build/ALPHA/gem5.opt configs/examples/fs.py -h </pre>
 +
 
 +
===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.
 +
 
 +
<ul>
 +
<li>Get gem5 with the proper changesets added</li>
 +
* Anything after [http://repo.gem5.org/gem5/rev/d65768b9ffc2]
 +
<pre>hg clone http://repo.gem5.org/gem5</pre>
 +
<li>Build gem5</li>
 +
<pre>scons build/ARM/gem5.opt -j 8</pre>
 +
<li>Get a DVFS-enabled Linux kernel</li>
 +
* From here: [https://gem5.googlesource.com/arm/linux-arm-legacy/]
 +
* Anything after / including [https://gem5.googlesource.com/arm/linux-arm-legacy/+/a75e551a89819c96bb762c25fa104b32eda7b99b]
 +
<pre>git clone --depth 10 https://gem5.googlesource.com/arm/linux-arm-legacy</pre>
 +
<li>Get a cross-compile tool chain</li>
 +
<pre>sudo apt-get install gcc-arm-linux-gnueabihf</pre>
 +
<li>Build the kernel</li>
 +
* See also [[Linux_kernel]]
 +
<pre>make ARCH=arm vexpress_gem5_dvfs_defconfig
 +
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8</pre>
 +
<li>Check / select the right DTS / DTB file</li>
 +
<pre>ls arch/arm/boot/dts/vexpress-v2*dvfs*</pre>
 +
<li>Get / prepare a disk image</li>
 +
<pre>wget http://www.gem5.org/dist/current/arm/arm-system-2013-07.tar.bz2
 +
tar xvjf arm-system-2013-07.tar.bz2</pre>
 +
<li>Add DVFS points to the configuration</li>
 +
<ul>
 +
<li>Enable and link the energy controller / DVFS handler
 +
<pre>patch -p1 << EOF
 +
diff --git a/configs/example/fs.py b/configs/example/fs.py
 +
--- a/configs/example/fs.py
 +
+++ b/configs/example/fs.py
 +
@@ -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.dvfs_handler.domains = test_sys.cpu_clk_domain
 +
+    test_sys.dvfs_handler.enable = 1
 +
 
 +
    if options.kernel is not None:
 +
        test_sys.kernel = binary(options.kernel)
 +
EOF</pre>
 +
</ul>
 +
* Can also change the clock frequencies here, or from command line
 +
<li>Start a simple test simulation</li>
 +
<pre>M5_PATH=$(pwd)/.. ./build/ARM/gem5.opt --debug-flags=DVFS,EnergyCtrl \
 +
  --debug-file=dfvs_debug.log configs/example/fs.py --cpu-type=AtomicSimpleCPU \
 +
  -n 2 --machine-type=VExpress_EMM --kernel=../linux-linaro-tracking-gem5/vmlinux \
 +
  --dtb-filename=../linux-linaro-tracking-gem5/arch/arm/boot/dts/\
 +
vexpress-v2p-ca15-tc1-gem5_dvfs_2cpus.dtb \
 +
  --disk-image=../disks/arm-ubuntu-natty-headless.img \
 +
  --cpu-clock=\['1 GHz','750 MHz','500 MHz'\]</pre>
 +
<li>Test DVFS functionality</li>
 +
<pre>util/term/m5term 3456
 +
<login>
 +
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
 +
echo 750187 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq</pre>
 +
</ul>
 +
====Futher Experiments====
 +
<ul>
 +
<li>Set up different voltages for the operating points
 +
<pre>patch -p1 < EOF
 +
diff --git a/configs/example/fs.py b/configs/example/fs.py
 +
--- a/configs/example/fs.py
 +
+++ b/configs/example/fs.py
 +
@@ -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.dvfs_handler.domains = test_sys.cpu_clk_domain
 +
+    test_sys.dvfs_handler.enable = 1
 +
 
 +
    if options.kernel is not None:
 +
        test_sys.kernel = binary(options.kernel)
 +
EOF</pre>
 +
<li>Per-core DVFS</li>
 +
<ul>
 +
<li>Set up separate clock (and voltage) domains per core</li>
 +
<li>Separate clock domains need separate clusters in the device tree
 +
<pre>diff -u linux-linaro-tracking-gem5/arch/arm/boot/dts/\
 +
vexpress-v2p-ca15-tc1-gem5_dvfs_{,per_core_}4cpus.dts</code></pre>
 +
<li>Change the <tt>socket_id</tt> to have a separate socket per CPU core
 +
</ul>

Latest revision as of 10:57, 18 February 2019

Usage

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
Usage
=====
  gem5.debug [gem5 options] script.py [script options]

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

Options
=======
--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
                        script
--pdb                   Invoke the python debugger before running the script
--path=PATH[:PATH], -p PATH[:PATH]
                        Prepend PATH to the system path when invoking the
                        script
--quiet, -q             Reduce verbosity
...

The default options that gem5 uses to run can be set by creating an ~/.m5/options.py 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 options.py.

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/se.py -h
Usage: se.py [options]

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.
  --ruby                
  -d, --detailed        
  -t, --timing          
  --inorder             
  -n NUM_CPUS, --num-cpus=NUM_CPUS
  --caches              
  --l2cache             
  --fastmem             
  --clock=CLOCK         
  --num-dirs=NUM_DIRS   
  --num-l2caches=NUM_L2CACHES
  --l1d_size=L1D_SIZE   
  --l1i_size=L1I_SIZE   
  --l2_size=L2_SIZE       
  --l1d_assoc=L1D_ASSOC
  --l1i_assoc=L1I_ASSOC
  --l2_assoc=L2_ASSOC   
...

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 se.py and fs.py. These scripts are present in configs/examples directory. se.py is meant for simulation using the system call emulation mode, while fs.py 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 can be statically/dynamically linked. configs/examples/se.py is used for configuring and running simulations in this mode. What follows is probably the simplest example of how to use se.py. The binary file to simulated is specified with option -c.

$ ./build/ALPHA/gem5.opt ./configs/example/se.py -c ./tests/test-progs/hello/bin/alpha/linux/hello 
gem5 Simulator System.  http://gem5.org
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/se.py -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
**** REAL SIMULATION ****
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/fs.py 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 fs.py configuration file in the gem5/configs/examples directory. For example:

% build/ALPHA/gem5.debug -d /tmp/output configs/example/fs.py
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/fs.py
      0: system.tsunami.io.rtc: 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 fs.py 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 192.168.0.10 txqueuelen 1000
/sbin/ifconfig lo 127.0.0.1
echo -n "running surge client..."
/bin/bash -c "cd /benchmarks/surge && ./Surge 2 100 1 192.168.0.1 5.
echo -n "halting machine"
m5 exit

m5term

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/fs.py -b NetperfMaerts 

To see a comprehensive list of all benchmarks available:

%./build/ALPHA/gem5.opt configs/examples/fs.py -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 http://repo.gem5.org/gem5
  • 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 https://gem5.googlesource.com/arm/linux-arm-legacy
  • 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 http://www.gem5.org/dist/current/arm/arm-system-2013-07.tar.bz2
    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/fs.py b/configs/example/fs.py
      --- a/configs/example/fs.py
      +++ b/configs/example/fs.py
      @@ -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.dvfs_handler.domains = test_sys.cpu_clk_domain
      +    test_sys.dvfs_handler.enable = 1
      
           if options.kernel is not None:
               test_sys.kernel = binary(options.kernel)
      EOF
    • 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/fs.py --cpu-type=AtomicSimpleCPU \
      -n 2 --machine-type=VExpress_EMM --kernel=../linux-linaro-tracking-gem5/vmlinux \
      --dtb-filename=../linux-linaro-tracking-gem5/arch/arm/boot/dts/\
    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
    <login>
    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/fs.py b/configs/example/fs.py
    --- a/configs/example/fs.py
    +++ b/configs/example/fs.py
    @@ -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.dvfs_handler.domains = test_sys.cpu_clk_domain
    +    test_sys.dvfs_handler.enable = 1
      
         if options.kernel is not None:
             test_sys.kernel = binary(options.kernel)
    EOF
  • 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/\
      vexpress-v2p-ca15-tc1-gem5_dvfs_{,per_core_}4cpus.dts</code>
    • Change the socket_id to have a separate socket per CPU core