README revision 11971
111832SChristian.Menard@tu-dresden.deThis directory contains a demo of a coupling between gem5 and SystemC-TLM.  It
211832SChristian.Menard@tu-dresden.deis based on the gem5-systemc implementation in utils/systemc. This Readme gives
311832SChristian.Menard@tu-dresden.dean overall overview (I), describes the source files in this directory (II),
411832SChristian.Menard@tu-dresden.deexplains the build steps (III), shows how to run example simulations (IV-VI)
511832SChristian.Menard@tu-dresden.deand lists known issues (VII).
610993Sjungma@eit.uni-kl.de
710993Sjungma@eit.uni-kl.de
811832SChristian.Menard@tu-dresden.deI. Overview
911832SChristian.Menard@tu-dresden.de===========
1011832SChristian.Menard@tu-dresden.de
1111832SChristian.Menard@tu-dresden.deThe sources in this directory provide three SystemC modules that manage the
1211832SChristian.Menard@tu-dresden.deSystemC/gem5 co-simulation: Gem5SimControl, Gem5MasterTransactor, and
1311832SChristian.Menard@tu-dresden.deGem5SlaveTransactor. They also implement gem5's ExternalMaster::Port interface
1411832SChristian.Menard@tu-dresden.de(SCMasterPort) and ExternalSlave::Port interface (SCSlavePort).
1511832SChristian.Menard@tu-dresden.de
1611832SChristian.Menard@tu-dresden.de**SCMasterPort** and **Gem5MasterTransactor** together form a TLM-to-gem5
1711832SChristian.Menard@tu-dresden.debridge. SCMasterPort implements gem5's ExternalMaster::Port interface and forms
1811832SChristian.Menard@tu-dresden.dethe gem5 end of the bridge. Gem5MasterTransactor is a SystemC module that
1911832SChristian.Menard@tu-dresden.deprovides a target socket and represents the TLM side of the bridge. All TLM
2011832SChristian.Menard@tu-dresden.derequests send to this target socket, are translated to gem5 requests and
2111832SChristian.Menard@tu-dresden.deforwarded to the gem5 world through the SCMasterPort. Then the gem5 world
2211832SChristian.Menard@tu-dresden.dehandles the request and eventually issues a response. When the response arrives
2311832SChristian.Menard@tu-dresden.deat the SCMasterPort it gets translated back into a TLM response and forwarded
2411832SChristian.Menard@tu-dresden.deto the TLM world through target socket of the Gem5MasterTransactor.
2511832SChristian.Menard@tu-dresden.deSCMasterPort and Gem5MasterTransactor are bound to each other by configuring
2611832SChristian.Menard@tu-dresden.dethem for the same port name.
2711832SChristian.Menard@tu-dresden.de
2811832SChristian.Menard@tu-dresden.de**SCSlavePort** and **Gem5SlaveTransactor** together form a gem5-to-TLM bridge.
2911832SChristian.Menard@tu-dresden.deGem5SlaveTransactor is a SystemC module that provides a initiator socket and
3011832SChristian.Menard@tu-dresden.derepresents the TLM end of the bridge. SCSlavePort implements gem5's
3111832SChristian.Menard@tu-dresden.deExternalSlave::Port interface and forms the gem5 side of the bridge. All gem5
3211971Szulian@eit.uni-kl.derequests sent to the SCSlavePort, are translated to TLM requests and forwarded
3311832SChristian.Menard@tu-dresden.deto the TLM world through the initiator socket of the Gem5SlaveTransactor. Then
3411832SChristian.Menard@tu-dresden.dethe TLM world handles the request and eventually issues a response. When the
3511971Szulian@eit.uni-kl.deresponse arrives at the Gem5SlaveTransactor it gets translated back into a
3611971Szulian@eit.uni-kl.degem5 response and forwarded to the gem5 world through the SCSlavePort. SCSLavePort
3711832SChristian.Menard@tu-dresden.deand Gem5SlaveTransactor are bound to each other by configuring them for the
3811832SChristian.Menard@tu-dresden.desame port name.
3911832SChristian.Menard@tu-dresden.de
4011832SChristian.Menard@tu-dresden.de**Gem5SimControl** is the central SystemC module that represents the complete
4111832SChristian.Menard@tu-dresden.degem5 world. It is responsible for instantiating all gem5 objects according to a
4211832SChristian.Menard@tu-dresden.degiven configuration file, for configuring the simulation and for maintaining
4311832SChristian.Menard@tu-dresden.dethe gem5 event queue. It also keeps track of all SCMasterPort and SCSlavePort
4411832SChristian.Menard@tu-dresden.deand responsible for connecting all Gem5MasterTransactor and Gem5SlaveTransactor
4511832SChristian.Menard@tu-dresden.demodules to their gem5 counterparts. This module must be instantiated exactly
4611832SChristian.Menard@tu-dresden.deonce in order to run a gem5 simulation from within an SystemC environment.
4711832SChristian.Menard@tu-dresden.de
4811832SChristian.Menard@tu-dresden.de
4911832SChristian.Menard@tu-dresden.deII. Files
5011832SChristian.Menard@tu-dresden.de=========
5111832SChristian.Menard@tu-dresden.de
5211832SChristian.Menard@tu-dresden.de    sc_slave_port.{cc,hh}     -- Implements SCSlavePort
5311832SChristian.Menard@tu-dresden.de    sc_master_port.{cc,hh}    -- Implements SCMasterPort
5411832SChristian.Menard@tu-dresden.de    sc_mm.{cc,hh}             -- Implementation of a TLM memory manager
5511832SChristian.Menard@tu-dresden.de    sc_ext.{cc,hh}            -- TLM extension that carries a gem5 packet
5611832SChristian.Menard@tu-dresden.de    sc_peq.{cc,hh}            -- TLM PEQ for scheduling gem5 events
5711832SChristian.Menard@tu-dresden.de    sim_control.{cc,hh}       -- Implements Gem5SimControl
5811832SChristian.Menard@tu-dresden.de    slave_transactor.{cc,hh}  -- Implements Gem5SlaveTransactor
5911832SChristian.Menard@tu-dresden.de    master_transactor.{cc,hh} -- Implements Gem5MasterTransactor
6011832SChristian.Menard@tu-dresden.de
6111832SChristian.Menard@tu-dresden.de    example/common/cli_parser.{cc,hh}     -- Simple cli argument parser
6211832SChristian.Menard@tu-dresden.de    example/common/report_hanlder.{cc,hh} -- Custom SystemC report handler
6311832SChristian.Menard@tu-dresden.de
6411832SChristian.Menard@tu-dresden.de    example/slave_port/main.cc           -- demonstration of the slave port
6511832SChristian.Menard@tu-dresden.de    example/slave_port/sc_target.{cc,hh} -- an example TLM LT/AT memory module
6611832SChristian.Menard@tu-dresden.de    example/slave_port/tlm.py            -- simple gem5 configuration
6711832SChristian.Menard@tu-dresden.de    example/slave_port/tlm_elastic.py    -- gem5 configuration with an elastic
6811832SChristian.Menard@tu-dresden.de                                            trace replayer
6911832SChristian.Menard@tu-dresden.de    example/slave_port/tgen.cfg          -- elastic traceplayer configuration
7011832SChristian.Menard@tu-dresden.de
7111832SChristian.Menard@tu-dresden.de    example/master_port/main.cc          -- demonstration of the master port
7211832SChristian.Menard@tu-dresden.de    example/master_port/traffic_generator.{cc/hh}
7311832SChristian.Menard@tu-dresden.de                                         -- an example traffic generator module
7411832SChristian.Menard@tu-dresden.de    example/master_port/tlm.py           -- simple gem5 configuration
7510993Sjungma@eit.uni-kl.de
7610993Sjungma@eit.uni-kl.deOther Files will be used from utils/systemc example:
7710993Sjungma@eit.uni-kl.de
7810993Sjungma@eit.uni-kl.de    sc_logger.{cc,hh},
7910993Sjungma@eit.uni-kl.de    sc_module.{cc,hh},
8010993Sjungma@eit.uni-kl.de    sc_gem5_control.{cc,hh},
8110993Sjungma@eit.uni-kl.de    stats.{cc,hh}
8210993Sjungma@eit.uni-kl.de
8310993Sjungma@eit.uni-kl.de
8411832SChristian.Menard@tu-dresden.deIII. Build
8511832SChristian.Menard@tu-dresden.de==========
8610993Sjungma@eit.uni-kl.de
8710993Sjungma@eit.uni-kl.deFirst build a normal gem5 (cxx-config not needed, Python needed).
8810993Sjungma@eit.uni-kl.deSecond build gem5 as a library with cxx-config support and (optionally)
8910993Sjungma@eit.uni-kl.dewithout python.
9010993Sjungma@eit.uni-kl.de
9110993Sjungma@eit.uni-kl.de> cd ../..
9210993Sjungma@eit.uni-kl.de> scons build/ARM/gem5.opt
9311832SChristian.Menard@tu-dresden.de> scons --with-cxx-config --without-python --without-tcmalloc \
9411832SChristian.Menard@tu-dresden.de>       build/ARM/libgem5_opt.so
9511099Sabdul.mutaal@gmail.com> cd util/tlm
9610993Sjungma@eit.uni-kl.de
9711791Sjungma@eit.uni-kl.deNote: For MAC / OSX this command should be used:
9811832SChristian.Menard@tu-dresden.de> scons --with-cxx-config --without-python --without-tcmalloc \
9911832SChristian.Menard@tu-dresden.de>       build/ARM/libgem5_opt.dylib
10011791Sjungma@eit.uni-kl.de
10110993Sjungma@eit.uni-kl.deSet a proper LD_LIBRARY_PATH e.g. for bash:
10210993Sjungma@eit.uni-kl.de> export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/gem5/build/ARM/"
10310993Sjungma@eit.uni-kl.de
10411791Sjungma@eit.uni-kl.deor for MAC / OSX:
10511791Sjungma@eit.uni-kl.de> export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/path/to/gem5/build/ARM/"
10611791Sjungma@eit.uni-kl.de
10711832SChristian.Menard@tu-dresden.deThe build system finds your SystemC installation using pkg-config. Make sure
10811832SChristian.Menard@tu-dresden.dethat pkg-config is installed and your systemc.pc is within your
10911832SChristian.Menard@tu-dresden.dePKG_CONFIG_PATH. You can add SystemC to the PKG_CONFIG_PATH using the following
11011832SChristian.Menard@tu-dresden.decommand:
11111832SChristian.Menard@tu-dresden.de> export PKG_CONFIG_PATH="/path/to/systemc/lib-<arch>/pkgconfig/:$PKG_CONFIG_PATH"
11211791Sjungma@eit.uni-kl.de
11311832SChristian.Menard@tu-dresden.deTo build one of the examples:
11411791Sjungma@eit.uni-kl.de
11511832SChristian.Menard@tu-dresden.de> cd examples/{master,slave}_port
11611832SChristian.Menard@tu-dresden.de> scons
11711832SChristian.Menard@tu-dresden.de> cd ../../
11811791Sjungma@eit.uni-kl.de
11910993Sjungma@eit.uni-kl.de
12011832SChristian.Menard@tu-dresden.deIV. Simple Examples
12111832SChristian.Menard@tu-dresden.de===================
12210993Sjungma@eit.uni-kl.de
12311832SChristian.Menard@tu-dresden.de> cd examples/{master,slave}_port
12410993Sjungma@eit.uni-kl.de
12511832SChristian.Menard@tu-dresden.deIn order to run our example simulation, we first need to create a config.ini
12611832SChristian.Menard@tu-dresden.dethat represents the gem5 configuration. We do so by starting gem5 with the
12711832SChristian.Menard@tu-dresden.dedesired python configuration script.
12810993Sjungma@eit.uni-kl.de
12911832SChristian.Menard@tu-dresden.de> ../../../../build/ARM/gem5.opt ./tlm.py
13011832SChristian.Menard@tu-dresden.de
13111832SChristian.Menard@tu-dresden.deThe message "fatal: Can't find port handler type 'tlm_{master,slave}'" is okay.
13210993Sjungma@eit.uni-kl.deThe configuration will be stored in the m5out/ directory
13310993Sjungma@eit.uni-kl.de
13411832SChristian.Menard@tu-dresden.deThe build step creates a binary gem5.opt.sc in the example directory.  It can
13511832SChristian.Menard@tu-dresden.denow be used to load in the generated configuration file from the previous
13610993Sjungma@eit.uni-kl.denormal gem5 run.
13710993Sjungma@eit.uni-kl.de
13810993Sjungma@eit.uni-kl.deTry:
13910993Sjungma@eit.uni-kl.de
14010993Sjungma@eit.uni-kl.de> ./gem5.opt.sc m5out/config.ini -e 1000000
14110993Sjungma@eit.uni-kl.de
14210993Sjungma@eit.uni-kl.deIt should run a simulation for 1us.
14310993Sjungma@eit.uni-kl.de
14411832SChristian.Menard@tu-dresden.deTo see more information what happens inside the TLM modules use the -v flag:
14510993Sjungma@eit.uni-kl.de
14611832SChristian.Menard@tu-dresden.de> ./gem5.opt.sc m5out/config.ini -e 1000000 -v
14710993Sjungma@eit.uni-kl.de
14810993Sjungma@eit.uni-kl.deTo see more information about the port coupling use:
14910993Sjungma@eit.uni-kl.de
15010993Sjungma@eit.uni-kl.de> ./gem5.opt.sc m5out/config.ini -e 1000000 -d ExternalPort
15110993Sjungma@eit.uni-kl.de
15211832SChristian.Menard@tu-dresden.de
15311832SChristian.Menard@tu-dresden.deV. Full System Setup
15410993Sjungma@eit.uni-kl.de=====================
15510993Sjungma@eit.uni-kl.de
15611832SChristian.Menard@tu-dresden.deApart from the simple examples, there is a full system example that uses
15711832SChristian.Menard@tu-dresden.dethe gem5-to-TLM bridge.
15811832SChristian.Menard@tu-dresden.de
15911832SChristian.Menard@tu-dresden.de>cd examples/slave_port
16011832SChristian.Menard@tu-dresden.de
16111832SChristian.Menard@tu-dresden.deBuild gem5 as described in Section III. Then, make a config file for the
16210993Sjungma@eit.uni-kl.deC++-configured gem5 using normal gem5
16310993Sjungma@eit.uni-kl.de
16411832SChristian.Menard@tu-dresden.de> ../../../../build/ARM/gem5.opt ../../../../configs/example/fs.py   \
16511832SChristian.Menard@tu-dresden.de  --tlm-memory=transactor --cpu-type=timing --num-cpu=1              \
16611832SChristian.Menard@tu-dresden.de  --mem-type=SimpleMemory --mem-size=512MB --mem-channels=1 --caches \
16711832SChristian.Menard@tu-dresden.de  --l2cache --machine-type=VExpress_EMM                              \
16811832SChristian.Menard@tu-dresden.de  --dtb-filename=vexpress.aarch32.ll_20131205.0-gem5.1cpu.dtb        \
16911832SChristian.Menard@tu-dresden.de  --kernel=vmlinux.aarch32.ll_20131205.0-gem5                        \
17010993Sjungma@eit.uni-kl.de  --disk-image=linux-aarch32-ael.img
17110993Sjungma@eit.uni-kl.de
17211832SChristian.Menard@tu-dresden.deThe message "fatal: Can't find port handler type 'tlm_slave'" is okay.
17310993Sjungma@eit.uni-kl.deThe configuration will be stored in the m5out/ directory
17410993Sjungma@eit.uni-kl.de
17510993Sjungma@eit.uni-kl.deThe binary 'gem5.opt.sc' can now be used to load in the generated config
17610993Sjungma@eit.uni-kl.defile from the previous normal gem5 run.
17710993Sjungma@eit.uni-kl.de
17810993Sjungma@eit.uni-kl.deTry:
17910993Sjungma@eit.uni-kl.de
18010993Sjungma@eit.uni-kl.de> ./gem5.opt.sc m5out/config.ini -o 2147483648
18110993Sjungma@eit.uni-kl.de
18210993Sjungma@eit.uni-kl.deThe parameter -o specifies the begining of the memory region (0x80000000).
18310993Sjungma@eit.uni-kl.deThe system should boot now.
18410993Sjungma@eit.uni-kl.de
18511832SChristian.Menard@tu-dresden.deFor convenience a run_gem5.sh file holds all those commands
18611554Sjungma@eit.uni-kl.de
18711554Sjungma@eit.uni-kl.de
18811832SChristian.Menard@tu-dresden.deVI. Elastic Trace Setup
18911554Sjungma@eit.uni-kl.de========================
19011554Sjungma@eit.uni-kl.de
19111554Sjungma@eit.uni-kl.deElastic traces can also be replayed into the SystemC world.
19211554Sjungma@eit.uni-kl.deFor more information on elastic traces please refer to:
19311554Sjungma@eit.uni-kl.de
19411554Sjungma@eit.uni-kl.de - http://www.gem5.org/TraceCPU
19511554Sjungma@eit.uni-kl.de
19611554Sjungma@eit.uni-kl.de - Exploring System Performance using Elastic Traces:
19711554Sjungma@eit.uni-kl.de   Fast, Accurate and Portable
19811554Sjungma@eit.uni-kl.de   R. Jagtap, S. Diestelhorst, A. Hansson, M. Jung, N. Wehn.
19911554Sjungma@eit.uni-kl.de   IEEE International Conference on Embedded Computer Systems Architectures
20011554Sjungma@eit.uni-kl.de   Modeling and Simulation (SAMOS), July, 2016, Samos Island, Greece.
20111554Sjungma@eit.uni-kl.de
20211832SChristian.Menard@tu-dresden.deSimilar IV. the simulation can be set up with this command:
20311554Sjungma@eit.uni-kl.de
20411832SChristian.Menard@tu-dresden.de> ../../../../build/ARM/gem5.opt ./tlm_elastic.py
20511554Sjungma@eit.uni-kl.de
20611554Sjungma@eit.uni-kl.deThen:
20711554Sjungma@eit.uni-kl.de
20811554Sjungma@eit.uni-kl.de> ./gem5.opt.sc m5out/config.ini
20911832SChristian.Menard@tu-dresden.de
21011832SChristian.Menard@tu-dresden.de
21111832SChristian.Menard@tu-dresden.deVII. Knwon issues
21211832SChristian.Menard@tu-dresden.de=================
21311832SChristian.Menard@tu-dresden.de
21411832SChristian.Menard@tu-dresden.de* For some toolchains, compiling libgem5 with tcmalloc leads to errors
21511832SChristian.Menard@tu-dresden.de  ('tcmalloc Attempt to free invalid pointer xxx') when linking libgem5 into a
21611832SChristian.Menard@tu-dresden.de  SystemC application.
21711832SChristian.Menard@tu-dresden.de* When SystemC was build with --enable-pthreads, SystemC applications linked
218