checkpointing: minor cleanup.
authorSteve Reinhardt <steve.reinhardt@amd.com>
Tue, 6 Jul 2010 04:39:38 +0000 (21:39 -0700)
committerSteve Reinhardt <steve.reinhardt@amd.com>
Tue, 6 Jul 2010 04:39:38 +0000 (21:39 -0700)
Move some static checkpoint stuff into the
Checkpoint object namespace.

src/sim/serialize.cc
src/sim/serialize.hh

index 27831ef3229d96aec025c241df13dac0568c6dd9..5f854a776c28022cb5b0e39c981981ef58541dbc 100644 (file)
@@ -427,8 +427,7 @@ Serializable::unserialize(Checkpoint *cp, const string &section)
 void
 Serializable::serializeAll(const string &cpt_dir)
 {
-    setCheckpointDir(cpt_dir);
-    string dir = Checkpoint::dir();
+    string dir = Checkpoint::setDir(cpt_dir);
     if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
             fatal("couldn't mkdir %s\n", dir);
 
@@ -446,14 +445,10 @@ Serializable::serializeAll(const string &cpt_dir)
 void
 Serializable::unserializeAll(const string &cpt_dir)
 {
-    setCheckpointDir(cpt_dir);
-    string dir = Checkpoint::dir();
-    string cpt_file = dir + Checkpoint::baseFilename;
-    string section = "";
+    string dir = Checkpoint::setDir(cpt_dir);
 
-    DPRINTFR(Config, "Loading checkpoint dir '%s'\n",
-             dir);
-    Checkpoint *cp = new Checkpoint(dir, section);
+    DPRINTFR(Config, "Loading checkpoint dir '%s'\n", dir);
+    Checkpoint *cp = new Checkpoint(dir);
     unserializeGlobals(cp);
     SimObject::unserializeAll(cp);
 }
@@ -464,27 +459,6 @@ Serializable::unserializeGlobals(Checkpoint *cp)
     globals.unserialize(cp);
 }
 
-const char *Checkpoint::baseFilename = "m5.cpt";
-
-static string checkpointDirBase;
-
-void
-setCheckpointDir(const string &name)
-{
-    checkpointDirBase = name;
-    if (checkpointDirBase[checkpointDirBase.size() - 1] != '/')
-        checkpointDirBase += "/";
-}
-
-string
-Checkpoint::dir()
-{
-    // use csprintf to insert curTick into directory name if it
-    // appears to have a format placeholder in it.
-    return (checkpointDirBase.find("%") != string::npos) ?
-        csprintf(checkpointDirBase, curTick) : checkpointDirBase;
-}
-
 void
 debug_serialize(const string &cpt_dir)
 {
@@ -554,8 +528,31 @@ Serializable::create(Checkpoint *cp, const string &section)
 }
 
 
-Checkpoint::Checkpoint(const string &cpt_dir, const string &path)
-    : db(new IniFile), basePath(path), cptDir(cpt_dir)
+const char *Checkpoint::baseFilename = "m5.cpt";
+
+string Checkpoint::currentDirectory;
+
+string
+Checkpoint::setDir(const string &name)
+{
+    // use csprintf to insert curTick into directory name if it
+    // appears to have a format placeholder in it.
+    currentDirectory = (name.find("%") != string::npos) ?
+        csprintf(name, curTick) : name;
+    if (currentDirectory[currentDirectory.size() - 1] != '/')
+        currentDirectory += "/";
+    return currentDirectory;
+}
+
+string
+Checkpoint::dir()
+{
+    return currentDirectory;
+}
+
+
+Checkpoint::Checkpoint(const string &cpt_dir)
+    : db(new IniFile), cptDir(cpt_dir)
 {
     string filename = cpt_dir + "/" + Checkpoint::baseFilename;
     if (!db->load(filename)) {
index cf1a672be9fa69cc7b8d7260614c65d451bcc461..677a3fd92ec898041dd09916ba1a4e340b42d43e 100644 (file)
@@ -219,19 +219,14 @@ class SerializableClass
 SerializableClass the##OBJ_CLASS##Class(CLASS_NAME,                        \
                                          OBJ_CLASS::createForUnserialize);
 
-void
-setCheckpointDir(const std::string &name);
-
 class Checkpoint
 {
   private:
 
     IniFile *db;
-    const std::string basePath;
-    std::map<std::string, Serializable*> objMap;
 
   public:
-    Checkpoint(const std::string &cpt_dir, const std::string &path);
+    Checkpoint(const std::string &cpt_dir);
 
     const std::string cptDir;
 
@@ -245,7 +240,20 @@ class Checkpoint
 
     // The following static functions have to do with checkpoint
     // creation rather than restoration.  This class makes a handy
-    // namespace for them though.
+    // namespace for them though.  Currently no Checkpoint object is
+    // created on serialization (only unserialization) so we track the
+    // directory name as a global.  It would be nice to change this
+    // someday
+
+  private:
+    // current directory we're serializing into.
+    static std::string currentDirectory;
+
+  public:
+    // Set the current directory.  This function takes care of
+    // inserting curTick if there's a '%d' in the argument, and
+    // appends a '/' if necessary.  The final name is returned.
+    static std::string setDir(const std::string &base_name);
 
     // Export current checkpoint directory name so other objects can
     // derive filenames from it (e.g., memory).  The return value is