Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/38178 )

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

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 <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38178
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Hoa Nguyen <hoangu...@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Maintainer: Jason Lowe-Power <power...@gmail.com>
---
M src/base/statistics.cc
M src/base/statistics.hh
M src/base/stats/info.cc
M src/base/stats/info.hh
4 files changed, 44 insertions(+), 21 deletions(-)

Approvals:
Jason Lowe-Power: Looks good to me, but someone else must approve; Looks good to me, approved
  Hoa Nguyen: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/statistics.cc b/src/base/statistics.cc
index c4782f6..39e76b6 100644
--- a/src/base/statistics.cc
+++ b/src/base/statistics.cc
@@ -99,7 +99,7 @@
 void
 InfoAccess::setParams(const StorageParams *params)
 {
-    info()->storageParams = params;
+    info()->setStorageParams(params);
 }

 void
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index 1885954..18f52cb 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -440,7 +440,7 @@

         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 @@

         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 @@
     void
     doInit()
     {
-        new (storage) Storage(this->info()->storageParams);
+        new (storage) Storage(this->info()->getStorageParams());
         this->setInit();
     }

@@ -624,8 +624,8 @@

     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 @@
         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 @@
         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 @@
         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 @@
         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 @@
     void
     doInit()
     {
-        new (storage) Storage(this->info()->storageParams);
+        new (storage) Storage(this->info()->getStorageParams());
         this->setInit();
     }

@@ -1333,7 +1333,7 @@
     prepare()
     {
         Info *info = this->info();
-        data()->prepare(info->storageParams, info->data);
+        data()->prepare(info->getStorageParams(), info->data);
     }

     /**
@@ -1342,7 +1342,7 @@
     void
     reset()
     {
-        data()->reset(this->info()->storageParams);
+        data()->reset(this->info()->getStorageParams());
     }

     /**
@@ -1387,7 +1387,7 @@
         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 @@
         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 @@
     void
     doInit()
     {
-        new (storage) Storage(this->info()->storageParams);
+        new (storage) Storage(this->info()->getStorageParams());
         this->setInit();
     }

@@ -2467,7 +2467,7 @@
     prepare()
     {
         Info *info = this->info();
-        data()->prepare(info->storageParams, info->data);
+        data()->prepare(info->getStorageParams(), info->data);
     }

     /**
@@ -2476,7 +2476,7 @@
     void
     reset()
     {
-        data()->reset(this->info()->storageParams);
+        data()->reset(this->info()->getStorageParams());
     }
 };

diff --git a/src/base/stats/info.cc b/src/base/stats/info.cc
index edc4290..c40b559 100644
--- a/src/base/stats/info.cc
+++ b/src/base/stats/info.cc
@@ -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 @@
 }

 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 @@
 {
 }

+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)
 {
diff --git a/src/base/stats/info.hh b/src/base/stats/info.hh
index 70e2e2c..9a5e2e7 100644
--- a/src/base/stats/info.hh
+++ b/src/base/stats/info.hh
@@ -31,6 +31,7 @@

 #include <cstdint>
 #include <map>
+#include <memory>
 #include <string>
 #include <vector>

@@ -100,8 +101,8 @@
     static int id_count;
     int id;

-  public:
-    const StorageParams *storageParams;
+  private:
+    std::unique_ptr<const StorageParams> storageParams;

   public:
     Info();
@@ -119,6 +120,15 @@
     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
      * @return true for success



14 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/38178
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I4c2496d08241f155793ed35e3463512d9ea06f83
Gerrit-Change-Number: 38178
Gerrit-PatchSet: 16
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to