Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/38702 )

Change subject: misc: Prefer ProbeListenerArg over ProbeListenerArgBase
......................................................................

misc: Prefer ProbeListenerArg over ProbeListenerArgBase

Some of the use cases of ProbeListenerArgBase are merely
reimplementing the functionality of ProbeListenerArg.

As a side effect some functions now receive const
references as arguments.

Jira: https://gem5.atlassian.net/browse/GEM5-857

Change-Id: I93947214c301be95cc27e9f8817ecc99c24f042c
Signed-off-by: Daniel R. Carvalho <[email protected]>
---
M src/arch/arm/pmu.cc
M src/arch/arm/pmu.hh
M src/mem/cache/compressors/frequent_values.cc
M src/mem/cache/compressors/frequent_values.hh
M src/mem/cache/prefetch/pif.cc
M src/mem/cache/prefetch/pif.hh
M src/mem/probes/base.cc
M src/mem/probes/base.hh
M src/sim/power/power_model.cc
M src/sim/power/power_model.hh
10 files changed, 18 insertions(+), 108 deletions(-)



diff --git a/src/arch/arm/pmu.cc b/src/arch/arm/pmu.cc
index 5d87ccc..c7489f6 100644
--- a/src/arch/arm/pmu.cc
+++ b/src/arch/arm/pmu.cc
@@ -448,7 +448,7 @@
 }

 void
-PMU::PMUEvent::increment(const uint64_t val)
+PMU::PMUEvent::increment(const uint64_t &val)
 {
     for (auto& counter: userCounters) {
         counter->add(val);
@@ -466,12 +466,6 @@
 }

 void
-PMU::RegularEvent::RegularProbe::notify(const uint64_t &val)
-{
-    parentEvent->increment(val);
-}
-
-void
 PMU::RegularEvent::enable()
 {
     for (auto &listener : listeners) {
diff --git a/src/arch/arm/pmu.hh b/src/arch/arm/pmu.hh
index 8bffef2..64d3b3d 100644
--- a/src/arch/arm/pmu.hh
+++ b/src/arch/arm/pmu.hh
@@ -316,7 +316,7 @@
          * @param the quantity by which to increment the attached counter
          * values
          */
-        virtual void increment(const uint64_t val);
+        virtual void increment(const uint64_t &val);

         /**
          * Enable the current event
@@ -347,32 +347,19 @@
         {
             panic_if(!object,"malformed probe-point"
                 " definition with name %s\n", name);
-            auto listener = new RegularProbe(this);
+ auto listener = new ProbeListenerArg<RegularEvent, uint64_t>(this,
+                &RegularEvent::increment);
             object->getProbeManager()->addListener(name, listener);
             listeners.emplace_back(listener);
         }

       protected:
-        struct RegularProbe: public  ProbeListenerArgBase<uint64_t>
-        {
-            RegularProbe(RegularEvent *parent)
-              : ProbeListenerArgBase(), parentEvent(parent)
-            {}
-
-            RegularProbe() = delete;
-
-            void notify(const uint64_t &val);
-
-          protected:
-            RegularEvent *parentEvent;
-        };
-
         /**
          * Set of probe listeners tapping onto each of the input micro-arch
          * events which compose this pmu event.
          * These pointers are managed by the probe.
          */
-        std::vector<RegularProbe*> listeners;
+        std::vector<ProbeListenerArg<RegularEvent, uint64_t>*> listeners;

         void enable() override;

diff --git a/src/mem/cache/compressors/frequent_values.cc b/src/mem/cache/compressors/frequent_values.cc
index a89f437..da75d4a 100644
--- a/src/mem/cache/compressors/frequent_values.cc
+++ b/src/mem/cache/compressors/frequent_values.cc
@@ -256,7 +256,7 @@
 }

 void
-FrequentValues::probeNotify(const DataUpdate &data_update)
+FrequentValues::probeNotify(const BaseCache::DataUpdate &data_update)
 {
     // Do not update VFT if not sampling
     if (phase == SAMPLING) {
@@ -284,7 +284,8 @@
 {
     assert(cache != nullptr);
     cache->getProbeManager()->addListener("Data Update",
-        new FrequentValuesListener(*this));
+        new ProbeListenerArg<FrequentValues, BaseCache::DataUpdate>(this,
+        &FrequentValues::probeNotify));
 }

 } // namespace Compressor
diff --git a/src/mem/cache/compressors/frequent_values.hh b/src/mem/cache/compressors/frequent_values.hh
index e09be8a..25aedcb 100644
--- a/src/mem/cache/compressors/frequent_values.hh
+++ b/src/mem/cache/compressors/frequent_values.hh
@@ -59,26 +59,6 @@
   private:
     class CompData;

-    using DataUpdate = BaseCache::DataUpdate;
-
-    class FrequentValuesListener : public ProbeListenerArgBase<DataUpdate>
-    {
-      protected:
-        FrequentValues &parent;
-
-      public:
-        FrequentValuesListener(FrequentValues &_parent)
-          : ProbeListenerArgBase(), parent(_parent)
-        {
-        }
-
-        void
-        notify(const DataUpdate &data_update) override
-        {
-            parent.probeNotify(data_update);
-        }
-    };
-
     /** Whether Huffman encoding is applied to the VFT indices. */
     const bool useHuffmanEncoding;

@@ -185,7 +165,7 @@
      *
      * @param data_update The data regarding the entry's contents update.
      */
-    void probeNotify(const DataUpdate &data_update);
+    void probeNotify(const BaseCache::DataUpdate &data_update);

     void regProbeListeners() override;
 };
diff --git a/src/mem/cache/prefetch/pif.cc b/src/mem/cache/prefetch/pif.cc
index 2bce80d..487ac52 100644
--- a/src/mem/cache/prefetch/pif.cc
+++ b/src/mem/cache/prefetch/pif.cc
@@ -128,7 +128,7 @@
 }

 void
