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
This commit is contained in:
parent
64a47b8ec1
commit
78ae8764a9
7 changed files with 108 additions and 28 deletions
|
@ -187,8 +187,8 @@ base_sources = Split('''
|
||||||
sim/serialize.cc
|
sim/serialize.cc
|
||||||
sim/sim_events.cc
|
sim/sim_events.cc
|
||||||
sim/sim_exit.cc
|
sim/sim_exit.cc
|
||||||
sim/sim_init.cc
|
|
||||||
sim/sim_object.cc
|
sim/sim_object.cc
|
||||||
|
sim/startup.cc
|
||||||
sim/stat_context.cc
|
sim/stat_context.cc
|
||||||
sim/stat_control.cc
|
sim/stat_control.cc
|
||||||
sim/trace_context.cc
|
sim/trace_context.cc
|
||||||
|
|
|
@ -51,7 +51,6 @@
|
||||||
#include "sim/host.hh"
|
#include "sim/host.hh"
|
||||||
#include "sim/sim_events.hh"
|
#include "sim/sim_events.hh"
|
||||||
#include "sim/sim_exit.hh"
|
#include "sim/sim_exit.hh"
|
||||||
#include "sim/sim_init.hh"
|
|
||||||
#include "sim/sim_object.hh"
|
#include "sim/sim_object.hh"
|
||||||
#include "sim/stat_control.hh"
|
#include "sim/stat_control.hh"
|
||||||
#include "sim/stats.hh"
|
#include "sim/stats.hh"
|
||||||
|
@ -350,6 +349,9 @@ main(int argc, char **argv)
|
||||||
configHierarchy.build();
|
configHierarchy.build();
|
||||||
configHierarchy.createSimObjects();
|
configHierarchy.createSimObjects();
|
||||||
|
|
||||||
|
// Do a second pass to finish initializing the sim objects
|
||||||
|
SimObject::initAll();
|
||||||
|
|
||||||
// Restore checkpointed state, if any.
|
// Restore checkpointed state, if any.
|
||||||
configHierarchy.unserializeSimObjects();
|
configHierarchy.unserializeSimObjects();
|
||||||
|
|
||||||
|
@ -382,9 +384,8 @@ main(int argc, char **argv)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SimInit();
|
|
||||||
warn("Entering event queue. Starting simulation...\n");
|
warn("Entering event queue. Starting simulation...\n");
|
||||||
|
SimStartup();
|
||||||
while (!mainEventQueue.empty()) {
|
while (!mainEventQueue.empty()) {
|
||||||
assert(curTick <= mainEventQueue.nextTick() &&
|
assert(curTick <= mainEventQueue.nextTick() &&
|
||||||
"event scheduled in the past");
|
"event scheduled in the past");
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "sim/configfile.hh"
|
#include "sim/configfile.hh"
|
||||||
|
#include "sim/startup.hh"
|
||||||
|
|
||||||
// forward decls
|
// forward decls
|
||||||
class BaseParam;
|
class BaseParam;
|
||||||
|
@ -44,7 +45,7 @@ class SimObject;
|
||||||
// SimObjectBuilder (which derives from ParamContext), but abstracted
|
// SimObjectBuilder (which derives from ParamContext), but abstracted
|
||||||
// here to support more global simulator control parameters as well.
|
// here to support more global simulator control parameters as well.
|
||||||
//
|
//
|
||||||
class ParamContext
|
class ParamContext : protected StartupCallback
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include "sim/param.hh"
|
#include "sim/param.hh"
|
||||||
#include "sim/sim_events.hh"
|
#include "sim/sim_events.hh"
|
||||||
#include "sim/sim_exit.hh"
|
#include "sim/sim_exit.hh"
|
||||||
#include "sim/sim_init.hh"
|
#include "sim/startup.hh"
|
||||||
#include "sim/stats.hh"
|
#include "sim/stats.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -210,12 +210,11 @@ ProgressEvent::description()
|
||||||
|
|
||||||
// Parameter space for execution address tracing options. Derive
|
// Parameter space for execution address tracing options. Derive
|
||||||
// from ParamContext so we can override checkParams() function.
|
// from ParamContext so we can override checkParams() function.
|
||||||
class ProgressParamContext : public ParamContext
|
struct ProgressParamContext : public ParamContext
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
ProgressParamContext(const string &_iniSection)
|
ProgressParamContext(const string &_iniSection)
|
||||||
: ParamContext(_iniSection) {}
|
: ParamContext(_iniSection) {}
|
||||||
void checkParams();
|
void startup();
|
||||||
};
|
};
|
||||||
|
|
||||||
ProgressParamContext progessMessageParams("progress");
|
ProgressParamContext progessMessageParams("progress");
|
||||||
|
@ -223,24 +222,9 @@ ProgressParamContext progessMessageParams("progress");
|
||||||
Param<Tick> progress_interval(&progessMessageParams, "cycle",
|
Param<Tick> progress_interval(&progessMessageParams, "cycle",
|
||||||
"cycle interval for progress messages");
|
"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
|
void
|
||||||
ProgressParamContext::checkParams()
|
ProgressParamContext::startup()
|
||||||
{
|
{
|
||||||
if (progress_interval.isValid())
|
if (progress_interval.isValid())
|
||||||
registerInitCallback(new SetupProgress(progress_interval));
|
new ProgressEvent(&mainEventQueue, progress_interval);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,14 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "sim/serialize.hh"
|
#include "sim/serialize.hh"
|
||||||
|
#include "sim/startup.hh"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Abstract superclass for simulation objects. Represents things that
|
* Abstract superclass for simulation objects. Represents things that
|
||||||
* correspond to physical components and can be specified via the
|
* correspond to physical components and can be specified via the
|
||||||
* config file (CPUs, caches, etc.).
|
* config file (CPUs, caches, etc.).
|
||||||
*/
|
*/
|
||||||
class SimObject : public Serializable
|
class SimObject : public Serializable, protected StartupCallback
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string objName;
|
std::string objName;
|
||||||
|
@ -65,7 +66,8 @@ class SimObject : public Serializable
|
||||||
|
|
||||||
virtual const std::string name() const { return objName; }
|
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();
|
virtual void init();
|
||||||
static void initAll();
|
static void initAll();
|
||||||
|
|
||||||
|
|
51
sim/startup.cc
Normal file
51
sim/startup.cc
Normal file
|
@ -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 <list>
|
||||||
|
|
||||||
|
#include "base/misc.hh"
|
||||||
|
#include "sim/startup.hh"
|
||||||
|
#include "sim/debug.hh"
|
||||||
|
|
||||||
|
typedef std::list<StartupCallback *> 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;
|
||||||
|
}
|
||||||
|
}
|
41
sim/startup.hh
Normal file
41
sim/startup.hh
Normal file
|
@ -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__
|
Loading…
Reference in a new issue