Part I: Getting started with gem5

Building gem5

  • Download gem5 source
hg clone
git clone
git checkout -b asplos
  • Build gem5...
scons -j5 build/X86/gem5.opt


  • Slide on scons command
  • Slide on SimObjects
  • Slide on discrete event simulation

Configuration scripts

  • Slide on gem5 interface

  • slide showing system we’re going to build
    • If possible, draw this on the board, or leave it up.
  • This script is the simplest system you can create.
    • We’ll discuss some of what we’re doing now
    • We’ll go into more details on most of this later
  • Make new folder: configs/tutorial

  • Create new file: configs/tutorial/

  • Import all compiled objects

import m5
from m5.objects import *
  • Instantiate a System
system = System()
  • Set default clock domain and voltage domain
system.clk_domain = SrcClockDomain()
system.clk_domain.clock = '1GHz'
system.clk_domain.voltage_domain = VoltageDomain()
  • Set memory mode to timing and default address range
system.mem_mode = 'timing'
system.mem_ranges = [AddrRange('512MB')]
  • Create a CPU
system.cpu = TimingSimpleCPU()
  • Create the membus
system.membus = SystemXBar()
  • Connect the CPU ports to the membus
system.cpu.icache_port = system.membus.slave
system.cpu.dcache_port = system.membus.slave
  • Create the interrupt controllers (note: x86 only)
system.cpu.interrupts[0].pio = system.membus.master
system.cpu.interrupts[0].int_master = system.membus.slave
system.cpu.interrupts[0].int_slave = system.membus.master

system.system_port = system.membus.slave
  • Create a memory controller
  • Set the memory controller’s range
  • Connect the membus to the memory controller
system.mem_ctrl = DDR3_1600_8x8()
system.mem_ctrl.range = system.mem_ranges[0]
system.mem_ctrl.port = system.membus.master

  • Now, done with the “System”
  • next step: Set up the workload
  • Note: We’re using SE mode
  • Create a process
  • Set the binary
  • Set the CPU to use the process
  • Create the threads
process = Process()
process.cmd = ['tests/test-progs/hello/bin/x86/linux/hello']
system.cpu.workload = process
  • Create the “root”.

  • All scripts must have a root

  • Instantiate the system
    • This is where all the C++ objects are created
root = Root(full_system = False, system = system)
  • Now, we can simulate.
  • Remember, this is just Python
print("Beginning simulation!")
exit_event = m5.simulate()

print('Exiting @ tick {} because {}'
      .format(m5.curTick(), exit_event.getCause()))
  • Run gem5!
build/X86/gem5.opt configs/tutorial/


  • Slide on running

  • Slide on ports
    • More details to come!
  • slide on SE vs FS mode

Adding caches

  • Quick overview of what you can do in python


  • Look at src/mem/cache/
  • Look at configs/learning_gem5/part1/
  • Look at configs/learning_gem5/part1/
  • Run
build/X86/gem5.opt configs/learning_gem5/part1/
  • Run -h and show that you can add command-line parameters
build/X86/gem5.opt configs/learning_gem5/part1/ -h
  • Run with two different cache sizes and show there are different outputs
build/X86/gem5.opt configs/learning_gem5/part1/ --l1d_size=2kB


Understanding gem5’s output

  • Slide on output generated


  • Look at config.ini
  • Look at dotfile
  • Look at stats.txt


  • Slide talking about stats.txt

If extra time...

Using the example config scripts

Talk about using

Talk about common options: cpu-type, sys-clock, cpu-clock, mem-type, caches, l2cache, ruby, -m, -I, -c, -o, –output, etc.