From c71dfc17a7f5601de06085b6c2fe5efd9e3ea11f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 10 Oct 2018 17:28:09 -0700 Subject: util: Move the existing systemc example into a subdirectory. This example is for how to embed gem5 within systemc and make it use the systemc event queue. This used to be the only method of using gem5 and systemc together, but now that there are other options, it's ambiguous to have it as the only thing in the util/systemc directory. This change moves it into a gem5_within_systemc subdirectory which clearly shows what type of integration that example corresponds with. Change-Id: I426d68ccb618397d820bef492cbb1ff8ef4a979b Reviewed-on: https://gem5-review.googlesource.com/c/13375 Reviewed-by: Gabe Black Maintainer: Gabe Black --- util/systemc/Makefile | 70 ---- util/systemc/README | 82 ---- util/systemc/gem5_within_systemc/Makefile | 70 ++++ util/systemc/gem5_within_systemc/README | 83 ++++ util/systemc/gem5_within_systemc/main.cc | 446 +++++++++++++++++++++ .../systemc/gem5_within_systemc/sc_gem5_control.cc | 309 ++++++++++++++ .../systemc/gem5_within_systemc/sc_gem5_control.hh | 168 ++++++++ util/systemc/gem5_within_systemc/sc_logger.cc | 152 +++++++ util/systemc/gem5_within_systemc/sc_logger.hh | 80 ++++ util/systemc/gem5_within_systemc/sc_module.cc | 300 ++++++++++++++ util/systemc/gem5_within_systemc/sc_module.hh | 165 ++++++++ util/systemc/gem5_within_systemc/stats.cc | 159 ++++++++ util/systemc/gem5_within_systemc/stats.hh | 65 +++ util/systemc/main.cc | 446 --------------------- util/systemc/sc_gem5_control.cc | 309 -------------- util/systemc/sc_gem5_control.hh | 168 -------- util/systemc/sc_logger.cc | 152 ------- util/systemc/sc_logger.hh | 80 ---- util/systemc/sc_module.cc | 300 -------------- util/systemc/sc_module.hh | 165 -------- util/systemc/stats.cc | 159 -------- util/systemc/stats.hh | 65 --- 22 files changed, 1997 insertions(+), 1996 deletions(-) delete mode 100644 util/systemc/Makefile delete mode 100644 util/systemc/README create mode 100644 util/systemc/gem5_within_systemc/Makefile create mode 100644 util/systemc/gem5_within_systemc/README create mode 100644 util/systemc/gem5_within_systemc/main.cc create mode 100644 util/systemc/gem5_within_systemc/sc_gem5_control.cc create mode 100644 util/systemc/gem5_within_systemc/sc_gem5_control.hh create mode 100644 util/systemc/gem5_within_systemc/sc_logger.cc create mode 100644 util/systemc/gem5_within_systemc/sc_logger.hh create mode 100644 util/systemc/gem5_within_systemc/sc_module.cc create mode 100644 util/systemc/gem5_within_systemc/sc_module.hh create mode 100644 util/systemc/gem5_within_systemc/stats.cc create mode 100644 util/systemc/gem5_within_systemc/stats.hh delete mode 100644 util/systemc/main.cc delete mode 100644 util/systemc/sc_gem5_control.cc delete mode 100644 util/systemc/sc_gem5_control.hh delete mode 100644 util/systemc/sc_logger.cc delete mode 100644 util/systemc/sc_logger.hh delete mode 100644 util/systemc/sc_module.cc delete mode 100644 util/systemc/sc_module.hh delete mode 100644 util/systemc/stats.cc delete mode 100644 util/systemc/stats.hh (limited to 'util') diff --git a/util/systemc/Makefile b/util/systemc/Makefile deleted file mode 100644 index 24d1e52f2..000000000 --- a/util/systemc/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) 2012-2014 ARM Limited -# All rights reserved -# -# The license below extends only to copyright in the software and shall -# not be construed as granting a license to any other intellectual -# property including but not limited to intellectual property relating -# to a hardware implementation of the functionality of the software -# licensed hereunder. You may use the software subject to the license -# terms below provided that you ensure that this notice is replicated -# unmodified and in its entirety in all distributions of the software, -# modified or unmodified, in source code or in binary form. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Authors: Andrew Bardsley - -ARCH = ARM -VARIANT = opt - -SYSTEMC_INC = ./systemc/include -SYSTEMC_LIB = ./systemc/lib-linux64 - -CXXFLAGS = -I../../build/$(ARCH) -L../../build/$(ARCH) -CXXFLAGS += -I$(SYSTEMC_INC) -L$(SYSTEMC_LIB) -CXXFLAGS += -std=c++0x -CXXFLAGS += -g -LIBS = -lgem5_$(VARIANT) -lsystemc - -ALL = gem5.$(VARIANT).sc - -all: $(ALL) - -.cc.o: - $(CXX) $(CXXFLAGS) -c -o $@ $< - -sc_gem5_control.o: sc_gem5_control.cc sc_gem5_control.hh -sc_logger.o: sc_logger.cc sc_logger.hh -sc_module.o: sc_module.cc sc_module.hh -stats.o: stats.cc stats.hh -main.o: main.cc sc_logger.hh sc_module.hh stats.hh - -gem5.$(VARIANT).sc: main.o stats.o \ - sc_gem5_control.o sc_logger.o sc_module.o - $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) - -clean: - $(RM) $(ALL) - $(RM) *.o - $(RM) -r m5out diff --git a/util/systemc/README b/util/systemc/README deleted file mode 100644 index b05c81058..000000000 --- a/util/systemc/README +++ /dev/null @@ -1,82 +0,0 @@ -This directory contains a demo of C++ configuration of gem5. The intention -is to provide a mechanism to allow pre-generated config.ini files generated -by Python-based gem5 to be reloaded in library-base versions of gem5 -embedded in other systems using C++ calls for simulation control. - -This directory contain a demo of hosting a C++ configured version of gem5 -onto SystemC's event loop. The hosting is achieved by replacing 'simulate' -with a SystemC object which implements an event loop using SystemC scheduler -mechanisms. - -The sc_... files here should probably be hosted in a diferent directory and -buildable as a library. - -Files: - - main.cc -- demonstration top level - sc_logger.{cc,hh} -- rehosting of DPRINTF onto SC_REPORT - sc_module.{cc,hh} -- SystemC simulation loop base class - sc_gem5_control.{cc,hh} -- Alternative extra wrapping to allow gem5 - Systems to be instantiated as single - sc_module objects. - stats.{cc,hh} -- Stats dumping (copied from util/cxx_config) - -Read main.cc for more details of the implementation and sc_... files for - -To build: - -First build gem5 as a library with cxx-config support and (optionally) -without python. Also build a normal gem5 (cxx-config not needed, Python -needed): - -> cd ../.. -> scons build/ARM/gem5.opt -> scons --with-cxx-config --without-python build/ARM/libgem5_opt.so -> cd util/systemc - -Note: For MAC / OSX this command should be used: -> scons --with-cxx-config --without-python build/ARM/libgem5_opt.dylib - -Set a proper LD_LIBRARY_PATH e.g. for bash: -> export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/gem5/build/ARM/" - -or for MAC / OSX: -> export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/path/to/gem5/build/ARM/" - - -Then edit the Makefile to set the paths for SystemC, e.g: - - Linux: - SYSTEMC_INC = /opt/systemc/include - SYSTEMC_LIB = /opt/systemc/lib-linux64 - - MAC / OSX: - SYSTEMC_INC = /opt/systemc/include - SYSTEMC_LIB = /opt/systemc/lib-macosx64 - -Then run make: - -> make - -Make a config file for the C++-configured gem5 using normal gem5 - -> ../../build/ARM/gem5.opt ../../configs/example/se.py -c \ -> ../../tests/test-progs/hello/bin/arm/linux/hello - -The binary 'gem5.opt.cxx' can now be used to load in the generated config -file from the previous normal gem5 run. - -Try: - -> ./gem5.opt.cxx m5out/config.ini - -This should print: - -> Hello world! - -The .ini file can also be read by the Python .ini file reader example: - -> ../../build/ARM/gem5.opt ../../configs/example/read_ini.py m5out/config.ini - -If you are interested in SystemC Transaction Level Modeling (TLM2) please have -a look into /util/tlm. diff --git a/util/systemc/gem5_within_systemc/Makefile b/util/systemc/gem5_within_systemc/Makefile new file mode 100644 index 000000000..100402c15 --- /dev/null +++ b/util/systemc/gem5_within_systemc/Makefile @@ -0,0 +1,70 @@ +# Copyright (c) 2012-2014 ARM Limited +# All rights reserved +# +# The license below extends only to copyright in the software and shall +# not be construed as granting a license to any other intellectual +# property including but not limited to intellectual property relating +# to a hardware implementation of the functionality of the software +# licensed hereunder. You may use the software subject to the license +# terms below provided that you ensure that this notice is replicated +# unmodified and in its entirety in all distributions of the software, +# modified or unmodified, in source code or in binary form. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Authors: Andrew Bardsley + +ARCH = ARM +VARIANT = opt + +SYSTEMC_INC = ./systemc/include +SYSTEMC_LIB = ./systemc/lib-linux64 + +CXXFLAGS = -I../../../build/$(ARCH) -L../../../build/$(ARCH) +CXXFLAGS += -I$(SYSTEMC_INC) -L$(SYSTEMC_LIB) +CXXFLAGS += -std=c++0x +CXXFLAGS += -g +LIBS = -lgem5_$(VARIANT) -lsystemc + +ALL = gem5.$(VARIANT).sc + +all: $(ALL) + +.cc.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +sc_gem5_control.o: sc_gem5_control.cc sc_gem5_control.hh +sc_logger.o: sc_logger.cc sc_logger.hh +sc_module.o: sc_module.cc sc_module.hh +stats.o: stats.cc stats.hh +main.o: main.cc sc_logger.hh sc_module.hh stats.hh + +gem5.$(VARIANT).sc: main.o stats.o \ + sc_gem5_control.o sc_logger.o sc_module.o + $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) + +clean: + $(RM) $(ALL) + $(RM) *.o + $(RM) -r m5out diff --git a/util/systemc/gem5_within_systemc/README b/util/systemc/gem5_within_systemc/README new file mode 100644 index 000000000..9ee1103a8 --- /dev/null +++ b/util/systemc/gem5_within_systemc/README @@ -0,0 +1,83 @@ +This directory contains a demo of C++ configuration of gem5. The intention +is to provide a mechanism to allow pre-generated config.ini files generated +by Python-based gem5 to be reloaded in library-base versions of gem5 +embedded in other systems using C++ calls for simulation control. + +This directory contain a demo of hosting a C++ configured version of gem5 +onto SystemC's event loop. The hosting is achieved by replacing 'simulate' +with a SystemC object which implements an event loop using SystemC scheduler +mechanisms. + +The sc_... files here should probably be hosted in a diferent directory and +buildable as a library. + +Files: + + main.cc -- demonstration top level + sc_logger.{cc,hh} -- rehosting of DPRINTF onto SC_REPORT + sc_module.{cc,hh} -- SystemC simulation loop base class + sc_gem5_control.{cc,hh} -- Alternative extra wrapping to allow gem5 + Systems to be instantiated as single + sc_module objects. + stats.{cc,hh} -- Stats dumping (copied from util/cxx_config) + +Read main.cc for more details of the implementation and sc_... files for + +To build: + +First build gem5 as a library with cxx-config support and (optionally) +without python. Also build a normal gem5 (cxx-config not needed, Python +needed): + +> cd ../../.. +> scons build/ARM/gem5.opt +> scons --with-cxx-config --without-python build/ARM/libgem5_opt.so +> cd util/systemc + +Note: For MAC / OSX this command should be used: +> scons --with-cxx-config --without-python build/ARM/libgem5_opt.dylib + +Set a proper LD_LIBRARY_PATH e.g. for bash: +> export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/gem5/build/ARM/" + +or for MAC / OSX: +> export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/path/to/gem5/build/ARM/" + + +Then edit the Makefile to set the paths for SystemC, e.g: + + Linux: + SYSTEMC_INC = /opt/systemc/include + SYSTEMC_LIB = /opt/systemc/lib-linux64 + + MAC / OSX: + SYSTEMC_INC = /opt/systemc/include + SYSTEMC_LIB = /opt/systemc/lib-macosx64 + +Then run make: + +> make + +Make a config file for the C++-configured gem5 using normal gem5 + +> ../../../build/ARM/gem5.opt ../../../configs/example/se.py -c \ +> ../../../tests/test-progs/hello/bin/arm/linux/hello + +The binary 'gem5.opt.cxx' can now be used to load in the generated config +file from the previous normal gem5 run. + +Try: + +> ./gem5.opt.cxx m5out/config.ini + +This should print: + +> Hello world! + +The .ini file can also be read by the Python .ini file reader example: + +> ../../../build/ARM/gem5.opt ../../../configs/example/read_ini.py \ +> m5out/config.ini + +If you are interested in SystemC Transaction Level Modeling (TLM2) please have +a look into /util/tlm. diff --git a/util/systemc/gem5_within_systemc/main.cc b/util/systemc/gem5_within_systemc/main.cc new file mode 100644 index 000000000..9d88b63cb --- /dev/null +++ b/util/systemc/gem5_within_systemc/main.cc @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2014 ARM Limited + * All rights reserved + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Andrew Bardsley + * Abdul Mutaal Ahmad + */ + +/** + * @file + * + * Example top level file for SystemC integration with C++-only + * instantiation. + * + * Build with something like: + * + * scons --without-python build/ARM/libgem5_opt.so + * + * g++ -std=c++0x -Ibuild/ARM -Isrc -DTRACING_ON \ + * -o gem5cxx.opt -Lbuild/ARM -lgem5_opt \ + * src/sim/sc_main_cxx.cc src/sim/cxx_stats.cc \ + * src/sim/sc_module.cc src/sim/sc_logger.cc + */ + +#include +#include +#include +#include + +#include "base/statistics.hh" +#include "base/str.hh" +#include "base/trace.hh" +#include "cpu/base.hh" +#include "sc_logger.hh" +#include "sc_module.hh" +#include "sim/cxx_config_ini.hh" +#include "sim/cxx_manager.hh" +#include "sim/init_signals.hh" +#include "sim/serialize.hh" +#include "sim/simulate.hh" +#include "sim/stat_control.hh" +#include "sim/system.hh" +#include "stats.hh" + +// Defining global string variable decalred in stats.hh +std::string filename; + +void +usage(const std::string &prog_name) +{ + std::cerr << "Usage: " << prog_name << ( + " [