/****************************************************************************** * Getting Started with GEM5 Simulator @ LaCASA Laboratory (lacasa.uah.edu) * This tutorial should help you get started with gem5 on computers in LaCASA lab. * It is tested on eb245-mhealth3 machine that runs 64-bit CentOS 6.3 OS. * Author: Aleksandar Milenkovic * Date: July 2013 ******************************************************************************/ Gem5 is a modular platform for computer system architecture research, supporting both system-level architecture as well as processor microarchitecture. The ultimate source information is http://www.m5sim.org/Main_Page. Documentation page at http://www.m5sim.org/Documentation contains a number of useful instructions. This tutorial is not a replacement for all these tutorials, it may simply help you get started faster on our machines. If you are using LaCASA machines you do not need to download and install gem5. gem5 is typically available in /opt/gem5 directory. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Download ------------- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< [milenka@EB245-mhealth3 opt]$ pwd /opt [milenka@EB245-mhealth3 opt]$ hg clone http://repo.gem5.org/gem5 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Building gem5 ----------------- Tools * GCC/G++ 4.2+ (or clang 2.9+) * Python 2.4+ * SCons 0.98.1+ * http://www.scons.org * SWIG 1.3.40+ * http://www.swig.org To install them on Ubuntu: sudo apt-get install python-dev scons m4 build-essential g++ swig zlib-dev To install them on CentOS: sudo yum groupinstall "Development Tools" 3. Compiling targets ---------------------- build// - ISAs: ARM, ALPHA, MIPS, SPARC, POWER, X86 - Binaries * gem5.debug debug build, symbols, tracing, assert * gem5.opt optimized build, symbols, tracing, assert * gem5.fast optimized build, no debugging, no symbols, no tracing, no assertions * gem5.prof gem5.fast + profiling support - Compile gem5.opt for ARM ISA [milenka@EB245-mhealth3 gem5]$ scons build/ARM/gem5.opt - Compile gem5.opt for X86 [milenka@EB245-mhealth3 gem5]$ scons build/X86/gem5.opt 4. Running simulations ------------------------ [milenka@EB245-mhealth3 gem5]$ ./build/ARM/gem5.opt -h Usage ===== gem5.opt [gem5 options] script.py [script options] 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 5. Modes of operation ---------------------- - Full system (FS) * For booting operating systems * Models bare hardware, including devices * Interrupts, exceptions, privileged instructions, fault handlers * Simulated UART output * Simulated frame buffer output - Syscall emulation (SE) * For running individual applications, or set of applications on MP * Models user-visible ISA plus common system calls * System calls emulated, typically by calling host OS * Simplified address translation model, no scheduling 6. Sample Run - Syscall emulation (Hello world!) ------------------------------------------------ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< [milenka@EB245-mhealth3 gem5]$ ./build/ARM/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello gem5 Simulator System. http://gem5.org gem5 is copyrighted software; use the --copyright option for details. gem5 compiled Feb 13 2013 11:10:22 gem5 started Feb 13 2013 12:45:42 gem5 executing on EB245-mhealth3 command line: ./build/ARM/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/arm/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... Hello world! hack: be nice to actually delete the event here Exiting @ tick 3102500 because target called exit() [milenka@EB245-mhealth3 gem5]$ ./build/X86/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/x86/linux/hello gem5 Simulator System. http://gem5.org gem5 is copyrighted software; use the --copyright option for details. gem5 compiled Jul 6 2013 16:46:21 gem5 started Jul 6 2013 21:50:55 gem5 executing on EB245-mhealth3 command line: ./build/X86/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/x86/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... warn: instruction 'fldcw_Mw' unimplemented Hello world! hack: be nice to actually delete the event here Exiting @ tick 5941500 because target called exit() [milenka@EB245-mhealth3 gem5]$ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 7. Sample Run - Full System ---------------------------- Visit: http://www.m5sim.org/Running_gem5 a) Add M5_PATH into .bashrc file. M5_PATH="/opt/full_system_images" b) Run real simulation ./build/ARM/gem5.opt configs/example/fs.py --disk-image=/opt/full_system_images/disks/arm-ubuntu-natty-headless.img c) Open new terminal window and use telnet to connect to 127.0.0.1 @3456 telnet 127.0.0.1 3456 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. ==== m5 slave terminal: Terminal 0 ==== d) Login in the telnet session (root, no password) Instead of telnet, we can use m5term e) got to /opt/gem5/util/term [milenka@EB245-mhealth3 term]$ ls m5term Makefile term.c f) Note: compile program if not compiled [milenka@EB245-mhealth3 term]$ make gcc -o m5term term.c [milenka@EB245-mhealth3 term]$ sudo install -o root -m 555 m5term /usr/local/bin g) Connect to localhost @ 3456 [milenka@EB245-mhealth3 term]$ m5term localhost 3456 ==== m5 slave terminal: Terminal 0 ==== [ 0.000000] Linux version 2.6.38.8-gem5 (saidi@zeep) (gcc version 4.5.2 (Sourcery G++ Lite 2011.03-41) ) #1 SMP Mon Aug 15 21:18:38 EDT 2011 [ 0.000000] CPU: ARMv7 Processor [350fc000] revision 0 (ARMv7), cr=10c53c7f .... [ 2.242205] Freeing init memory: 132K Ubuntu 11.04 gem5sim ttySA0 gem5sim login: root h) Run an example command in the terminal root@gem5sim:~# time ps PID TTY TIME CMD 688 ttyAMA0 00:00:00 login 2922 ttyAMA0 00:00:00 bash 2933 ttyAMA0 00:00:00 ps real 0m0.010s user 0m0.000s sys 0m0.000s root@gem5sim:~# i) Drop a checkpoint root@gem5sim:~# m5 checkpoint j) Exit simulation root@gem5sim:~# m5 exit [milenka@EB245-mhealth3 term]$ In the gem5 window you should see the following messages: ---- Writing checkpoint info: Entering event queue @ 313264840806500. Starting simulation... Exiting @ tick 353984807607500 because m5_exit instruction encountered [milenka@EB245-mhealth3 gem5]$ ---- 11. Tracing ------------ a) Tracing the ARM hello test program ./build/ARM/gem5.opt --debug-flags=Exec,ExecTicks configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello | more 0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000 gem5 Simulator System. http://gem5.org gem5 is copyrighted software; use the --copyright option for details. gem5 compiled Feb 13 2013 11:10:22 gem5 started Jul 8 2013 13:55:35 gem5 executing on EB245-mhealth3 command line: ./build/ARM/gem5.opt --debug-flags=Exec,ExecTicks configs/example/se.py -c tests/test-progs/hello/b in/arm/linux/hello Global frequency set at 1000000000000 ticks per second **** REAL SIMULATION **** info: Entering event queue @ 0. Starting simulation... 0: system.cpu T0 : 0x8150 : ldr r12, [pc, #36] : MemRead : D=0x0000000000008960 A=0x817c 500: system.cpu T0 : 0x8154 : mov fp, #0 : IntAlu : D=0x0000000000000000 1000: system.cpu T0 : 0x8158.0 : ldr r1, [sp] #4 : MemRead : D=0x0000000000000001 A=0xbefffef0 1500: system.cpu T0 : 0x8158.1 : addi_uop sp, sp, #4 : IntAlu : D=0x00000000befffef4 2000: system.cpu T0 : 0x815c : mov r2, sp : IntAlu : D=0x00000000befffef4 2500: system.cpu T0 : 0x8160.0 : str r2, [sp, #-4]! : MemWrite : D=0x00000000befffef4 A=0xbefffef0 3000: system.cpu T0 : 0x8160.1 : subi_uop sp, sp, #4 : IntAlu : D=0x00000000befffef0 3500: system.cpu T0 : 0x8164.0 : str r0, [sp, #-4]! : MemWrite : D=0x0000000000000000 A=0xbefffeec 4000: system.cpu T0 : 0x8164.1 : subi_uop sp, sp, #4 : IntAlu : D=0x00000000befffeec 4500: system.cpu T0 : 0x8168 : ldr r0, [pc, #16] : MemRead : D=0x0000000000008248 A=0x8180 5000: system.cpu T0 : 0x816c : ldr r3, [pc, #16] : MemRead : D=0x00000000000089a8 A=0x8184 5500: system.cpu T0 : 0x8170.0 : str r12, [sp, #-4]! : MemWrite : D=0x0000000000008960 A=0xbefffee8 6000: system.cpu T0 : 0x8170.1 : subi_uop sp, sp, #4 : IntAlu : D=0x00000000befffee8 6500: system.cpu T0 : 0x8174 : bl : IntAlu : D=0x0000000000008178 7000: system.cpu T0 : 0x826c : ldr r12, [pc, #664] : MemRead : D=0x0000000000000000 A=0x850c 7500: system.cpu T0 : 0x8270.0 : addi_uop r34, sp, #0 : IntAlu : D=0x00000000befffee8 8000: system.cpu T0 : 0x8270.1 : str_uop r4, [r34, #24] : MemWrite : D=0x0000000000000000 A=0xbefffed0 8500: system.cpu T0 : 0x8270.2 : str_uop r5, [r34, #20] : MemWrite : D=0x0000000000000000 A=0xbefffed4 9000: system.cpu T0 : 0x8270.3 : str_uop r6, [r34, #16] : MemWrite : D=0x0000000000000000 A=0xbefffed8 9500: system.cpu T0 : 0x8270.4 : str_uop r7, [r34, #12] : MemWrite : D=0x0000000000000000 A=0xbefffedc --More-- b) For x86: [milenka@EB245-mhealth3 gem5]$ ./build/X86/gem5.opt --debug-flags=Exec,ExecTicks configs/example/se.py -c tests/t est-progs/hello/bin/x86/linux/hello | more 0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000 gem5 Simulator System. http://gem5.org gem5 is copyrighted software; use the --copyright option for details. gem5 compiled Jul 6 2013 16:46:21 gem5 started Jul 8 2013 13:56:30 gem5 executing on EB245-mhealth3 command line: ./build/X86/gem5.opt --debug-flags=Exec,ExecTicks configs/example/se.py -c tests/test-progs/hello/b in/x86/linux/hello Global frequency set at 1000000000000 ticks per second **** REAL SIMULATION **** info: Entering event queue @ 0. Starting simulation... 0: system.cpu T0 : 0x400190. 0 : XOR_R_R : xor rbp, rbp, rbp : IntAlu : D=0x0000000000000000 500: system.cpu T0 : 0x400193.0 : MOV_R_R : mov r9, r9, rdx : IntAlu : D=0x0000000000000000 1000: system.cpu T0 : 0x400196.0 : POP_R : ld t1, SS:[rsp] : MemRead : D=0x0000000000000001 A=0x7fffffff ee30 1500: system.cpu T0 : 0x400196.1 : POP_R : addi rsp, rsp, 0x8 : IntAlu : D=0x00007fffffffee38 2000: system.cpu T0 : 0x400196.2 : POP_R : mov rsi, rsi, t1 : IntAlu : D=0x0000000000000001 3000: system.cpu T0 : 0x400197.0 : MOV_R_R : mov rdx, rdx, rsp : IntAlu : D=0x00007fffffffee38 3500: system.cpu T0 : 0x40019a.0 : AND_R_I : limm t1, 0xfffffffffffffff0 : IntAlu : D=0xfffffffffffffff0 4000: system.cpu T0 : 0x40019a.1 : AND_R_I : and rsp, rsp, t1 : IntAlu : D=0x0000000000000000 4500: system.cpu T0 : 0x40019e.0 : PUSH_R : st rax, SS:[rsp + 0xfffffffffffffff8] : MemWrite : D=0x00000 00000000000 A=0x7fffffffee28 5000: system.cpu T0 : 0x40019e.1 : PUSH_R : subi rsp, rsp, 0x8 : IntAlu : D=0x00007fffffffee28 5500: system.cpu T0 : 0x40019f.0 : PUSH_R : st rsp, SS:[rsp + 0xfffffffffffffff8] : MemWrite : D=0x00007 fffffffee28 A=0x7fffffffee20 6000: system.cpu T0 : 0x40019f.1 : PUSH_R : subi rsp, rsp, 0x8 : IntAlu : D=0x00007fffffffee20 6500: system.cpu T0 : 0x4001a0.0 : MOV_R_I : limm r8, 0x40a060 : IntAlu : D=0x000000000040a060 7500: system.cpu T0 : 0x4001a7.0 : MOV_R_I : limm rcx, 0x409ff0 : IntAlu : D=0x0000000000409ff0 8500: system.cpu T0 : 0x4001ae.0 : MOV_R_I : limm rdi, 0x400274 : IntAlu : D=0x0000000000400274 9500: system.cpu T0 : 0x4001b5.0 : CALL_NEAR_I : limm t1, 0x9846 : IntAlu : D=0x0000000000009846 10000: system.cpu T0 : 0x4001b5.1 : CALL_NEAR_I : rdip t7, %ctrl153, : IntAlu : D=0x00000000004001ba --More-- c) Tracing into a file: the output file hello.arm.trace.out will be created in the /opt/gem5/m5out directory [milenka@EB245-mhealth3 gem5]$ ./build/ARM/gem5.opt --debug-flags=Exec,ExecTicks --trace-file=hello.arm.trace.out configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello d) Simulation output: the stats.txt in /opt/gem5/m5out contains the statistics collected during simulation. ---------- Begin Simulation Statistics ---------- sim_seconds 0.000003 # Number of seconds simulated sim_ticks 3102500 # Number of ticks simulated final_tick 3102500 # Number of ticks from beginning of simulation (restored fr sim_freq 1000000000000 # Frequency of simulated ticks host_inst_rate 173897 # Simulator instruction rate (inst/s) host_op_rate 214719 # Simulator op (including micro ops) rate (op/s) host_tick_rate 107521907 # Simulator tick rate (ticks/s) host_mem_usage 751116 # Number of bytes of host memory used host_seconds 0.03 # Real time elapsed on the host sim_insts 5013 # Number of instructions simulated sim_ops 6193 # Number of ops (including micro ops) simulated system.physmem.bytes_read::cpu.inst 20104 # Number of bytes read from this memory system.physmem.bytes_read::cpu.data 4672 # Number of bytes read from this memory system.physmem.bytes_read::total 24776 # Number of bytes read from this memory system.physmem.bytes_inst_read::cpu.inst 20104 # Number of instructions bytes read from this memory system.physmem.bytes_inst_read::total 20104 # Number of instructions bytes read from this memory system.physmem.bytes_written::cpu.data 3696 # Number of bytes written to this memory system.physmem.bytes_written::total 3696 # Number of bytes written to this memory system.physmem.num_reads::cpu.inst 5026 # Number of read requests responded to by this memory system.physmem.num_reads::cpu.data 1221 # Number of read requests responded to by this memory system.physmem.num_reads::total 6247 # Number of read requests responded to by this memory system.physmem.num_writes::cpu.data 936 # Number of write requests responded to by this memory system.physmem.num_writes::total 936 # Number of write requests responded to by this memory system.physmem.bw_read::cpu.inst 6479935536 # Total read bandwidth from this memory (bytes/s) system.physmem.bw_read::cpu.data 1505882353 # Total read bandwidth from this memory (bytes/s) system.physmem.bw_read::total 7985817889 # Total read bandwidth from this memory (bytes/s) system.physmem.bw_inst_read::cpu.inst 6479935536 # Instruction read bandwidth from this memory (bytes/s) system.physmem.bw_inst_read::total 6479935536 # Instruction read bandwidth from this memory (bytes/s) system.physmem.bw_write::cpu.data 1191297341 # Write bandwidth from this memory (bytes/s) e) Tracing into zipped file ./build/ARM/gem5.opt --debug-flags=Exec,ExecTicks --trace-file=hello1.arm.trace.out.gz configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello