gem5  v22.1.0.0
units.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __BASE_STATS_UNITS_HH__
30 #define __BASE_STATS_UNITS_HH__
31 
32 #include <type_traits>
33 
34 #include "base/compiler.hh"
35 #include "base/cprintf.hh"
36 
37 namespace gem5
38 {
39 
43 #define UNIT_CYCLE GEM5_DEPRECATED_MACRO( \
44  UNIT_CYCLE, statistics::units::Cycle::get(), \
45  "Use statistics::units::Cycle::get()")
46 #define UNIT_TICK GEM5_DEPRECATED_MACRO( \
47  UNIT_TICK, statistics::units::Tick::get(), "Use statistics::units::Tick::get()")
48 #define UNIT_SECOND GEM5_DEPRECATED_MACRO( \
49  UNIT_SECOND, statistics::units::Second::get(), \
50  "Use statistics::units::Second::get()")
51 #define UNIT_BIT GEM5_DEPRECATED_MACRO( \
52  UNIT_BIT, statistics::units::Bit::get(), "Use statistics::units::Bit::get()")
53 #define UNIT_BYTE GEM5_DEPRECATED_MACRO( \
54  UNIT_BYTE, statistics::units::Byte::get(), "Use statistics::units::Byte::get()")
55 #define UNIT_JOULE GEM5_DEPRECATED_MACRO( \
56  UNIT_JOULE, statistics::units::Joule::get(), \
57  "Use statistics::units::Joule::get()")
58 #define UNIT_VOLT GEM5_DEPRECATED_MACRO( \
59  UNIT_VOLD, statistics::units::Volt::get(), "Use statistics::units::Volt::get()")
60 #define UNIT_CELSIUS GEM5_DEPRECATED_MACRO( \
61  UNIT_CELSIUS, statistics::units::DegreeCelsius::get(), \
62  "Use statistics::units::DegreeCelsius::get()")
63 #define UNIT_RATE(T1, T2) GEM5_DEPRECATED_MACRO( \
64  UNIT_RATE, (statistics::units::Rate<T1, T2>::get()), \
65  "Use statistics::units::Rate<T1, T2>::get()")
66 #define UNIT_RATIO GEM5_DEPRECATED_MACRO( \
67  UNIT_RATIO, statistics::units::Ratio::get(), \
68  "Use statistics::units::Ratio::get()")
69 #define UNIT_COUNT GEM5_DEPRECATED_MACRO( \
70  UNIT_COUNT, statistics::units::Count::get(), \
71  "Use statistics::units::Count::get()")
72 #define UNIT_WATT GEM5_DEPRECATED_MACRO( \
73  UNIT_WATT, statistics::units::Watt::get(), "Use statistics::units::Watt::get()")
74 #define UNIT_UNSPECIFIED GEM5_DEPRECATED_MACRO( \
75  UNIT_UNSPECIFIED, statistics::units::Unspecified::get(), \
76  "Use statistics::units::Unspecified::get()")
77 
78 GEM5_DEPRECATED_NAMESPACE(Stats, statistics);
79 namespace statistics
80 {
81 
114 namespace units
115 {
116 
122 class Base
123 {
124  public:
125  virtual std::string getUnitString() const = 0;
126 };
127 
128 class Cycle : public Base
129 {
130  private:
131  Cycle() {}
132  public:
133  Cycle(Cycle const&) = delete;
134  void operator=(Cycle const&) = delete;
135  static Cycle*
136  get()
137  {
138  static Cycle instance;
139  return &instance;
140  }
141  static std::string toString() { return "Cycle"; }
142  std::string getUnitString() const override { return Cycle::toString(); }
143 };
144 
145 class Tick : public Base
146 {
147  private:
148  Tick() {}
149  public:
150  Tick(Tick const&) = delete;
151  void operator=(Tick const&) = delete;
152  static Tick*
153  get()
154  {
155  static Tick instance;
156  return &instance;
157  }
158  static std::string toString() { return "Tick"; }
159  std::string getUnitString() const override { return Tick::toString(); }
160 };
161 
162 class Second : public Base
163 {
164  private:
165  Second() {}
166  public:
167  Second(Second const&) = delete;
168  void operator=(Second const&) = delete;
169  static Second*
170  get()
171  {
172  static Second instance;
173  return &instance;
174  }
175  static std::string toString() { return "Second"; }
176  std::string getUnitString() const override { return Second::toString(); }
177 };
178 
179 class Bit : public Base
180 {
181  private:
182  Bit() {}
183  public:
184  Bit(Bit const&) = delete;
185  void operator=(Bit const&) = delete;
186  static Bit*
187  get()
188  {
189  static Bit instance;
190  return &instance;
191  }
192  static std::string toString() { return "Bit"; }
193  std::string getUnitString() const override { return Bit::toString(); }
194 };
195 
196 class Byte : public Base
197 {
198  private:
199  Byte() {}
200  public:
201  Byte(Byte const&) = delete;
202  void operator=(Byte const&) = delete;
203  static Byte*
204  get()
205  {
206  static Byte instance;
207  return &instance;
208  }
209  static std::string toString() { return "Byte"; }
210  std::string getUnitString() const override { return Byte::toString(); }
211 };
212 
213 class Watt : public Base
214 {
215  private:
216  Watt() {}
217  public:
218  Watt(Watt const&) = delete;
219  void operator=(Watt const&) = delete;
220  static Watt*
221  get()
222  {
223  static Watt instance;
224  return &instance;
225  }
226  static std::string toString() { return "Watt"; }
227  std::string getUnitString() const override { return Watt::toString(); }
228 };
229 
230 
231 class Joule : public Base
232 {
233  private:
234  Joule() {}
235  public:
236  Joule(Joule const&) = delete;
237  void operator=(Joule const&) = delete;
238  static Joule*
239  get()
240  {
241  static Joule instance;
242  return &instance;
243  }
244  static std::string toString() { return "Joule"; }
245  std::string getUnitString() const override { return Joule::toString(); }
246 };
247 
248 class Volt : public Base
249 {
250  private:
251  Volt() {}
252  public:
253  Volt(Volt const&) = delete;
254  void operator=(Volt const&) = delete;
255  static Volt*
256  get()
257  {
258  static Volt instance;
259  return &instance;
260  }
261  static std::string toString() { return "Volt"; }
262  std::string getUnitString() const override { return Volt::toString(); }
263 };
264 
265 class DegreeCelsius : public Base
266 {
267  private:
269  public:
270  DegreeCelsius(DegreeCelsius const&) = delete;
271  void operator=(DegreeCelsius const&) = delete;
272  static DegreeCelsius*
273  get()
274  {
275  static DegreeCelsius instance;
276  return &instance;
277  }
278  static std::string toString() { return "Celsius"; }
279  std::string
280  getUnitString() const override
281  {
282  return DegreeCelsius::toString();
283  }
284 };
285 
286 
287 class Count : public Base
288 {
289  private:
290  Count() {}
291  public:
292  Count(Count const&) = delete;
293  void operator=(Count const&) = delete;
294  static Count*
295  get()
296  {
297  static Count instance;
298  return &instance;
299  }
300  static std::string toString() { return "Count"; }
301  std::string getUnitString() const override { return Count::toString(); }
302 };
303 
304 class Ratio : public Base
305 {
306  private:
307  Ratio() {}
308  public:
309  Ratio(Ratio const&) = delete;
310  void operator=(Ratio const&) = delete;
311  static Ratio*
312  get()
313  {
314  static Ratio instance;
315  return &instance;
316  }
317  static std::string toString() { return "Ratio"; }
318  std::string getUnitString() const override { return Ratio::toString(); }
319 };
320 
321 class Unspecified : public Base
322 {
323  private:
325  public:
326  Unspecified(Unspecified const&) = delete;
327  void operator=(Unspecified const&) = delete;
328  static Unspecified*
329  get()
330  {
331  static Unspecified instance;
332  return &instance;
333  }
334  static std::string toString() { return "Unspecified"; }
335  std::string
336  getUnitString() const override
337  {
338  return Unspecified::toString();
339  }
340 };
341 
342 template <typename T1, typename T2>
343 class Rate : public Base
344 {
345  static_assert(std::is_base_of_v<Base, T1>, "Rate(T1,T2) must have "
346  "T1 and T2 derived from statistics::units::Base");
347  static_assert(std::is_base_of_v<Base, T2>, "Rate(T1,T2) must have "
348  "T1 and T2 derived from statistics::units::Base");
349  static_assert(!std::is_same_v<T1, T2> || std::is_same_v<T1, Count> ||
350  std::is_same_v<T1, Unspecified>,
351  "Rate(T1,T2) must have T1 and T2 of different types; "
352  "otherwise, it would be a Ratio");
353 
354  private:
355  Rate<T1,T2>() {}
356  public:
357  Rate<T1,T2>(Rate<T1,T2> const&) = delete;
358  void operator=(Rate<T1,T2> const&) = delete;
359  static Rate<T1,T2>*
360  get()
361  {
362  static Rate<T1,T2> instance;
363  return &instance;
364  }
365  static std::string
367  {
368  return csprintf("(%s/%s)", T1::toString(), T2::toString());
369  }
370  std::string
371  getUnitString() const override
372  {
373  return Rate<T1,T2>::toString();
374  }
375 };
376 
377 } // namespace units
378 } // namespace statistics
379 } // namespace gem5
380 
381 #endif // __BASE_STATS_UNITS_HH__
The Base class is the parent class of all unit classes.
Definition: units.hh:123
virtual std::string getUnitString() const =0
void operator=(Bit const &)=delete
static Bit * get()
Definition: units.hh:187
static std::string toString()
Definition: units.hh:192
std::string getUnitString() const override
Definition: units.hh:193
Bit(Bit const &)=delete
static Byte * get()
Definition: units.hh:204
std::string getUnitString() const override
Definition: units.hh:210
Byte(Byte const &)=delete
static std::string toString()
Definition: units.hh:209
void operator=(Byte const &)=delete
Count(Count const &)=delete
std::string getUnitString() const override
Definition: units.hh:301
void operator=(Count const &)=delete
static std::string toString()
Definition: units.hh:300
static Count * get()
Definition: units.hh:295
static std::string toString()
Definition: units.hh:141
static Cycle * get()
Definition: units.hh:136
void operator=(Cycle const &)=delete
std::string getUnitString() const override
Definition: units.hh:142
Cycle(Cycle const &)=delete
static DegreeCelsius * get()
Definition: units.hh:273
std::string getUnitString() const override
Definition: units.hh:280
DegreeCelsius(DegreeCelsius const &)=delete
void operator=(DegreeCelsius const &)=delete
static std::string toString()
Definition: units.hh:278
std::string getUnitString() const override
Definition: units.hh:245
static Joule * get()
Definition: units.hh:239
void operator=(Joule const &)=delete
Joule(Joule const &)=delete
static std::string toString()
Definition: units.hh:244
static std::string toString()
Definition: units.hh:366
static Rate< T1, T2 > * get()
Definition: units.hh:360
void operator=(Rate< T1, T2 > const &)=delete
std::string getUnitString() const override
Definition: units.hh:371
void operator=(Ratio const &)=delete
static Ratio * get()
Definition: units.hh:312
static std::string toString()
Definition: units.hh:317
Ratio(Ratio const &)=delete
std::string getUnitString() const override
Definition: units.hh:318
std::string getUnitString() const override
Definition: units.hh:176
void operator=(Second const &)=delete
Second(Second const &)=delete
static std::string toString()
Definition: units.hh:175
static Second * get()
Definition: units.hh:170
static std::string toString()
Definition: units.hh:158
static Tick * get()
Definition: units.hh:153
Tick(Tick const &)=delete
std::string getUnitString() const override
Definition: units.hh:159
void operator=(Tick const &)=delete
static std::string toString()
Definition: units.hh:334
std::string getUnitString() const override
Definition: units.hh:336
void operator=(Unspecified const &)=delete
Unspecified(Unspecified const &)=delete
static Unspecified * get()
Definition: units.hh:329
Volt(Volt const &)=delete
static Volt * get()
Definition: units.hh:256
void operator=(Volt const &)=delete
std::string getUnitString() const override
Definition: units.hh:262
static std::string toString()
Definition: units.hh:261
void operator=(Watt const &)=delete
static std::string toString()
Definition: units.hh:226
std::string getUnitString() const override
Definition: units.hh:227
Watt(Watt const &)=delete
static Watt * get()
Definition: units.hh:221
GEM5_DEPRECATED_NAMESPACE(Units, units)
Units for Stats.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1