Hoa Nguyen has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/40993 )
Change subject: base-stats: Add support for unit prefixes
......................................................................
base-stats: Add support for unit prefixes
Change-Id: Ic15f2933f731bb032f27885b6e3ee71efc365712
Signed-off-by: Hoa Nguyen <[email protected]>
---
A src/base/stats/unit_prefixes.hh
M src/base/stats/units.hh
M src/cpu/base.cc
M src/cpu/minor/stats.cc
4 files changed, 229 insertions(+), 98 deletions(-)
diff --git a/src/base/stats/unit_prefixes.hh
b/src/base/stats/unit_prefixes.hh
new file mode 100644
index 0000000..355f8b4
--- /dev/null
+++ b/src/base/stats/unit_prefixes.hh
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2021 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __BASE_STATS_UNIT_PREFIXES_HH__
+#define __BASE_STATS_UNIT_PREFIXES_HH__
+
+namespace Stats {
+
+/**
+ * Unit Prefixes for Stats.
+ *
+ * The supported units are:
+ * - Kilo: 1e3
+ */
+namespace Units {
+
+/**
+ * The Base class is the parent class of all unit classes.
+ * This class is intended to an abstract class specifying common behaviors
of
+ * all unit classes.
+ */
+class Base
+{
+};
+
+class One : public Base
+{
+ public:
+ static std::string toString() { return ""; }
+};
+
+
+class Kilo : public Base
+{
+ public:
+ static std::string toString() { return "Kilo"; }
+};
+
+class Mega : public Base
+{
+ public:
+ static std::string toString() { return "Mega"; }
+};
+
+} // namespace UnitPrefixes
+
+} // namespace Stats
+
+#endif // __BASE_STATS_UNITS_HH__
\ No newline at end of file
diff --git a/src/base/stats/units.hh b/src/base/stats/units.hh
index 66fe9ce..6ffb263 100644
--- a/src/base/stats/units.hh
+++ b/src/base/stats/units.hh
@@ -36,22 +36,34 @@
/**
* Convenience macros to declare the unit of a stat.
*/
-#define UNIT_CYCLE Stats::Units::Cycle::get()
-#define UNIT_TICK Stats::Units::Tick::get()
-#define UNIT_SECOND Stats::Units::Second::get()
-#define UNIT_INSTRUCTION Stats::Units::Instruction::get()
-#define UNIT_MICROOP Stats::Units::MicroOp::get()
-#define UNIT_BIT Stats::Units::Bit::get()
-#define UNIT_BYTE Stats::Units::Byte::get()
-#define UNIT_JOULE Stats::Units::Joule::get()
-#define UNIT_VOLT Stats::Units::Volt::get()
-#define UNIT_CELSIUS Stats::Units::DegreeCelsius::get()
-#define UNIT_RATE(T1, T2) Stats::Units::Rate<T1, T2>::get()
-#define UNIT_RATIO Stats::Units::Ratio::get()
-#define UNIT_COUNT Stats::Units::Count::get()
+#define UNIT_PREFIX_PICO Stats::Units::Prefixes::Pico
+#define UNIT_PREFIX_NANO Stats::Units::Prefixes::Nano
+#define UNIT_PREFIX_MICRO Stats::Units::Prefixes::Micro
+#define UNIT_PREFIX_MILLI Stats::Units::Prefixes::Milli
+#define UNIT_PREFIX_ONE Stats::Units::Prefixes::One
+#define UNIT_PREFIX_KILO Stats::Units::Prefixes::Kilo
+#define UNIT_PREFIX_MEGA Stats::Units::Prefixes::Mega
+#define UNIT_PREFIX_GIGA Stats::Units::Prefixes::Giga
+
+
+#define UNIT_CYCLE Stats::Units::Cycle<UNIT_PREFIX_ONE>::get()
+#define UNIT_TICK Stats::Units::Tick<UNIT_PREFIX_ONE>::get()
+#define UNIT_SECOND Stats::Units::Second<UNIT_PREFIX_ONE>::get()
+#define UNIT_INSTRUCTION Stats::Units::Instruction<UNIT_PREFIX_ONE>::get()
+#define UNIT_MICROOP Stats::Units::MicroOp<UNIT_PREFIX_ONE>::get()
+#define UNIT_BIT Stats::Units::Bit<UNIT_PREFIX_ONE>::get()
+#define UNIT_BYTE Stats::Units::Byte<UNIT_PREFIX_ONE>::get()
+#define UNIT_JOULE Stats::Units::Joule<UNIT_PREFIX_ONE>::get()
+#define UNIT_VOLT Stats::Units::Volt<UNIT_PREFIX_ONE>::get()
+#define UNIT_CELSIUS Stats::Units::DegreeCelsius<UNIT_PREFIX_ONE>::get()
+#define UNIT_RATE(T1, T2) Stats::Units::Rate<T1<UNIT_PREFIX_ONE>,\
+ T2<UNIT_PREFIX_ONE>>::get()
+#define UNIT_RATIO Stats::Units::Ratio<UNIT_PREFIX_ONE>::get()
+#define UNIT_COUNT Stats::Units::Count<UNIT_PREFIX_ONE>::get()
#define UNIT_UNSPECIFIED Stats::Units::Unspecified::get()
-#define UNIT_WATT UNIT_RATE(Stats::Units::Joule, Stats::Units::Second)
+#define UNIT_WATT UNIT_RATE(Stats::Units::Joule,\
+ Stats::Units::Second)
namespace Stats {
@@ -97,77 +109,111 @@
* This class is intended to an abstract class specifying common behaviors
of
* all unit classes.
*/
+namespace Prefixes {
+ class Base
+ {
+ };
+
+ class One : public Base
+ {
+ public:
+ static std::string toString() { return ""; }
+ };
+
+
+ class Kilo : public Base
+ {
+ public:
+ static std::string toString() { return "kilo"; }
+ };
+
+ class Mega : public Base
+ {
+ public:
+ static std::string toString() { return "mega"; }
+ };
+
+} // namespace Prefixes
+
class Base
{
public:
virtual std::string getUnitString() const = 0;
};
+template <typename TPrefix>
class Cycle : public Base
{
private:
- Cycle() {}
+ Cycle<TPrefix>() {}
public:
- Cycle(Cycle const&) = delete;
- void operator=(Cycle const&) = delete;
- static Cycle*
+ Cycle<TPrefix>(Cycle<TPrefix> const&) = delete;
+ void operator=(Cycle<TPrefix> const&) = delete;
+ static Cycle<TPrefix>*
get()
{
- static Cycle instance;
+ static Cycle<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Cycle"; }
+ static std::string toString() { return TPrefix::toString() + "Cycle"; }
std::string getUnitString() const override { return Cycle::toString();
}
};
+template <typename TPrefix>
class Tick : public Base
{
private:
- Tick() {}
+ Tick<TPrefix>() {}
public:
- Tick(Tick const&) = delete;
- void operator=(Tick const&) = delete;
- static Tick*
+ Tick<TPrefix>(Tick<TPrefix> const&) = delete;
+ void operator=(Tick<TPrefix> const&) = delete;
+ static Tick<TPrefix>*
get()
{
- static Tick instance;
+ static Tick<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Tick"; }
+ static std::string toString() { return TPrefix::toString() + "Tick"; }
std::string getUnitString() const override { return Tick::toString(); }
};
+template <typename TPrefix>
class Second : public Base
{
private:
- Second() {}
+ Second<TPrefix>() {}
public:
- Second(Second const&) = delete;
- void operator=(Second const&) = delete;
- static Second*
+ Second<TPrefix>(Second<TPrefix> const&) = delete;
+ void operator=(Second<TPrefix> const&) = delete;
+ static Second<TPrefix>*
get()
{
- static Second instance;
+ static Second<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Second"; }
+ static std::string toString() { return TPrefix::toString() + "Second";
}
std::string getUnitString() const override { return
Second::toString(); }
};
+template <typename TPrefix>
class Instruction : public Base
{
private:
- Instruction() {}
+ Instruction<TPrefix>() {}
public:
- Instruction(Instruction const&) = delete;
- void operator=(Instruction const&) = delete;
- static Instruction*
+ Instruction<TPrefix>(Instruction<TPrefix> const&) = delete;
+ void operator=(Instruction<TPrefix> const&) = delete;
+ static Instruction<TPrefix>*
get()
{
- static Instruction instance;
+ static Instruction<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Instruction"; }
+ static std::string
+ toString()
+ {
+ return TPrefix::toString() + "Instruction";
+ }
std::string
getUnitString() const override
{
@@ -175,123 +221,129 @@
}
};
+template <typename TPrefix>
class MicroOp : public Base
{
private:
- MicroOp() {}
+ MicroOp<TPrefix>() {}
public:
- MicroOp(MicroOp const&) = delete;
- void operator=(MicroOp const&) = delete;
- static MicroOp*
+ MicroOp<TPrefix>(MicroOp<TPrefix> const&) = delete;
+ void operator=(MicroOp<TPrefix> const&) = delete;
+ static MicroOp<TPrefix>*
get()
{
- static MicroOp instance;
+ static MicroOp<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "MicroOp"; }
+ static std::string toString() { return TPrefix::toString()
+ "MicroOp"; }
std::string getUnitString() const override { return
MicroOp::toString(); }
};
+template <typename TPrefix>
class Bit : public Base
{
private:
- Bit() {}
+ Bit<TPrefix>() {}
public:
- Bit(Bit const&) = delete;
- void operator=(Bit const&) = delete;
- static Bit*
+ Bit<TPrefix>(Bit<TPrefix> const&) = delete;
+ void operator=(Bit<TPrefix> const&) = delete;
+ static Bit<TPrefix>*
get()
{
- static Bit instance;
+ static Bit<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Bit"; }
+ static std::string toString() { return TPrefix::toString() + "Bit"; }
std::string getUnitString() const override { return Bit::toString(); }
};
+template <typename TPrefix>
class Byte : public Base
{
private:
- Byte() {}
+ Byte<TPrefix>() {}
public:
- Byte(Byte const&) = delete;
- void operator=(Byte const&) = delete;
- static Byte*
+ Byte<TPrefix>(Byte<TPrefix> const&) = delete;
+ void operator=(Byte<TPrefix> const&) = delete;
+ static Byte<TPrefix>*
get()
{
- static Byte instance;
+ static Byte<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Byte"; }
+ static std::string toString() { return TPrefix::toString() + "Byte"; }
std::string getUnitString() const override { return Byte::toString(); }
};
+template <typename TPrefix>
class Watt : public Base
{
private:
- Watt() {}
+ Watt<TPrefix>() {}
public:
- Watt(Watt const&) = delete;
- void operator=(Watt const&) = delete;
- static Watt*
+ Watt<TPrefix>(Watt<TPrefix> const&) = delete;
+ void operator=(Watt<TPrefix> const&) = delete;
+ static Watt<TPrefix>*
get()
{
- static Watt instance;
+ static Watt<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Watt"; }
+ static std::string toString() { return TPrefix::toString() + "Watt"; }
std::string getUnitString() const override { return Watt::toString(); }
};
-
+template <typename TPrefix>
class Joule : public Base
{
private:
- Joule() {}
+ Joule<TPrefix>() {}
public:
- Joule(Joule const&) = delete;
- void operator=(Joule const&) = delete;
- static Joule*
+ Joule<TPrefix>(Joule<TPrefix> const&) = delete;
+ void operator=(Joule<TPrefix> const&) = delete;
+ static Joule<TPrefix>*
get()
{
- static Joule instance;
+ static Joule<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Joule"; }
+ static std::string toString() { return TPrefix::toString() + "Joule"; }
std::string getUnitString() const override { return Joule::toString();
}
};
+template <typename TPrefix>
class Volt : public Base
{
private:
- Volt() {}
+ Volt<TPrefix>() {}
public:
- Volt(Volt const&) = delete;
- void operator=(Volt const&) = delete;
- static Volt*
+ Volt<TPrefix>(Volt<TPrefix> const&) = delete;
+ void operator=(Volt<TPrefix> const&) = delete;
+ static Volt<TPrefix>*
get()
{
- static Volt instance;
+ static Volt<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Volt"; }
+ static std::string toString() { return TPrefix::toString() + "Volt"; }
std::string getUnitString() const override { return Volt::toString(); }
};
+template <typename TPrefix>
class DegreeCelsius : public Base
{
private:
- DegreeCelsius() {}
+ DegreeCelsius<TPrefix>() {}
public:
- DegreeCelsius(DegreeCelsius const&) = delete;
- void operator=(DegreeCelsius const&) = delete;
- static DegreeCelsius*
+ DegreeCelsius<TPrefix>(DegreeCelsius<TPrefix> const&) = delete;
+ void operator=(DegreeCelsius<TPrefix> const&) = delete;
+ static DegreeCelsius<TPrefix>*
get()
{
- static DegreeCelsius instance;
+ static DegreeCelsius<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Celsius"; }
+ static std::string toString() { return TPrefix::toString()
+ "Celsius"; }
std::string
getUnitString() const override
{
@@ -299,21 +351,21 @@
}
};
-
+template <typename TPrefix>
class Count : public Base
{
private:
- Count() {}
+ Count<TPrefix>() {}
public:
- Count(Count const&) = delete;
- void operator=(Count const&) = delete;
- static Count*
+ Count<TPrefix>(Count<TPrefix> const&) = delete;
+ void operator=(Count<TPrefix> const&) = delete;
+ static Count<TPrefix>*
get()
{
- static Count instance;
+ static Count<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Count"; }
+ static std::string toString() { return TPrefix::toString() + "Count"; }
std::string getUnitString() const override { return Count::toString();
}
};
@@ -349,20 +401,21 @@
}
};
+template <typename TPrefix>
class Ratio : public Base
{
private:
- Ratio() {}
+ Ratio<TPrefix>() {}
public:
- Ratio(Ratio const&) = delete;
- void operator=(Ratio const&) = delete;
- static Ratio*
+ Ratio<TPrefix>(Ratio<TPrefix> const&) = delete;
+ void operator=(Ratio<TPrefix> const&) = delete;
+ static Ratio<TPrefix>*
get()
{
- static Ratio instance;
+ static Ratio<TPrefix> instance;
return &instance;
}
- static std::string toString() { return "Ratio"; }
+ static std::string toString() { return TPrefix::toString() + "Ratio"; }
std::string getUnitString() const override { return Ratio::toString();
}
};
diff --git a/src/cpu/base.cc b/src/cpu/base.cc
index f98837c..17f6f26 100644
--- a/src/cpu/base.cc
+++ b/src/cpu/base.cc
@@ -737,10 +737,12 @@
ADD_STAT(simOps, UNIT_COUNT,
"Number of ops (including micro ops) simulated"),
ADD_STAT(hostInstRate,
- UNIT_RATE(Stats::Units::Count, Stats::Units::Second),
+ UNIT_RATE(Stats::Units::Count,\
+ Stats::Units::Second),
"Simulator instruction rate (inst/s)"),
ADD_STAT(hostOpRate,
- UNIT_RATE(Stats::Units::Count, Stats::Units::Second),
+ UNIT_RATE(Stats::Units::Count,\
+ Stats::Units::Second),
"Simulator op (including micro ops) rate (op/s)")
{
simInsts
diff --git a/src/cpu/minor/stats.cc b/src/cpu/minor/stats.cc
index 8c29cd4..1c9af25 100644
--- a/src/cpu/minor/stats.cc
+++ b/src/cpu/minor/stats.cc
@@ -53,9 +53,11 @@
ADD_STAT(quiesceCycles, UNIT_CYCLE,
"Total number of cycles that CPU has spent quiesced or
waiting "
"for an interrupt"),
- ADD_STAT(cpi, UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
+ ADD_STAT(cpi, UNIT_RATE(Stats::Units::Cycle,
+ Stats::Units::Count),
"CPI: cycles per instruction"),
- ADD_STAT(ipc, UNIT_RATE(Stats::Units::Count, Stats::Units::Cycle),
+ ADD_STAT(ipc, UNIT_RATE(Stats::Units::Count,
+ Stats::Units::Cycle),
"IPC: instructions per cycle"),
ADD_STAT(committedInstType, UNIT_COUNT, "Class of committed
instruction")
{
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40993
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ic15f2933f731bb032f27885b6e3ee71efc365712
Gerrit-Change-Number: 40993
Gerrit-PatchSet: 1
Gerrit-Owner: Hoa Nguyen <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s