From 836920ac5ddda578aaba3913ba3975fe19a8f84d Mon Sep 17 00:00:00 2001 From: Hoa Nguyen Date: Thu, 22 Oct 2020 12:20:28 -0700 Subject: [PATCH] mem,stats: Update stats style for mem/probes and mem/qos Change-Id: I47a094eb8fc56ef998ec3c971dab68ba39b092e3 Signed-off-by: Hoa Nguyen Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36476 Reviewed-by: Daniel Carvalho Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/mem/probes/mem_footprint.cc | 45 ++++++++++++++----------------- src/mem/probes/mem_footprint.hh | 24 ++++++++++------- src/mem/probes/stack_dist.cc | 47 +++++++++++++++------------------ src/mem/probes/stack_dist.hh | 30 +++++++++++---------- src/mem/qos/mem_sink.cc | 22 ++++++--------- src/mem/qos/mem_sink.hh | 16 ++++++----- 6 files changed, 90 insertions(+), 94 deletions(-) diff --git a/src/mem/probes/mem_footprint.cc b/src/mem/probes/mem_footprint.cc index 7e38fad45..9dad04b4f 100644 --- a/src/mem/probes/mem_footprint.cc +++ b/src/mem/probes/mem_footprint.cc @@ -51,7 +51,8 @@ MemFootprintProbe::MemFootprintProbe(const MemFootprintProbeParams &p) cacheLinesAll(), pages(), pagesAll(), - system(p.system) + system(p.system), + stats(this) { fatal_if(!isPowerOf2(system->cacheLineSize()), "MemFootprintProbe expects cache line size is power of 2."); @@ -59,30 +60,24 @@ MemFootprintProbe::MemFootprintProbe(const MemFootprintProbeParams &p) "MemFootprintProbe expects page size parameter is power of 2"); } -void -MemFootprintProbe::regStats() +MemFootprintProbe:: +MemFootprintProbeStats::MemFootprintProbeStats(MemFootprintProbe *parent) + : Stats::Group(parent), + ADD_STAT(cacheLine, "Memory footprint at cache line granularity"), + ADD_STAT(cacheLineTotal, "Total memory footprint at cache line " + "granularity since simulation begin"), + ADD_STAT(page, "Memory footprint at page granularity"), + ADD_STAT(pageTotal, "Total memory footprint at page granularity since " + "simulation begin") { - BaseMemProbe::regStats(); - using namespace Stats; // clang-format off - fpCacheLine.name(name() + ".cacheline") - .desc("Memory footprint at cache line granularity") - .flags(nozero | nonan); - fpCacheLineTotal.name(name() + ".cacheline_total") - .desc("Total memory footprint at cache line granularity since " - "simulation begin") - .flags(nozero | nonan); - fpPage.name(name() + ".page") - .desc("Memory footprint at page granularity") - .flags(nozero | nonan); - fpPageTotal.name(name() + ".page_total") - .desc("Total memory footprint at page granularity since simulation " - "begin") - .flags(nozero | nonan); + cacheLine.flags(nozero | nonan); + cacheLineTotal.flags(nozero | nonan); + page.flags(nozero | nonan); + pageTotal.flags(nozero | nonan); // clang-format on - - registerResetCallback([this]() { statReset(); }); + registerResetCallback([parent]() { parent->statReset(); }); } void @@ -108,10 +103,10 @@ MemFootprintProbe::handleRequest(const ProbePoints::PacketInfo &pi) assert(cacheLines.size() <= cacheLinesAll.size()); assert(pages.size() <= pagesAll.size()); - fpCacheLine = cacheLines.size() << cacheLineSizeLg2; - fpCacheLineTotal = cacheLinesAll.size() << cacheLineSizeLg2; - fpPage = pages.size() << pageSizeLg2; - fpPageTotal = pagesAll.size() << pageSizeLg2; + stats.cacheLine = cacheLines.size() << cacheLineSizeLg2; + stats.cacheLineTotal = cacheLinesAll.size() << cacheLineSizeLg2; + stats.page = pages.size() << pageSizeLg2; + stats.pageTotal = pagesAll.size() << pageSizeLg2; } void diff --git a/src/mem/probes/mem_footprint.hh b/src/mem/probes/mem_footprint.hh index 71438c05d..803a99c34 100644 --- a/src/mem/probes/mem_footprint.hh +++ b/src/mem/probes/mem_footprint.hh @@ -57,7 +57,6 @@ class MemFootprintProbe : public BaseMemProbe typedef std::unordered_set AddrSet; MemFootprintProbe(const MemFootprintProbeParams &p); - void regStats() override; // Fix footprint tracking state on stat reset void statReset(); @@ -72,14 +71,19 @@ class MemFootprintProbe : public BaseMemProbe void insertAddr(Addr addr, AddrSet *set, uint64_t limit); void handleRequest(const ProbePoints::PacketInfo &pkt_info) override; - /// Footprint at cache line size granularity - Stats::Scalar fpCacheLine; - /// Footprint at cache line size granularity, since simulation begin - Stats::Scalar fpCacheLineTotal; - /// Footprint at page granularity - Stats::Scalar fpPage; - /// Footprint at page granularity, since simulation begin - Stats::Scalar fpPageTotal; + struct MemFootprintProbeStats : public Stats::Group + { + MemFootprintProbeStats(MemFootprintProbe *parent); + + /// Footprint at cache line size granularity + Stats::Scalar cacheLine; + /// Footprint at cache line size granularity, since simulation begin + Stats::Scalar cacheLineTotal; + /// Footprint at page granularity + Stats::Scalar page; + /// Footprint at page granularity, since simulation begin + Stats::Scalar pageTotal; + }; // Addr set to track unique cache lines accessed AddrSet cacheLines; @@ -90,6 +94,8 @@ class MemFootprintProbe : public BaseMemProbe // Addr set to track unique pages accessed since simulation begin AddrSet pagesAll; System *system; + + MemFootprintProbeStats stats; }; #endif //__MEM_PROBES_MEM_FOOTPRINT_HH__ diff --git a/src/mem/probes/stack_dist.cc b/src/mem/probes/stack_dist.cc index 57f919999..d3c2f66e5 100644 --- a/src/mem/probes/stack_dist.cc +++ b/src/mem/probes/stack_dist.cc @@ -45,50 +45,45 @@ StackDistProbe::StackDistProbe(const StackDistProbeParams &p) lineSize(p.line_size), disableLinearHists(p.disable_linear_hists), disableLogHists(p.disable_log_hists), - calc(p.verify) + calc(p.verify), + stats(this) { fatal_if(p.system->cacheLineSize() > p.line_size, "The stack distance probe must use a cache line size that is " "larger or equal to the system's cahce line size."); } -void -StackDistProbe::regStats() +StackDistProbe:: +StackDistProbeStats::StackDistProbeStats(StackDistProbe *parent) + : Stats::Group(parent), + ADD_STAT(readLinearHist, "Reads linear distribution"), + ADD_STAT(readLogHist, "Reads logarithmic distribution"), + ADD_STAT(writeLinearHist, "Writes linear distribution"), + ADD_STAT(writeLogHist, "Writes logarithmic distribution"), + ADD_STAT(infiniteSD, "Number of requests with infinite stack distance") { - BaseMemProbe::regStats(); + using namespace Stats; const StackDistProbeParams &p = - dynamic_cast(params()); - - using namespace Stats; + dynamic_cast(parent->params()); readLinearHist .init(p.linear_hist_bins) - .name(name() + ".readLinearHist") - .desc("Reads linear distribution") - .flags(disableLinearHists ? nozero : pdf); + .flags(parent->disableLinearHists ? nozero : pdf); readLogHist .init(p.log_hist_bins) - .name(name() + ".readLogHist") - .desc("Reads logarithmic distribution") - .flags(disableLogHists ? nozero : pdf); + .flags(parent->disableLogHists ? nozero : pdf); writeLinearHist .init(p.linear_hist_bins) - .name(name() + ".writeLinearHist") - .desc("Writes linear distribution") - .flags(disableLinearHists ? nozero : pdf); + .flags(parent->disableLinearHists ? nozero : pdf); writeLogHist .init(p.log_hist_bins) - .name(name() + ".writeLogHist") - .desc("Writes logarithmic distribution") - .flags(disableLogHists ? nozero : pdf); + .flags(parent->disableLogHists ? nozero : pdf); infiniteSD - .name(name() + ".infinity") - .desc("Number of requests with infinite stack distance") .flags(nozero); } @@ -106,16 +101,16 @@ StackDistProbe::handleRequest(const ProbePoints::PacketInfo &pkt_info) // Calculate the stack distance const uint64_t sd(calc.calcStackDistAndUpdate(aligned_addr).first); if (sd == StackDistCalc::Infinity) { - infiniteSD++; + stats.infiniteSD++; return; } // Sample the stack distance of the address in linear bins if (!disableLinearHists) { if (pkt_info.cmd.isRead()) - readLinearHist.sample(sd); + stats.readLinearHist.sample(sd); else - writeLinearHist.sample(sd); + stats.writeLinearHist.sample(sd); } if (!disableLogHists) { @@ -123,8 +118,8 @@ StackDistProbe::handleRequest(const ProbePoints::PacketInfo &pkt_info) // Sample the stack distance of the address in log bins if (pkt_info.cmd.isRead()) - readLogHist.sample(sd_lg2); + stats.readLogHist.sample(sd_lg2); else - writeLogHist.sample(sd_lg2); + stats.writeLogHist.sample(sd_lg2); } } diff --git a/src/mem/probes/stack_dist.hh b/src/mem/probes/stack_dist.hh index 4a6ae547d..009705eb6 100644 --- a/src/mem/probes/stack_dist.hh +++ b/src/mem/probes/stack_dist.hh @@ -50,8 +50,6 @@ class StackDistProbe : public BaseMemProbe public: StackDistProbe(const StackDistProbeParams ¶ms); - void regStats() override; - protected: void handleRequest(const ProbePoints::PacketInfo &pkt_info) override; @@ -66,23 +64,27 @@ class StackDistProbe : public BaseMemProbe const bool disableLogHists; protected: - // Reads linear histogram - Stats::Histogram readLinearHist; + StackDistCalc calc; - // Reads logarithmic histogram - Stats::SparseHistogram readLogHist; + struct StackDistProbeStats : public Stats::Group + { + StackDistProbeStats(StackDistProbe* parent); - // Writes linear histogram - Stats::Histogram writeLinearHist; + // Reads linear histogram + Stats::Histogram readLinearHist; - // Writes logarithmic histogram - Stats::SparseHistogram writeLogHist; + // Reads logarithmic histogram + Stats::SparseHistogram readLogHist; - // Writes logarithmic histogram - Stats::Scalar infiniteSD; + // Writes linear histogram + Stats::Histogram writeLinearHist; - protected: - StackDistCalc calc; + // Writes logarithmic histogram + Stats::SparseHistogram writeLogHist; + + // Writes logarithmic histogram + Stats::Scalar infiniteSD; + } stats; }; diff --git a/src/mem/qos/mem_sink.cc b/src/mem/qos/mem_sink.cc index 9d57500b8..8114090c7 100644 --- a/src/mem/qos/mem_sink.cc +++ b/src/mem/qos/mem_sink.cc @@ -52,7 +52,8 @@ MemSinkCtrl::MemSinkCtrl(const QoSMemSinkCtrlParams &p) readBufferSize(p.read_buffer_size), writeBufferSize(p.write_buffer_size), port(name() + ".port", *this), interface(p.interface), - retryRdReq(false), retryWrReq(false), nextRequest(0), nextReqEvent(this) + retryRdReq(false), retryWrReq(false), nextRequest(0), nextReqEvent(this), + stats(this) { // Resize read and write queue to allocate space // for configured QoS priorities @@ -155,7 +156,7 @@ MemSinkCtrl::recvTimingReq(PacketPtr pkt) "%s Read queue full, not accepting\n", __func__); // Remember that we have to retry this port retryRdReq = true; - numReadRetries++; + stats.numReadRetries++; req_accepted = false; } else { // Enqueue the incoming packet into corresponding @@ -169,7 +170,7 @@ MemSinkCtrl::recvTimingReq(PacketPtr pkt) "%s Write queue full, not accepting\n", __func__); // Remember that we have to retry this port retryWrReq = true; - numWriteRetries++; + stats.numWriteRetries++; req_accepted = false; } else { // Enqueue the incoming packet into corresponding QoS @@ -332,18 +333,11 @@ MemSinkCtrl::drain() } } -void -MemSinkCtrl::regStats() +MemSinkCtrl::MemSinkCtrlStats::MemSinkCtrlStats(Stats::Group *parent) + : Stats::Group(parent), + ADD_STAT(numReadRetries, "Number of read retries"), + ADD_STAT(numWriteRetries, "Number of write retries") { - MemCtrl::regStats(); - - // Initialize all the stats - using namespace Stats; - - numReadRetries.name(name() + ".numReadRetries") - .desc("Number of read retries"); - numWriteRetries.name(name() + ".numWriteRetries") - .desc("Number of write retries"); } MemSinkCtrl::MemoryPort::MemoryPort(const std::string& n, diff --git a/src/mem/qos/mem_sink.hh b/src/mem/qos/mem_sink.hh index e9c3e7416..8a9708d89 100644 --- a/src/mem/qos/mem_sink.hh +++ b/src/mem/qos/mem_sink.hh @@ -181,11 +181,16 @@ class MemSinkCtrl : public MemCtrl /** Next request service time */ Tick nextRequest; - /** Count the number of read retries */ - Stats::Scalar numReadRetries; + struct MemSinkCtrlStats : public Stats::Group + { + MemSinkCtrlStats(Stats::Group *parent); + + /** Count the number of read retries */ + Stats::Scalar numReadRetries; - /** Count the number of write retries */ - Stats::Scalar numWriteRetries; + /** Count the number of write retries */ + Stats::Scalar numWriteRetries; + }; /** * QoS-aware (per priority) incoming read requests packets queue @@ -247,8 +252,7 @@ class MemSinkCtrl : public MemCtrl */ bool recvTimingReq(PacketPtr pkt); - /** Registers statistics */ - void regStats() override; + MemSinkCtrlStats stats; }; } // namespace QoS -- 2.30.2