}
}
-void
-EventQueue::serialize(CheckpointOut &cp) const
-{
- std::list<Event *> eventPtrs;
-
- int numEvents = 0;
- Event *nextBin = head;
- while (nextBin) {
- Event *nextInBin = nextBin;
-
- while (nextInBin) {
- if (nextInBin->flags.isSet(Event::AutoSerialize)) {
- eventPtrs.push_back(nextInBin);
- paramOut(cp, csprintf("event%d", numEvents++),
- nextInBin->name());
- }
- nextInBin = nextInBin->nextInBin;
- }
-
- nextBin = nextBin->nextBin;
- }
-
- SERIALIZE_SCALAR(numEvents);
-
- for (Event *ev : eventPtrs)
- ev->serializeSection(cp, ev->name());
-}
-
-void
-EventQueue::unserialize(CheckpointIn &cp)
-{
- int numEvents;
- UNSERIALIZE_SCALAR(numEvents);
-
- std::string eventName;
- for (int i = 0; i < numEvents; i++) {
- // get the pointer value associated with the event
- paramIn(cp, csprintf("event%d", i), eventName);
-
- // create the event based on its pointer value
- Serializable *obj(Serializable::create(cp, eventName));
- Event *event(dynamic_cast<Event *>(obj));
- fatal_if(!event,
- "Event queue unserialized something that wasn't an event.\n");
-
- checkpointReschedule(event);
- }
-}
-
void
EventQueue::checkpointReschedule(Event *event)
{
static const FlagsType Squashed = 0x0001; // has been squashed
static const FlagsType Scheduled = 0x0002; // has been scheduled
static const FlagsType AutoDelete = 0x0004; // delete after dispatch
- static const FlagsType AutoSerialize = 0x0008; // must be serialized
+ /**
+ * This used to be AutoSerialize. This value can't be reused
+ * without changing the checkpoint version since the flag field
+ * gets serialized.
+ */
+ static const FlagsType Reserved0 = 0x0008;
static const FlagsType IsExitEvent = 0x0010; // special exit event
static const FlagsType IsMainQueue = 0x0020; // on main event queue
static const FlagsType Initialized = 0x7a40; // somewhat random bits
* otherwise they risk being scheduled in the past by
* handleAsyncInsertions().
*/
-class EventQueue : public Serializable
+class EventQueue
{
private:
std::string objName;
void unlock() { service_mutex.unlock(); }
/**@}*/
-#ifndef SWIG
- void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
- void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
-#endif
-
/**
* Reschedule an event after a checkpoint.
*
Globals::serialize(CheckpointOut &cp) const
{
paramOut(cp, "curTick", curTick());
- paramOut(cp, "numMainEventQueues", numMainEventQueues);
-
}
void
Globals::unserialize(CheckpointIn &cp)
{
paramIn(cp, "curTick", unserializedCurTick);
- paramIn(cp, "numMainEventQueues", numMainEventQueues);
}
Serializable::Serializable()
outstream << "## checkpoint generated: " << ctime(&t);
globals.serializeSection(outstream, "Globals");
- for (uint32_t i = 0; i < numMainEventQueues; ++i)
- mainEventQueue[i]->serializeSection(outstream, "MainEventQueue");
SimObject::serializeAll(outstream);
}
{
globals.unserializeSection(cp, "Globals");
- for (uint32_t i = 0; i < numMainEventQueues; ++i) {
+ for (uint32_t i = 0; i < numMainEventQueues; ++i)
mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
- mainEventQueue[i]->unserializeSection(cp, "MainEventQueue");
- }
}
Serializable::ScopedCheckpointSection::~ScopedCheckpointSection()
Serializable::serializeAll(cpt_dir);
}
-
-////////////////////////////////////////////////////////////////////////
-//
-// SerializableClass member definitions
-//
-////////////////////////////////////////////////////////////////////////
-
-// Map of class names to SerializableBuilder creation functions.
-// Need to make this a pointer so we can force initialization on the
-// first reference; otherwise, some SerializableClass constructors
-// may be invoked before the classMap constructor.
-map<string, SerializableClass::CreateFunc> *SerializableClass::classMap = 0;
-
-// SerializableClass constructor: add mapping to classMap
-SerializableClass::SerializableClass(const string &className,
- CreateFunc createFunc)
-{
- if (classMap == NULL)
- classMap = new map<string, SerializableClass::CreateFunc>();
-
- if ((*classMap)[className])
- fatal("Error: simulation object class %s redefined\n", className);
-
- // add className --> createFunc to class map
- (*classMap)[className] = createFunc;
-}
-
-//
-//
-Serializable *
-SerializableClass::createObject(CheckpointIn &cp, const string §ion)
-{
- string className;
-
- if (!cp.find(section, "type", className)) {
- fatal("Serializable::create: no 'type' entry in section '%s'.\n",
- section);
- }
-
- CreateFunc createFunc = (*classMap)[className];
-
- if (createFunc == NULL) {
- fatal("Serializable::create: no create function for class '%s'.\n",
- className);
- }
-
- Serializable *object = createFunc(cp, section);
-
- assert(object != NULL);
-
- return object;
-}
-
const std::string &
Serializable::currentSection()
{
return path.top();
}
-Serializable *
-Serializable::create(CheckpointIn &cp, const string §ion)
-{
- Serializable *object = SerializableClass::createObject(cp, section);
- object->unserializeSection(cp, section);
- return object;
-}
-
-
const char *CheckpointIn::baseFilename = "m5.cpt";
string CheckpointIn::currentDirectory;
/** Get the fully-qualified name of the active section */
static const std::string ¤tSection();
- static Serializable *create(CheckpointIn &cp, const std::string §ion);
-
static int ckptCount;
static int ckptMaxCount;
static int ckptPrevCount;
void debug_serialize(const std::string &cpt_dir);
-//
-// An instance of SerializableClass corresponds to a class derived from
-// Serializable. The SerializableClass instance serves to bind the string
-// name (found in the config file) to a function that creates an
-// instance of the appropriate derived class.
-//
-// This would be much cleaner in Smalltalk or Objective-C, where types
-// are first-class objects themselves.
-//
-class SerializableClass
-{
- public:
-
- // Type CreateFunc is a pointer to a function that creates a new
- // simulation object builder based on a .ini-file parameter
- // section (specified by the first string argument), a unique name
- // for the object (specified by the second string argument), and
- // an optional config hierarchy node (specified by the third
- // argument). A pointer to the new SerializableBuilder is returned.
- typedef Serializable *(*CreateFunc)(CheckpointIn &cp,
- const std::string §ion);
-
- static std::map<std::string,CreateFunc> *classMap;
-
- // Constructor. For example:
- //
- // SerializableClass baseCacheSerializableClass("BaseCacheSerializable",
- // newBaseCacheSerializableBuilder);
- //
- SerializableClass(const std::string &className, CreateFunc createFunc);
-
- // create Serializable given name of class and pointer to
- // configuration hierarchy node
- static Serializable *createObject(CheckpointIn &cp,
- const std::string §ion);
-};
-
-//
-// Macros to encapsulate the magic of declaring & defining
-// SerializableBuilder and SerializableClass objects
-//
-
-#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \
-SerializableClass the##OBJ_CLASS##Class(CLASS_NAME, \
- OBJ_CLASS::createForUnserialize);
-
class CheckpointIn
{