kvm, mem: Refactor some Event subclasses into lambdas
authorSean Wilson <spwilson2@wisc.edu>
Tue, 27 Jun 2017 21:22:24 +0000 (16:22 -0500)
committerSean Wilson <spwilson2@wisc.edu>
Wed, 12 Jul 2017 20:07:05 +0000 (20:07 +0000)
Change-Id: Ifafdcf4692d58a17f90e66ff8de8fa3e146c34bb
Signed-off-by: Sean Wilson <spwilson2@wisc.edu>
Reviewed-on: https://gem5-review.googlesource.com/3924
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/cpu/kvm/base.cc
src/cpu/kvm/base.hh
src/mem/external_slave.cc

index 23a408084946bfb086adc708b8f9cadbd5cfa1f0..250c6a2705c790a3af9601fbbb9e732ca2de966a 100644 (file)
@@ -74,7 +74,8 @@ BaseKvmCPU::BaseKvmCPU(BaseKvmCPUParams *params)
       vcpuID(vm.allocVCPUID()), vcpuFD(-1), vcpuMMapSize(0),
       _kvmRun(NULL), mmioRing(NULL),
       pageSize(sysconf(_SC_PAGE_SIZE)),
-      tickEvent(*this),
+      tickEvent([this]{ tick(); }, "BaseKvmCPU tick",
+                false, Event::CPU_Tick_Pri),
       activeInstPeriod(0),
       perfControlledByTimer(params->usePerfOverflow),
       hostFactor(params->hostFactor),
index 6f30c55e48bb9781c5804f6390e5fdc5f35a8fc8..29872e7447b8433cc4af16d3c7ce67b005d21345 100644 (file)
@@ -630,20 +630,6 @@ class BaseKvmCPU : public BaseCPU
     pthread_t vcpuThread;
 
   private:
-    struct TickEvent : public Event
-    {
-        BaseKvmCPU &cpu;
-
-        TickEvent(BaseKvmCPU &c)
-            : Event(CPU_Tick_Pri), cpu(c) {}
-
-        void process() { cpu.tick(); }
-
-        const char *description() const {
-            return "BaseKvmCPU tick";
-        }
-    };
-
     /**
      * Service MMIO requests in the mmioRing.
      *
@@ -708,7 +694,7 @@ class BaseKvmCPU : public BaseCPU
     /** Cached page size of the host */
     const long pageSize;
 
-    TickEvent tickEvent;
+    EventFunctionWrapper tickEvent;
 
     /**
      * Setup an instruction break if there is one pending.
index 990e3561a23da7df3904d63fa7531bd2f4c349ad..ac93e669ce461566bb3fd6b51a020aba5ee5083c 100644 (file)
 class StubSlavePort : public ExternalSlave::Port
 {
   public:
-    class ResponseEvent : public Event
-    {
-      public:
-        StubSlavePort &owner;
-
-        ResponseEvent(StubSlavePort &owner_) : owner(owner_) { }
-
-        void process();
-    };
+    void processResponseEvent();
 
-    ResponseEvent responseEvent;
+    EventFunctionWrapper responseEvent;
 
     /** Stub can handle a single request at a time.  This will be
      *  NULL when no packet is in flight */
@@ -75,7 +67,8 @@ class StubSlavePort : public ExternalSlave::Port
     StubSlavePort(const std::string &name_,
         ExternalSlave &owner_) :
         ExternalSlave::Port(name_, owner_),
-        responseEvent(*this), responsePacket(NULL), mustRetry(false)
+        responseEvent([this]{ processResponseEvent(); }, name()),
+        responsePacket(NULL), mustRetry(false)
     { }
 
     Tick recvAtomic(PacketPtr packet);
@@ -123,18 +116,18 @@ StubSlavePort::recvFunctional(PacketPtr packet)
 }
 
 void
-StubSlavePort::ResponseEvent::process()
+StubSlavePort::processResponseEvent()
 {
-    owner.responsePacket->makeResponse();
-    owner.responsePacket->headerDelay = 0;
-    owner.responsePacket->payloadDelay = 0;
+    responsePacket->makeResponse();
+    responsePacket->headerDelay = 0;
+    responsePacket->payloadDelay = 0;
 
-    if (owner.sendTimingResp(owner.responsePacket)) {
-        owner.responsePacket = NULL;
+    if (sendTimingResp(responsePacket)) {
+        responsePacket = NULL;
 
-        if (owner.mustRetry)
-            owner.sendRetryReq();
-        owner.mustRetry = false;
+        if (mustRetry)
+            sendRetryReq();
+        mustRetry = false;
     }
 }