52 #include <sys/types.h>
66 #include "debug/Checkpoint.hh"
124 os << (
unsigned int)value;
154 os << (value ?
"true" :
"false");
203 if (param.size() > 0)
206 while (it != param.end()) {
218 typename set<T>::const_iterator it = param.begin();
221 if (param.size() > 0)
224 while (it != param.end()) {
239 fatal(
"Can't unserialize '%s:%s'\n", section, name);
251 warn(
"optional parameter %s:%s not present\n", section, name);
261 const T *param,
unsigned size)
266 for (
unsigned i = 1;
i <
size; ++
i) {
280 if (!cp.
find(section, name, str)) {
281 fatal(
"Can't unserialize '%s:%s'\n", section, name);
294 if (tokens.size() !=
size) {
295 fatal(
"Array size mismatch on %s:%s'\n", section, name);
305 string err(
"could not parse \"");
314 param[
i] = scalar_value;
324 if (!cp.
find(section, name, str)) {
325 fatal(
"Can't unserialize '%s:%s'\n", section, name);
338 param.resize(tokens.size());
347 string err(
"could not parse \"");
356 param[
i] = scalar_value;
366 if (!cp.
find(section, name, str)) {
367 fatal(
"Can't unserialize '%s:%s'\n", section, name);
377 string err(
"could not parse \"");
386 param.push_back(scalar_value);
396 if (!cp.
find(section, name, str)) {
397 fatal(
"Can't unserialize '%s:%s'\n", section, name);
407 string err(
"could not parse \"");
416 param.insert(scalar_value);
425 if (!cp.
findObj(section, name, param)) {
426 fatal(
"Can't unserialize '%s:%s'\n", section, name);
431 #define INSTANTIATE_PARAM_TEMPLATES(type) \
433 paramOut(CheckpointOut &os, const string &name, type const ¶m); \
435 paramIn(CheckpointIn &cp, const string &name, type & param); \
437 optParamIn(CheckpointIn &cp, const string &name, type & param, \
440 arrayParamOut(CheckpointOut &os, const string &name, \
441 type const *param, unsigned size); \
443 arrayParamIn(CheckpointIn &cp, const string &name, \
444 type *param, unsigned size); \
446 arrayParamOut(CheckpointOut &os, const string &name, \
447 const vector<type> ¶m); \
449 arrayParamIn(CheckpointIn &cp, const string &name, \
450 vector<type> ¶m); \
452 arrayParamOut(CheckpointOut &os, const string &name, \
453 const list<type> ¶m); \
455 arrayParamIn(CheckpointIn &cp, const string &name, \
489 : unserializedCurTick(0) {}
491 void serialize(CheckpointOut &cp)
const override;
514 paramIn(cp,
"curTick", unserializedCurTick);
518 if (!cp.
find(section,
"version_tags", str)) {
519 warn(
"**********************************************************\n");
520 warn(
"!!!! Checkpoint uses an old versioning scheme. !!!!\n");
521 warn(
"Run the checkpoint upgrader (util/cpt_upgrader.py) on your "
523 warn(
"**********************************************************\n");
527 std::set<std::string> cpt_tags;
532 if (cpt_tags.find(
t) == cpt_tags.end()) {
535 warn(
"*****************************************************\n");
536 warn(
"!!!! Checkpoint is missing the following version tags:\n");
543 warn(
"You might experience some issues when restoring and should run "
544 "the checkpoint upgrader (util/cpt_upgrader.py) on your "
546 warn(
"**********************************************************\n");
550 for (
const auto&
t : cpt_tags) {
551 if (version_tags.find(
t) == version_tags.end()) {
554 warn(
"*****************************************************\n");
555 warn(
"!!!! gem5 is missing the following version tags:\n");
562 warn(
"Running a checkpoint with incompatible version tags is not "
563 "supported. While it might work, you may experience incorrect "
564 "behavior or crashes.\n");
565 warn(
"**********************************************************\n");
595 if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
596 fatal(
"couldn't mkdir %s\n", dir);
599 ofstream outstream(cpt_file.c_str());
600 time_t
t = time(NULL);
601 if (!outstream.is_open())
602 fatal(
"Unable to open file %s for writing\n", cpt_file.c_str());
603 outstream <<
"## checkpoint generated: " << ctime(&t);
621 assert(!path.empty());
622 DPRINTF(Checkpoint,
"Popping: %s\n", path.top());
632 path.push(
csprintf(
"%s.%s", path.top(), obj_name));
634 DPRINTF(Checkpoint,
"ScopedCheckpointSection::pushName: %s\n", obj_name);
640 DPRINTF(Checkpoint,
"ScopedCheckpointSection::nameOut: %s\n",
654 assert(!path.empty());
668 currentDirectory = (name.find(
"%") != string::npos) ?
670 if (currentDirectory[currentDirectory.size() - 1] !=
'/')
671 currentDirectory +=
"/";
672 return currentDirectory;
678 return currentDirectory;
683 : db(new
IniFile), objNameResolver(resolver), cptDir(setDir(cpt_dir))
686 if (!
db->
load(filename)) {
687 fatal(
"Can't load checkpoint file '%s'\n", filename);
705 return db->
find(section, entry, value);
715 if (!
db->
find(section, entry, path))
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static void unserializeGlobals(CheckpointIn &cp)
bool to_bool(const std::string &value, bool &retval)
Turn a string representation of a boolean into a boolean value.
void pushName(const char *name)
const std::string & name()
static std::stack< std::string > path
void arrayParamIn(CheckpointIn &cp, const string &name, T *param, unsigned size)
SimObjectResolver & objNameResolver
std::set< std::string > version_tags
The version tags for this build of the simulator, to be stored in the Globals section during serializ...
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
static std::string currentDirectory
static void serializeAll(CheckpointOut &cp)
Serialize all SimObjects in the system.
void paramIn(CheckpointIn &cp, const string &name, T ¶m)
bool optParamIn(CheckpointIn &cp, const string &name, T ¶m, bool warn)
void debug_serialize(const string &cpt_dir)
bool parseParam(const string &s, T &value)
vector< EventQueue * > mainEventQueue
Array for main event queues.
Globals globals
The one and only instance of the Globals class.
Container for serializing global variables (not associated with any serialized object).
Base class to wrap object resolving functionality.
#define INSTANTIATE_PARAM_TEMPLATES(type)
virtual SimObject * resolveSimObject(const std::string &name)=0
#define SERIALIZE_CONTAINER(member)
Tick curTick()
The current simulated tick.
std::string csprintf(const char *format, const Args &...args)
bool find(const std::string §ion, const std::string &entry, std::string &value)
bool entryExists(const std::string §ion, const std::string &entry) const
Determine whether the entry exists within named section exists in the .ini file.
uint64_t Tick
Tick count type.
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
bool find(const std::string §ion, const std::string &entry, std::string &value) const
Find value corresponding to given section and entry names.
bool load(std::istream &f)
Load parameter settings from given istream.
~ScopedCheckpointSection()
Declaration of IniFile object.
void nameOut(CheckpointOut &cp)
Basic support for object serialization.
void paramOut(CheckpointOut &os, const string &name, const T ¶m)
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::ostream CheckpointOut
uint32_t numMainEventQueues
Current number of allocated main event queues.
bool sectionExists(const std::string §ion)
void showParam(CheckpointOut &os, const T &value)
static const std::string & currentSection()
Get the fully-qualified name of the active section.
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
bool entryExists(const std::string §ion, const std::string &entry)
bool findObj(const std::string §ion, const std::string &entry, SimObject *&value)
void serialize(CheckpointOut &cp) const override
Internal gem5 representation of a Pixel.
void unserialize(CheckpointIn &cp) override
Scoped checkpoint section helper class.
bool to_number(const std::string &value, Pixel &retval)
bool sectionExists(const std::string §ion) const
Determine whether the named section exists in the .ini file.
Abstract superclass for simulation objects.
This class represents the contents of a ".ini" file.
static const char * baseFilename
void objParamIn(CheckpointIn &cp, const string &name, SimObject *¶m)
CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver)
static std::string setDir(const std::string &base_name)
static void serializeAll(const std::string &cpt_dir)
void arrayParamOut(CheckpointOut &os, const string &name, const vector< T > ¶m)