From: Gabe Black Date: Fri, 14 Aug 2020 07:22:09 +0000 (-0700) Subject: misc: Make the stats callbacks use CallbackQueue2. X-Git-Tag: v20.1.0.0~288 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9ed3c7668b54033d673c0c251a86e8e26f955c59;p=gem5.git misc: Make the stats callbacks use CallbackQueue2. Issue-on: https://gem5.atlassian.net/browse/GEM5-698 Change-Id: Idcbe04bdf4299925f321aa0ece263d86ed3fc8df Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32645 Reviewed-by: Andreas Sandberg Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/base/statistics.cc b/src/base/statistics.cc index e4315baf9..156fcbbe4 100644 --- a/src/base/statistics.cc +++ b/src/base/statistics.cc @@ -518,8 +518,8 @@ registerHandlers(Handler reset_handler, Handler dump_handler) dumpHandler = dump_handler; } -CallbackQueue dumpQueue; -CallbackQueue resetQueue; +CallbackQueue2 dumpQueue; +CallbackQueue2 resetQueue; void processResetQueue() @@ -534,9 +534,9 @@ processDumpQueue() } void -registerResetCallback(Callback *cb) +registerResetCallback(const std::function &callback) { - resetQueue.add(cb); + resetQueue.push_back(callback); } bool _enabled = false; @@ -586,9 +586,9 @@ resolve(const std::string &name) } void -registerDumpCallback(Callback *cb) +registerDumpCallback(const std::function &callback) { - dumpQueue.add(cb); + dumpQueue.push_back(callback); } } // namespace Stats diff --git a/src/base/statistics.hh b/src/base/statistics.hh index ee541fbc8..96cd43fec 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -82,8 +82,6 @@ #include "base/str.hh" #include "base/types.hh" -class Callback; - /** The current simulated tick. */ extern Tick curTick(); @@ -3364,13 +3362,13 @@ void registerHandlers(Handler reset_handler, Handler dump_handler); * Register a callback that should be called whenever statistics are * reset */ -void registerResetCallback(Callback *cb); +void registerResetCallback(const std::function &callback); /** * Register a callback that should be called whenever statistics are * about to be dumped */ -void registerDumpCallback(Callback *cb); +void registerDumpCallback(const std::function &callback); /** * Process all the callbacks in the reset callbacks queue diff --git a/src/cpu/profile.cc b/src/cpu/profile.cc index 393740be9..d132fc138 100644 --- a/src/cpu/profile.cc +++ b/src/cpu/profile.cc @@ -97,13 +97,7 @@ FunctionProfile::FunctionProfile(std::unique_ptr _trace, const Loader::SymbolTable &_symtab) : symtab(_symtab), trace(std::move(_trace)) { - reset = new MakeCallback(this); - Stats::registerResetCallback(reset); -} - -FunctionProfile::~FunctionProfile() -{ - delete reset; + Stats::registerResetCallback([this]() { clear(); }); } ProfileNode * diff --git a/src/cpu/profile.hh b/src/cpu/profile.hh index 0f2d8a838..b58447afa 100644 --- a/src/cpu/profile.hh +++ b/src/cpu/profile.hh @@ -124,13 +124,11 @@ class ProfileNode void clear(); }; -class Callback; class FunctionProfile { private: friend class ProfileNode; - Callback *reset = nullptr; const Loader::SymbolTable &symtab; ProfileNode top; std::map pc_count; @@ -139,7 +137,6 @@ class FunctionProfile public: FunctionProfile(std::unique_ptr _trace, const Loader::SymbolTable &symtab); - ~FunctionProfile(); ProfileNode *consume(ThreadContext *tc, const StaticInstPtr &inst); ProfileNode *consume(const std::vector &stack); diff --git a/src/mem/probes/mem_footprint.cc b/src/mem/probes/mem_footprint.cc index c90719088..970756803 100644 --- a/src/mem/probes/mem_footprint.cc +++ b/src/mem/probes/mem_footprint.cc @@ -82,9 +82,7 @@ MemFootprintProbe::regStats() .flags(nozero | nonan); // clang-format on - registerResetCallback( - new MakeCallback( - this)); + registerResetCallback([this]() { statReset(); }); } void diff --git a/src/mem/ruby/network/Network.cc b/src/mem/ruby/network/Network.cc index ba847e5e8..bf3b637c3 100644 --- a/src/mem/ruby/network/Network.cc +++ b/src/mem/ruby/network/Network.cc @@ -125,7 +125,7 @@ Network::Network(const Params *p) } // Register a callback function for combining the statistics - Stats::registerDumpCallback(new StatsCallback(this)); + Stats::registerDumpCallback([this]() { collateStats(); }); for (auto &it : dynamic_cast(this)->params()->ext_links) { it->params()->ext_node->initNetQueues(); diff --git a/src/mem/ruby/network/Network.hh b/src/mem/ruby/network/Network.hh index bba0c5e7f..6348f6c47 100644 --- a/src/mem/ruby/network/Network.hh +++ b/src/mem/ruby/network/Network.hh @@ -160,24 +160,6 @@ class Network : public ClockedObject std::vector m_ordered; private: - //! Callback class used for collating statistics from all the - //! controller of this type. - class StatsCallback : public Callback - { - private: - Network *ctr; - - public: - virtual ~StatsCallback() {} - - StatsCallback(Network *_ctr) - : ctr(_ctr) - { - } - - void process() {ctr->collateStats();} - }; - // Global address map struct AddrMapNode { NodeID id; diff --git a/src/mem/ruby/slicc_interface/AbstractController.cc b/src/mem/ruby/slicc_interface/AbstractController.cc index d2b337038..599a54b88 100644 --- a/src/mem/ruby/slicc_interface/AbstractController.cc +++ b/src/mem/ruby/slicc_interface/AbstractController.cc @@ -61,7 +61,7 @@ AbstractController::AbstractController(const Params *p) if (m_version == 0) { // Combine the statistics from all controllers // of this particular type. - Stats::registerDumpCallback(new StatsCallback(this)); + Stats::registerDumpCallback([this]() { collateStats(); }); } } diff --git a/src/mem/ruby/slicc_interface/AbstractController.hh b/src/mem/ruby/slicc_interface/AbstractController.hh index 750a620bd..4820e5c07 100644 --- a/src/mem/ruby/slicc_interface/AbstractController.hh +++ b/src/mem/ruby/slicc_interface/AbstractController.hh @@ -214,19 +214,6 @@ class AbstractController : public ClockedObject, public Consumer Stats::Histogram m_delayHistogram; std::vector m_delayVCHistogram; - //! Callback class used for collating statistics from all the - //! controller of this type. - class StatsCallback : public Callback - { - private: - AbstractController *ctr; - - public: - virtual ~StatsCallback() {} - StatsCallback(AbstractController *_ctr) : ctr(_ctr) {} - void process() {ctr->collateStats();} - }; - /** * Port that forwards requests and receives responses from the * memory controller. diff --git a/src/mem/ruby/system/RubySystem.cc b/src/mem/ruby/system/RubySystem.cc index 5babf2dda..c35ab023f 100644 --- a/src/mem/ruby/system/RubySystem.cc +++ b/src/mem/ruby/system/RubySystem.cc @@ -86,7 +86,7 @@ RubySystem::RubySystem(const Params *p) m_abstract_controls.resize(MachineType_NUM); // Collate the statistics before they are printed. - Stats::registerDumpCallback(new RubyStatsCallback(this)); + Stats::registerDumpCallback([this]() { collateStats(); }); // Create the profiler m_profiler = new Profiler(p, this); m_phys_mem = p->phys_mem; diff --git a/src/mem/ruby/system/RubySystem.hh b/src/mem/ruby/system/RubySystem.hh index 7ce5ce078..d14b3833c 100644 --- a/src/mem/ruby/system/RubySystem.hh +++ b/src/mem/ruby/system/RubySystem.hh @@ -151,15 +151,4 @@ class RubySystem : public ClockedObject std::vector > m_abstract_controls; }; -class RubyStatsCallback : public Callback -{ - private: - RubySystem *m_ruby_system; - - public: - virtual ~RubyStatsCallback() {} - RubyStatsCallback(RubySystem *system) : m_ruby_system(system) {} - void process() { m_ruby_system->collateStats(); } -}; - #endif //__MEM_RUBY_SYSTEM_RUBYSYSTEM_HH__ diff --git a/src/sim/stat_control.cc b/src/sim/stat_control.cc index 291698c82..9464c0d0d 100644 --- a/src/sim/stat_control.cc +++ b/src/sim/stat_control.cc @@ -70,15 +70,6 @@ Tick startTick; GlobalEvent *dumpEvent; -struct SimTicksReset : public Callback -{ - void process() - { - statTime.setTimer(); - startTick = curTick(); - } -}; - double statElapsedTime() { @@ -101,8 +92,6 @@ statFinalTick() return curTick(); } -SimTicksReset simTicksReset; - struct Global { Stats::Formula hostInstRate; @@ -198,7 +187,10 @@ Global::Global() hostOpRate = simOps / hostSeconds; hostTickRate = simTicks / hostSeconds; - registerResetCallback(&simTicksReset); + registerResetCallback([]() { + statTime.setTimer(); + startTick = curTick(); + }); } void