gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
37namespace 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
78namespace statistics
79{
80
112namespace units
113{
114
120class Base
121{
122 public:
123 virtual std::string getUnitString() const = 0;
124};
125
126class Cycle : public Base
127{
128 private:
129 Cycle() {}
130 public:
131 Cycle(Cycle const&) = delete;
132 void operator=(Cycle const&) = delete;
133 static Cycle*
135 {
136 static Cycle instance;
137 return &instance;
138 }
139 static std::string toString() { return "Cycle"; }
140 std::string getUnitString() const override { return Cycle::toString(); }
141};
142
143class Tick : public Base
144{
145 private:
146 Tick() {}
147 public:
148 Tick(Tick const&) = delete;
149 void operator=(Tick const&) = delete;
150 static Tick*
152 {
153 static Tick instance;
154 return &instance;
155 }
156 static std::string toString() { return "Tick"; }
157 std::string getUnitString() const override { return Tick::toString(); }
158};
159
160class Second : public Base
161{
162 private:
164 public:
165 Second(Second const&) = delete;
166 void operator=(Second const&) = delete;
167 static Second*
169 {
170 static Second instance;
171 return &instance;
172 }
173 static std::string toString() { return "Second"; }
174 std::string getUnitString() const override { return Second::toString(); }
175};
176
177class Bit : public Base
178{
179 private:
180 Bit() {}
181 public:
182 Bit(Bit const&) = delete;
183 void operator=(Bit const&) = delete;
184 static Bit*
186 {
187 static Bit instance;
188 return &instance;
189 }
190 static std::string toString() { return "Bit"; }
191 std::string getUnitString() const override { return Bit::toString(); }
192};
193
194class Byte : public Base
195{
196 private:
197 Byte() {}
198 public:
199 Byte(Byte const&) = delete;
200 void operator=(Byte const&) = delete;
201 static Byte*
203 {
204 static Byte instance;
205 return &instance;
206 }
207 static std::string toString() { return "Byte"; }
208 std::string getUnitString() const override { return Byte::toString(); }
209};
210
211class Watt : public Base
212{
213 private:
214 Watt() {}
215 public:
216 Watt(Watt const&) = delete;
217 void operator=(Watt const&) = delete;
218 static Watt*
220 {
221 static Watt instance;
222 return &instance;
223 }
224 static std::string toString() { return "Watt"; }
225 std::string getUnitString() const override { return Watt::toString(); }
226};
227
228
229class Joule : public Base
230{
231 private:
232 Joule() {}
233 public:
234 Joule(Joule const&) = delete;
235 void operator=(Joule const&) = delete;
236 static Joule*
238 {
239 static Joule instance;
240 return &instance;
241 }
242 static std::string toString() { return "Joule"; }
243 std::string getUnitString() const override { return Joule::toString(); }
244};
245
246class Volt : public Base
247{
248 private:
249 Volt() {}
250 public:
251 Volt(Volt const&) = delete;
252 void operator=(Volt const&) = delete;
253 static Volt*
255 {
256 static Volt instance;
257 return &instance;
258 }
259 static std::string toString() { return "Volt"; }
260 std::string getUnitString() const override { return Volt::toString(); }
261};
262
263class DegreeCelsius : public Base
264{
265 private:
267 public:
268 DegreeCelsius(DegreeCelsius const&) = delete;
269 void operator=(DegreeCelsius const&) = delete;
270 static DegreeCelsius*
272 {
273 static DegreeCelsius instance;
274 return &instance;
275 }
276 static std::string toString() { return "Celsius"; }
277 std::string
278 getUnitString() const override
279 {
281 }
282};
283
284
285class Count : public Base
286{
287 private:
288 Count() {}
289 public:
290 Count(Count const&) = delete;
291 void operator=(Count const&) = delete;
292 static Count*
294 {
295 static Count instance;
296 return &instance;
297 }
298 static std::string toString() { return "Count"; }
299 std::string getUnitString() const override { return Count::toString(); }
300};
301
302class Ratio : public Base
303{
304 private:
305 Ratio() {}
306 public:
307 Ratio(Ratio const&) = delete;
308 void operator=(Ratio const&) = delete;
309 static Ratio*
311 {
312 static Ratio instance;
313 return &instance;
314 }
315 static std::string toString() { return "Ratio"; }
316 std::string getUnitString() const override { return Ratio::toString(); }
317};
318
319class Unspecified : public Base
320{
321 private:
323 public:
324 Unspecified(Unspecified const&) = delete;
325 void operator=(Unspecified const&) = delete;
326 static Unspecified*
328 {
329 static Unspecified instance;
330 return &instance;
331 }
332 static std::string toString() { return "Unspecified"; }
333 std::string
334 getUnitString() const override
335 {
336 return Unspecified::toString();
337 }
338};
339
340template <typename T1, typename T2>
341class Rate : public Base
342{
343 static_assert(std::is_base_of_v<Base, T1>, "Rate(T1,T2) must have "
344 "T1 and T2 derived from statistics::units::Base");
345 static_assert(std::is_base_of_v<Base, T2>, "Rate(T1,T2) must have "
346 "T1 and T2 derived from statistics::units::Base");
347 static_assert(!std::is_same_v<T1, T2> || std::is_same_v<T1, Count> ||
348 std::is_same_v<T1, Unspecified>,
349 "Rate(T1,T2) must have T1 and T2 of different types; "
350 "otherwise, it would be a Ratio");
351
352 private:
353 Rate<T1,T2>() {}
354 public:
355 Rate<T1,T2>(Rate<T1,T2> const&) = delete;
356 void operator=(Rate<T1,T2> const&) = delete;
357 static Rate<T1,T2>*
359 {
360 static Rate<T1,T2> instance;
361 return &instance;
362 }
363 static std::string
365 {
366 return csprintf("(%s/%s)", T1::toString(), T2::toString());
367 }
368 std::string
369 getUnitString() const override
370 {
371 return Rate<T1,T2>::toString();
372 }
373};
374
375} // namespace units
376} // namespace statistics
377} // namespace gem5
378
379#endif // __BASE_STATS_UNITS_HH__
The Base class is the parent class of all unit classes.
Definition units.hh:121
virtual std::string getUnitString() const =0
void operator=(Bit const &)=delete
static std::string toString()
Definition units.hh:190
std::string getUnitString() const override
Definition units.hh:191
Bit(Bit const &)=delete
std::string getUnitString() const override
Definition units.hh:208
Byte(Byte const &)=delete
static std::string toString()
Definition units.hh:207
void operator=(Byte const &)=delete
Count(Count const &)=delete
std::string getUnitString() const override
Definition units.hh:299
void operator=(Count const &)=delete
static std::string toString()
Definition units.hh:298
static std::string toString()
Definition units.hh:139
void operator=(Cycle const &)=delete
std::string getUnitString() const override
Definition units.hh:140
Cycle(Cycle const &)=delete
std::string getUnitString() const override
Definition units.hh:278
DegreeCelsius(DegreeCelsius const &)=delete
void operator=(DegreeCelsius const &)=delete
static DegreeCelsius * get()
Definition units.hh:271
static std::string toString()
Definition units.hh:276
std::string getUnitString() const override
Definition units.hh:243
void operator=(Joule const &)=delete
Joule(Joule const &)=delete
static std::string toString()
Definition units.hh:242
static std::string toString()
Definition units.hh:364
static Rate< T1, T2 > * get()
Definition units.hh:358
void operator=(Rate< T1, T2 > const &)=delete
std::string getUnitString() const override
Definition units.hh:369
void operator=(Ratio const &)=delete
static std::string toString()
Definition units.hh:315
Ratio(Ratio const &)=delete
std::string getUnitString() const override
Definition units.hh:316
std::string getUnitString() const override
Definition units.hh:174
void operator=(Second const &)=delete
Second(Second const &)=delete
static std::string toString()
Definition units.hh:173
static Second * get()
Definition units.hh:168
static std::string toString()
Definition units.hh:156
Tick(Tick const &)=delete
std::string getUnitString() const override
Definition units.hh:157
void operator=(Tick const &)=delete
static std::string toString()
Definition units.hh:332
std::string getUnitString() const override
Definition units.hh:334
void operator=(Unspecified const &)=delete
static Unspecified * get()
Definition units.hh:327
Unspecified(Unspecified const &)=delete
Volt(Volt const &)=delete
void operator=(Volt const &)=delete
std::string getUnitString() const override
Definition units.hh:260
static std::string toString()
Definition units.hh:259
void operator=(Watt const &)=delete
static std::string toString()
Definition units.hh:224
std::string getUnitString() const override
Definition units.hh:225
Watt(Watt const &)=delete
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0