Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/32648 )

Change subject: dev: Replace the Callback class with lambdas in ARM's flash devices.
......................................................................

dev: Replace the Callback class with lambdas in ARM's flash devices.

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...@gmail.com>
Maintainer: Gabe Black <gabebl...@google.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/dev/arm/abstract_nvm.hh
M src/dev/arm/flash_device.cc
M src/dev/arm/flash_device.hh
M src/dev/arm/ufs_device.cc
M src/dev/arm/ufs_device.hh
5 files changed, 37 insertions(+), 47 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/dev/arm/abstract_nvm.hh b/src/dev/arm/abstract_nvm.hh
index dd44e19..dbcfa70 100644
--- a/src/dev/arm/abstract_nvm.hh
+++ b/src/dev/arm/abstract_nvm.hh
@@ -99,9 +99,9 @@
      * 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__
diff --git a/src/dev/arm/flash_device.cc b/src/dev/arm/flash_device.cc
index a31deb1..d8f1469 100644
--- a/src/dev/arm/flash_device.cc
+++ b/src/dev/arm/flash_device.cc
@@ -160,8 +160,8 @@
  * 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 @@
             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 @@
* 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();
                 }
             }
         }
diff --git a/src/dev/arm/flash_device.hh b/src/dev/arm/flash_device.hh
index 07c6a6c..a0ff83f 100644
--- a/src/dev/arm/flash_device.hh
+++ b/src/dev/arm/flash_device.hh
@@ -87,7 +87,7 @@

     struct CallBackEntry {
         Tick time;
-        Callback *function;
+        std::function<void()> function;
     };

     struct FlashDeviceStats {
@@ -105,19 +105,22 @@
     };

     /** 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 @@
     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();
diff --git a/src/dev/arm/ufs_device.cc b/src/dev/arm/ufs_device.cc
index 82cbd88..b11eb7b 100644
--- a/src/dev/arm/ufs_device.cc
+++ b/src/dev/arm/ufs_device.cc
@@ -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 @@
      * 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 @@
             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 @@

         //Callback UFS Host
         setSignal();
-        signalDone->process();
+        signalDone();
     }

 }
@@ -2213,7 +2207,7 @@

         /**Callback: transferdone*/
         setSignal();
-        signalDone->process();
+        signalDone();
     }

 }
@@ -2231,7 +2225,7 @@
      * UFSHostDevice::readCallback
      */
     setReadSignal();
-    deviceReadCallback->process();
+    deviceReadCallback();

     //Are we done yet?
     SSDReadDone();
diff --git a/src/dev/arm/ufs_device.hh b/src/dev/arm/ufs_device.hh
index 95faa77..d3ea35d 100644
--- a/src/dev/arm/ufs_device.hh
+++ b/src/dev/arm/ufs_device.hh
@@ -143,6 +143,7 @@
 #define __DEV_ARM_UFS_DEVICE_HH__

 #include <deque>
+#include <functional>

 #include "base/addr_range.hh"
 #include "base/bitfield.hh"
@@ -535,11 +536,13 @@
     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 @@
         /**
          * 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
@@ -1135,14 +1138,6 @@
     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 * is scheduled. A transfer event might schedule a SCSI event, all events

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/32648
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: I2694dd1952b7412c27c83c9d15d4645899bd28e2
Gerrit-Change-Number: 32648
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: Mahyar Samani <msam...@ucdavis.edu>
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