gem5 v24.0.0.0
Loading...
Searching...
No Matches
storage.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Daniel R. Carvalho
3 * Copyright (c) 2003-2005 The Regents of The University of Michigan
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __BASE_STATS_STORAGE_HH__
31#define __BASE_STATS_STORAGE_HH__
32
33#include <cassert>
34#include <cmath>
35
36#include "base/cast.hh"
37#include "base/compiler.hh"
38#include "base/logging.hh"
39#include "base/stats/types.hh"
40#include "sim/cur_tick.hh"
41
42namespace gem5
43{
44
45namespace statistics
46{
47
49{
50 virtual ~StorageParams() = default;
51};
52
57{
58 private:
61
62 public:
63 struct Params : public StorageParams {};
64
69 StatStor(const StorageParams* const storage_params)
70 : data(Counter())
71 { }
72
77 void set(Counter val) { data = val; }
78
83 void inc(Counter val) { data += val; }
84
89 void dec(Counter val) { data -= val; }
90
95 Counter value() const { return data; }
96
101 Result result() const { return (Result)data; }
102
106 void prepare(const StorageParams* const storage_params) { }
107
111 void reset(const StorageParams* const storage_params) { data = Counter(); }
112
116 bool zero() const { return data == Counter(); }
117};
118
127{
128 private:
134 mutable Result total;
136 mutable Tick last;
137
138 public:
139 struct Params : public StorageParams {};
140
144 AvgStor(const StorageParams* const storage_params)
145 : current(0), lastReset(0), total(0), last(0)
146 { }
147
153 void
155 {
156 total += current * (curTick() - last);
157 last = curTick();
158 current = val;
159 }
160
165 void inc(Counter val) { set(current + val); }
166
171 void dec(Counter val) { set(current - val); }
172
177 Counter value() const { return current; }
178
183 Result
184 result() const
185 {
186 assert(last == curTick());
187 return (Result)(total + current) / (Result)(curTick() - lastReset + 1);
188 }
189
193 bool zero() const { return total == 0.0; }
194
198 void
199 prepare(const StorageParams* const storage_params)
200 {
201 total += current * (curTick() - last);
202 last = curTick();
203 }
204
208 void
209 reset(const StorageParams* const storage_params)
210 {
211 total = 0.0;
212 last = curTick();
213 lastReset = curTick();
214 }
215
216};
217
220{
223};
224
233{
234 private:
241
258
259 public:
261 struct Params : public DistParams
262 {
271
272 Params(Counter _min, Counter _max, Counter _bucket_size)
273 : DistParams(Dist), min(_min), max(_max), bucket_size(_bucket_size),
274 buckets(0)
275 {
277 "Bucket size (%f) must be greater than zero", bucket_size);
278 warn_if(std::floor((max - min + 1.0) / bucket_size) !=
279 std::ceil((max - min + 1.0) / bucket_size),
280 "Bucket size (%f) does not divide range [%f:%f] into equal-" \
281 "sized buckets. Rounding up.", bucket_size, min + 1.0, max);
282
283 buckets = std::ceil((max - min + 1.0) / bucket_size);
284 }
285 };
286
287 DistStor(const StorageParams* const storage_params)
288 : cvec(safe_cast<const Params *>(storage_params)->buckets)
289 {
290 reset(storage_params);
291 }
292
298 void sample(Counter val, int number);
299
304 size_type size() const { return cvec.size(); }
305
310 bool
311 zero() const
312 {
313 return samples == Counter();
314 }
315
316 void
317 prepare(const StorageParams* const storage_params, DistData &data)
318 {
319 const Params *params = safe_cast<const Params *>(storage_params);
320
321 assert(params->type == Dist);
322 data.type = params->type;
323 data.min = params->min;
324 data.max = params->max;
325 data.bucket_size = params->bucket_size;
326
327 data.min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
328 data.max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
329 data.underflow = underflow;
330 data.overflow = overflow;
331
332 data.cvec.resize(params->buckets);
333 for (off_type i = 0; i < params->buckets; ++i)
334 data.cvec[i] = cvec[i];
335
336 data.sum = sum;
337 data.squares = squares;
338 data.samples = samples;
339 }
340
344 void
345 reset(const StorageParams* const storage_params)
346 {
347 const Params *params = safe_cast<const Params *>(storage_params);
348 min_track = params->min;
349 max_track = params->max;
350 bucket_size = params->bucket_size;
351
352 min_val = CounterLimits::max();
353 max_val = CounterLimits::min();
354 underflow = Counter();
355 overflow = Counter();
356
357 size_type size = cvec.size();
358 for (off_type i = 0; i < size; ++i)
359 cvec[i] = Counter();
360
361 sum = Counter();
362 squares = Counter();
363 samples = Counter();
364 }
365};
366
399{
400 private:
407
418
428 void growUp();
429
441 void growOut();
442
455 void growDown();
456
457 public:
459 struct Params : public DistParams
460 {
463
466 {
467 fatal_if(_buckets < 2,
468 "There must be at least two buckets in a histogram");
469 buckets = _buckets;
470 }
471 };
472
473 HistStor(const StorageParams* const storage_params)
474 : cvec(safe_cast<const Params *>(storage_params)->buckets)
475 {
476 reset(storage_params);
477 }
478
483 void add(HistStor *other);
484
490 void sample(Counter val, int number);
491
496 size_type size() const { return cvec.size(); }
497
502 bool
503 zero() const
504 {
505 return samples == Counter();
506 }
507
508 void
509 prepare(const StorageParams* const storage_params, DistData &data)
510 {
511 const Params *params = safe_cast<const Params *>(storage_params);
512
513 assert(params->type == Hist);
514 data.type = params->type;
515 data.min = min_bucket;
516 data.max = max_bucket + bucket_size - 1;
517 data.bucket_size = bucket_size;
518
519 data.min_val = min_bucket;
520 data.max_val = max_bucket;
521
522 int buckets = params->buckets;
523 data.cvec.resize(buckets);
524 for (off_type i = 0; i < buckets; ++i)
525 data.cvec[i] = cvec[i];
526
527 data.sum = sum;
528 data.logs = logs;
529 data.squares = squares;
530 data.samples = samples;
531 }
532
536 void
537 reset(const StorageParams* const storage_params)
538 {
539 const Params *params = safe_cast<const Params *>(storage_params);
540 min_bucket = 0;
541 max_bucket = params->buckets - 1;
542 bucket_size = 1;
543
544 size_type size = cvec.size();
545 for (off_type i = 0; i < size; ++i)
546 cvec[i] = Counter();
547
548 sum = Counter();
549 squares = Counter();
550 samples = Counter();
551 logs = Counter();
552 }
553};
554
560{
561 private:
568
569 public:
570 struct Params : public DistParams
571 {
573 };
574
578 SampleStor(const StorageParams* const storage_params)
580 { }
581
589 void
590 sample(Counter val, int number)
591 {
592 sum += val * number;
593 squares += val * val * number;
594 samples += number;
595 }
596
601 size_type size() const { return 1; }
602
607 bool zero() const { return samples == Counter(); }
608
609 void
610 prepare(const StorageParams* const storage_params, DistData &data)
611 {
612 const Params *params = safe_cast<const Params *>(storage_params);
613
614 assert(params->type == Deviation);
615 data.type = params->type;
616 data.sum = sum;
617 data.squares = squares;
618 data.samples = samples;
619 }
620
624 void
625 reset(const StorageParams* const storage_params)
626 {
627 sum = Counter();
628 squares = Counter();
629 samples = Counter();
630 }
631};
632
638{
639 private:
644
645 public:
646 struct Params : public DistParams
647 {
649 };
650
654 AvgSampleStor(const StorageParams* const storage_params)
655 : sum(Counter()), squares(Counter())
656 {}
657
664 void
665 sample(Counter val, int number)
666 {
667 sum += val * number;
668 squares += val * val * number;
669 }
670
675 size_type size() const { return 1; }
676
681 bool zero() const { return sum == Counter(); }
682
683 void
684 prepare(const StorageParams* const storage_params, DistData &data)
685 {
686 const Params *params = safe_cast<const Params *>(storage_params);
687
688 assert(params->type == Deviation);
689 data.type = params->type;
690 data.sum = sum;
691 data.squares = squares;
692 data.samples = curTick();
693 }
694
698 void
699 reset(const StorageParams* const storage_params)
700 {
701 sum = Counter();
702 squares = Counter();
703 }
704};
705
714{
715 private:
720
721 public:
723 struct Params : public DistParams
724 {
726 };
727
728 SparseHistStor(const StorageParams* const storage_params)
729 {
730 reset(storage_params);
731 }
732
738 void
739 sample(Counter val, int number)
740 {
741 cmap[val] += number;
742 samples += number;
743 }
744
749 size_type size() const { return cmap.size(); }
750
755 bool
756 zero() const
757 {
758 return samples == Counter();
759 }
760
761 void
762 prepare(const StorageParams* const storage_params, SparseHistData &data)
763 {
764 MCounter::iterator it;
765 data.cmap.clear();
766 for (it = cmap.begin(); it != cmap.end(); it++) {
767 data.cmap[(*it).first] = (*it).second;
768 }
769
770 data.samples = samples;
771 }
772
776 void
777 reset(const StorageParams* const storage_params)
778 {
779 cmap.clear();
780 samples = 0;
781 }
782};
783
784} // namespace statistics
785} // namespace gem5
786
787#endif // __BASE_STATS_STORAGE_HH__
const char data[]
Templatized storage for distribution that calculates per tick mean and variance.
Definition storage.hh:638
bool zero() const
Return true if no samples have been added.
Definition storage.hh:681
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:699
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition storage.hh:665
size_type size() const
Return the number of entries, in this case 1.
Definition storage.hh:675
AvgSampleStor(const StorageParams *const storage_params)
Create and initialize this storage.
Definition storage.hh:654
void prepare(const StorageParams *const storage_params, DistData &data)
Definition storage.hh:684
Counter squares
Current sum of squares.
Definition storage.hh:643
Counter sum
Current total.
Definition storage.hh:641
Templatized storage and interface to a per-tick average stat.
Definition storage.hh:127
Counter current
The current count.
Definition storage.hh:130
Counter value() const
Return the current count.
Definition storage.hh:177
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:209
Result total
The total count for all tick.
Definition storage.hh:134
void inc(Counter val)
Increment the current count by the provided value, calls set.
Definition storage.hh:165
Result result() const
Return the current average.
Definition storage.hh:184
Tick last
The tick that current last changed.
Definition storage.hh:136
void dec(Counter val)
Deccrement the current count by the provided value, calls set.
Definition storage.hh:171
Tick lastReset
The tick of the last reset.
Definition storage.hh:132
void prepare(const StorageParams *const storage_params)
Prepare stat data for dumping or serialization.
Definition storage.hh:199
AvgStor(const StorageParams *const storage_params)
Build and initializes this stat storage.
Definition storage.hh:144
void set(Counter val)
Set the current count to the one provided, update the total and last set values.
Definition storage.hh:154
Templatized storage and interface for a distribution stat.
Definition storage.hh:233
size_type size() const
Return the number of buckets in this distribution.
Definition storage.hh:304
Counter min_val
The smallest value sampled.
Definition storage.hh:243
Counter sum
The current sum.
Definition storage.hh:251
DistStor(const StorageParams *const storage_params)
Definition storage.hh:287
Counter samples
The number of samples.
Definition storage.hh:255
VCounter cvec
Counter for each bucket.
Definition storage.hh:257
Counter underflow
The number of values sampled less than min.
Definition storage.hh:247
Counter squares
The sum of squares.
Definition storage.hh:253
void prepare(const StorageParams *const storage_params, DistData &data)
Definition storage.hh:317
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition storage.cc:53
Counter min_track
The minimum value to track.
Definition storage.hh:236
Counter bucket_size
The number of entries in each bucket.
Definition storage.hh:240
Counter overflow
The number of values sampled more than max.
Definition storage.hh:249
Counter max_val
The largest value sampled.
Definition storage.hh:245
bool zero() const
Returns true if any calls to sample have been made.
Definition storage.hh:311
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:345
Counter max_track
The maximum value to track.
Definition storage.hh:238
Templatized storage and interface for a histogram stat.
Definition storage.hh:399
Counter sum
The current sum.
Definition storage.hh:409
Counter samples
The number of samples.
Definition storage.hh:415
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:537
void add(HistStor *other)
Adds the contents of the given storage to this storage.
Definition storage.cc:209
void growUp()
Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double ...
Definition storage.cc:154
HistStor(const StorageParams *const storage_params)
Definition storage.hh:473
Counter min_bucket
Lower bound of the first bucket's range.
Definition storage.hh:402
void growOut()
Given a bucket size B, and a range of values [M, N], where M < 0, this function doubles the bucket si...
Definition storage.cc:76
Counter bucket_size
The number of entries in each bucket.
Definition storage.hh:406
size_type size() const
Return the number of buckets in this distribution.
Definition storage.hh:496
VCounter cvec
Counter for each bucket.
Definition storage.hh:417
bool zero() const
Returns true if any calls to sample have been made.
Definition storage.hh:503
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition storage.cc:176
void growDown()
Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double ...
Definition storage.cc:115
void prepare(const StorageParams *const storage_params, DistData &data)
Definition storage.hh:509
Counter logs
The sum of logarithm of each sample, used to compute geometric mean.
Definition storage.hh:411
Counter max_bucket
Lower bound of the last bucket's range.
Definition storage.hh:404
Counter squares
The sum of squares.
Definition storage.hh:413
Templatized storage and interface for a distribution that calculates mean and variance.
Definition storage.hh:560
Counter sum
The current sum.
Definition storage.hh:563
size_type size() const
Return the number of entries in this stat, 1.
Definition storage.hh:601
bool zero() const
Return true if no samples have been added.
Definition storage.hh:607
Counter squares
The sum of squares.
Definition storage.hh:565
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:625
void prepare(const StorageParams *const storage_params, DistData &data)
Definition storage.hh:610
Counter samples
The number of samples.
Definition storage.hh:567
SampleStor(const StorageParams *const storage_params)
Create and initialize this storage.
Definition storage.hh:578
void sample(Counter val, int number)
Add a value the given number of times to this running average.
Definition storage.hh:590
Templatized storage and interface for a sparse histogram stat.
Definition storage.hh:714
size_type size() const
Return the number of buckets in this distribution.
Definition storage.hh:749
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:777
SparseHistStor(const StorageParams *const storage_params)
Definition storage.hh:728
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition storage.hh:739
Counter samples
Counter for number of samples.
Definition storage.hh:717
void prepare(const StorageParams *const storage_params, SparseHistData &data)
Definition storage.hh:762
bool zero() const
Returns true if any calls to sample have been made.
Definition storage.hh:756
MCounter cmap
Counter for each bucket.
Definition storage.hh:719
Templatized storage and interface for a simple scalar stat.
Definition storage.hh:57
void prepare(const StorageParams *const storage_params)
Prepare stat data for dumping or serialization.
Definition storage.hh:106
Result result() const
Return the value of this stat as a result type.
Definition storage.hh:101
StatStor(const StorageParams *const storage_params)
Builds this storage element and calls the base constructor of the datatype.
Definition storage.hh:69
void dec(Counter val)
Decrement the stat by the given value.
Definition storage.hh:89
Counter value() const
Return the value of this stat as its base type.
Definition storage.hh:95
void set(Counter val)
The the stat to the given value.
Definition storage.hh:77
void inc(Counter val)
Increment the stat by the given value.
Definition storage.hh:83
Counter data
The statistic value.
Definition storage.hh:60
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Definition storage.hh:111
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition logging.hh:283
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 12, 11 > set
Bitfield< 63 > val
Definition misc.hh:804
unsigned int size_type
Definition types.hh:59
std::map< Counter, int > MCounter
map of counters
Definition types.hh:50
double Counter
All counters are of 64-bit values.
Definition types.hh:46
unsigned int off_type
Definition types.hh:60
double Result
All results are doubles.
Definition types.hh:55
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
T safe_cast(U &&ref_or_ptr)
Definition cast.hh:74
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Tick
Tick count type.
Definition types.hh:58
General container for distribution data.
Definition types.hh:66
The parameters for a distribution stat.
Definition storage.hh:220
The parameters for a distribution stat.
Definition storage.hh:262
size_type buckets
The number of buckets.
Definition storage.hh:270
Counter max
The maximum value to track.
Definition storage.hh:266
Counter bucket_size
The number of entries in each bucket.
Definition storage.hh:268
Counter min
The minimum value to track.
Definition storage.hh:264
Params(Counter _min, Counter _max, Counter _bucket_size)
Definition storage.hh:272
The parameters for a distribution stat.
Definition storage.hh:460
size_type buckets
The number of buckets.
Definition storage.hh:462
Data structure of sparse histogram.
Definition types.hh:85
The parameters for a sparse histogram stat.
Definition storage.hh:724
virtual ~StorageParams()=default

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