gem5  v22.1.0.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
gem5::statistics::HistStor Class Reference

Templatized storage and interface for a histogram stat. More...

#include <storage.hh>

Classes

struct  Params
 The parameters for a distribution stat. More...
 

Public Member Functions

 HistStor (const StorageParams *const storage_params)
 
void add (HistStor *other)
 Adds the contents of the given storage to this storage. More...
 
void sample (Counter val, int number)
 Add a value to the distribution for the given number of times. More...
 
size_type size () const
 Return the number of buckets in this distribution. More...
 
bool zero () const
 Returns true if any calls to sample have been made. More...
 
void prepare (const StorageParams *const storage_params, DistData &data)
 
void reset (const StorageParams *const storage_params)
 Reset stat value to default. More...
 

Private Member Functions

void growUp ()
 Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the positive infinite; that is, double the upper range of this storage so that the range becomes [0, 2*N]. More...
 
void growOut ()
 Given a bucket size B, and a range of values [M, N], where M < 0, this function doubles the bucket size to double the range of values towards both positive and negative infinites; that is, it doubles both the lower and the upper range of this storage so that the range becomes [2*M, 2*N]. More...
 
void growDown ()
 Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the negative infinite; that is, it doubles the lower range of this storage so that the middle buckes contaihs zero as a lower bound. More...
 

Private Attributes

Counter min_bucket
 Lower bound of the first bucket's range. More...
 
Counter max_bucket
 Lower bound of the last bucket's range. More...
 
Counter bucket_size
 The number of entries in each bucket. More...
 
Counter sum
 The current sum. More...
 
Counter logs
 The sum of logarithm of each sample, used to compute geometric mean. More...
 
Counter squares
 The sum of squares. More...
 
Counter samples
 The number of samples. More...
 
VCounter cvec
 Counter for each bucket. More...
 

Detailed Description

Templatized storage and interface for a histogram stat.

The number of buckets is fixed on initialization; however, the bucket size isn't. That means that when samples that are outside the current range are seen, the bucket size will be increased so that each bucket can hold a bigger range of values. When that happens, the bucket's contents are re- located.

The min and max bucket values can only be, respectively, decreased and increased when sampling. If this wasn't true, samples that were previously within the buclet range could not be anymore within the valid range, making the storage's state incoherent. These values are set back to their initial states on reset().

The bucket range always is zero-centric. While the storage does not contain negative values the bucket range will keep its lower bound at zero, doubling the upper bound when needed; However, as soon a negative value is sampled, zero becomes the lower bound of the middle (rounded up) bucket. Although this means that the histogram will not be symmetric if negative values are sampled, it makes it possible to grow the buckets without keeping track of the individual values.

