dev: Replace the Callback class with lambdas in ARM's flash devices.
authorGabe Black <gabeblack@google.com>
Fri, 14 Aug 2020 08:09:30 +0000 (01:09 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 18 Aug 2020 23:20:58 +0000 (23:20 +0000)
Issue-on: https://gem5.atlassian.net/browse/GEM5-698
Change-Id: I2694dd1952b7412c27c83c9d15d4645899bd28e2
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32648
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/dev/arm/abstract_nvm.hh
src/dev/arm/flash_device.cc
src/dev/arm/flash_device.hh
src/dev/arm/ufs_device.cc
src/dev/arm/ufs_device.hh

index dd44e19b72de20806d596c960259ee9f1e0dd38a..dbcfa70b63982805d7bf622ee46060bf99168ff5 100644 (file)
@@ -99,9 +99,9 @@ class AbstractNVM : public SimObject
      * data transfer between the disk and the disk controller.
      */
     virtual void readMemory(uint64_t address, uint32_t amount,
-                            Callback *event) = 0;
+                            const std::function<void()> &event) = 0;
     virtual void writeMemory(uint64_t address, uint32_t amount,
-                             Callback *event) = 0;
+                             const std::function<void()> &event) = 0;
 };
 
 #endif //__DEV_ARM_ABSTRACT_NVM_HH__
index a31deb1649438a49da63595a889dbaa79e1bc17e..d8f14691f9f93bbcb82f75d62d2ee25e31b4bf73 100644 (file)
@@ -160,8 +160,8 @@ FlashDevice::~FlashDevice()
  * an event that uses the callback function on completion of the action.
  */
 void
-FlashDevice::accessDevice(uint64_t address, uint32_t amount, Callback *event,
-                          Actions action)
+FlashDevice::accessDevice(uint64_t address, uint32_t amount,
+                          const std::function<void()> &event, Actions action)
 {
     DPRINTF(FlashDevice, "Flash calculation for %d bytes in %d pages\n"
             , amount, pageSize);
@@ -258,7 +258,6 @@ FlashDevice::accessDevice(uint64_t address, uint32_t amount, Callback *event,
             else
                 cbe.time = time[count] +
                            planeEventQueue[count].back().time;
-            cbe.function = NULL;
             planeEventQueue[count].push_back(cbe);
 
             DPRINTF(FlashDevice, "scheduled at: %ld\n", cbe.time);
@@ -308,14 +307,13 @@ FlashDevice::actionComplete()
                  * the callback entry first need to be cleared before it can
                  * be called.
                  */
-                Callback *temp = planeEventQueue[plane_address].front().
-                                 function;
+                auto temp = planeEventQueue[plane_address].front().function;
                 planeEventQueue[plane_address].pop_front();
 
                 /**Found a callback, lets make it happen*/
-                if (temp != NULL) {
+                if (temp) {
                     DPRINTF(FlashDevice, "Callback, %d\n", plane_address);
-                    temp->process();
+                    temp();
                 }
             }
         }
index 07c6a6c27d8327b56e8dede164fba9dffec2a8ef..a0ff83f6406d3ab6eb95a3be80eb737468eed6d5 100644 (file)
@@ -87,7 +87,7 @@ class FlashDevice : public AbstractNVM
 
     struct CallBackEntry {
         Tick time;
-        Callback *function;
+        std::function<void()> function;
     };
 
     struct FlashDeviceStats {
@@ -105,19 +105,22 @@ class FlashDevice : public AbstractNVM
     };
 
     /** Device access functions Inherrited from AbstractNVM*/
-    void initializeMemory(uint64_t disk_size, uint32_t sector_size) override
+    void
+    initializeMemory(uint64_t disk_size, uint32_t sector_size) override
     {
         initializeFlash(disk_size, sector_size);
     }
 
-    void readMemory(uint64_t address, uint32_t amount,
-                    Callback *event) override
+    void
+    readMemory(uint64_t address, uint32_t amount,
+               const std::function<void()> &event) override
     {
         accessDevice(address, amount, event, ActionRead);
     }
 
-    void writeMemory(uint64_t address, uint32_t amount,
-                     Callback *event) override
+    void
+    writeMemory(uint64_t address, uint32_t amount,
+                const std::function<void()> &event) override
     {
         accessDevice(address, amount, event, ActionWrite);
     }
@@ -126,8 +129,8 @@ class FlashDevice : public AbstractNVM
     void initializeFlash(uint64_t disk_size, uint32_t sector_size);
 
     /**Flash action function*/
-    void accessDevice(uint64_t address, uint32_t amount, Callback *event,
-                      Actions action);
+    void accessDevice(uint64_t address, uint32_t amount,
+                      const std::function<void()> &event, Actions action);
 
     /** Event rescheduler*/
     void actionComplete();
index 82cbd88c29e9f74cded87238b72445f4e41806d7..b11eb7bc751a5e6b9cebd392bf474a0d50d0a65b 100644 (file)
@@ -73,8 +73,8 @@
  * Constructor and destructor functions of UFSHCM device
  */
 UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p,
-                             uint32_t lun_id, Callback *transfer_cb,
-                             Callback *read_cb):
+                             uint32_t lun_id, const Callback &transfer_cb,
+                             const Callback &read_cb):
     SimObject(p),
     flashDisk(p->image[lun_id]),
     flashDevice(p->internalflash[lun_id]),
