Merge zizzer:/bk/m5
[gem5.git] / sim / serialize.cc
index f8d6b46bf2e03c90f0c3168748986e30fb9839ca..ec72414985c9f1c65a75bbf0a2c68df732fe1089 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,6 +29,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 #include <fstream>
 #include <list>
@@ -37,6 +38,7 @@
 
 #include "base/inifile.hh"
 #include "base/misc.hh"
+#include "base/output.hh"
 #include "base/str.hh"
 #include "base/trace.hh"
 #include "sim/config_node.hh"
 #include "sim/param.hh"
 #include "sim/serialize.hh"
 #include "sim/sim_events.hh"
+#include "sim/sim_exit.hh"
 #include "sim/sim_object.hh"
 
 using namespace std;
 
+int Serializable::maxCount = 0;
+int Serializable::count = 0;
+
 void
 Serializable::nameOut(ostream &os)
 {
@@ -166,15 +172,16 @@ template void                                                             \
 arrayParamIn(Checkpoint *cp, const std::string &section,               \
              const std::string &name, type *param, int size);
 
-
-INSTANTIATE_PARAM_TEMPLATES(int8_t)
-INSTANTIATE_PARAM_TEMPLATES(uint8_t)
-INSTANTIATE_PARAM_TEMPLATES(int16_t)
-INSTANTIATE_PARAM_TEMPLATES(uint16_t)
-INSTANTIATE_PARAM_TEMPLATES(int32_t)
-INSTANTIATE_PARAM_TEMPLATES(uint32_t)
-INSTANTIATE_PARAM_TEMPLATES(int64_t)
-INSTANTIATE_PARAM_TEMPLATES(uint64_t)
+INSTANTIATE_PARAM_TEMPLATES(signed char)
+INSTANTIATE_PARAM_TEMPLATES(unsigned char)
+INSTANTIATE_PARAM_TEMPLATES(signed short)
+INSTANTIATE_PARAM_TEMPLATES(unsigned short)
+INSTANTIATE_PARAM_TEMPLATES(signed int)
+INSTANTIATE_PARAM_TEMPLATES(unsigned int)
+INSTANTIATE_PARAM_TEMPLATES(signed long)
+INSTANTIATE_PARAM_TEMPLATES(unsigned long)
+INSTANTIATE_PARAM_TEMPLATES(signed long long)
+INSTANTIATE_PARAM_TEMPLATES(unsigned long long)
 INSTANTIATE_PARAM_TEMPLATES(bool)
 INSTANTIATE_PARAM_TEMPLATES(string)
 
@@ -233,6 +240,9 @@ Serializable::serializeAll()
 
     globals.serialize(outstream);
     SimObject::serializeAll(outstream);
+
+    if (maxCount && ++count >= maxCount)
+        SimExit(curTick + 1, "Maximum number of checkpoints dropped");
 }
 
 
@@ -319,7 +329,8 @@ Param<Counter> serialize_period(&serialParams,
                                 "period to repeat serializations",
                                 0);
 
-
+Param<int> serialize_count(&serialParams, "count",
+                           "maximum number of checkpoints to drop");
 
 SerializeParamContext::SerializeParamContext(const string &section)
     : ParamContext(section), event(NULL)
@@ -332,14 +343,7 @@ SerializeParamContext::~SerializeParamContext()
 void
 SerializeParamContext::checkParams()
 {
-    if (serialize_dir.isValid()) {
-        checkpointDirBase = serialize_dir;
-    } else {
-        if (outputDirectory.empty())
-            checkpointDirBase = "m5.%012d";
-        else
-            checkpointDirBase = outputDirectory + "cpt.%012d";
-    }
+    checkpointDirBase = simout.resolve(serialize_dir);
 
     // guarantee that directory ends with a '/'
     if (checkpointDirBase[checkpointDirBase.size() - 1] != '/')
@@ -347,6 +351,8 @@ SerializeParamContext::checkParams()
 
     if (serialize_cycle > 0)
         Checkpoint::setup(serialize_cycle, serialize_period);
+
+    Serializable::maxCount = serialize_count;
 }
 
 void
@@ -431,7 +437,7 @@ Serializable::create(Checkpoint *cp, const std::string &section)
 
 Checkpoint::Checkpoint(const std::string &cpt_dir, const std::string &path,
                        const ConfigNode *_configNode)
-    : db(new IniFile), basePath(path), configNode(_configNode)
+    : db(new IniFile), basePath(path), configNode(_configNode), cptDir(cpt_dir)
 {
     string filename = cpt_dir + "/" + Checkpoint::baseFilename;
     if (!db->load(filename)) {