Modify handling of serialize:dir parameter to make it more useful.
Move global checkpoint-related functions and vars into Checkpoint class (as statics). arch/alpha/pseudo_inst.cc: dev/disk_image.cc: Move global checkpoint-related functions and vars into Checkpoint class (as statics). sim/serialize.cc: Move global checkpoint-related functions and vars into Checkpoint class (as statics). Checkpoint constructor now takes checkpoint directory name instead of file name. Make serialize:dir parameter actually set checkpoint directory name instead of directory in which checkpoint directory is created. If the value contains a '%', the curTick value is sprintf'd into the format to create the directory name. The default is backwards compatible with the old fixed name ("m5.%012d"). sim/serialize.hh: Move global checkpoint-related functions and vars into Checkpoint class (as statics). Checkpoint constructor now takes checkpoint directory name instead of file name. --HG-- extra : convert_revision : d0aa87b62911f405a4f5811271b9e6351fdd9fe4
This commit is contained in:
parent
7e07aa9300
commit
510eef0fa0
4 changed files with 43 additions and 26 deletions
|
@ -127,7 +127,7 @@ namespace AlphaPseudo
|
||||||
Tick when = curTick + NS2Ticks(delay);
|
Tick when = curTick + NS2Ticks(delay);
|
||||||
Tick repeat = NS2Ticks(period);
|
Tick repeat = NS2Ticks(period);
|
||||||
|
|
||||||
SetupCheckpoint(when, repeat);
|
Checkpoint::setup(when, repeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Context : public ParamContext
|
class Context : public ParamContext
|
||||||
|
|
|
@ -405,7 +405,7 @@ CowDiskImage::write(const uint8_t *data, off_t offset)
|
||||||
void
|
void
|
||||||
CowDiskImage::serialize(ostream &os)
|
CowDiskImage::serialize(ostream &os)
|
||||||
{
|
{
|
||||||
string cowFilename = CheckpointDir() + name() + ".cow";
|
string cowFilename = Checkpoint::dir() + name() + ".cow";
|
||||||
SERIALIZE_SCALAR(cowFilename);
|
SERIALIZE_SCALAR(cowFilename);
|
||||||
save(cowFilename);
|
save(cowFilename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,11 +222,11 @@ Globals::unserialize(Checkpoint *cp)
|
||||||
void
|
void
|
||||||
Serializable::serializeAll()
|
Serializable::serializeAll()
|
||||||
{
|
{
|
||||||
string dir = CheckpointDir();
|
string dir = Checkpoint::dir();
|
||||||
if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
|
if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
|
||||||
warn("could mkdir %s\n", dir);
|
fatal("couldn't mkdir %s\n", dir);
|
||||||
|
|
||||||
string cpt_file = dir + "m5.cpt";
|
string cpt_file = dir + Checkpoint::baseFilename;
|
||||||
ofstream outstream(cpt_file.c_str());
|
ofstream outstream(cpt_file.c_str());
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
outstream << "// checkpoint generated: " << ctime(&t);
|
outstream << "// checkpoint generated: " << ctime(&t);
|
||||||
|
@ -273,19 +273,21 @@ SerializeEvent::process()
|
||||||
schedule(curTick + repeat);
|
schedule(curTick + repeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
string __CheckpointDirBase;
|
const char *Checkpoint::baseFilename = "m5.cpt";
|
||||||
|
|
||||||
|
static string checkpointDirBase;
|
||||||
|
|
||||||
string
|
string
|
||||||
CheckpointDir()
|
Checkpoint::dir()
|
||||||
{
|
{
|
||||||
if (__CheckpointDirBase.empty())
|
// use csprintf to insert curTick into directory name if it
|
||||||
return __CheckpointDirBase;
|
// appears to have a format placeholder in it.
|
||||||
|
return (checkpointDirBase.find("%") != string::npos) ?
|
||||||
return csprintf("%s/m5.%012d/", __CheckpointDirBase, curTick);
|
csprintf(checkpointDirBase, curTick) : checkpointDirBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SetupCheckpoint(Tick when, Tick period)
|
Checkpoint::setup(Tick when, Tick period)
|
||||||
{
|
{
|
||||||
new SerializeEvent(when, period);
|
new SerializeEvent(when, period);
|
||||||
}
|
}
|
||||||
|
@ -304,8 +306,9 @@ class SerializeParamContext : public ParamContext
|
||||||
SerializeParamContext serialParams("serialize");
|
SerializeParamContext serialParams("serialize");
|
||||||
|
|
||||||
Param<string> serialize_dir(&serialParams,
|
Param<string> serialize_dir(&serialParams,
|
||||||
"dir",
|
"dir",
|
||||||
"dir to stick checkpoint in", ".");
|
"dir to stick checkpoint in "
|
||||||
|
"(sprintf format with cycle #)", "m5.%012d");
|
||||||
|
|
||||||
Param<Counter> serialize_cycle(&serialParams,
|
Param<Counter> serialize_cycle(&serialParams,
|
||||||
"cycle",
|
"cycle",
|
||||||
|
@ -330,9 +333,14 @@ SerializeParamContext::~SerializeParamContext()
|
||||||
void
|
void
|
||||||
SerializeParamContext::checkParams()
|
SerializeParamContext::checkParams()
|
||||||
{
|
{
|
||||||
__CheckpointDirBase = serialize_dir;
|
checkpointDirBase = serialize_dir;
|
||||||
|
// guarantee that directory ends with a '/'
|
||||||
|
if (checkpointDirBase[checkpointDirBase.size() - 1] != '/') {
|
||||||
|
checkpointDirBase += "/";
|
||||||
|
}
|
||||||
|
|
||||||
if (serialize_cycle > 0)
|
if (serialize_cycle > 0)
|
||||||
SetupCheckpoint(serialize_cycle, serialize_period);
|
Checkpoint::setup(serialize_cycle, serialize_period);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -415,10 +423,11 @@ Serializable::create(Checkpoint *cp, const std::string §ion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Checkpoint::Checkpoint(const std::string &filename, const std::string &path,
|
Checkpoint::Checkpoint(const std::string &cpt_dir, const std::string &path,
|
||||||
const ConfigNode *_configNode)
|
const ConfigNode *_configNode)
|
||||||
: db(new IniFile), basePath(path), configNode(_configNode)
|
: db(new IniFile), basePath(path), configNode(_configNode)
|
||||||
{
|
{
|
||||||
|
string filename = cpt_dir + "/" + Checkpoint::baseFilename;
|
||||||
if (!db->load(filename)) {
|
if (!db->load(filename)) {
|
||||||
fatal("Can't load checkpoint file '%s'\n", filename);
|
fatal("Can't load checkpoint file '%s'\n", filename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ class Checkpoint
|
||||||
std::map<std::string, Serializable*> objMap;
|
std::map<std::string, Serializable*> objMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Checkpoint(const std::string &filename, const std::string &path,
|
Checkpoint(const std::string &cpt_dir, const std::string &path,
|
||||||
const ConfigNode *_configNode);
|
const ConfigNode *_configNode);
|
||||||
|
|
||||||
bool find(const std::string §ion, const std::string &entry,
|
bool find(const std::string §ion, const std::string &entry,
|
||||||
|
@ -217,14 +217,22 @@ class Checkpoint
|
||||||
Serializable *&value);
|
Serializable *&value);
|
||||||
|
|
||||||
bool sectionExists(const std::string §ion);
|
bool sectionExists(const std::string §ion);
|
||||||
|
|
||||||
|
// The following static functions have to do with checkpoint
|
||||||
|
// creation rather than restoration. This class makes a handy
|
||||||
|
// namespace for them though.
|
||||||
|
|
||||||
|
// Export current checkpoint directory name so other objects can
|
||||||
|
// derive filenames from it (e.g., memory). The return value is
|
||||||
|
// guaranteed to end in '/' so filenames can be directly appended.
|
||||||
|
// This function is only valid while a checkpoint is being created.
|
||||||
|
static std::string dir();
|
||||||
|
|
||||||
|
// Filename for base checkpoint file within directory.
|
||||||
|
static const char *baseFilename;
|
||||||
|
|
||||||
|
// Set up a checkpoint creation event or series of events.
|
||||||
|
static void setup(Tick when, Tick period = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Export checkpoint filename param so other objects can derive
|
|
||||||
// filenames from it (e.g., memory).
|
|
||||||
//
|
|
||||||
std::string CheckpointDir();
|
|
||||||
void SetupCheckpoint(Tick when, Tick period = 0);
|
|
||||||
|
|
||||||
#endif // __SERIALIZE_HH__
|
#endif // __SERIALIZE_HH__
|
||||||
|
|
Loading…
Reference in a new issue