base-stats: Use smart pointer for info's storageParams

Previously the storage params were not being deallocated.
Make sure this happens by managing it with smart pointers.

As a side effect, encapsulate this variable to facilitate
future changes.

Change-Id: I4c2496d08241f155793ed35e3463512d9ea06f83
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38178
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
Daniel R. Carvalho
2020-12-02 16:51:09 +01:00
committed by Daniel Carvalho
parent 70194795c3
commit bb596f55e3
4 changed files with 44 additions and 21 deletions

View File

@@ -99,7 +99,7 @@ InfoAccess::setInfo(Group *parent, Info *info)
void
InfoAccess::setParams(const StorageParams *params)
{
info()->storageParams = params;
info()->setStorageParams(params);
}
void

View File

@@ -440,7 +440,7 @@ class DataWrapVec : public DataWrap<Derived, InfoProxyType>
size_t size = self.size();
for (off_type i = 0; i < size; ++i)
self.data(i)->prepare(info->storageParams);
self.data(i)->prepare(info->getStorageParams());
}
void
@@ -451,7 +451,7 @@ class DataWrapVec : public DataWrap<Derived, InfoProxyType>
size_t size = self.size();
for (off_type i = 0; i < size; ++i)
self.data(i)->reset(info->storageParams);
self.data(i)->reset(info->getStorageParams());
}
};
@@ -551,7 +551,7 @@ class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
void
doInit()
{
new (storage) Storage(this->info()->storageParams);
new (storage) Storage(this->info()->getStorageParams());
this->setInit();
}
@@ -624,8 +624,8 @@ class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
bool zero() const { return result() == 0.0; }
void reset() { data()->reset(this->info()->storageParams); }
void prepare() { data()->prepare(this->info()->storageParams); }
void reset() { data()->reset(this->info()->getStorageParams()); }
void prepare() { data()->prepare(this->info()->getStorageParams()); }
};
class ProxyInfo : public ScalarInfo
@@ -952,7 +952,7 @@ class VectorBase : public DataWrapVec<Derived, VectorInfoProxy>
fatal_if(s <= 0, "Storage size must be positive");
fatal_if(check(), "Stat has already been initialized");
storage.resize(s, new Storage(this->info()->storageParams));
storage.resize(s, new Storage(this->info()->getStorageParams()));
this->setInit();
}
@@ -1178,7 +1178,7 @@ class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
info->x = _x;
info->y = _y;
storage.resize(x * y, new Storage(info->storageParams));
storage.resize(x * y, new Storage(info->getStorageParams()));
this->setInit();
return self;
@@ -1225,7 +1225,7 @@ class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
size_type size = this->size();
for (off_type i = 0; i < size; ++i)
data(i)->prepare(info->storageParams);
data(i)->prepare(info->getStorageParams());
info->cvec.resize(size);
for (off_type i = 0; i < size; ++i)
@@ -1241,7 +1241,7 @@ class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
Info *info = this->info();
size_type size = this->size();
for (off_type i = 0; i < size; ++i)
data(i)->reset(info->storageParams);
data(i)->reset(info->getStorageParams());
}
bool
@@ -1297,7 +1297,7 @@ class DistBase : public DataWrap<Derived, DistInfoProxy>
void
doInit()
{
new (storage) Storage(this->info()->storageParams);
new (storage) Storage(this->info()->getStorageParams());
this->setInit();
}
@@ -1333,7 +1333,7 @@ class DistBase : public DataWrap<Derived, DistInfoProxy>
prepare()
{
Info *info = this->info();
data()->prepare(info->storageParams, info->data);
data()->prepare(info->getStorageParams(), info->data);
}
/**
@@ -1342,7 +1342,7 @@ class DistBase : public DataWrap<Derived, DistInfoProxy>
void
reset()
{
data()->reset(this->info()->storageParams);
data()->reset(this->info()->getStorageParams());
}
/**
@@ -1387,7 +1387,7 @@ class VectorDistBase : public DataWrapVec<Derived, VectorDistInfoProxy>
fatal_if(s <= 0, "Storage size must be positive");
fatal_if(check(), "Stat has already been initialized");
storage.resize(s, new Storage(this->info()->storageParams));
storage.resize(s, new Storage(this->info()->getStorageParams()));
this->setInit();
}
@@ -1434,7 +1434,7 @@ class VectorDistBase : public DataWrapVec<Derived, VectorDistInfoProxy>
size_type size = this->size();
info->data.resize(size);
for (off_type i = 0; i < size; ++i)
data(i)->prepare(info->storageParams, info->data[i]);
data(i)->prepare(info->getStorageParams(), info->data[i]);
}
bool
@@ -2431,7 +2431,7 @@ class SparseHistBase : public DataWrap<Derived, SparseHistInfoProxy>
void
doInit()
{
new (storage) Storage(this->info()->storageParams);
new (storage) Storage(this->info()->getStorageParams());
this->setInit();
}
@@ -2467,7 +2467,7 @@ class SparseHistBase : public DataWrap<Derived, SparseHistInfoProxy>
prepare()
{
Info *info = this->info();
data()->prepare(info->storageParams, info->data);
data()->prepare(info->getStorageParams(), info->data);
}
/**
@@ -2476,7 +2476,7 @@ class SparseHistBase : public DataWrap<Derived, SparseHistInfoProxy>
void
reset()
{
data()->reset(this->info()->storageParams);
data()->reset(this->info()->getStorageParams());
}
};

View File

@@ -46,6 +46,7 @@
#include "base/cprintf.hh"
#include "base/debug.hh"
#include "base/logging.hh"
#include "base/stats/storage.hh"
#include "base/str.hh"
namespace gem5
@@ -69,7 +70,7 @@ nameMap()
}
Info::Info()
: flags(none), precision(-1), prereq(0), storageParams(NULL)
: flags(none), precision(-1), prereq(0), storageParams()
{
id = id_count++;
if (debug_break_id >= 0 and debug_break_id == id)
@@ -80,6 +81,18 @@ Info::~Info()
{
}
StorageParams const*
Info::getStorageParams() const
{
return storageParams.get();
}
void
Info::setStorageParams(const StorageParams *const params)
{
return storageParams.reset(params);
}
bool
validateStatName(const std::string &name)
{

View File

@@ -31,6 +31,7 @@
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -100,8 +101,8 @@ class Info
static int id_count;
int id;
public:
const StorageParams *storageParams;
private:
std::unique_ptr<const StorageParams> storageParams;
public:
Info();
@@ -118,6 +119,15 @@ class Info
void setSeparator(std::string _sep) { separatorString = _sep;}
/**
* Getter for the storage params. These parameters should only be modified
* using the respective setter.
* @sa setStorageParams
*/
StorageParams const* getStorageParams() const;
/** Setter for the storage params. */
void setStorageParams(const StorageParams *const params);
/**
* Check that this stat has been set up properly and is ready for
* use