From 78ae8764a9d876d377f3e35de7e412f154402580 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 3 Nov 2004 11:47:55 -0500 Subject: add a new phase to the simulator. Basically the simulator now goes through the following phases. 1) Construct all param contexts 2) Call the checkParams() on each context 3) Build the configuration hierarchy 4) Construct all SimObjects 5) Initialize all SimObjects by calling init() on each one 6) Unserialize the checkpoint 7) Register all statisitcs 8) Check validity of all statistics (after that, no new stats) 9) Reset all stats. 10) Call SimStartup() which calls startup() on all SimObjects, ParamContexts, and any other object deriving from StartupCallback SConscript: no more SimInit() we have SimStartup() now sim/param.hh: Make all params have a startup callback. sim/sim_events.cc: the init callbacks no longer exist. We can simplify code by using startup(). sim/sim_object.hh: Make all SimObjects derive from StartupCallback --HG-- extra : convert_revision : ab81e259eb5510cc597f7bacb2bfb619fb4cc15f --- sim/main.cc | 7 ++++--- sim/param.hh | 3 ++- sim/sim_events.cc | 26 +++++--------------------- sim/sim_object.hh | 6 ++++-- sim/startup.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ sim/startup.hh | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 27 deletions(-) create mode 100644 sim/startup.cc create mode 100644 sim/startup.hh (limited to 'sim') diff --git a/sim/main.cc b/sim/main.cc index 46738a4c7..e8ac58786 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -51,7 +51,6 @@ #include "sim/host.hh" #include "sim/sim_events.hh" #include "sim/sim_exit.hh" -#include "sim/sim_init.hh" #include "sim/sim_object.hh" #include "sim/stat_control.hh" #include "sim/stats.hh" @@ -350,6 +349,9 @@ main(int argc, char **argv) configHierarchy.build(); configHierarchy.createSimObjects(); + // Do a second pass to finish initializing the sim objects + SimObject::initAll(); + // Restore checkpointed state, if any. configHierarchy.unserializeSimObjects(); @@ -382,9 +384,8 @@ main(int argc, char **argv) exit(1); } - SimInit(); warn("Entering event queue. Starting simulation...\n"); - + SimStartup(); while (!mainEventQueue.empty()) { assert(curTick <= mainEventQueue.nextTick() && "event scheduled in the past"); diff --git a/sim/param.hh b/sim/param.hh index 6706820c2..ac57afa31 100644 --- a/sim/param.hh +++ b/sim/param.hh @@ -34,6 +34,7 @@ #include #include "sim/configfile.hh" +#include "sim/startup.hh" // forward decls class BaseParam; @@ -44,7 +45,7 @@ class SimObject; // SimObjectBuilder (which derives from ParamContext), but abstracted // here to support more global simulator control parameters as well. // -class ParamContext +class ParamContext : protected StartupCallback { private: diff --git a/sim/sim_events.cc b/sim/sim_events.cc index c454fdcf9..99c09f259 100644 --- a/sim/sim_events.cc +++ b/sim/sim_events.cc @@ -34,7 +34,7 @@ #include "sim/param.hh" #include "sim/sim_events.hh" #include "sim/sim_exit.hh" -#include "sim/sim_init.hh" +#include "sim/startup.hh" #include "sim/stats.hh" using namespace std; @@ -210,12 +210,11 @@ ProgressEvent::description() // Parameter space for execution address tracing options. Derive // from ParamContext so we can override checkParams() function. -class ProgressParamContext : public ParamContext +struct ProgressParamContext : public ParamContext { - public: ProgressParamContext(const string &_iniSection) : ParamContext(_iniSection) {} - void checkParams(); + void startup(); }; ProgressParamContext progessMessageParams("progress"); @@ -223,24 +222,9 @@ ProgressParamContext progessMessageParams("progress"); Param progress_interval(&progessMessageParams, "cycle", "cycle interval for progress messages"); -namespace { - struct SetupProgress : public Callback - { - Tick interval; - SetupProgress(Tick tick) : interval(tick) {} - - virtual void process() - { - new ProgressEvent(&mainEventQueue, interval); - delete this; - } - }; -} - -/* check execute options */ void -ProgressParamContext::checkParams() +ProgressParamContext::startup() { if (progress_interval.isValid()) - registerInitCallback(new SetupProgress(progress_interval)); + new ProgressEvent(&mainEventQueue, progress_interval); } diff --git a/sim/sim_object.hh b/sim/sim_object.hh index dfd70f8ec..f4b316ebb 100644 --- a/sim/sim_object.hh +++ b/sim/sim_object.hh @@ -39,13 +39,14 @@ #include #include "sim/serialize.hh" +#include "sim/startup.hh" /* * Abstract superclass for simulation objects. Represents things that * correspond to physical components and can be specified via the * config file (CPUs, caches, etc.). */ -class SimObject : public Serializable +class SimObject : public Serializable, protected StartupCallback { protected: std::string objName; @@ -65,7 +66,8 @@ class SimObject : public Serializable virtual const std::string name() const { return objName; } - // initialization pass of all objects. Gets invoked by SimInit() + // initialization pass of all objects. + // Gets invoked after construction, before unserialize. virtual void init(); static void initAll(); diff --git a/sim/startup.cc b/sim/startup.cc new file mode 100644 index 000000000..ebb4c0bc0 --- /dev/null +++ b/sim/startup.cc @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004 The Regents of The University of Michigan + * All rights reserved. + * + * 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. + */ + +#include + +#include "base/misc.hh" +#include "sim/startup.hh" +#include "sim/debug.hh" + +typedef std::list startupq_t; +startupq_t &startupq() { static startupq_t queue; return queue; } +StartupCallback::StartupCallback() { startupq().push_back(this); } +StartupCallback::~StartupCallback() { startupq().remove(this); } +void StartupCallback::startup() { } + +void +SimStartup() +{ + startupq_t::iterator i = startupq().begin(); + startupq_t::iterator end = startupq().end(); + + while (i != end) { + (*i)->startup(); + ++i; + } +} diff --git a/sim/startup.hh b/sim/startup.hh new file mode 100644 index 000000000..e6c03a500 --- /dev/null +++ b/sim/startup.hh @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2004 The Regents of The University of Michigan + * All rights reserved. + * + * 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. + */ + +#ifndef __SIM_STARTUP_HH__ +#define __SIM_STARTUP_HH__ + +struct StartupCallback +{ + StartupCallback(); + virtual ~StartupCallback(); + virtual void startup(); +}; + +void SimStartup(); + +#endif // __SIM_STARTUP_HH__ -- cgit v1.2.3