sim: Make the drain state a global typed enum
The drain state enum is currently a part of the Drainable interface. The same state machine will be used by the DrainManager to identify the global state of the simulator. Make the drain state a global typed enum to better cater for this usage scenario.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012 ARM Limited
|
||||
* Copyright (c) 2012, 2015 ARM Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* The license below extends only to copyright in the software and shall
|
||||
@@ -58,7 +58,7 @@ DrainManager::drainCycleDone()
|
||||
|
||||
|
||||
Drainable::Drainable()
|
||||
: _drainState(Running)
|
||||
: _drainState(DrainState::Running)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -69,5 +69,5 @@ Drainable::~Drainable()
|
||||
void
|
||||
Drainable::drainResume()
|
||||
{
|
||||
_drainState = Running;
|
||||
_drainState = DrainState::Running;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012 ARM Limited
|
||||
* Copyright (c) 2012, 2015 ARM Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* The license below extends only to copyright in the software and shall
|
||||
@@ -45,7 +45,33 @@
|
||||
|
||||
#include "base/flags.hh"
|
||||
|
||||
class Event;
|
||||
class Drainable;
|
||||
|
||||
#ifndef SWIG // SWIG doesn't support strongly typed enums
|
||||
/**
|
||||
* Object drain/handover states
|
||||
*
|
||||
* An object starts out in the Running state. When the simulator
|
||||
* prepares to take a snapshot or prepares a CPU for handover, it
|
||||
* calls the drain() method to transfer the object into the Draining
|
||||
* or Drained state. If any object enters the Draining state
|
||||
* (Drainable::drain() returning >0), simulation continues until it
|
||||
* all objects have entered the Drained state.
|
||||
*
|
||||
* Before resuming simulation, the simulator calls resume() to
|
||||
* transfer the object to the Running state.
|
||||
*
|
||||
* \note Even though the state of an object (visible to the rest of
|
||||
* the world through Drainable::getState()) could be used to determine
|
||||
* if all objects have entered the Drained state, the protocol is
|
||||
* actually a bit more elaborate. See Drainable::drain() for details.
|
||||
*/
|
||||
enum class DrainState {
|
||||
Running, /** Running normally */
|
||||
Draining, /** Draining buffers pending serialization/handover */
|
||||
Drained /** Buffers drained, ready for serialization/handover */
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This class coordinates draining of a System.
|
||||
@@ -141,30 +167,6 @@ class DrainManager
|
||||
class Drainable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Object drain/handover states
|
||||
*
|
||||
* An object starts out in the Running state. When the simulator
|
||||
* prepares to take a snapshot or prepares a CPU for handover, it
|
||||
* calls the drain() method to transfer the object into the
|
||||
* Draining or Drained state. If any object enters the Draining
|
||||
* state (drain() returning >0), simulation continues until it all
|
||||
* objects have entered the Drained state.
|
||||
*
|
||||
* Before resuming simulation, the simulator calls resume() to
|
||||
* transfer the object to the Running state.
|
||||
*
|
||||
* \note Even though the state of an object (visible to the rest
|
||||
* of the world through getState()) could be used to determine if
|
||||
* all objects have entered the Drained state, the protocol is
|
||||
* actually a bit more elaborate. See drain() for details.
|
||||
*/
|
||||
enum State {
|
||||
Running, /** Running normally */
|
||||
Draining, /** Draining buffers pending serialization/handover */
|
||||
Drained /** Buffers drained, ready for serialization/handover */
|
||||
};
|
||||
|
||||
Drainable();
|
||||
virtual ~Drainable();
|
||||
|
||||
@@ -225,15 +227,13 @@ class Drainable
|
||||
*/
|
||||
virtual void memInvalidate() {};
|
||||
|
||||
State getDrainState() const { return _drainState; }
|
||||
DrainState getDrainState() const { return _drainState; }
|
||||
|
||||
protected:
|
||||
void setDrainState(State new_state) { _drainState = new_state; }
|
||||
|
||||
void setDrainState(DrainState new_state) { _drainState = new_state; }
|
||||
|
||||
private:
|
||||
State _drainState;
|
||||
|
||||
DrainState _drainState;
|
||||
};
|
||||
|
||||
DrainManager *createDrainManager();
|
||||
|
||||
@@ -183,7 +183,7 @@ debugObjectBreak(const char *objs)
|
||||
unsigned int
|
||||
SimObject::drain(DrainManager *drain_manager)
|
||||
{
|
||||
setDrainState(Drained);
|
||||
setDrainState(DrainState::Drained);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ System::getMasterPort(const std::string &if_name, PortID idx)
|
||||
void
|
||||
System::setMemoryMode(Enums::MemoryMode mode)
|
||||
{
|
||||
assert(getDrainState() == Drainable::Drained);
|
||||
assert(getDrainState() == DrainState::Drained);
|
||||
memoryMode = mode;
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ System::isMemAddr(Addr addr) const
|
||||
unsigned int
|
||||
System::drain(DrainManager *dm)
|
||||
{
|
||||
setDrainState(Drainable::Drained);
|
||||
setDrainState(DrainState::Drained);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user