ruby: Refactor some Event subclasses to lambdas
authorSean Wilson <spwilson2@wisc.edu>
Wed, 28 Jun 2017 18:34:02 +0000 (13:34 -0500)
committerSean Wilson <spwilson2@wisc.edu>
Wed, 12 Jul 2017 20:07:05 +0000 (20:07 +0000)
Change-Id: I9f47a20a869553515a759d9a29c05f6ce4b42d64
Signed-off-by: Sean Wilson <spwilson2@wisc.edu>
Reviewed-on: https://gem5-review.googlesource.com/3930
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
src/mem/ruby/common/Consumer.cc
src/mem/ruby/common/Consumer.hh
src/mem/ruby/system/GPUCoalescer.cc
src/mem/ruby/system/GPUCoalescer.hh
src/mem/ruby/system/RubySystem.cc
src/mem/ruby/system/RubySystem.hh
src/mem/ruby/system/Sequencer.cc
src/mem/ruby/system/Sequencer.hh

index 59605d51b70f26b63137f0e1977fe1b90618acf2..f68ee14d0401a6c9de98f25f853ec8602050fe91 100644 (file)
@@ -41,7 +41,9 @@ Consumer::scheduleEventAbsolute(Tick evt_time)
 {
     if (!alreadyScheduled(evt_time)) {
         // This wakeup is not redundant
-        ConsumerEvent *evt = new ConsumerEvent(this);
+        auto *evt = new EventFunctionWrapper(
+            [this]{ wakeup(); }, "Consumer Event", true);
+
         em->schedule(evt, evt_time);
         insertScheduledWakeupTime(evt_time);
     }
index 20f2bdd0f642c7cce1e730221918a79045b39d71..b0d35bf70c1262167d188fb143de5caab1763816 100644 (file)
@@ -76,20 +76,6 @@ class Consumer
   private:
     std::set<Tick> m_scheduled_wakeups;
     ClockedObject *em;
-
-    class ConsumerEvent : public Event
-    {
-      public:
-          ConsumerEvent(Consumer* _consumer)
-              : Event(Default_Pri, AutoDelete), m_consumer_ptr(_consumer)
-          {
-          }
-
-          void process() { m_consumer_ptr->wakeup(); }
-
-      private:
-          Consumer* m_consumer_ptr;
-    };
 };
 
 inline std::ostream&
index 991b217179a7187163872f1669b626321ea46fcc..a615c40fd1927029b2934b953dca6d46cfbe9eae 100644 (file)
@@ -116,7 +116,10 @@ reqSegmentToHSASegment(Request* req)
 }
 
 GPUCoalescer::GPUCoalescer(const Params *p)
-    : RubyPort(p), issueEvent(this), deadlockCheckEvent(this)
+    : RubyPort(p),
+      issueEvent([this]{ completeIssue(); }, "Issue coalesced request",
+                 false, Event::Progress_Event_Pri),
+      deadlockCheckEvent([this]{ wakeup(); }, "GPUCoalescer deadlock check")
 {
     m_store_waiting_on_load_cycles = 0;
     m_store_waiting_on_store_cycles = 0;
@@ -996,11 +999,6 @@ GPUCoalescer::recordRequestType(SequencerRequestType requestType) {
             SequencerRequestType_to_string(requestType));
 }
 
-GPUCoalescer::IssueEvent::IssueEvent(GPUCoalescer* _seq)
-    : Event(Progress_Event_Pri), seq(_seq)
-{
-}
-
 
 void
 GPUCoalescer::completeIssue()
@@ -1041,18 +1039,6 @@ GPUCoalescer::completeIssue()
     newKernelEnds.clear();
 }
 
-void
-GPUCoalescer::IssueEvent::process()
-{
-    seq->completeIssue();
-}
-
-const char *
-GPUCoalescer::IssueEvent::description() const
-{
-    return "Issue coalesced request";
-}
-
 void
 GPUCoalescer::evictionCallback(Addr address)
 {
index 2b42e19331f083664efbfb99a3da014c0697f6dc..894683811648b667c33a0cb1a3c2225117e200f0 100644 (file)
@@ -255,17 +255,7 @@ class GPUCoalescer : public RubyPort
 
     bool handleLlsc(Addr address, GPUCoalescerRequest* request);
 
-    class IssueEvent : public Event
-    {
-      private:
-        GPUCoalescer *seq;
-      public:
-        IssueEvent(GPUCoalescer *_seq);
-        void process();
-        const char *description() const;
-    };
-
-    IssueEvent issueEvent;
+    EventFunctionWrapper issueEvent;
 
 
   // Changed to protected to enable inheritance by VIPER Coalescer
@@ -305,22 +295,7 @@ class GPUCoalescer : public RubyPort
 
     bool m_runningGarnetStandalone;
 
-    class GPUCoalescerWakeupEvent : public Event
-    {
-      private:
-        GPUCoalescer *m_GPUCoalescer_ptr;
-
-      public:
-        GPUCoalescerWakeupEvent(GPUCoalescer *_seq) :
-            m_GPUCoalescer_ptr(_seq) {}
-        void process() { m_GPUCoalescer_ptr->wakeup(); }
-        const char *description() const
-        {
-            return "GPUCoalescer deadlock check";
-        }
-    };
-
-    GPUCoalescerWakeupEvent deadlockCheckEvent;
+    EventFunctionWrapper deadlockCheckEvent;
     bool assumingRfOCoherence;
 
     // m5 style stats for TCP hit/miss counts
@@ -382,4 +357,3 @@ operator<<(std::ostream& out, const GPUCoalescer& obj)
 }
 
 #endif // __MEM_RUBY_SYSTEM_GPU_COALESCER_HH__
