gem5学习10——运行

原文参见:gem5 Running gem5

使用

gem5命令行有四个部分,gem5二进制文件,二进制文件选项,仿真脚本,脚本选项。传给gem5二进制文件和脚本的选项分别处理,使用时确保使用正确的选项。

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

gem5选项

运行gem5时使用-h标记打印出帮助信息,包含所有支持的仿真器选项。下面是一部分:

% 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。

脚本选项

命令行的脚本部分以脚本文件的路径开始,包括想传递给脚本的所有选项。大部分示例脚本允许传递-h或--help标记给脚本来查看特定选项。下面是一个例子:
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 Scriptsgem5学习9——配置/模拟脚本)介绍了如何书写模拟脚本,选项部分介绍了如何添加自己的命令行选项。最常用的模拟脚本是se.py和fs.py。这些脚本位于configs/examples目录下。se.py用于模拟系统调用模式,fs.py用于全系统模拟。大多数情况下,可以使用这两个脚本,无需修改。理解这两个脚本可以帮助决定如何根据自己的情况进行修改。

系统调用(SE)仿真

该模式下,只需要指定待模拟的二进制文件。二进制文件应该静态编译,因为仿真器不动态链接可执行文件。使用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 ..."将命令行变量传给二进制文件。

全系统(FS)仿真

该模式对完整的系统进行仿真,根据仿真环境提供操作系统。可以使用configs/example/fs.py来配置并仿真。该脚本的选项使用了合理的默认值。

启动Linux

假设已经编译了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...>

基本选项

默认情况下,fs.py脚本启动Linux并在系统控制台启动一个shell。为了将控制台信息与仿真器输入输出信息分开,控制台使用TCP端口。为了与控制台交互,必须使用如telnet的程序连接到该端口上,例如:
% telnet localhost 3456
Telnet可能与gem5不太兼容,如果经常使用控制台,可以使用 M5term代替telnet。gem5默认使用端口3456,如果该端口正在使用中,端口号会增加直到找到空闲端口。实际使用的端口号输出在gem5输出端。
除了加载Linux内核,gem5将一个或多个磁盘镜像挂载到文件系统上。至少挂载一个磁盘镜像作为根文件系统。想运行的所有应用程序二进制文件必须在这些磁盘镜像上。为了无需与shell交互就运行测试程序,gem5可以加载.rcS文件来取代通常的Linux启动脚本,在启动OS后直接运行。.rcS文件可以用于配置网络接口,执行特殊的gem5指令,或者在磁盘镜像上执行二进制文件。Linux二进制文件、磁盘镜像和.rcS文件的指针都在仿真脚本中进行了设置(可以查看 Configuration/Simulation Scriptsgem5学习9——配置/模拟脚本)。例如进入根文件系统的/目录下,输入ls,会显示:
  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

m5term

m5term程序允许用户连接到全系统gem5仿真控制台接口。进入util/term目录,编译m5term:
	% cd gem5/util/term 
	% make
	gcc  -o m5term term.c
	% make install
	sudo install -o root -m 555 m5term /usr/local/bin

m5term的使用
./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可以与仿真器交互,但是用户必须经常设置不同的终端。下面是一个m5term简短的例子:
	% 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
	#

全系统测试程序

现在已经有几个全系统测试程序可以运行了。二进制文件在磁盘镜像文件里,.rcS文件在gem5/configs/boot/目录下。运行时,只需要设置测试程序选项。例如:
%./build/ALPHA/gem5.opt  configs/example/fs.py -b NetperfMaerts 
查看全部测试程序:
%./build/ALPHA/gem5.opt configs/examples/fs.py -h 

DVFS实验

下面是一个快速教程,开始一个DVFS开启的系统,Linux DVFS管理员可以更改正在进行仿真的电压和频率。目前,driver和接口属于Linux kernel/gem5的ARM-specific部分,但没有原因表明为什么不可以移植到其他架构上。

快速指令

这些指令适用于基于Ubuntu的系统,但可以很容易地移植或扩展到其他系统。
获取gem5
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
参考: Linux_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
打开并连接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
这里还可以修改时钟频率,通过命令行也可以
开始简单的测试仿真
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
<login>
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

Per-core DVFS
为每个核设置独立的时钟和电压
设备树中不同时钟域需要不同cluster
diff -u linux-linaro-tracking-gem5/arch/arm/boot/dts/\
vexpress-v2p-ca15-tc1-gem5_dvfs_{,per_core_}4cpus.dts</code>
每个核修改socket_id,有独立的socket

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值