comm_monitor.hh revision 11804
12SN/A/* 22190SN/A * Copyright (c) 2012-2013, 2015 ARM Limited 32SN/A * Copyright (c) 2016 Google Inc. 42SN/A * All rights reserved. 52SN/A * 62SN/A * The license below extends only to copyright in the software and shall 72SN/A * not be construed as granting a license to any other intellectual 82SN/A * property including but not limited to intellectual property relating 92SN/A * to a hardware implementation of the functionality of the software 102SN/A * licensed hereunder. You may use the software subject to the license 112SN/A * terms below provided that you ensure that this notice is replicated 122SN/A * unmodified and in its entirety in all distributions of the software, 132SN/A * modified or unmodified, in source code or in binary form. 142SN/A * 152SN/A * Redistribution and use in source and binary forms, with or without 162SN/A * modification, are permitted provided that the following conditions are 172SN/A * met: redistributions of source code must retain the above copyright 182SN/A * notice, this list of conditions and the following disclaimer; 192SN/A * redistributions in binary form must reproduce the above copyright 202SN/A * notice, this list of conditions and the following disclaimer in the 212SN/A * documentation and/or other materials provided with the distribution; 222SN/A * neither the name of the copyright holders nor the names of its 232SN/A * contributors may be used to endorse or promote products derived from 242SN/A * this software without specific prior written permission. 252SN/A * 262SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 272665SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 282665SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 302SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 312680Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 322680Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 332SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 348229Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 357680Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 367680Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 376329Sgblack@eecs.umich.edu * 383453Sgblack@eecs.umich.edu * Authors: Thomas Grass 396216Snate@binkert.org * Andreas Hansson 401858SN/A * Rahul Thakur 416658Snate@binkert.org */ 422SN/A 432190SN/A#ifndef __MEM_COMM_MONITOR_HH__ 442190SN/A#define __MEM_COMM_MONITOR_HH__ 453453Sgblack@eecs.umich.edu 463453Sgblack@eecs.umich.edu#include "base/statistics.hh" 476022Sgblack@eecs.umich.edu#include "mem/mem_object.hh" 483453Sgblack@eecs.umich.edu#include "params/CommMonitor.hh" 492190SN/A#include "sim/probe/mem.hh" 507680Sgblack@eecs.umich.edu 518541Sgblack@eecs.umich.edu/** 522313SN/A * The communication monitor is a MemObject which can monitor statistics of 538706Sandreas.hansson@arm.com * the communication happening between two ports in the memory system. 548706Sandreas.hansson@arm.com * 558706Sandreas.hansson@arm.com * Currently the following stats are implemented: Histograms of read/write 562190SN/A * transactions, read/write burst lengths, read/write bandwidth, 572190SN/A * outstanding read/write requests, read latency and inter transaction time 583548Sgblack@eecs.umich.edu * (read-read, write-write, read/write-read/write). Furthermore it allows 593548Sgblack@eecs.umich.edu * to capture the number of accesses to an address over time ("heat map"). 603548Sgblack@eecs.umich.edu * All stats can be disabled from Python. 613548Sgblack@eecs.umich.edu */ 622330SN/Aclass CommMonitor : public MemObject 632SN/A{ 642680Sktlim@umich.edu 652680Sktlim@umich.edu public: // Construction & SimObject interfaces 662680Sktlim@umich.edu 672680Sktlim@umich.edu /** Parameters of communication monitor */ 682680Sktlim@umich.edu typedef CommMonitorParams Params; 692680Sktlim@umich.edu const Params* params() const 702680Sktlim@umich.edu { return reinterpret_cast<const Params*>(_params); } 712680Sktlim@umich.edu 722680Sktlim@umich.edu /** 732680Sktlim@umich.edu * Constructor based on the Python params 742680Sktlim@umich.edu * 752682Sktlim@umich.edu * @param params Python parameters 762680Sktlim@umich.edu */ 772680Sktlim@umich.edu CommMonitor(Params* params); 782680Sktlim@umich.edu 792680Sktlim@umich.edu void init() override; 802680Sktlim@umich.edu void regStats() override; 812SN/A void startup() override; 822107SN/A void regProbePoints() override; 832107SN/A 842190SN/A public: // MemObject interfaces 852455SN/A BaseMasterPort& getMasterPort(const std::string& if_name, 862455SN/A PortID idx = InvalidPortID) override; 872159SN/A 882SN/A BaseSlavePort& getSlavePort(const std::string& if_name, 896029Ssteve.reinhardt@amd.com PortID idx = InvalidPortID) override; 90246SN/A 91246SN/A private: 92246SN/A 93246SN/A /** 94246SN/A * Sender state class for the monitor so that we can annotate 95246SN/A * packets with a transmit time and receive time. 96246SN/A */ 972190SN/A class CommMonitorSenderState : public Packet::SenderState 98246SN/A { 99246SN/A 100246SN/A public: 101246SN/A 102246SN/A /** 103246SN/A * Construct a new sender state and store the time so we can 104246SN/A * calculate round-trip latency. 1052SN/A * 1062680Sktlim@umich.edu * @param _transmitTime Time of packet transmission 1072423SN/A */ 1082190SN/A CommMonitorSenderState(Tick _transmitTime) 109180SN/A : transmitTime(_transmitTime) 1105712Shsul@eecs.umich.edu { } 1112190SN/A 1125715Shsul@eecs.umich.edu /** Destructor */ 1135715Shsul@eecs.umich.edu ~CommMonitorSenderState() { } 1145715Shsul@eecs.umich.edu 1155714Shsul@eecs.umich.edu /** Tick when request is transmitted */ 1165714Shsul@eecs.umich.edu Tick transmitTime; 1175714Shsul@eecs.umich.edu 1185714Shsul@eecs.umich.edu }; 1195714Shsul@eecs.umich.edu 1206022Sgblack@eecs.umich.edu /** 1212190SN/A * This is the master port of the communication monitor. All recv 1226022Sgblack@eecs.umich.edu * functions call a function in CommMonitor, where the 1232521SN/A * send function of the slave port is called. Besides this, these 1248541Sgblack@eecs.umich.edu * functions can also perform actions for capturing statistics. 1258541Sgblack@eecs.umich.edu */ 1264997Sgblack@eecs.umich.edu class MonitorMasterPort : public MasterPort 1274997Sgblack@eecs.umich.edu { 1285803Snate@binkert.org 1293548Sgblack@eecs.umich.edu public: 1302654SN/A 1318706Sandreas.hansson@arm.com MonitorMasterPort(const std::string& _name, CommMonitor& _mon) 1322521SN/A : MasterPort(_name, &_mon), mon(_mon) 1338706Sandreas.hansson@arm.com { } 1343673Srdreslin@umich.edu 1358706Sandreas.hansson@arm.com protected: 1368706Sandreas.hansson@arm.com 1378706Sandreas.hansson@arm.com void recvFunctionalSnoop(PacketPtr pkt) 1388706Sandreas.hansson@arm.com { 1398706Sandreas.hansson@arm.com mon.recvFunctionalSnoop(pkt); 1408706Sandreas.hansson@arm.com } 1418706Sandreas.hansson@arm.com 1422190SN/A Tick recvAtomicSnoop(PacketPtr pkt) 1438706Sandreas.hansson@arm.com { 1442518SN/A return mon.recvAtomicSnoop(pkt); 1452190SN/A } 1462190SN/A 1472190SN/A bool recvTimingResp(PacketPtr pkt) 1482190SN/A { 1492159SN/A return mon.recvTimingResp(pkt); 1502235SN/A } 1512103SN/A 152393SN/A void recvTimingSnoopReq(PacketPtr pkt) 153393SN/A { 1542190SN/A mon.recvTimingSnoopReq(pkt); 155393SN/A } 156393SN/A 1575250Sksewell@umich.edu void recvRangeChange() 158393SN/A { 159393SN/A mon.recvRangeChange(); 1605250Sksewell@umich.edu } 1612159SN/A 1622159SN/A bool isSnooping() const 1632190SN/A { 1642159SN/A return mon.isSnooping(); 1652159SN/A } 1662680Sktlim@umich.edu 1672159SN/A void recvReqRetry() 1682190SN/A { 1692159SN/A mon.recvReqRetry(); 1702190SN/A } 1712190SN/A 1722159SN/A void recvRetrySnoopResp() 1732235SN/A { 1742313SN/A mon.recvRetrySnoopResp(); 1752235SN/A } 1762235SN/A 1772235SN/A private: 1782235SN/A 1792235SN/A CommMonitor& mon; 1802254SN/A 1812254SN/A }; 1822254SN/A 1832235SN/A /** Instance of master port, facing the memory side */ 1842235SN/A MonitorMasterPort masterPort; 1852680Sktlim@umich.edu 1862159SN/A /** 1872190SN/A * This is the slave port of the communication monitor. All recv 1882159SN/A * functions call a function in CommMonitor, where the 1892159SN/A * send function of the master port is called. Besides this, these 1902159SN/A * functions can also perform actions for capturing statistics. 1912159SN/A */ 1922190SN/A class MonitorSlavePort : public SlavePort 1932159SN/A { 1942455SN/A 1952159SN/A public: 1962455SN/A 1972159SN/A MonitorSlavePort(const std::string& _name, CommMonitor& _mon) 1982190SN/A : SlavePort(_name, &_mon), mon(_mon) 1992159SN/A { } 2002455SN/A 2012159SN/A protected: 2022455SN/A 2032455SN/A void recvFunctional(PacketPtr pkt) 2047720Sgblack@eecs.umich.edu { 2052159SN/A mon.recvFunctional(pkt); 2067720Sgblack@eecs.umich.edu } 2072159SN/A 2087720Sgblack@eecs.umich.edu Tick recvAtomic(PacketPtr pkt) 2092159SN/A { 2107720Sgblack@eecs.umich.edu return mon.recvAtomic(pkt); 2112159SN/A } 2127720Sgblack@eecs.umich.edu 2135260Sksewell@umich.edu bool recvTimingReq(PacketPtr pkt) 2144172Ssaidi@eecs.umich.edu { 2154172Ssaidi@eecs.umich.edu return mon.recvTimingReq(pkt); 2162190SN/A } 2172159SN/A 2184172Ssaidi@eecs.umich.edu bool recvTimingSnoopResp(PacketPtr pkt) 2192190SN/A { 2203468Sgblack@eecs.umich.edu return mon.recvTimingSnoopResp(pkt); 2212190SN/A } 2226313Sgblack@eecs.umich.edu 2236313Sgblack@eecs.umich.edu AddrRangeList getAddrRanges() const 2246313Sgblack@eecs.umich.edu { 2256221Snate@binkert.org return mon.getAddrRanges(); 2266221Snate@binkert.org } 2276221Snate@binkert.org 2286221Snate@binkert.org void recvRespRetry() 2296221Snate@binkert.org { 2304661Sksewell@umich.edu mon.recvRespRetry(); 2316221Snate@binkert.org } 2326221Snate@binkert.org 2336221Snate@binkert.org private: 2346221Snate@binkert.org 2354661Sksewell@umich.edu CommMonitor& mon; 2362235SN/A 2372235SN/A }; 2382190SN/A 2392190SN/A /** Instance of slave port, i.e. on the CPU side */ 2402190SN/A MonitorSlavePort slavePort; 2412159SN/A 2422235SN/A void recvFunctional(PacketPtr pkt); 2432190SN/A 2442190SN/A void recvFunctionalSnoop(PacketPtr pkt); 2452159SN/A 2462235SN/A Tick recvAtomic(PacketPtr pkt); 2472190SN/A 2482834Sksewell@umich.edu Tick recvAtomicSnoop(PacketPtr pkt); 2494111Sgblack@eecs.umich.edu 2504111Sgblack@eecs.umich.edu bool recvTimingReq(PacketPtr pkt); 2512834Sksewell@umich.edu 2522834Sksewell@umich.edu bool recvTimingResp(PacketPtr pkt); 2532834Sksewell@umich.edu 2542834Sksewell@umich.edu void recvTimingSnoopReq(PacketPtr pkt); 2552159SN/A 2562525SN/A bool recvTimingSnoopResp(PacketPtr pkt); 2575217Ssaidi@eecs.umich.edu 2585217Ssaidi@eecs.umich.edu void recvRetrySnoopResp(); 2592159SN/A 2602159SN/A AddrRangeList getAddrRanges() const; 2612682Sktlim@umich.edu 2622682Sktlim@umich.edu bool isSnooping() const; 2632682Sktlim@umich.edu 2642682Sktlim@umich.edu void recvReqRetry(); 2652682Sktlim@umich.edu 2662682Sktlim@umich.edu void recvRespRetry(); 2672682Sktlim@umich.edu 2682682Sktlim@umich.edu void recvRangeChange(); 2692682Sktlim@umich.edu 2702682Sktlim@umich.edu /** Stats declarations, all in a struct for convenience. */ 2712680Sktlim@umich.edu struct MonitorStats 2722680Sktlim@umich.edu { 2732190SN/A 2742190SN/A /** Disable flag for burst length historgrams **/ 2752680Sktlim@umich.edu bool disableBurstLengthHists; 2762680Sktlim@umich.edu 2772159SN/A /** Histogram of read burst lengths */ 2782190SN/A Stats::Histogram readBurstLengthHist; 2792680Sktlim@umich.edu 2802SN/A /** Histogram of write burst lengths */ 2812SN/A Stats::Histogram writeBurstLengthHist; 2822SN/A 2832680Sktlim@umich.edu /** Disable flag for the bandwidth histograms */ 2842SN/A bool disableBandwidthHists; 2855712Shsul@eecs.umich.edu 2862SN/A /** 2875715Shsul@eecs.umich.edu * Histogram for read bandwidth per sample window. The 2885715Shsul@eecs.umich.edu * internal counter is an unsigned int rather than a stat. 2895715Shsul@eecs.umich.edu */ 2905714Shsul@eecs.umich.edu unsigned int readBytes; 2915714Shsul@eecs.umich.edu Stats::Histogram readBandwidthHist; 2925714Shsul@eecs.umich.edu Stats::Formula averageReadBW; 2935714Shsul@eecs.umich.edu Stats::Scalar totalReadBytes; 2945714Shsul@eecs.umich.edu 2956022Sgblack@eecs.umich.edu /** 2961917SN/A * Histogram for write bandwidth per sample window. The 2976022Sgblack@eecs.umich.edu * internal counter is an unsigned int rather than a stat. 2982521SN/A */ 2998541Sgblack@eecs.umich.edu unsigned int writtenBytes; 3008541Sgblack@eecs.umich.edu Stats::Histogram writeBandwidthHist; 3014997Sgblack@eecs.umich.edu Stats::Formula averageWriteBW; 3024997Sgblack@eecs.umich.edu Stats::Scalar totalWrittenBytes; 3035803Snate@binkert.org 3043548Sgblack@eecs.umich.edu /** Disable flag for latency histograms. */ 3053548Sgblack@eecs.umich.edu bool disableLatencyHists; 3062654SN/A 3078706Sandreas.hansson@arm.com /** Histogram of read request-to-response latencies */ 3082521SN/A Stats::Histogram readLatencyHist; 3098706Sandreas.hansson@arm.com 3103673Srdreslin@umich.edu /** Histogram of write request-to-response latencies */ 3118706Sandreas.hansson@arm.com Stats::Histogram writeLatencyHist; 3122SN/A 3138706Sandreas.hansson@arm.com /** Disable flag for ITT distributions. */ 3142518SN/A bool disableITTDists; 3152680Sktlim@umich.edu 3162SN/A /** 3172SN/A * Inter transaction time (ITT) distributions. There are 3182680Sktlim@umich.edu * histograms of the time between two read, write or arbitrary 319595SN/A * accesses. The time of a request is the tick at which the 3202680Sktlim@umich.edu * request is forwarded by the monitor. 3212SN/A */ 3222190SN/A Stats::Distribution ittReadRead; 3232190SN/A Stats::Distribution ittWriteWrite; 3242680Sktlim@umich.edu Stats::Distribution ittReqReq; 3252SN/A Tick timeOfLastRead; 3262190SN/A Tick timeOfLastWrite; 3275250Sksewell@umich.edu Tick timeOfLastReq; 3282SN/A 3292190SN/A /** Disable flag for outstanding histograms. */ 3305250Sksewell@umich.edu bool disableOutstandingHists; 331217SN/A 3321858SN/A /** 3332680Sktlim@umich.edu * Histogram of outstanding read requests. Counter for 3342190SN/A * outstanding read requests is an unsigned integer because 3352190SN/A * it should not be reset when stats are reset. 3362680Sktlim@umich.edu */ 3372680Sktlim@umich.edu Stats::Histogram outstandingReadsHist; 3382190SN/A unsigned int outstandingReadReqs; 3392680Sktlim@umich.edu 3402190SN/A /** 3412680Sktlim@umich.edu * Histogram of outstanding write requests. Counter for 3422190SN/A * outstanding write requests is an unsigned integer because 3432680Sktlim@umich.edu * it should not be reset when stats are reset. 3442190SN/A */ 3452235SN/A Stats::Histogram outstandingWritesHist; 3462680Sktlim@umich.edu unsigned int outstandingWriteReqs; 3472235SN/A 3482680Sktlim@umich.edu /** Disable flag for transaction histograms. */ 3492680Sktlim@umich.edu bool disableTransactionHists; 3502254SN/A 3512680Sktlim@umich.edu /** Histogram of number of read transactions per time bin */ 3522680Sktlim@umich.edu Stats::Histogram readTransHist; 3532235SN/A unsigned int readTrans; 3542SN/A 3552190SN/A /** Histogram of number of timing write transactions per time bin */ 3562680Sktlim@umich.edu Stats::Histogram writeTransHist; 3572SN/A unsigned int writeTrans; 3582680Sktlim@umich.edu 359716SN/A /** Disable flag for address distributions. */ 3602SN/A bool disableAddrDists; 3612SN/A 3622SN/A /** Address mask for sources of read accesses to be captured */ 3632SN/A const Addr readAddrMask; 3642680Sktlim@umich.edu 3652SN/A /** Address mask for sources of write accesses to be captured */ 3662455SN/A const Addr writeAddrMask; 3672680Sktlim@umich.edu 3682SN/A /** 3692455SN/A * Histogram of number of read accesses to addresses over 3702680Sktlim@umich.edu * time. 3712SN/A */ 3722SN/A Stats::SparseHistogram readAddrDist; 3732680Sktlim@umich.edu 3742SN/A /** 3752455SN/A * Histogram of number of write accesses to addresses over 3762680Sktlim@umich.edu * time. 3772SN/A */ 3782455SN/A Stats::SparseHistogram writeAddrDist; 3792680Sktlim@umich.edu 3802SN/A /** 3817720Sgblack@eecs.umich.edu * Create the monitor stats and initialise all the members 3822SN/A * that are not statistics themselves, but used to control the 3837720Sgblack@eecs.umich.edu * stats or track values during a sample period. 3842206SN/A */ 3857720Sgblack@eecs.umich.edu MonitorStats(const CommMonitorParams* params) : 3867720Sgblack@eecs.umich.edu disableBurstLengthHists(params->disable_burst_length_hists), 3877720Sgblack@eecs.umich.edu disableBandwidthHists(params->disable_bandwidth_hists), 3885260Sksewell@umich.edu readBytes(0), writtenBytes(0), 3897597Sminkyu.jeong@arm.com disableLatencyHists(params->disable_latency_hists), 3907597Sminkyu.jeong@arm.com disableITTDists(params->disable_itt_dists), 3917597Sminkyu.jeong@arm.com timeOfLastRead(0), timeOfLastWrite(0), timeOfLastReq(0), 3927597Sminkyu.jeong@arm.com disableOutstandingHists(params->disable_outstanding_hists), 3937597Sminkyu.jeong@arm.com outstandingReadReqs(0), outstandingWriteReqs(0), 3944172Ssaidi@eecs.umich.edu disableTransactionHists(params->disable_transaction_hists), 3954172Ssaidi@eecs.umich.edu readTrans(0), writeTrans(0), 3964172Ssaidi@eecs.umich.edu disableAddrDists(params->disable_addr_dists), 3972159SN/A readAddrMask(params->read_addr_mask), 3982680Sktlim@umich.edu writeAddrMask(params->write_addr_mask) 3992SN/A { } 4004172Ssaidi@eecs.umich.edu 4014172Ssaidi@eecs.umich.edu void updateReqStats(const ProbePoints::PacketInfo& pkt, bool is_atomic, 4022SN/A bool expects_response); 4033468Sgblack@eecs.umich.edu void updateRespStats(const ProbePoints::PacketInfo& pkt, Tick latency, 4042680Sktlim@umich.edu bool is_atomic); 4052SN/A }; 4066313Sgblack@eecs.umich.edu 4076313Sgblack@eecs.umich.edu /** This function is called periodically at the end of each time bin */ 4086313Sgblack@eecs.umich.edu void samplePeriodic(); 4096313Sgblack@eecs.umich.edu 4106313Sgblack@eecs.umich.edu /** Periodic event called at the end of each simulation time bin */ 4116313Sgblack@eecs.umich.edu EventWrapper<CommMonitor, &CommMonitor::samplePeriodic> samplePeriodicEvent; 4122190SN/A 4132680Sktlim@umich.edu /** 4142190SN/A *@{ 4152190SN/A * @name Configuration 4162680Sktlim@umich.edu */ 4172SN/A 4182190SN/A /** Length of simulation time bin*/ 4192680Sktlim@umich.edu const Tick samplePeriodTicks; 4202190SN/A /** Sample period in seconds */ 4211858SN/A const double samplePeriod; 4224111Sgblack@eecs.umich.edu 4234111Sgblack@eecs.umich.edu /** @} */ 4244111Sgblack@eecs.umich.edu 4252680Sktlim@umich.edu /** Instantiate stats */ 4262SN/A MonitorStats stats; 4272SN/A 4282SN/A protected: // Probe points 4292190SN/A /** 430 * @{ 431 * @name Memory system probe points 432 */ 433 434 /** Successfully forwarded request packet */ 435 ProbePoints::PacketUPtr ppPktReq; 436 437 /** Successfully forwarded response packet */ 438 ProbePoints::PacketUPtr ppPktResp; 439 440 /** @} */ 441}; 442 443#endif //__MEM_COMM_MONITOR_HH__ 444