13
SoC CAD 111/06/09 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 黃 黃 Department of Electrical Engineering National Cheng Kung University Tainan, Taiwan, R.O.C

SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

Embed Size (px)

Citation preview

Page 1: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

SoC CAD

112/04/18

1

Function call sequence for gem5: system.py & simulate.py & simulate.cc

黃喬楷

Department of Electrical Engineering

National Cheng Kung University

Tainan, Taiwan, R.O.C

Page 2: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 2 Huang, Ciao Kai

SoC CADInitialization Function Call Sequence (1/2)

The figure below shows the function call sequence for the initialization of gem5 when running the "Hello, World" example.

Each node in the graph gives the path to the source code file in which the function is located.

This representation should aid in the first steps of familiarization with the basic initialization steps of gem5, including how the configuration files are used and how the objects are constructed.

Page 3: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 3 Huang, Ciao Kai

SoC CADInitialization Function Call Sequence (2/2)

function call sequence for gem5 ”Hello,World” example

ARM

Page 4: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 4 Huang, Ciao Kai

SoC CADSystem.py (1/5)

from m5.SimObject import SimObjectfrom m5.defines import buildEnvfrom m5.params import *from m5.proxy import *from SimpleMemory import *

class MemoryMode(Enum): vals = ['invalid', 'atomic', 'timing', 'atomic_noncaching']

class System(MemObject): type = 'System' cxx_header = "sim/system.hh" system_port = MasterPort("System port")

memories = VectorParam.AbstractMemory(Self.all,"All memories in the system") mem_mode = Param.MemoryMode('atomic', "The mode the memory system is in")

# The memory ranges are to be populated when creating the system such that these can be passed # from the I/O subsystem through an I/O bridge or cache

mem_ranges = VectorParam.AddrRange([], "Ranges that constitute main memory") cache_line_size = Param.Unsigned(64, "Cache line size in bytes")

Page 5: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 5 Huang, Ciao Kai

SoC CADSystem.py (2/5)

