summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/statistics.cc50
-rw-r--r--base/statistics.hh130
-rw-r--r--dev/disk_image.cc2
-rw-r--r--kern/tru64/tru64_events.hh2
-rw-r--r--sim/serialize.cc36
-rw-r--r--sim/serialize.hh4
-rw-r--r--sim/system.cc4
-rw-r--r--sim/system.hh4
8 files changed, 112 insertions, 120 deletions
diff --git a/base/statistics.cc b/base/statistics.cc
index 69b663dbb..737f8f73b 100644
--- a/base/statistics.cc
+++ b/base/statistics.cc
@@ -129,8 +129,8 @@ class Database
typedef list<Stat *> list_t;
typedef map<const Stat *, StatData *> map_t;
- list<GenBin *> bins;
- map<const GenBin *, std::string > bin_names;
+ list<MainBin *> bins;
+ map<const MainBin *, std::string > bin_names;
list_t binnedStats;
list_t allStats;
@@ -148,7 +148,7 @@ class Database
void reset();
void regStat(Stat *stat);
StatData *print(Stat *stat);
- void regBin(GenBin *bin, std::string name);
+ void regBin(MainBin *bin, std::string name);
};
Database::Database()
@@ -171,14 +171,14 @@ Database::dump(ostream &stream)
}
#endif //FS_MEASURE
- list<GenBin *>::iterator j = bins.begin();
- list<GenBin *>::iterator bins_end=bins.end();
+ list<MainBin *>::iterator j = bins.begin();
+ list<MainBin *>::iterator bins_end=bins.end();
if (!bins.empty()) {
ccprintf(stream, "PRINTING BINNED STATS\n");
while (j != bins_end) {
(*j)->activate();
- map<const GenBin *, std::string>::const_iterator iter;
+ map<const MainBin *, std::string>::const_iterator iter;
iter = bin_names.find(*j);
if (iter == bin_names.end())
panic("a binned stat not found in names map!");
@@ -272,12 +272,12 @@ Database::reset()
++i;
}
- MainBin *orig = MainBin::current();
+ MainBin *orig = MainBin::curBin();
- list<GenBin *>::iterator bi = bins.begin();
- list<GenBin *>::iterator be = bins.end();
+ list<MainBin *>::iterator bi = bins.begin();
+ list<MainBin *>::iterator be = bins.end();
while (bi != be) {
- GenBin *bin = *bi;
+ MainBin *bin = *bi;
bin->activate();
i = allStats.begin();
@@ -289,7 +289,8 @@ Database::reset()
++bi;
}
- orig->activate();
+ if (orig)
+ orig->activate();
}
void
@@ -307,7 +308,7 @@ Database::regStat(Stat *stat)
}
void
-Database::regBin(GenBin *bin, std::string name)
+Database::regBin(MainBin *bin, std::string name)
{
if (bin_names.find(bin) != bin_names.end())
panic("shouldn't register bin twice");
@@ -747,7 +748,7 @@ VectorDisplay(std::ostream &stream,
_pdf = vec[i] / _total;
_cdf += _pdf;
} else {
- _pdf = _cdf = NAN;
+ _pdf = _cdf = 0.0;
}
if (!(myflags & cdf)) {
PrintOne(stream, vec[i], subname, subdesc, myprecision,
@@ -909,36 +910,35 @@ FancyDisplay(ostream &stream, const string &name, const string &desc,
PrintOne(stream, total, "**Ignore: " + name + NAMESEP + "TOT", desc, precision, flags);
}
-BinBase::BinBase()
- : mem(NULL), memsize(-1)
+} // namespace Detail
+
+MainBin::MainBin(const std::string &name)
+ : _name(name), mem(NULL), memsize(-1)
{
+ Detail::StatDB().regBin(this, name);
}
-BinBase::~BinBase()
+MainBin::~MainBin()
{
if (mem)
delete [] mem;
}
char *
-BinBase::memory()
+MainBin::memory(off_t off)
{
if (!mem) {
mem = new char[memsize];
memset(mem, 0, memsize);
}
- return mem;
-}
+ if (memsize == -1)
+ memsize = CeilPow2((size_t) offset());
-void
-GenBin::regBin(GenBin *bin, std::string name)
-{
- Detail::StatDB().regBin(bin, name);
+ assert(offset() <= size());
+ return mem + off;
}
-} // namespace Detail
-
void
check()
{
diff --git a/base/statistics.hh b/base/statistics.hh
index 28c380602..ded1470f4 100644
--- a/base/statistics.hh
+++ b/base/statistics.hh
@@ -1403,7 +1403,8 @@ struct FancyStor
variance = (ftot * fsq - (fsum * fsum)) / (ftot * (ftot - 1.0));
}
- FancyDisplay(stream, name, desc, precision, flags, mean, variance, ftot);
+ FancyDisplay(stream, name, desc, precision, flags, mean,
+ variance, ftot);
}
/**
@@ -2170,64 +2171,43 @@ class Temp
operator NodePtr() { return node;}
};
+} // namespace Detail
+
//////////////////////////////////////////////////////////////////////
//
// Binning Interface
//
//////////////////////////////////////////////////////////////////////
-
-class BinBase
+struct MainBin
{
private:
+ std::string _name;
char *mem;
protected:
off_t memsize;
off_t size() const { return memsize; }
- char *memory();
-
- public:
- BinBase();
- virtual ~BinBase();
-};
+ char *memory(off_t off);
-} // namespace Detail
-
-class GenBin : public Detail::BinBase
-{
public:
- GenBin() : BinBase() {}
- virtual ~GenBin() {};
-
- virtual void activate() = 0;
- virtual std::string name() const = 0;
- void regBin(GenBin *bin, std::string name);
-};
-
-template <class BinType>
-struct StatBin : public GenBin
-{
- private:
- std::string _name;
-
- public:
- std::string name() const { return _name;}
-
- static StatBin *&curBin() {
- static StatBin *current = NULL;
+ static MainBin *&curBin()
+ {
+ static MainBin *current = NULL;
return current;
}
- static void setCurBin(StatBin *bin) { curBin() = bin; }
- static StatBin *current() { assert(curBin()); return curBin(); }
+ static void setCurBin(MainBin *bin) { curBin() = bin; }
+ static MainBin *current() { assert(curBin()); return curBin(); }
- static off_t &offset() {
+ static off_t &offset()
+ {
static off_t offset = 0;
return offset;
}
- static off_t new_offset(size_t size) {
+ static off_t new_offset(size_t size)
+ {
size_t mask = sizeof(u_int64_t) - 1;
off_t off = offset();
@@ -2236,23 +2216,24 @@ struct StatBin : public GenBin
return off;
}
- explicit StatBin(std::string name) : GenBin() { _name = name; this->regBin(this, name); }
+ public:
+ MainBin(const std::string &name);
+ ~MainBin();
- char *memory(off_t off) {
- if (memsize == -1) {
- memsize = CeilPow2((size_t) offset());
- }
- assert(offset() <= size());
- return Detail::BinBase::memory() + off;
+ const std::string &
+ name() const
+ {
+ return _name;
}
- virtual void activate() {
+ void
+ activate()
+ {
setCurBin(this);
#ifdef FS_MEASURE
DPRINTF(TCPIP, "activating %s Bin\n", name());
#endif
}
- static void activate(StatBin &bin) { setCurBin(&bin); }
class BinBase
{
@@ -2261,10 +2242,12 @@ struct StatBin : public GenBin
public:
BinBase() : offset(-1) {}
- void allocate(size_t size) {
+ void allocate(size_t size)
+ {
offset = new_offset(size);
}
- char *access() {
+ char *access()
+ {
assert(offset != -1);
return current()->memory(offset);
}
@@ -2284,7 +2267,9 @@ struct StatBin : public GenBin
int size() const { return 1; }
- Storage *data(Params &params) {
+ Storage *
+ data(Params &params)
+ {
assert(initialized());
char *ptr = access();
char *flags = ptr + sizeof(Storage);
@@ -2294,7 +2279,9 @@ struct StatBin : public GenBin
}
return reinterpret_cast<Storage *>(ptr);
}
- void reset()
+
+ void
+ reset()
{
char *ptr = access();
char *flags = ptr + size() * sizeof(Storage);
@@ -2320,7 +2307,8 @@ struct StatBin : public GenBin
VectorBin() : _size(0) {}
bool initialized() const { return _size > 0; }
- void init(int s, Params &params) {
+ void init(int s, Params &params)
+ {
assert(!initialized());
assert(s > 0);
_size = s;
@@ -2329,7 +2317,8 @@ struct StatBin : public GenBin
int size() const { return _size; }
- Storage *data(int index, Params &params) {
+ Storage *data(int index, Params &params)
+ {
assert(initialized());
assert(index >= 0 && index < size());
char *ptr = access();
@@ -2357,9 +2346,6 @@ struct StatBin : public GenBin
};
};
-class MainBinType {};
-typedef StatBin<MainBinType> MainBin;
-
struct NoBin
{
template <class Storage>
@@ -2379,11 +2365,13 @@ struct NoBin
}
bool initialized() const { return true; }
- void init(Params &params) {
+ void init(Params &params)
+ {
new (ptr) Storage(params);
}
int size() const{ return 1; }
- Storage *data(Params &params) {
+ Storage *data(Params &params)
+ {
assert(initialized());
return reinterpret_cast<Storage *>(ptr);
}
@@ -2420,7 +2408,8 @@ struct NoBin
}
bool initialized() const { return ptr != NULL; }
- void init(int s, Params &params) {
+ void init(int s, Params &params)
+ {
assert(s > 0 && "size must be positive!");
assert(!initialized());
_size = s;
@@ -2431,7 +2420,8 @@ struct NoBin
int size() const { return _size; }
- Storage *data(int index, Params &params) {
+ Storage *data(int index, Params &params)
+ {
assert(initialized());
assert(index >= 0 && index < size());
return reinterpret_cast<Storage *>(ptr + index * sizeof(Storage));
@@ -2461,9 +2451,9 @@ struct NoBin
*/
/**
- * This is an easy way to assign all your stats to be binned or not binned. If the typedef
- * is NoBin, nothing is binned. If it is MainBin (or whatever *Bin), then all stats are binned
- * under that Bin.
+ * This is an easy way to assign all your stats to be binned or not
+ * binned. If the typedef is NoBin, nothing is binned. If it is
+ * MainBin, then all stats are binned under that Bin.
*/
#ifdef FS_MEASURE
typedef MainBin DefaultBin;
@@ -2768,12 +2758,13 @@ class Formula : public Detail::VectorStat
*/
const rvec_t &val() const { return root->val(); }
/**
- * Return the total Formula result. If there is a Vector component to this
- * Formula, then this is the result of the Formula if the formula is applied
- * after summing all the components of the Vector. For example, if Formula
- * is x/y where x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If there is no
- * Vector component, total() returns the same value as the first entry in the rvec_t
- * val() returns.
+ * Return the total Formula result. If there is a Vector
+ * component to this Formula, then this is the result of the
+ * Formula if the formula is applied after summing all the
+ * components of the Vector. For example, if Formula is x/y where
+ * x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If
+ * there is no Vector component, total() returns the same value as
+ * the first entry in the rvec_t val() returns.
* @return The total of the result vector.
*/
result_t total() const { return root->total(); }
@@ -2788,8 +2779,9 @@ class Formula : public Detail::VectorStat
return root->size();
}
/**
- * Return true if Formula is binned. i.e. any of its children nodes are binned
- *@return True if Formula is binned.
+ * Return true if Formula is binned. i.e. any of its children
+ * nodes are binned
+ * @return True if Formula is binned.
*/
virtual bool binned() const { return root->binned(); }
diff --git a/dev/disk_image.cc b/dev/disk_image.cc
index a1a220de1..cbcd16a25 100644
--- a/dev/disk_image.cc
+++ b/dev/disk_image.cc
@@ -405,7 +405,7 @@ CowDiskImage::write(const uint8_t *data, off_t offset)
void
CowDiskImage::serialize(ostream &os)
{
- string cowFilename = CheckpointFile() + "." + name() + ".cow";
+ string cowFilename = CheckpointDir() + name() + ".cow";
SERIALIZE_SCALAR(cowFilename);
save(cowFilename);
}
diff --git a/kern/tru64/tru64_events.hh b/kern/tru64/tru64_events.hh
index a8f0eb865..2067f2ef3 100644
--- a/kern/tru64/tru64_events.hh
+++ b/kern/tru64/tru64_events.hh
@@ -92,7 +92,7 @@ class FnEvent : public PCEvent
private:
std::string _name;
- Statistics::GenBin *myBin;
+ Statistics::MainBin *myBin;
};
#endif //FS_MEASURE
#endif // __TRU64_EVENTS_HH__
diff --git a/sim/serialize.cc b/sim/serialize.cc
index 0eb26c31d..1fce6e7b1 100644
--- a/sim/serialize.cc
+++ b/sim/serialize.cc
@@ -27,23 +27,24 @@
*/
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <fstream>
#include <list>
#include <string>
#include <vector>
+#include "base/inifile.hh"
#include "base/misc.hh"
#include "base/str.hh"
-
+#include "base/trace.hh"
+#include "sim/config_node.hh"
#include "sim/eventq.hh"
#include "sim/param.hh"
#include "sim/serialize.hh"
-#include "base/inifile.hh"
#include "sim/sim_events.hh"
#include "sim/sim_object.hh"
-#include "base/trace.hh"
-#include "sim/config_node.hh"
using namespace std;
@@ -252,8 +253,11 @@ Serializer::serialize()
Serializeable::serializer = this;
- file = CheckpointFile();
- string cpt_file = file + ".cpt";
+ string dir = CheckpointDir();
+ if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
+ warn("could mkdir %s\n", dir);
+
+ string cpt_file = dir + "m5.cpt";
output = new ofstream(cpt_file.c_str());
time_t t = time(NULL);
*output << "// checkpoint generated: " << ctime(&t);
@@ -279,13 +283,11 @@ Serializer::serialize()
delete output;
output = NULL;
- file = "";
}
class SerializeEvent : public Event
{
protected:
- string file;
Tick repeat;
public:
@@ -314,15 +316,15 @@ SerializeEvent::process()
schedule(curTick + repeat);
}
-string __CheckpointFileBase;
+string __CheckpointDirBase;
string
-CheckpointFile()
+CheckpointDir()
{
- if (__CheckpointFileBase.empty())
- return __CheckpointFileBase;
+ if (__CheckpointDirBase.empty())
+ return __CheckpointDirBase;
- return csprintf("%s.%d", __CheckpointFileBase, curTick);
+ return csprintf("%s/m5.%012d/", __CheckpointDirBase, curTick);
}
void
@@ -344,9 +346,9 @@ class SerializeParamContext : public ParamContext
SerializeParamContext serialParams("serialize");
-Param<string> serialize_file(&serialParams,
- "file",
- "file to write to", "m5");
+Param<string> serialize_dir(&serialParams,
+ "dir",
+ "dir to stick checkpoint in", ".");
Param<Counter> serialize_cycle(&serialParams,
"cycle",
@@ -371,7 +373,7 @@ SerializeParamContext::~SerializeParamContext()
void
SerializeParamContext::checkParams()
{
- __CheckpointFileBase = serialize_file;
+ __CheckpointDirBase = serialize_dir;
if (serialize_cycle > 0)
SetupCheckpoint(serialize_cycle, serialize_period);
}
diff --git a/sim/serialize.hh b/sim/serialize.hh
index 09e91d816..bc40d0ad2 100644
--- a/sim/serialize.hh
+++ b/sim/serialize.hh
@@ -135,7 +135,6 @@ class Serializer
protected:
typedef std::list<Serializeable *> serlist_t;
serlist_t objects;
- std::string file;
std::ostream *output;
std::ostream &out() const;
@@ -149,7 +148,6 @@ class Serializer
public:
void serialize();
- const std::string &filename() const { return file; }
};
//
@@ -253,7 +251,7 @@ class Checkpoint
// Export checkpoint filename param so other objects can derive
// filenames from it (e.g., memory).
//
-std::string CheckpointFile();
+std::string CheckpointDir();
void SetupCheckpoint(Tick when, Tick period = 0);
#endif // __SERIALIZE_HH__
diff --git a/sim/system.cc b/sim/system.cc
index 58e290d1a..db93250ee 100644
--- a/sim/system.cc
+++ b/sim/system.cc
@@ -105,10 +105,10 @@ printSystems()
}
#ifdef FS_MEASURE
-Statistics::GenBin *
+Statistics::MainBin *
System::getBin(const std::string &name)
{
- std::map<const std::string, Statistics::GenBin *>::const_iterator i;
+ std::map<const std::string, Statistics::MainBin *>::const_iterator i;
i = fnBins.find(name);
if (i == fnBins.end())
panic("trying to getBin that is not on system map!");
diff --git a/sim/system.hh b/sim/system.hh
index 741dea0db..8348a144e 100644
--- a/sim/system.hh
+++ b/sim/system.hh
@@ -52,7 +52,7 @@ class System : public SimObject
{
#ifdef FS_MEASURE
protected:
- std::map<const std::string, Statistics::GenBin *> fnBins;
+ std::map<const std::string, Statistics::MainBin *> fnBins;
std::map<const Addr, SWContext *> swCtxMap;
#endif //FS_MEASURE
@@ -85,7 +85,7 @@ class System : public SimObject
virtual bool breakpoint() = 0;
#ifdef FS_MEASURE
- Statistics::GenBin * getBin(const std::string &name);
+ Statistics::MainBin * getBin(const std::string &name);
virtual bool findCaller(std::string, std::string) const = 0;
SWContext *findContext(Addr pcb);