This happens because if zero was not a lower or upper bound, when its value was doubled, the lower and upper bound of the bucket containing zero would intersect with middle values of the previous and next buckets. For example, if the bucket containing zero has range [-2,2[, therefore its neighbor buckets would have ranges at [-6,-2[ and [2,6[. When the buckets are grown, the zero bucket would grow its range to [-4,4[, which cannot be easily extracted from the neighor buckets.

Definition at line 399 of file storage.hh.

Constructor & Destructor Documentation

◆ HistStor()

gem5::statistics::HistStor::HistStor ( const StorageParams *const  storage_params)
inline

Definition at line 474 of file storage.hh.

References reset().

Member Function Documentation

◆ add()

void gem5::statistics::HistStor::add ( HistStor other)

Adds the contents of the given storage to this storage.

Parameters
otherThe other storage to be added.

Definition at line 210 of file storage.cc.

References bucket_size, cvec, growUp(), gem5::ArmISA::i, logs, min_bucket, samples, size(), squares, and sum.

Referenced by TEST().

◆ growDown()

void gem5::statistics::HistStor::growDown ( )
private

Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the negative infinite; that is, it doubles the lower range of this storage so that the middle buckes contaihs zero as a lower bound.

As such, the storage range becomes [-N, N+B] if there is an odd number of buckets, and [-N-B, N+B] if there is an even number of buckets.

Because the bucket size is doubled, the buckets contents are rearranged, and the original range of values are redistributed to free buckets for the newly appended ranges.

Definition at line 116 of file storage.cc.

References bucket_size, cvec, gem5::ArmISA::i, max_bucket, min_bucket, size(), and zero().

Referenced by sample().

◆ growOut()

void gem5::statistics::HistStor::growOut ( )
private

Given a bucket size B, and a range of values [M, N], where M < 0, this function doubles the bucket size to double the range of values towards both positive and negative infinites; that is, it doubles both the lower and the upper range of this storage so that the range becomes [2*M, 2*N].

Because the bucket size is doubled, the buckets contents are rearranged, and the original range of values are redistributed to free buckets for the newly appended ranges.

Definition at line 77 of file storage.cc.

References bucket_size, cvec, gem5::ArmISA::i, max_bucket, min_bucket, size(), and zero().

Referenced by sample().

◆ growUp()

void gem5::statistics::HistStor::growUp ( )
private

Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the positive infinite; that is, double the upper range of this storage so that the range becomes [0, 2*N].

Because the bucket size is doubled, the buckets contents are rearranged, since the original range of values is mapped to the lower half buckets.

Definition at line 155 of file storage.cc.

References bucket_size, cvec, gem5::ArmISA::i, max_bucket, and size().

Referenced by add(), and sample().

◆ prepare()

void gem5::statistics::HistStor::prepare ( const StorageParams *const  storage_params,
DistData data 
)
inline

◆ reset()

void gem5::statistics::HistStor::reset ( const StorageParams *const  storage_params)
inline

Reset stat value to default.

Definition at line 538 of file storage.hh.

References bucket_size, gem5::statistics::HistStor::Params::buckets, cvec, gem5::ArmISA::i, logs, max_bucket, min_bucket, samples, size(), squares, and sum.

Referenced by HistStor(), and TEST().

◆ sample()

void gem5::statistics::HistStor::sample ( Counter  val,
int  number 
)

Add a value to the distribution for the given number of times.

Parameters
valThe value to add.
numberThe number of times to add the value.

Definition at line 177 of file storage.cc.

References bucket_size, cvec, growDown(), growOut(), growUp(), gem5::MipsISA::index, logs, max_bucket, min_bucket, samples, size(), squares, sum, and gem5::X86ISA::val.

Referenced by prepareCheckHistStor(), and TEST().

◆ size()

size_type gem5::statistics::HistStor::size ( ) const
inline

Return the number of buckets in this distribution.

Returns
the number of buckets.

Definition at line 497 of file storage.hh.

References cvec.

Referenced by add(), growDown(), growOut(), growUp(), reset(), sample(), and TEST().

◆ zero()

bool gem5::statistics::HistStor::zero ( ) const
inline

Returns true if any calls to sample have been made.

Returns
True if any values have been sampled.

Definition at line 504 of file storage.hh.

References samples.

Referenced by growDown(), growOut(), and TEST().

Member Data Documentation

◆ bucket_size

Counter gem5::statistics::HistStor::bucket_size
private

The number of entries in each bucket.

Definition at line 407 of file storage.hh.

Referenced by add(), growDown(), growOut(), growUp(), prepare(), reset(), and sample().

◆ cvec

VCounter gem5::statistics::HistStor::cvec
private

Counter for each bucket.

Definition at line 418 of file storage.hh.

Referenced by add(), growDown(), growOut(), growUp(), prepare(), reset(), sample(), and size().

◆ logs

Counter gem5::statistics::HistStor::logs
private

The sum of logarithm of each sample, used to compute geometric mean.

Definition at line 412 of file storage.hh.

Referenced by add(), prepare(), reset(), and sample().

◆ max_bucket

Counter gem5::statistics::HistStor::max_bucket
private

Lower bound of the last bucket's range.

Definition at line 405 of file storage.hh.

Referenced by growDown(), growOut(), growUp(), prepare(), reset(), and sample().

◆ min_bucket

Counter gem5::statistics::HistStor::min_bucket
private

Lower bound of the first bucket's range.

Definition at line 403 of file storage.hh.

Referenced by add(), growDown(), growOut(), prepare(), reset(), and sample().

◆ samples

Counter gem5::statistics::HistStor::samples
private

The number of samples.

Definition at line 416 of file storage.hh.

Referenced by add(), prepare(), reset(), sample(), and zero().

◆ squares

Counter gem5::statistics::HistStor::squares
private

The sum of squares.

Definition at line 414 of file storage.hh.

Referenced by add(), prepare(), reset(), and sample().

◆ sum

Counter gem5::statistics::HistStor::sum
private

The current sum.

Definition at line 410 of file storage.hh.

Referenced by add(), prepare(), reset(), and sample().


The documentation for this class was generated from the following files:

Generated on Wed Dec 21 2022 10:24:27 for gem5 by doxygen 1.9.1