summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2004-05-12 15:49:01 -0400
committerNathan Binkert <binkertn@umich.edu>2004-05-12 15:49:01 -0400
commita4d7bb113aa4ed398a2ec7f6fb01b6d866fba60c (patch)
tree2b835b7bde9e58e45eed34796b7c63e877d61260 /base
parent2cc4fd87eb643c81d37954cbf4a226e78ebd34bc (diff)
downloadgem5-a4d7bb113aa4ed398a2ec7f6fb01b6d866fba60c.tar.xz
Make a new stat type of Value which is a scalar stat that
proxies for a real C/C++ scalar value or scalar functor. This replaces the scalar() and functor() terms that were previously used in formulas. This helps when dumping statistics because the formulas are not supposed to change. cpu/base_cpu.cc: Add a number of cycles stat to the cpu object that tracks the number of cycles that the cpu has executed. This starts to pave the way for cpu cycles being different from event ticks. cpu/base_cpu.hh: provide a functor for calculating all simulated instructions of all CPUs and a virtual function for determining that number. To deal with the change from functor() to Value::functor() cpu/simple_cpu/simple_cpu.cc: simTicks -> numCycles numInsts is now a real Scalar stat, not a Formula cpu/simple_cpu/simple_cpu.hh: numInsts is now a real Scalar stat, not a Formula count all instructions sim/stat_control.cc: simInsts, simTicks, hostMemory, and hostSeconds are no longer Statistics::Formula but rather Statistics::Value add new stat for tick frequency sim/stats.hh: don't need everything to be extern. test/Makefile: Make stuff work a tad bit better test/stattest.cc: test out Statistics::Value --HG-- extra : convert_revision : c812e8baa2b17c08abf3a68ed1e1125dc6f2cfb4
Diffstat (limited to 'base')
-rw-r--r--base/statistics.hh218
1 files changed, 117 insertions, 101 deletions
diff --git a/base/statistics.hh b/base/statistics.hh
index e7fc18d74..ee09cc622 100644
--- a/base/statistics.hh
+++ b/base/statistics.hh
@@ -139,11 +139,13 @@ struct StatData
static bool less(StatData *stat1, StatData *stat2);
};
-struct ScalarData : public StatData
+class ScalarData : public StatData
{
+ public:
virtual Counter value() const = 0;
virtual Result result() const = 0;
virtual Result total() const = 0;
+ virtual void visit(Visit &visitor) { visitor.visit(*this); }
};
template <class Stat>
@@ -162,8 +164,6 @@ class ScalarStatData : public ScalarData
virtual Result total() const { return s.total(); }
virtual void reset() { s.reset(); }
virtual bool zero() const { return s.zero(); }
-
- virtual void visit(Visit &visitor) { visitor.visit(*this); }
};
struct VectorData : public StatData
@@ -394,6 +394,16 @@ class Wrap : public Child
return ptr;
}
+ protected:
+ /**
+ * Copy constructor, copies are not allowed.
+ */
+ Wrap(const Wrap &stat);
+ /**
+ * Can't copy stats.
+ */
+ void operator=(const Wrap &);
+
public:
Wrap()
{
@@ -726,16 +736,6 @@ class ScalarBase : public DataAccess
return _bin->data(*_params);
}
- protected:
- /**
- * Copy constructor, copies are not allowed.
- */
- ScalarBase(const ScalarBase &stat);
- /**
- * Can't copy stats.
- */
- const ScalarBase &operator=(const ScalarBase &);
-
public:
/**
* Return the current value of this stat as its base type.
@@ -822,6 +822,79 @@ class ScalarBase : public DataAccess
};
+class ProxyData : public ScalarData
+{
+ public:
+ virtual void visit(Visit &visitor) { visitor.visit(*this); }
+ virtual bool binned() const { return false; }
+ virtual std::string str() const { return to_string(value()); }
+ virtual size_t size() const { return 1; }
+ virtual bool zero() const { return value() == 0; }
+ virtual bool check() const { return true; }
+ virtual void reset() { }
+};
+
+template <class T>
+class ValueProxy : public ProxyData
+{
+ private:
+ T *scalar;
+
+ public:
+ ValueProxy(T &val) : scalar(&val) {}
+ virtual Counter value() const { return *scalar; }
+ virtual Result result() const { return *scalar; }
+ virtual Result total() const { return *scalar; }
+};
+
+template <class T>
+class FunctorProxy : public ProxyData
+{
+ private:
+ T *functor;
+
+ public:
+ FunctorProxy(T &func) : functor(&func) {}
+ virtual Counter value() const { return (*functor)(); }
+ virtual Result result() const { return (*functor)(); }
+ virtual Result total() const { return (*functor)(); }
+};
+
+class ValueBase : public DataAccess
+{
+ private:
+ ProxyData *proxy;
+
+ public:
+ ValueBase() : proxy(NULL) { }
+ ~ValueBase() { if (proxy) delete proxy; }
+
+ template <class T>
+ void scalar(T &value)
+ {
+ proxy = new ValueProxy<T>(value);
+ setInit();
+ }
+
+ template <class T>
+ void functor(T &func)
+ {
+ proxy = new FunctorProxy<T>(func);
+ setInit();
+ }
+
+ Counter value() { return proxy->value(); }
+ Result result() const { return proxy->result(); }
+ Result total() const { return proxy->total(); };
+ size_t size() const { return proxy->size(); }
+
+ bool binned() const { return proxy->binned(); }
+ std::string str() const { return proxy->str(); }
+ bool zero() const { return proxy->zero(); }
+ bool check() const { return proxy != NULL; }
+ void reset() { }
+};
+
//////////////////////////////////////////////////////////////////////
//
// Vector Statistics
@@ -869,13 +942,6 @@ class VectorBase : public DataAccess
return _bin->data(index, *_params);
}
- protected:
- // Copying stats is not allowed
- /** Copying stats isn't allowed. */
- VectorBase(const VectorBase &stat);
- /** Copying stats isn't allowed. */
- const VectorBase &operator=(const VectorBase &);
-
public:
void value(VCounter &vec) const
{
@@ -1127,11 +1193,6 @@ class Vector2dBase : public DataAccess
return _bin->data(index, *_params);
}
- protected:
- // Copying stats is not allowed
- Vector2dBase(const Vector2dBase &stat);
- const Vector2dBase &operator=(const Vector2dBase &);
-
public:
Vector2dBase() {}
@@ -1586,13 +1647,6 @@ class DistBase : public DataAccess
return _bin->data(*_params);
}
- protected:
- // Copying stats is not allowed
- /** Copies are not allowed. */
- DistBase(const DistBase &stat);
- /** Copies are not allowed. */
- const DistBase &operator=(const DistBase &);
-
public:
DistBase() { }
@@ -1659,11 +1713,6 @@ class VectorDistBase : public DataAccess
return _bin->data(index, *_params);
}
- protected:
- // Copying stats is not allowed
- VectorDistBase(const VectorDistBase &stat);
- const VectorDistBase &operator=(const VectorDistBase &);
-
public:
VectorDistBase() {}
@@ -1910,56 +1959,6 @@ class ConstNode : public Node
virtual std::string str() const { return to_string(vresult[0]); }
};
-template <class T>
-class FunctorNode : public Node
-{
- private:
- T &functor;
- mutable VResult vresult;
-
- public:
- FunctorNode(T &f) : functor(f) { vresult.resize(1); }
- const VResult &result() const
- {
- vresult[0] = (Result)functor();
- return vresult;
- }
- virtual Result total() const { return (Result)functor(); };
-
- virtual size_t size() const { return 1; }
- /**
- * Return true if stat is binned.
- *@return False since Functors aren't binned
- */
- virtual bool binned() const { return false; }
- virtual std::string str() const { return to_string(functor()); }
-};
-
-template <class T>
-class ScalarNode : public Node
-{
- private:
- T &scalar;
- mutable VResult vresult;
-
- public:
- ScalarNode(T &s) : scalar(s) { vresult.resize(1); }
- const VResult &result() const
- {
- vresult[0] = (Result)scalar;
- return vresult;
- }
- virtual Result total() const { return (Result)scalar; };
-
- virtual size_t size() const { return 1; }
- /**
- * Return true if stat is binned.
- *@return False since Scalar's aren't binned
- */
- virtual bool binned() const { return false; }
- virtual std::string str() const { return to_string(scalar); }
-};
-
template <class Op>
struct OpString;
@@ -2219,6 +2218,30 @@ class Scalar
void operator=(const U &v) { Base::operator=(v); }
};
+class Value
+ : public Wrap<Value,
+ ValueBase,
+ ScalarStatData>
+{
+ public:
+ /** The base implementation. */
+ typedef ValueBase Base;
+
+ template <class T>
+ Value &scalar(T &value)
+ {
+ Base::scalar(value);
+ return *this;
+ }
+
+ template <class T>
+ Value &functor(T &func)
+ {
+ Base::functor(func);
+ return *this;
+ }
+};
+
/**
* A stat that calculates the per cycle average of a value.
* @sa Stat, ScalarBase, AvgStor
@@ -2698,6 +2721,13 @@ class Temp
* Create a new ScalarStatNode.
* @param s The ScalarStat to place in a node.
*/
+ Temp(const Value &s)
+ : node(new ScalarStatNode(s.statData())) { }
+
+ /**
+ * Create a new ScalarStatNode.
+ * @param s The ScalarStat to place in a node.
+ */
template <class Bin>
Temp(const Average<Bin> &s)
: node(new ScalarStatNode(s.statData())) { }
@@ -2861,20 +2891,6 @@ constant(T val)
return NodePtr(new ConstNode<T>(val));
}
-template <typename T>
-inline Temp
-functor(T &val)
-{
- return NodePtr(new FunctorNode<T>(val));
-}
-
-template <typename T>
-inline Temp
-scalar(T &val)
-{
- return NodePtr(new ScalarNode<T>(val));
-}
-
inline Temp
sum(Temp val)
{