-PIF::notifyRetiredInst(const Addr pc)
+PIF::notifyRetiredInst(const Addr &pc)
 {
     // First access to the prefetcher
     if (temporalCompactor.size() == 0) {
@@ -230,15 +230,10 @@
 }

 void
-PIF::PrefetchListenerPC::notify(const Addr& pc)
-{
-    parent.notifyRetiredInst(pc);
-}
-
-void
 PIF::addEventProbeRetiredInsts(SimObject *obj, const char *name)
 {
- obj->getProbeManager()->addListener(name, new PrefetchListenerPC(*this));
+    obj->getProbeManager()->addListener(name,
+        new ProbeListenerArg<PIF, Addr>(this, &PIF::notifyRetiredInst));
 }

 } // namespace Prefetcher
diff --git a/src/mem/cache/prefetch/pif.hh b/src/mem/cache/prefetch/pif.hh
index b1589c5..52eff9f 100644
--- a/src/mem/cache/prefetch/pif.hh
+++ b/src/mem/cache/prefetch/pif.hh
@@ -152,22 +152,7 @@
          * Updates the prefetcher structures upon an instruction retired
          * @param pc PC of the instruction being retired
          */
-        void notifyRetiredInst(const Addr pc);
-
-        /**
-         * Probe Listener to handle probe events from the CPU
-         */
-        class PrefetchListenerPC : public ProbeListenerArgBase<Addr>
-        {
-          public:
-            PrefetchListenerPC(PIF &_parent)
-              : ProbeListenerArgBase(), parent(_parent)
-            {}
-            void notify(const Addr& pc) override;
-
-          protected:
-            PIF &parent;
-        };
+        void notifyRetiredInst(const Addr &pc);

     public:
         PIF(const PIFPrefetcherParams &p);
diff --git a/src/mem/probes/base.cc b/src/mem/probes/base.cc
index 9b012ee..6fdd588 100644
--- a/src/mem/probes/base.cc
+++ b/src/mem/probes/base.cc
@@ -52,6 +52,8 @@

     for (int i = 0; i < p.manager.size(); i++) {
         ProbeManager *const mgr(p.manager[i]->getProbeManager());
-        mgr->addListener(p.probe_name, new PacketListener(*this));
+        mgr->addListener(p.probe_name,
+ new ProbeListenerArg<BaseMemProbe, ProbePoints::PacketInfo>(this,
+            &BaseMemProbe::handleRequest));
     }
 }
diff --git a/src/mem/probes/base.hh b/src/mem/probes/base.hh
index 18e6855..3264422 100644
--- a/src/mem/probes/base.hh
+++ b/src/mem/probes/base.hh
@@ -70,24 +70,6 @@
      * Callback to analyse intercepted Packets.
      */
virtual void handleRequest(const ProbePoints::PacketInfo &pkt_info) = 0;
-
-  private:
- class PacketListener : public ProbeListenerArgBase<ProbePoints::PacketInfo>
-    {
-      public:
-        PacketListener(BaseMemProbe &_parent)
-          : ProbeListenerArgBase(), parent(_parent)
-        {}
-
-        void
-        notify(const ProbePoints::PacketInfo &pkt_info) override
-        {
-            parent.handleRequest(pkt_info);
-        }
-
-      protected:
-        BaseMemProbe &parent;
-    };
 };

 #endif //  __MEM_PROBES_BASE_HH__
diff --git a/src/sim/power/power_model.cc b/src/sim/power/power_model.cc
index 111d7d8..f3d7353 100644
--- a/src/sim/power/power_model.cc
+++ b/src/sim/power/power_model.cc
@@ -96,7 +96,8 @@
 PowerModel::regProbePoints()
 {
     this->subsystem->getProbeManager()->addListener("thermalUpdate",
-        new ThermalProbeListener(*this));
+        new ProbeListenerArg<PowerModel, double>(this,
+        &PowerModel::thermalUpdateCallback));
 }

 double
diff --git a/src/sim/power/power_model.hh b/src/sim/power/power_model.hh
index 8362531..2aa6527 100644
--- a/src/sim/power/power_model.hh
+++ b/src/sim/power/power_model.hh
@@ -128,23 +128,6 @@
     void thermalUpdateCallback(const double & temp);

   protected:
-    /** Listener class to catch thermal events */
-    class ThermalProbeListener : public ProbeListenerArgBase<double>
-    {
-      public:
-        ThermalProbeListener(PowerModel &_pm)
-          : ProbeListenerArgBase(), pm(_pm)
-        {}
-
-        void notify(const double &temp)
-        {
-            pm.thermalUpdateCallback(temp);
-        }
-
-      protected:
-        PowerModel &pm;
-    };
-
     /** Actual power models (one per power state) */
     std::vector<PowerModelState*> states_pm;


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/38702
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: I93947214c301be95cc27e9f8817ecc99c24f042c
Gerrit-Change-Number: 38702
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to