From: Gabe Black Date: Fri, 14 Aug 2020 08:09:30 +0000 (-0700) Subject: dev: Replace the Callback class with lambdas in ARM's flash devices. X-Git-Tag: v20.1.0.0~285 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=637aa00218ead358042bd1dfe2e50e58b07c87ad;p=gem5.git 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 Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/dev/arm/abstract_nvm.hh b/src/dev/arm/abstract_nvm.hh index dd44e19b7..dbcfa70b6 100644 --- a/src/dev/arm/abstract_nvm.hh +++ b/src/dev/arm/abstract_nvm.hh @@ -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 &event) = 0; virtual void writeMemory(uint64_t address, uint32_t amount, - Callback *event) = 0; + const std::function &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 a31deb164..d8f14691f 100644 --- a/src/dev/arm/flash_device.cc +++ b/src/dev/arm/flash_device.cc @@ -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 &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(); } } } diff --git a/src/dev/arm/flash_device.hh b/src/dev/arm/flash_device.hh index 07c6a6c27..a0ff83f64 100644 --- a/src/dev/arm/flash_device.hh +++ b/src/dev/arm/flash_device.hh @@ -87,7 +87,7 @@ class FlashDevice : public AbstractNVM struct CallBackEntry { Tick time; - Callback *function; + std::function 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 &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 &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 &event, Actions action); /** Event rescheduler*/ void actionComplete(); diff --git a/src/dev/arm/ufs_device.cc b/src/dev/arm/ufs_device.cc index 82cbd88c2..b11eb7bc7 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 @@ UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p, * or from the UFS SCSI device to the UFS host. */ signalDone = transfer_cb; - memReadCallback = new MakeCallback(this); + memReadCallback = [this]() { readCallback(); }; deviceReadCallback = read_cb; - memWriteCallback = new MakeCallback(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(this); - memReadCallback = new MakeCallback(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(); diff --git a/src/dev/arm/ufs_device.hh b/src/dev/arm/ufs_device.hh index 95faa7771..d3ea35da6 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 +#include #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; + /** * 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 readDoneEvent; std::deque 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