原文参见:gem5 Running gem5
gem5命令行有四个部分,gem5二进制文件,二进制文件选项,仿真脚本,脚本选项。传给gem5二进制文件和脚本的选项分别处理,使用时确保使用正确的选项。
% [gem5 options] [script options]
% 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
...
gem5的默认选项可以通过创建~/.m5/options.py文件,在其中设置选项。例如如果想指定标准错误和输出文件,可以在options.py中添加options.stdout_file=simout。
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
--num-l3caches=NUM_L3CACHES
--l1d_size=L1D_SIZE
--l1i_size=L1I_SIZE
--l2_size=L2_SIZE
--l3_size=L3_SIZE
--l1d_assoc=L1D_ASSOC
--l1i_assoc=L1I_ASSOC
--l2_assoc=L2_ASSOC
--l3_assoc=L3_ASSOC
...
脚本文件(Configuratino/Simulation Scripts,gem5学习9——配置/模拟脚本)介绍了如何书写模拟脚本,选项部分介绍了如何添加自己的命令行选项。最常用的模拟脚本是se.py和fs.py。这些脚本位于configs/examples目录下。se.py用于模拟系统调用模式,fs.py用于全系统模拟。大多数情况下,可以使用这两个脚本,无需修改。理解这两个脚本可以帮助决定如何根据自己的情况进行修改。
该模式下,只需要指定待模拟的二进制文件。二进制文件应该静态编译,因为仿真器不动态链接可执行文件。使用configs/examples/se.py配置并运行仿真。下面是如何使用se.py的简单例子,二进制文件通过-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()
指定命令行变量
可以在脚本中使用--options="arg1 arg2 ..."将命令行变量传给二进制文件。
该模式对完整的系统进行仿真,根据仿真环境提供操作系统。可以使用configs/example/fs.py来配置并仿真。该脚本的选项使用了合理的默认值。
假设已经编译了ALPHA版本,并下载安装了全系统二进制文件和磁盘镜像文件。运行gem5/configs/examples目录下的fs.py配置文件。例如:
% 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...>
% telnet localhost 3456
Telnet可能与gem5不太兼容,如果经常使用控制台,可以使用 M5term代替telnet。gem5默认使用端口3456,如果该端口正在使用中,端口号会增加直到找到空闲端口。实际使用的端口号输出在gem5输出端。
benchmarks etc lib mnt sbin usr
bin floppy lost+found modules sys var
dev home man proc tmp z
下面是一段.rcS文件代码:
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
% cd gem5/util/term
% make
gcc -o m5term term.c
% make install
sudo install -o root -m 555 m5term /usr/local/bin
./m5term
is the host that is running gem5
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 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
#
%./build/ALPHA/gem5.opt configs/example/fs.py -b NetperfMaerts
查看全部测试程序:
%./build/ALPHA/gem5.opt configs/examples/fs.py -h
hg clone http://repo.gem5.org/gem5
编译gem5
scons build/ARM/gem5.opt -j 8
获取开启DVFS的Linux kernel
git clone --depth 10 git://www.linux-arm.org/linux-linaro-tracking-gem5.git
获取交叉编译工具链
sudo apt-get install gcc-arm-linux-gnueabihf
编译kernel
make ARCH=arm vexpress_gem5_dvfs_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8
检查/选择正确的DTS/DTB文件
ls arch/arm/boot/dts/vexpress-v2*dvfs*
获取/准备磁盘镜像
wget http://www.gem5.org/dist/current/arm/arm-system-2013-07.tar.bz2
tar xvjf arm-system-2013-07.tar.bz2
配置中添加DVFS
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
这里还可以修改时钟频率,通过命令行也可以
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'\]
DVFS功能性测试
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
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
diff -u linux-linaro-tracking-gem5/arch/arm/boot/dts/\
vexpress-v2p-ca15-tc1-gem5_dvfs_{,per_core_}4cpus.dts
每个核修改socket_id,有独立的socket