Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/32644 )
Change subject: misc: Make registerExitCallback use CallbackQueue2.
......................................................................
misc: Make registerExitCallback use CallbackQueue2.
Issue-on: https://gem5.atlassian.net/browse/GEM5-698
Change-Id: I526d4a19ca4e54a6469a4ee26693c1c0400fcc70
---
M src/base/cp_annotate.cc
M src/cpu/inst_pb_trace.cc
M src/cpu/o3/probe/elastic_trace.cc
M src/dev/storage/disk_image.cc
M src/dev/virtio/fs9p.cc
M src/gpu-compute/compute_unit.cc
M src/gpu-compute/compute_unit.hh
M src/mem/cache/tags/base.cc
M src/mem/cache/tags/base.hh
M src/mem/dramsim2.cc
M src/mem/probes/mem_trace.cc
M src/sim/core.cc
M src/sim/core.hh
M src/sim/sim_exit.hh
14 files changed, 21 insertions(+), 96 deletions(-)
diff --git a/src/base/cp_annotate.cc b/src/base/cp_annotate.cc
index 159e6e0..c66b843 100644
--- a/src/base/cp_annotate.cc
+++ b/src/base/cp_annotate.cc
@@ -79,26 +79,6 @@
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 @@
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 3f3cfa8..7d7bbaa 100644
--- a/src/cpu/inst_pb_trace.cc
+++ b/src/cpu/inst_pb_trace.cc
@@ -91,9 +91,7 @@
traceStream->write(header_msg);
// get a callback when we exit so we can close the file
- Callback *cb = new MakeCallback<InstPBTrace,
- &InstPBTrace::closeStreams>(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 c328b3c..8292c33 100644
--- a/src/cpu/o3/probe/elastic_trace.cc
+++ b/src/cpu/o3/probe/elastic_trace.cc
@@ -88,9 +88,7 @@
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<ElasticTrace,
- &ElasticTrace::flushTraces>(this);
- registerExitCallback(cb);
+ registerExitCallback([this]() { flushTraces(); });
}
void
diff --git a/src/dev/storage/disk_image.cc b/src/dev/storage/disk_image.cc
index 319bccf..e4b1ce0 100644
--- a/src/dev/storage/disk_image.cc
+++ b/src/dev/storage/disk_image.cc
@@ -168,16 +168,6 @@
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 @@
}
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 a548d72..2392c0b 100644
--- a/src/dev/virtio/fs9p.cc
+++ b/src/dev/virtio/fs9p.cc
@@ -315,9 +315,7 @@
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<VirtIO9PDiod,
- &VirtIO9PDiod::terminateDiod>(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 067c254..7e0947f 100644
--- a/src/gpu-compute/compute_unit.cc
+++ b/src/gpu-compute/compute_unit.cc
@@ -179,8 +179,7 @@
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 @@
lastVaddrSimd[j].clear();
}
lastVaddrCU.clear();
- delete cuExitCallback;
delete ldsPort;
}
@@ -2460,16 +2458,15 @@
}
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 22960c0..cf51a86 100644
--- a/src/gpu-compute/compute_unit.hh
+++ b/src/gpu-compute/compute_unit.hh
@@ -350,11 +350,6 @@
/*
* 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 @@
typedef std::unordered_map<Addr, std::pair<int, int>> 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 bd6f55c..faad7be 100644
--- a/src/mem/cache/tags/base.cc
+++ b/src/mem/cache/tags/base.cc
@@ -64,7 +64,7 @@
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 90152d3..5f02462 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -353,12 +353,4 @@
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 029e7b8..aeafad0 100644
--- a/src/mem/dramsim2.cc
+++ b/src/mem/dramsim2.cc
@@ -68,9 +68,7 @@
// Register a callback to compensate for the destructor not
// being called. The callback prints the DRAMSim2 stats.
- Callback* cb = new MakeCallback<DRAMSim2Wrapper,
- &DRAMSim2Wrapper::printStats>(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 9031d60..a11b9e6 100644
--- a/src/mem/probes/mem_trace.cc
+++ b/src/mem/probes/mem_trace.cc
@@ -74,8 +74,7 @@
// 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<MemTraceProbe,
&MemTraceProbe::closeStreams>(this));
+ registerExitCallback([this]() { closeStreams(); });
}
void
diff --git a/src/sim/core.cc b/src/sim/core.cc
index 18c6985..de4ee11 100644
--- a/src/sim/core.cc
+++ b/src/sim/core.cc
@@ -126,10 +126,10 @@
/**
* 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 @@
* Register an exit callback.
*/
void
-registerExitCallback(Callback *callback)
+registerExitCallback(const std::function<void()> &callback)
{
- exitCallbacks().add(callback);
+ exitCallbacks().push_back(callback);
}
/**
diff --git a/src/sim/core.hh b/src/sim/core.hh
index 48b7096..2e443e7 100644
--- a/src/sim/core.hh
+++ b/src/sim/core.hh
@@ -35,6 +35,7 @@
* information, output directory and exit events
*/
+#include <functional>
#include <string>
#include "base/types.hh"
@@ -95,8 +96,7 @@
void setOutputDir(const std::string &dir);
-class Callback;
-void registerExitCallback(Callback *callback);
+void registerExitCallback(const std::function<void()> &callback);
void doExitCleanup();
#endif /* __SIM_CORE_HH__ */
diff --git a/src/sim/sim_exit.hh b/src/sim/sim_exit.hh
index b0b5111..a79d3e2 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<void()> &);
/// Schedule an event to exit the simulation loop (returning to
/// Python) at the end of the current cycle (curTick()). The message
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/32644
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: I526d4a19ca4e54a6469a4ee26693c1c0400fcc70
Gerrit-Change-Number: 32644
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s