comm_monitor.hh revision 12084
19444SAndreas.Sandberg@ARM.com/* 29444SAndreas.Sandberg@ARM.com * Copyright (c) 2012-2013, 2015 ARM Limited 39444SAndreas.Sandberg@ARM.com * Copyright (c) 2016 Google Inc. 49444SAndreas.Sandberg@ARM.com * Copyright (c) 2017, Centre National de la Recherche Scientifique 59444SAndreas.Sandberg@ARM.com * All rights reserved. 69444SAndreas.Sandberg@ARM.com * 79444SAndreas.Sandberg@ARM.com * The license below extends only to copyright in the software and shall 89444SAndreas.Sandberg@ARM.com * not be construed as granting a license to any other intellectual 99444SAndreas.Sandberg@ARM.com * property including but not limited to intellectual property relating 109444SAndreas.Sandberg@ARM.com * to a hardware implementation of the functionality of the software 119444SAndreas.Sandberg@ARM.com * licensed hereunder. You may use the software subject to the license 129444SAndreas.Sandberg@ARM.com * terms below provided that you ensure that this notice is replicated 139444SAndreas.Sandberg@ARM.com * unmodified and in its entirety in all distributions of the software, 142329SN/A * modified or unmodified, in source code or in binary form. 151689SN/A * 161689SN/A * Redistribution and use in source and binary forms, with or without 171689SN/A * modification, are permitted provided that the following conditions are 181689SN/A * met: redistributions of source code must retain the above copyright 191689SN/A * notice, this list of conditions and the following disclaimer; 201689SN/A * redistributions in binary form must reproduce the above copyright 211689SN/A * notice, this list of conditions and the following disclaimer in the 221689SN/A * documentation and/or other materials provided with the distribution; 231689SN/A * neither the name of the copyright holders nor the names of its 241689SN/A * contributors may be used to endorse or promote products derived from 251689SN/A * this software without specific prior written permission. 261689SN/A * 271689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 281689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 291689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 301689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 311689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 321689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 331689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 341689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 351689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 361689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 371689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 381689SN/A * 392665Ssaidi@eecs.umich.edu * Authors: Thomas Grass 402665Ssaidi@eecs.umich.edu * Andreas Hansson 411689SN/A * Rahul Thakur 421689SN/A * Pierre-Yves Peneau 439944Smatt.horsnell@ARM.com */ 449944Smatt.horsnell@ARM.com 459944Smatt.horsnell@ARM.com#ifndef __MEM_COMM_MONITOR_HH__ 468230Snate@binkert.org#define __MEM_COMM_MONITOR_HH__ 478230Snate@binkert.org 486658Snate@binkert.org#include "base/statistics.hh" 491717SN/A#include "mem/mem_object.hh" 508230Snate@binkert.org#include "params/CommMonitor.hh" 518232Snate@binkert.org#include "sim/probe/mem.hh" 528232Snate@binkert.org 539527SMatt.Horsnell@arm.com/** 546221Snate@binkert.org * The communication monitor is a MemObject which can monitor statistics of 558793Sgblack@eecs.umich.edu * the communication happening between two ports in the memory system. 561060SN/A * 578737Skoansin.tan@gmail.com * Currently the following stats are implemented: Histograms of read/write 588737Skoansin.tan@gmail.com * transactions, read/write burst lengths, read/write bandwidth, 598737Skoansin.tan@gmail.com * outstanding read/write requests, read latency and inter transaction time 605529Snate@binkert.org * (read-read, write-write, read/write-read/write). Furthermore it allows 611060SN/A * to capture the number of accesses to an address over time ("heat map"). 625529Snate@binkert.org * All stats can be disabled from Python. 634329Sktlim@umich.edu */ 644329Sktlim@umich.educlass CommMonitor : public MemObject 652292SN/A{ 662292SN/A 672292SN/A public: // Construction & SimObject interfaces 682292SN/A 695529Snate@binkert.org /** Parameters of communication monitor */ 701060SN/A typedef CommMonitorParams Params; 7110172Sdam.sunwoo@arm.com const Params* params() const 7210172Sdam.sunwoo@arm.com { return reinterpret_cast<const Params*>(_params); } 7310172Sdam.sunwoo@arm.com 7410172Sdam.sunwoo@arm.com /** 7510172Sdam.sunwoo@arm.com * Constructor based on the Python params 769444SAndreas.Sandberg@ARM.com * 779444SAndreas.Sandberg@ARM.com * @param params Python parameters 789444SAndreas.Sandberg@ARM.com */ 799444SAndreas.Sandberg@ARM.com CommMonitor(Params* params); 809444SAndreas.Sandberg@ARM.com 819444SAndreas.Sandberg@ARM.com void init() override; 829444SAndreas.Sandberg@ARM.com void regStats() override; 839444SAndreas.Sandberg@ARM.com void startup() override; 849444SAndreas.Sandberg@ARM.com void regProbePoints() override; 859444SAndreas.Sandberg@ARM.com 869444SAndreas.Sandberg@ARM.com public: // MemObject interfaces 879444SAndreas.Sandberg@ARM.com BaseMasterPort& getMasterPort(const std::string& if_name, 889444SAndreas.Sandberg@ARM.com PortID idx = InvalidPortID) override; 899444SAndreas.Sandberg@ARM.com 909444SAndreas.Sandberg@ARM.com BaseSlavePort& getSlavePort(const std::string& if_name, 912292SN/A PortID idx = InvalidPortID) override; 922292SN/A 932348SN/A private: 946221Snate@binkert.org 956221Snate@binkert.org /** 962292SN/A * Sender state class for the monitor so that we can annotate 976221Snate@binkert.org * packets with a transmit time and receive time. 986221Snate@binkert.org */ 996221Snate@binkert.org class CommMonitorSenderState : public Packet::SenderState 1002292SN/A { 1012292SN/A 1022292SN/A public: 1032292SN/A 1042292SN/A /** 1052292SN/A * Construct a new sender state and store the time so we can 1062292SN/A * calculate round-trip latency. 1072292SN/A * 1081060SN/A * @param _transmitTime Time of packet transmission 1091060SN/A */ 1101062SN/A CommMonitorSenderState(Tick _transmitTime) 1111062SN/A : transmitTime(_transmitTime) 1122292SN/A { } 1131062SN/A 1141062SN/A /** Destructor */ 1158240Snate@binkert.org ~CommMonitorSenderState() { } 1161062SN/A 1171062SN/A /** Tick when request is transmitted */ 1181062SN/A Tick transmitTime; 1198240Snate@binkert.org 1201062SN/A }; 1211062SN/A 1222292SN/A /** 1238240Snate@binkert.org * This is the master port of the communication monitor. All recv 1242292SN/A * functions call a function in CommMonitor, where the 1252292SN/A * send function of the slave port is called. Besides this, these 1261062SN/A * functions can also perform actions for capturing statistics. 1278240Snate@binkert.org */ 1281062SN/A class MonitorMasterPort : public MasterPort 1291062SN/A { 1301062SN/A 1318240Snate@binkert.org public: 1321062SN/A 1331062SN/A MonitorMasterPort(const std::string& _name, CommMonitor& _mon) 1342307SN/A : MasterPort(_name, &_mon), mon(_mon) 1358240Snate@binkert.org { } 1362307SN/A 1372307SN/A protected: 1381062SN/A 1398240Snate@binkert.org void recvFunctionalSnoop(PacketPtr pkt) 1401062SN/A { 1411062SN/A mon.recvFunctionalSnoop(pkt); 1421062SN/A } 1438240Snate@binkert.org 1441062SN/A Tick recvAtomicSnoop(PacketPtr pkt) 1451062SN/A { 1461062SN/A return mon.recvAtomicSnoop(pkt); 1471062SN/A } 1488240Snate@binkert.org 1491062SN/A bool recvTimingResp(PacketPtr pkt) 1501062SN/A { 1511062SN/A return mon.recvTimingResp(pkt); 1528240Snate@binkert.org } 1531062SN/A 1541062SN/A void recvTimingSnoopReq(PacketPtr pkt) 1551062SN/A { 1561062SN/A mon.recvTimingSnoopReq(pkt); 1571060SN/A } 1581060SN/A 1592292SN/A void recvRangeChange() 1601060SN/A { 1611060SN/A mon.recvRangeChange(); 1621060SN/A } 1631060SN/A 1641060SN/A bool isSnooping() const 1651060SN/A { 1661060SN/A return mon.isSnooping(); 1671060SN/A } 1681060SN/A 1691060SN/A void recvReqRetry() 1701060SN/A { 1711060SN/A mon.recvReqRetry(); 1721060SN/A } 1731060SN/A 1742292SN/A void recvRetrySnoopResp() 1751060SN/A { 1761060SN/A mon.recvRetrySnoopResp(); 1771060SN/A } 1781060SN/A 1791060SN/A private: 1801060SN/A 1811060SN/A CommMonitor& mon; 1821060SN/A 1831060SN/A }; 1842292SN/A 1851060SN/A /** Instance of master port, facing the memory side */ 1861060SN/A MonitorMasterPort masterPort; 1871060SN/A 1881060SN/A /** 1891060SN/A * This is the slave port of the communication monitor. All recv 1901060SN/A * functions call a function in CommMonitor, where the 1911060SN/A * send function of the master port is called. Besides this, these 1921060SN/A * functions can also perform actions for capturing statistics. 1932292SN/A */ 1946221Snate@binkert.org class MonitorSlavePort : public SlavePort 1952292SN/A { 1962292SN/A 1972292SN/A public: 1982292SN/A 1992307SN/A MonitorSlavePort(const std::string& _name, CommMonitor& _mon) 2009444SAndreas.Sandberg@ARM.com : SlavePort(_name, &_mon), mon(_mon) 2019444SAndreas.Sandberg@ARM.com { } 2022307SN/A 2036221Snate@binkert.org protected: 2049444SAndreas.Sandberg@ARM.com 2059444SAndreas.Sandberg@ARM.com void recvFunctional(PacketPtr pkt) 2062307SN/A { 2072307SN/A mon.recvFunctional(pkt); 2082307SN/A } 2092292SN/A 2102292SN/A Tick recvAtomic(PacketPtr pkt) 2116221Snate@binkert.org { 2122292SN/A return mon.recvAtomic(pkt); 2132292SN/A } 2142292SN/A 2152292SN/A bool recvTimingReq(PacketPtr pkt) 2162292SN/A { 2172292SN/A return mon.recvTimingReq(pkt); 2182292SN/A } 2192292SN/A 2202292SN/A bool recvTimingSnoopResp(PacketPtr pkt) 2212292SN/A { 2222292SN/A return mon.recvTimingSnoopResp(pkt); 2232292SN/A } 2242292SN/A 2252292SN/A AddrRangeList getAddrRanges() const 2262292SN/A { 2272292SN/A return mon.getAddrRanges(); 2282292SN/A } 2292292SN/A 2301681SN/A void recvRespRetry() 2312292SN/A { 2321681SN/A mon.recvRespRetry(); 2331681SN/A } 2341681SN/A 2351681SN/A private: 2361681SN/A 2372292SN/A CommMonitor& mon; 2386221Snate@binkert.org 2391060SN/A }; 2402292SN/A 2411060SN/A /** Instance of slave port, i.e. on the CPU side */ 2421060SN/A MonitorSlavePort slavePort; 2431060SN/A 2442292SN/A void recvFunctional(PacketPtr pkt); 2451060SN/A 2462348SN/A void recvFunctionalSnoop(PacketPtr pkt); 2472348SN/A 2482348SN/A Tick recvAtomic(PacketPtr pkt); 2492292SN/A 2502292SN/A Tick recvAtomicSnoop(PacketPtr pkt); 2512292SN/A 2522348SN/A bool recvTimingReq(PacketPtr pkt); 2539514SAli.Saidi@ARM.com 2549514SAli.Saidi@ARM.com bool recvTimingResp(PacketPtr pkt); 2559514SAli.Saidi@ARM.com 2562348SN/A void recvTimingSnoopReq(PacketPtr pkt); 2572348SN/A 2582348SN/A bool recvTimingSnoopResp(PacketPtr pkt); 2592348SN/A 2602292SN/A void recvRetrySnoopResp(); 2612292SN/A 2622292SN/A AddrRangeList getAddrRanges() const; 2632292SN/A 2641060SN/A bool isSnooping() const; 2651060SN/A 2661060SN/A void recvReqRetry(); 2672292SN/A 2686221Snate@binkert.org void recvRespRetry(); 2691060SN/A 2702292SN/A void recvRangeChange(); 2712292SN/A 2722292SN/A /** Stats declarations, all in a struct for convenience. */ 2732292SN/A struct MonitorStats 2742292SN/A { 2751060SN/A 2762292SN/A /** Disable flag for burst length histograms **/ 2772292SN/A bool disableBurstLengthHists; 2781060SN/A 2791681SN/A /** Histogram of read burst lengths */ 2802329SN/A Stats::Histogram readBurstLengthHist; 2812329SN/A 2822292SN/A /** Histogram of write burst lengths */ 2831060SN/A Stats::Histogram writeBurstLengthHist; 2841060SN/A 2851060SN/A /** Disable flag for the bandwidth histograms */ 2861060SN/A bool disableBandwidthHists; 2876221Snate@binkert.org 2881060SN/A /** 2897720Sgblack@eecs.umich.edu * Histogram for read bandwidth per sample window. The 2907720Sgblack@eecs.umich.edu * internal counter is an unsigned int rather than a stat. 2912292SN/A */ 2922348SN/A unsigned int readBytes; 2932292SN/A Stats::Histogram readBandwidthHist; 2942935Sksewell@umich.edu Stats::Formula averageReadBW; 2958842Smrinmoy.ghosh@arm.com Stats::Scalar totalReadBytes; 2966036Sksewell@umich.edu 2972292SN/A /** 2986036Sksewell@umich.edu * Histogram for write bandwidth per sample window. The 2997720Sgblack@eecs.umich.edu * internal counter is an unsigned int rather than a stat. 3008503Sgblack@eecs.umich.edu */ 3018842Smrinmoy.ghosh@arm.com unsigned int writtenBytes; 3028842Smrinmoy.ghosh@arm.com Stats::Histogram writeBandwidthHist; 3038842Smrinmoy.ghosh@arm.com Stats::Formula averageWriteBW; 3046036Sksewell@umich.edu Stats::Scalar totalWrittenBytes; 3053093Sksewell@umich.edu 3062935Sksewell@umich.edu /** Disable flag for latency histograms. */ 3072348SN/A bool disableLatencyHists; 3082292SN/A 3092292SN/A /** Histogram of read request-to-response latencies */ 3102292SN/A Stats::Histogram readLatencyHist; 3112292SN/A 3122292SN/A /** Histogram of write request-to-response latencies */ 3131060SN/A Stats::Histogram writeLatencyHist; 3142292SN/A 3151060SN/A /** Disable flag for ITT distributions. */ 3162292SN/A bool disableITTDists; 3172292SN/A 3182935Sksewell@umich.edu /** 3192731Sktlim@umich.edu * Inter transaction time (ITT) distributions. There are 3202292SN/A * histograms of the time between two read, write or arbitrary 3212292SN/A * accesses. The time of a request is the tick at which the 3222292SN/A * request is forwarded by the monitor. 3232348SN/A */ 3242348SN/A Stats::Distribution ittReadRead; 3252292SN/A Stats::Distribution ittWriteWrite; 3262292SN/A Stats::Distribution ittReqReq; 3272292SN/A Tick timeOfLastRead; 3281060SN/A Tick timeOfLastWrite; 3292292SN/A Tick timeOfLastReq; 3302292SN/A 3312292SN/A /** Disable flag for outstanding histograms. */ 3322292SN/A bool disableOutstandingHists; 3332292SN/A 3342935Sksewell@umich.edu /** 3352292SN/A * Histogram of outstanding read requests. Counter for 3362292SN/A * outstanding read requests is an unsigned integer because 3372292SN/A * it should not be reset when stats are reset. 3382292SN/A */ 3396221Snate@binkert.org Stats::Histogram outstandingReadsHist; 3402292SN/A unsigned int outstandingReadReqs; 3412292SN/A 3422292SN/A /** 3432292SN/A * Histogram of outstanding write requests. Counter for 3442292SN/A * outstanding write requests is an unsigned integer because 3458793Sgblack@eecs.umich.edu * it should not be reset when stats are reset. 3468793Sgblack@eecs.umich.edu */ 3472292SN/A Stats::Histogram outstandingWritesHist; 3488793Sgblack@eecs.umich.edu unsigned int outstandingWriteReqs; 3498793Sgblack@eecs.umich.edu 3508793Sgblack@eecs.umich.edu /** Disable flag for transaction histograms. */ 3518793Sgblack@eecs.umich.edu bool disableTransactionHists; 3528793Sgblack@eecs.umich.edu 3538793Sgblack@eecs.umich.edu /** Histogram of number of read transactions per time bin */ 3548793Sgblack@eecs.umich.edu Stats::Histogram readTransHist; 3558793Sgblack@eecs.umich.edu unsigned int readTrans; 3562292SN/A 3572292SN/A /** Histogram of number of timing write transactions per time bin */ 3582292SN/A Stats::Histogram writeTransHist; 3592292SN/A unsigned int writeTrans; 3602292SN/A 3612292SN/A /** Disable flag for address distributions. */ 3622292SN/A bool disableAddrDists; 3632292SN/A 3642292SN/A /** Address mask for sources of read accesses to be captured */ 3652292SN/A const Addr readAddrMask; 3662292SN/A 3672731Sktlim@umich.edu /** Address mask for sources of write accesses to be captured */ 3682292SN/A const Addr writeAddrMask; 3692292SN/A 3702292SN/A /** 3712292SN/A * Histogram of number of read accesses to addresses over 3722348SN/A * time. 3732348SN/A */ 3742292SN/A Stats::SparseHistogram readAddrDist; 3752292SN/A 3762292SN/A /** 3772292SN/A * Histogram of number of write accesses to addresses over 3782292SN/A * time. 3792292SN/A */ 3802292SN/A Stats::SparseHistogram writeAddrDist; 3812292SN/A 3822292SN/A /** 3832292SN/A * Create the monitor stats and initialise all the members 3842292SN/A * that are not statistics themselves, but used to control the 3852292SN/A * stats or track values during a sample period. 3862292SN/A */ 3876221Snate@binkert.org MonitorStats(const CommMonitorParams* params) : 3882292SN/A disableBurstLengthHists(params->disable_burst_length_hists), 3892292SN/A disableBandwidthHists(params->disable_bandwidth_hists), 3902292SN/A readBytes(0), writtenBytes(0), 3912292SN/A disableLatencyHists(params->disable_latency_hists), 3922292SN/A disableITTDists(params->disable_itt_dists), 3932292SN/A timeOfLastRead(0), timeOfLastWrite(0), timeOfLastReq(0), 3942292SN/A disableOutstandingHists(params->disable_outstanding_hists), 3952292SN/A outstandingReadReqs(0), outstandingWriteReqs(0), 3962292SN/A disableTransactionHists(params->disable_transaction_hists), 3972292SN/A readTrans(0), writeTrans(0), 3987720Sgblack@eecs.umich.edu disableAddrDists(params->disable_addr_dists), 3997720Sgblack@eecs.umich.edu readAddrMask(params->read_addr_mask), 4002292SN/A writeAddrMask(params->write_addr_mask) 4012292SN/A { } 4022292SN/A 4032292SN/A void updateReqStats(const ProbePoints::PacketInfo& pkt, bool is_atomic, 4042329SN/A bool expects_response); 4052292SN/A void updateRespStats(const ProbePoints::PacketInfo& pkt, Tick latency, 4062292SN/A bool is_atomic); 4072292SN/A }; 4082292SN/A 4092292SN/A /** This function is called periodically at the end of each time bin */ 4102292SN/A void samplePeriodic(); 4112292SN/A 4122292SN/A /** Periodic event called at the end of each simulation time bin */ 4136221Snate@binkert.org EventFunctionWrapper samplePeriodicEvent; 4146221Snate@binkert.org 4152292SN/A /** 4163867Sbinkertn@umich.edu *@{ 4176221Snate@binkert.org * @name Configuration 4183867Sbinkertn@umich.edu */ 4192292SN/A 4202292SN/A /** Length of simulation time bin*/ 4212292SN/A const Tick samplePeriodTicks; 4222292SN/A /** Sample period in seconds */ 4232292SN/A const double samplePeriod; 4242292SN/A 4252292SN/A /** @} */ 4262292SN/A 4272292SN/A /** Instantiate stats */ 4282292SN/A MonitorStats stats; 4292292SN/A 4302292SN/A protected: // Probe points 4316221Snate@binkert.org /** 4326221Snate@binkert.org * @{ 4332292SN/A * @name Memory system probe points 4343867Sbinkertn@umich.edu */ 4356221Snate@binkert.org 4362292SN/A /** Successfully forwarded request packet */ 4372292SN/A ProbePoints::PacketUPtr ppPktReq; 4382292SN/A 4392292SN/A /** Successfully forwarded response packet */ 4402292SN/A ProbePoints::PacketUPtr ppPktResp; 4412292SN/A 4422292SN/A /** @} */ 4432292SN/A}; 4442292SN/A 4452292SN/A#endif //__MEM_COMM_MONITOR_HH__ 4462292SN/A