From 40e8cac3067a6807b396b9291cb9d0739c1a0655 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 14 Aug 2020 00:02:17 -0700 Subject: [PATCH] misc: Make registerExitCallback use CallbackQueue2. Issue-on: https://gem5.atlassian.net/browse/GEM5-698 Change-Id: I526d4a19ca4e54a6469a4ee26693c1c0400fcc70 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32644 Reviewed-by: Andreas Sandberg Maintainer: Gabe Black Tested-by: kokoro --- src/base/cp_annotate.cc | 22 +--------------------- src/cpu/inst_pb_trace.cc | 4 +--- src/cpu/o3/probe/elastic_trace.cc | 4 +--- src/dev/storage/disk_image.cc | 12 +----------- src/dev/virtio/fs9p.cc | 4 +--- src/gpu-compute/compute_unit.cc | 13 +++++-------- src/gpu-compute/compute_unit.hh | 24 +----------------------- src/mem/cache/tags/base.cc | 2 +- src/mem/cache/tags/base.hh | 8 -------- src/mem/dramsim2.cc | 4 +--- src/mem/probes/mem_trace.cc | 3 +-- src/sim/core.cc | 8 ++++---- src/sim/core.hh | 4 ++-- src/sim/sim_exit.hh | 5 +---- 14 files changed, 21 insertions(+), 96 deletions(-) diff --git a/src/base/cp_annotate.cc b/src/base/cp_annotate.cc index 159e6e0f7..c66b8438b 100644 --- a/src/base/cp_annotate.cc +++ b/src/base/cp_annotate.cc @@ -79,26 +79,6 @@ using namespace TheISA; bool CPA::exists; CPA *CPA::_cpa; -class AnnotateDumpCallback : public Callback -{ - - private: - CPA *cpa; - public: - virtual void process(); - AnnotateDumpCallback(CPA *_cpa) - : cpa(_cpa) - {} -}; - -void -AnnotateDumpCallback::process() -{ - cpa->dump(true); - cpa->dumpKey(); -} - - CPA::CPA(Params *p) : SimObject(p), numSm(0), numSmt(0), numSys(0), numQs(0), conId(0) { @@ -140,7 +120,7 @@ CPA::startup() ah.key_off = 0; osbin->write((char*)&ah, sizeof(AnnotateHeader)); - registerExitCallback(new AnnotateDumpCallback(this)); + registerExitCallback([this]() { dump(true); dumpKey(); }); } uint64_t diff --git a/src/cpu/inst_pb_trace.cc b/src/cpu/inst_pb_trace.cc index 3f3cfa8fc..7d7bbaa6d 100644 --- a/src/cpu/inst_pb_trace.cc +++ b/src/cpu/inst_pb_trace.cc @@ -91,9 +91,7 @@ InstPBTrace::createTraceFile(std::string filename) traceStream->write(header_msg); // get a callback when we exit so we can close the file - Callback *cb = new MakeCallback(this); - registerExitCallback(cb); + registerExitCallback([this]() { closeStreams(); }); } void diff --git a/src/cpu/o3/probe/elastic_trace.cc b/src/cpu/o3/probe/elastic_trace.cc index c328b3c2e..8292c336e 100644 --- a/src/cpu/o3/probe/elastic_trace.cc +++ b/src/cpu/o3/probe/elastic_trace.cc @@ -88,9 +88,7 @@ ElasticTrace::ElasticTrace(const ElasticTraceParams* params) data_rec_header.set_window_size(depWindowSize); dataTraceStream->write(data_rec_header); // Register a callback to flush trace records and close the output streams. - Callback* cb = new MakeCallback(this); - registerExitCallback(cb); + registerExitCallback([this]() { flushTraces(); }); } void diff --git a/src/dev/storage/disk_image.cc b/src/dev/storage/disk_image.cc index 319bccf13..e4b1ce02c 100644 --- a/src/dev/storage/disk_image.cc +++ b/src/dev/storage/disk_image.cc @@ -168,16 +168,6 @@ RawDiskImageParams::create() const uint32_t CowDiskImage::VersionMajor = 1; const uint32_t CowDiskImage::VersionMinor = 0; -class CowDiskCallback : public Callback -{ - private: - CowDiskImage *image; - - public: - CowDiskCallback(CowDiskImage *i) : image(i) {} - void process() { image->save(); delete this; } -}; - CowDiskImage::CowDiskImage(const Params *p) : DiskImage(p), filename(p->image_file), child(p->child), table(NULL) { @@ -191,7 +181,7 @@ CowDiskImage::CowDiskImage(const Params *p) } if (!p->read_only) - registerExitCallback(new CowDiskCallback(this)); + registerExitCallback([this]() { save(); }); } } diff --git a/src/dev/virtio/fs9p.cc b/src/dev/virtio/fs9p.cc index a548d72e9..2392c0b91 100644 --- a/src/dev/virtio/fs9p.cc +++ b/src/dev/virtio/fs9p.cc @@ -315,9 +315,7 @@ VirtIO9PDiod::VirtIO9PDiod(Params *params) fd_to_diod(-1), fd_from_diod(-1), diod_pid(-1) { // Register an exit callback so we can kill the diod process - Callback* cb = new MakeCallback(this); - registerExitCallback(cb); + registerExitCallback([this]() { terminateDiod(); }); } VirtIO9PDiod::~VirtIO9PDiod() diff --git a/src/gpu-compute/compute_unit.cc b/src/gpu-compute/compute_unit.cc index 067c25469..7e0947f65 100644 --- a/src/gpu-compute/compute_unit.cc +++ b/src/gpu-compute/compute_unit.cc @@ -179,8 +179,7 @@ ComputeUnit::ComputeUnit(const Params *p) : ClockedObject(p), int tlbPort_width = perLaneTLB ? wfSize() : 1; tlbPort.resize(tlbPort_width); - cuExitCallback = new CUExitCallback(this); - registerExitCallback(cuExitCallback); + registerExitCallback([this]() { exitCallback(); }); lastExecCycle.resize(numVectorALUs, 0); @@ -215,7 +214,6 @@ ComputeUnit::~ComputeUnit() lastVaddrSimd[j].clear(); } lastVaddrCU.clear(); - delete cuExitCallback; delete ldsPort; } @@ -2460,16 +2458,15 @@ ComputeUnit::updatePageDivergenceDist(Addr addr) } void -ComputeUnit::CUExitCallback::process() +ComputeUnit::exitCallback() { - if (computeUnit->countPages) { - std::ostream *page_stat_file = - simout.create(computeUnit->name().c_str())->stream(); + if (countPages) { + std::ostream *page_stat_file = simout.create(name().c_str())->stream(); *page_stat_file << "page, wavefront accesses, workitem accesses" << std::endl; - for (auto iter : computeUnit->pageAccesses) { + for (auto iter : pageAccesses) { *page_stat_file << std::hex << iter.first << ","; *page_stat_file << std::dec << iter.second.first << ","; *page_stat_file << std::dec << iter.second.second << std::endl; diff --git a/src/gpu-compute/compute_unit.hh b/src/gpu-compute/compute_unit.hh index 22960c0c9..cf51a8636 100644 --- a/src/gpu-compute/compute_unit.hh +++ b/src/gpu-compute/compute_unit.hh @@ -350,11 +350,6 @@ class ComputeUnit : public ClockedObject /* * for Counting page accesses - * - * cuExitCallback inherits from Callback. When you register a callback - * function as an exit callback, it will get added to an exit callback - * queue, such that on simulation exit, all callbacks in the callback - * queue will have their process() function called. */ bool countPages; @@ -631,24 +626,7 @@ class ComputeUnit : public ClockedObject typedef std::unordered_map> pageDataStruct; pageDataStruct pageAccesses; - class CUExitCallback : public Callback - { - private: - ComputeUnit *computeUnit; - - public: - virtual ~CUExitCallback() { } - - CUExitCallback(ComputeUnit *_cu) - { - computeUnit = _cu; - } - - virtual void - process(); - }; - - CUExitCallback *cuExitCallback; + void exitCallback(); class GMTokenPort : public TokenMasterPort { diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc index bd6f55c30..faad7be05 100644 --- a/src/mem/cache/tags/base.cc +++ b/src/mem/cache/tags/base.cc @@ -64,7 +64,7 @@ BaseTags::BaseTags(const Params *p) dataBlks(new uint8_t[p->size]), // Allocate data storage in one big chunk stats(*this) { - registerExitCallback(new BaseTagsCallback(this)); + registerExitCallback([this]() { cleanupRefs(); }); } ReplaceableEntry* diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh index 90152d3b5..5f0246205 100644 --- a/src/mem/cache/tags/base.hh +++ b/src/mem/cache/tags/base.hh @@ -353,12 +353,4 @@ class BaseTags : public ClockedObject void computeStatsVisitor(CacheBlk &blk); }; -class BaseTagsCallback : public Callback -{ - BaseTags *tags; - public: - BaseTagsCallback(BaseTags *t) : tags(t) {} - virtual void process() { tags->cleanupRefs(); }; -}; - #endif //__MEM_CACHE_TAGS_BASE_HH__ diff --git a/src/mem/dramsim2.cc b/src/mem/dramsim2.cc index 029e7b8c1..aeafad041 100644 --- a/src/mem/dramsim2.cc +++ b/src/mem/dramsim2.cc @@ -68,9 +68,7 @@ DRAMSim2::DRAMSim2(const Params* p) : // Register a callback to compensate for the destructor not // being called. The callback prints the DRAMSim2 stats. - Callback* cb = new MakeCallback(wrapper); - registerExitCallback(cb); + registerExitCallback([&wrapper]() { wrapper->printStats(); }); } void diff --git a/src/mem/probes/mem_trace.cc b/src/mem/probes/mem_trace.cc index 9031d6083..a11b9e60a 100644 --- a/src/mem/probes/mem_trace.cc +++ b/src/mem/probes/mem_trace.cc @@ -74,8 +74,7 @@ MemTraceProbe::MemTraceProbe(MemTraceProbeParams *p) // Register a callback to compensate for the destructor not // being called. The callback forces the stream to flush and // closes the output file. - registerExitCallback( - new MakeCallback(this)); + registerExitCallback([this]() { closeStreams(); }); } void diff --git a/src/sim/core.cc b/src/sim/core.cc index 18c6985f8..8dd5c852f 100644 --- a/src/sim/core.cc +++ b/src/sim/core.cc @@ -126,10 +126,10 @@ setOutputDir(const string &dir) /** * Queue of C++ callbacks to invoke on simulator exit. */ -inline CallbackQueue & +inline CallbackQueue2 & exitCallbacks() { - static CallbackQueue theQueue; + static CallbackQueue2 theQueue; return theQueue; } @@ -137,9 +137,9 @@ exitCallbacks() * Register an exit callback. */ void -registerExitCallback(Callback *callback) +registerExitCallback(const std::function &callback) { - exitCallbacks().add(callback); + exitCallbacks().push_back(callback); } /** diff --git a/src/sim/core.hh b/src/sim/core.hh index 48b70960b..2e443e76e 100644 --- a/src/sim/core.hh +++ b/src/sim/core.hh @@ -35,6 +35,7 @@ * information, output directory and exit events */ +#include #include #include "base/types.hh" @@ -95,8 +96,7 @@ Tick getClockFrequency(); // Ticks per second. void setOutputDir(const std::string &dir); -class Callback; -void registerExitCallback(Callback *callback); +void registerExitCallback(const std::function &callback); void doExitCleanup(); #endif /* __SIM_CORE_HH__ */ diff --git a/src/sim/sim_exit.hh b/src/sim/sim_exit.hh index b0b5111b0..a79d3e2cd 100644 --- a/src/sim/sim_exit.hh +++ b/src/sim/sim_exit.hh @@ -35,12 +35,9 @@ Tick curTick(); -// forward declaration -class Callback; - /// Register a callback to be called when Python exits. Defined in /// sim/main.cc. -void registerExitCallback(Callback *); +void registerExitCallback(const std::function &); /// Schedule an event to exit the simulation loop (returning to /// Python) at the end of the current cycle (curTick()). The message -- 2.30.2