work_item_id = Param.Int(-1, "specific work item id") num_work_ids = Param.Int(16, "Number of distinct work item types") work_begin_cpu_id_exit = Param.Int(-1,"work started on specific id, now exit simulation") work_begin_ckpt_count = Param.Counter(0,"create checkpoint when work items begin count

value is reached") work_begin_exit_count = Param.Counter(0,"exit simulation when work items begin count value is

reached") work_end_ckpt_count = Param.Counter(0,"create checkpoint when work items end count value is

reached") work_end_exit_count = Param.Counter(0,"exit simulation when work items end count value is

reached") work_cpus_ckpt_count = Param.Counter(0,"create checkpoint when active cpu count value is

reached")

init_param = Param.UInt64(0, "numerical value to pass into simulator") boot_osflags = Param.String("a", "boot flags to pass to the kernel") kernel = Param.String("", "file that contains the kernel code") readfile = Param.String("", "file to read startup script from") symbolfile = Param.String("", "file to get the symbols from") load_addr_mask = Param.UInt64(0xffffffffff,"Address to mask loading binaries with") load_offset = Param.UInt64(0, "Address to offset loading binaries with")

Page 6: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 6 Huang, Ciao Kai

SoC CADSystem.py (3/5)

由於開頭導入所有 m5 package 的params module,可用 params內定義的函數成員。

在 params module中定義了

from m5.params import *

Page 7: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 7 Huang, Ciao Kai

SoC CADSystem.py (4/5)

Param = ParamFactory(ParamDesc)VectorParam = ParamFactory(VectorParamDesc)

cache_line_size = Param.Unsigned(64, "Cache line size in bytes")

class Unsigned(CheckedInt): cxx_type = 'unsigned'; size = 32; unsigned = True

work_item_id = Param.Int(-1, "specific work item id") num_work_ids = Param.Int(16, "Number of distinct work item types")

class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False

work_begin_ckpt_count = Param.Counter(0,"create checkpoint when work items begin count value is reached")

work_begin_exit_count = Param.Counter(0,"exit simulation when work items begin count value is reached")

work_end_ckpt_count = Param.Counter(0,"create checkpoint when work items end count value is reached")

work_end_exit_count = Param.Counter(0,"exit simulation when work items end count value is reached")

class Counter(CheckedInt): cxx_type = 'Counter'; size = 64; unsigned = True

Page 8: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 8 Huang, Ciao Kai

SoC CADSystem.py (5/5)

init_param = Param.UInt64(0, "numerical value to pass into simulator")load_addr_mask = Param.UInt64(0xffffffffff,"Address to mask loading binaries with")load_offset = Param.UInt64(0, "Address to offset loading binaries with")

class UInt64(CheckedInt): cxx_type = 'uint64_t'; size = 64; unsigned = True

boot_osflags = Param.String("a", "boot flags to pass to the kernel") kernel = Param.String("", "file that contains the kernel code") readfile = Param.String("", "file to read startup script from") symbolfile = Param.String("", "file to get the symbols from")

Page 9: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 9 Huang, Ciao Kai

SoC CADsimulate.cc : simulate() (1/3)

simulate(Tick num_cycles){ // The first time simulate() is called from the Python code, we need to create a thread for // each of event queues referenced by the instantiated sim objects. static bool threads_initialized = false; static std::vector<std::thread *> threads;

if (!threads_initialized) { … …

inform("Entering event queue @ %d. Starting simulation...\n", curTick());

if (num_cycles < MaxTick - curTick()) num_cycles = curTick() + num_cycles; else // counter would roll over or be set to MaxTick anyhow num_cycles = MaxTick;

GlobalEvent *limit_event = new GlobalSimLoopExitEvent(num_cycles, "simulate() limit reached", 0, 0);

GlobalSyncEvent *quantum_event = NULL; if (numMainEventQueues > 1) { … …

Page 10: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 10

Huang, Ciao Kai

SoC CADsimulate.cc : simulate() (2/3)

// all subordinate (created) threads should be waiting on the barrier; the arrival of the // main thread here will satisfy the barrier, and all threads will enter doSimLoop in parallel threadBarrier->wait(); Event *local_event = doSimLoop(mainEventQueue[0]); assert(local_event != NULL);

inParallelMode = false;

// locate the global exit event and return it to Python BaseGlobalEvent *global_event = local_event->globalEvent(); assert(global_event != NULL);

GlobalSimLoopExitEvent *global_exit_event = dynamic_cast<GlobalSimLoopExitEvent *>(global_event); assert(global_exit_event != NULL);

// if we didn't hit limit_event, delete it. if (global_exit_event != limit_event) { … … //! Delete the simulation quantum event. if (quantum_event != NULL) { … …

return global_exit_event;}

Page 11: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 11

Huang, Ciao Kai

SoC CADsimulate.cc : simulate() (3/3)

Simulate for num_cycles additional cycles.If num_cycles is -1 (the default), do not limit simulation; some other event

must terminate the loop. Exported to Python via SWIG.Returns:The SimLoopExitEvent that caused the loop to exit.Delete the simulation quantum event.

Page 12: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 12

Huang, Ciao Kai

SoC CADSimulate.py : instantiate() (1/2)

def instantiate(ckpt_dir=None): from m5 import options

root = objects.Root.getInstance()

if not root: fatal("Need to instantiate Root() before calling instantiate()")

# we need to fix the global frequency ticks.fixGlobalFrequency()

# Make sure SimObject-valued params are in the configuration hierarchy so we catch # them with future descendants() walks for obj in root.descendants(): obj.adoptOrphanParams()

# Check to see if any of the stat events are in the past after resuming from a checkpoint, # If so, this call will shift them to be at a valid time. updateStatEvents()

# Reset to put the stats in a consistent state. stats.reset()

Page 13: SoC CAD 2015/5/23 1 Function call sequence for gem5: system.py & simulate.py & simulate.cc 黃 喬 楷黃 喬 楷 Department of Electrical Engineering National Cheng

NCKU

SoC & ASIC Lab 13

Huang, Ciao Kai

SoC CADSimulate.py (2/2)

透過 Root.py.cc得到程式中所見 m5.objects.Root的檔案的絕對位置為 /home/asic/gem5/src/sim/Root.py

透過 gem5/src/Sconscript中定義了 obj = sim_objects = m5.SimObject.allClasses

完成實例後重新設定狀態使其處於一致的狀態。

_the_instance = None#一開始為零根據實例所增加的類別進行擴增def getInstance(cls):

return Root._the_instance

root = objects.Root.getInstance()

stats.reset()