@@ -97,11 +97,9 @@ UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p,
      * or from the UFS SCSI device to the UFS host.
      */
     signalDone = transfer_cb;
-    memReadCallback = new MakeCallback<UFSSCSIDevice,
-        &UFSHostDevice::UFSSCSIDevice::readCallback>(this);
+    memReadCallback = [this]() { readCallback(); };
     deviceReadCallback = read_cb;
-    memWriteCallback = new MakeCallback<UFSSCSIDevice,
-        &UFSHostDevice::UFSSCSIDevice::SSDWriteDone>(this);
+    memWriteCallback = [this]() { SSDWriteDone(); };
 
     /**
      * make ascii out of lun_id (and add more characters)
@@ -738,14 +736,10 @@ UFSHostDevice::UFSHostDevice(const UFSHostDeviceParams* p) :
             lunAvail);
     UFSDevice.resize(lunAvail);
 
-    transferDoneCallback = new MakeCallback<UFSHostDevice,
-        &UFSHostDevice::LUNSignal>(this);
-    memReadCallback = new MakeCallback<UFSHostDevice,
-        &UFSHostDevice::readCallback>(this);
-
     for (int count = 0; count < lunAvail; count++) {
-        UFSDevice[count] = new UFSSCSIDevice(p, count, transferDoneCallback,
-                                             memReadCallback);
+        UFSDevice[count] = new UFSSCSIDevice(p, count,
+                [this]() { LUNSignal(); },
+                [this]() { readCallback(); });
     }
 
     if (UFSSlots > 31)
@@ -2070,7 +2064,7 @@ UFSHostDevice::UFSSCSIDevice::SSDWriteDone()
 
         //Callback UFS Host
         setSignal();
-        signalDone->process();
+        signalDone();
     }
 
 }
@@ -2213,7 +2207,7 @@ UFSHostDevice::UFSSCSIDevice::SSDReadDone()
 
         /**Callback: transferdone*/
         setSignal();
-        signalDone->process();
+        signalDone();
     }
 
 }
@@ -2231,7 +2225,7 @@ UFSHostDevice::UFSSCSIDevice::readCallback()
      * UFSHostDevice::readCallback
      */
     setReadSignal();
-    deviceReadCallback->process();
+    deviceReadCallback();
 
     //Are we done yet?
     SSDReadDone();
index 95faa7771aec6f765f66be3ac31a78a2af05f066..d3ea35da624bca46c253f31b7999d389cb3767f7 100644 (file)
 #define __DEV_ARM_UFS_DEVICE_HH__
 
 #include <deque>
+#include <functional>
 
 #include "base/addr_range.hh"
 #include "base/bitfield.hh"
@@ -535,11 +536,13 @@ class UFSHostDevice : public DmaDevice
     class UFSSCSIDevice: SimObject
     {
       public:
+        using Callback = std::function<void()>;
+
         /**
          * Constructor and destructor
          */
-        UFSSCSIDevice(const UFSHostDeviceParams* p, uint32_t lun_id, Callback*
-                      transfer_cb, Callback *read_cb);
+        UFSSCSIDevice(const UFSHostDeviceParams* p, uint32_t lun_id,
+                      const Callback &transfer_cb, const Callback &read_cb);
         ~UFSSCSIDevice();
 
         /**
@@ -722,14 +725,14 @@ class UFSHostDevice : public DmaDevice
         /**
          * Callbacks between Host and Device
          */
-        Callback* signalDone;
-        Callback* deviceReadCallback;
+        Callback signalDone;
+        Callback deviceReadCallback;
 
         /**
          * Callbacks between Device and Memory
          */
-        Callback* memReadCallback;
-        Callback* memWriteCallback;
+        Callback memReadCallback;
+        Callback memWriteCallback;
 
         /*
          * Default response header layout. For more information refer to
@@ -1134,14 +1137,6 @@ class UFSHostDevice : public DmaDevice
     std::deque<EventFunctionWrapper> readDoneEvent;
     std::deque<EventFunctionWrapper> writeDoneEvent;
 
-    /**
-     * Callbacks for the logic units. One to indicate the completion of a
-     * transaction, the other one to indicate the completion of a read
-     * action.
-     */
-    Callback* transferDoneCallback;
-    Callback* memReadCallback;
-
     /**
      * The events that control the functionality.
      * After a doorbell has been set, either a taskevent or a transfer event