-
index e1717e519aecced6ef4c9530077ed1491c08b0a4..3d0470ca337d641f4f22758d76f6cfce67981bba 100644 (file)
@@ -380,12 +380,12 @@ RubySystem::startup()
 }
 
 void
-RubySystem::RubyEvent::process()
+RubySystem::processRubyEvent()
 {
-    if (RubySystem::getWarmupEnabled()) {
-        m_ruby_system->m_cache_recorder->enqueueNextFetchRequest();
-    } else if (RubySystem::getCooldownEnabled()) {
-        m_ruby_system->m_cache_recorder->enqueueNextFlushRequest();
+    if (getWarmupEnabled()) {
+        m_cache_recorder->enqueueNextFetchRequest();
+    } else if (getCooldownEnabled()) {
+        m_cache_recorder->enqueueNextFlushRequest();
     }
 }
 
index 8ebd3494ab63fe731e7844ca811e6e7fd17bbaf7..407a253f34fafe39061c6799fe936931bca0176f 100644 (file)
@@ -50,21 +50,6 @@ class AbstractController;
 class RubySystem : public ClockedObject
 {
   public:
-    class RubyEvent : public Event
-    {
-      public:
-        RubyEvent(RubySystem* _ruby_system)
-        {
-            m_ruby_system = _ruby_system;
-        }
-      private:
-        void process();
-
-        RubySystem* m_ruby_system;
-    };
-
-    friend class RubyEvent;
-
     typedef RubySystemParams Params;
     RubySystem(const Params *p);
     ~RubySystem();
@@ -111,7 +96,8 @@ class RubySystem : public ClockedObject
     bool eventQueueEmpty() { return eventq->empty(); }
     void enqueueRubyEvent(Tick tick)
     {
-        RubyEvent* e = new RubyEvent(this);
+        auto e = new EventFunctionWrapper(
+            [this]{ processRubyEvent(); }, "RubyEvent");
         schedule(e, tick);
     }
 
@@ -130,6 +116,7 @@ class RubySystem : public ClockedObject
     static void writeCompressedTrace(uint8_t *raw_data, std::string file,
                                      uint64_t uncompressed_trace_size);
 
+    void processRubyEvent();
   private:
     // configuration parameters
     static bool m_randomization;
index 97afa5ec6e6bbfde2763b44573a496afff03013b..541b52138622e1ae9d615c0d10652263d3cacf8e 100644 (file)
@@ -53,7 +53,8 @@ RubySequencerParams::create()
 }
 
 Sequencer::Sequencer(const Params *p)
-    : RubyPort(p), m_IncompleteTimes(MachineType_NUM), deadlockCheckEvent(this)
+    : RubyPort(p), m_IncompleteTimes(MachineType_NUM),
+      deadlockCheckEvent([this]{ wakeup(); }, "Sequencer deadlock check")
 {
     m_outstanding_count = 0;
 
index 8c009b567464716c131691379b5b87753485a058..fcfa8ad86a70d157f9186563a36bdc8c3fdfded4 100644 (file)
@@ -237,19 +237,7 @@ class Sequencer : public RubyPort
     std::vector<Stats::Histogram *> m_FirstResponseToCompletionDelayHist;
     std::vector<Stats::Counter> m_IncompleteTimes;
 
-
-    class SequencerWakeupEvent : public Event
-    {
-      private:
-        Sequencer *m_sequencer_ptr;
-
-      public:
-        SequencerWakeupEvent(Sequencer *_seq) : m_sequencer_ptr(_seq) {}
-        void process() { m_sequencer_ptr->wakeup(); }
-        const char *description() const { return "Sequencer deadlock check"; }
-    };
-
-    SequencerWakeupEvent deadlockCheckEvent;
+    EventFunctionWrapper deadlockCheckEvent;
 };
 
 inline std::ostream&