comm_monitor.hh revision 10412:6400a2ab4e22
14776SN/A/* 27414SAli.Saidi@ARM.com * Copyright (c) 2012-2013 ARM Limited 37414SAli.Saidi@ARM.com * All rights reserved 47414SAli.Saidi@ARM.com * 57414SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 67414SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 77414SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 87414SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 97414SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 107414SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 117414SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 127414SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 137414SAli.Saidi@ARM.com * 146365SN/A * Redistribution and use in source and binary forms, with or without 154776SN/A * modification, are permitted provided that the following conditions are 164776SN/A * met: redistributions of source code must retain the above copyright 174776SN/A * notice, this list of conditions and the following disclaimer; 184776SN/A * redistributions in binary form must reproduce the above copyright 194776SN/A * notice, this list of conditions and the following disclaimer in the 204776SN/A * documentation and/or other materials provided with the distribution; 214776SN/A * neither the name of the copyright holders nor the names of its 224776SN/A * contributors may be used to endorse or promote products derived from 234776SN/A * this software without specific prior written permission. 244776SN/A * 254776SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 264776SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 274776SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 284776SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 294776SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 304776SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 314776SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 324776SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 334776SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 344776SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 354776SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 364776SN/A * 374776SN/A * Authors: Thomas Grass 384776SN/A * Andreas Hansson 394776SN/A */ 406365SN/A 414776SN/A#ifndef __MEM_COMM_MONITOR_HH__ 424776SN/A#define __MEM_COMM_MONITOR_HH__ 436397Sgblack@eecs.umich.edu 446397Sgblack@eecs.umich.edu#include "base/statistics.hh" 456397Sgblack@eecs.umich.edu#include "base/time.hh" 464776SN/A#include "mem/mem_object.hh" 476397Sgblack@eecs.umich.edu#include "params/CommMonitor.hh" 484776SN/A#include "proto/protoio.hh" 494776SN/A#include "sim/system.hh" 504776SN/A 516398Sgblack@eecs.umich.edu/** 526397Sgblack@eecs.umich.edu * The communication monitor is a MemObject which can monitor statistics of 536397Sgblack@eecs.umich.edu * the communication happening between two ports in the memory system. 546397Sgblack@eecs.umich.edu * 556397Sgblack@eecs.umich.edu * Currently the following stats are implemented: Histograms of read/write 566365SN/A * transactions, read/write burst lengths, read/write bandwidth, 576398Sgblack@eecs.umich.edu * outstanding read/write requests, read latency and inter transaction time 586398Sgblack@eecs.umich.edu * (read-read, write-write, read/write-read/write). Furthermore it allows 596398Sgblack@eecs.umich.edu * to capture the number of accesses to an address over time ("heat map"). 606398Sgblack@eecs.umich.edu * All stats can be disabled from Python. 616398Sgblack@eecs.umich.edu */ 626398Sgblack@eecs.umich.educlass CommMonitor : public MemObject 636398Sgblack@eecs.umich.edu{ 646398Sgblack@eecs.umich.edu 656398Sgblack@eecs.umich.edu public: 666411Sgblack@eecs.umich.edu 676411Sgblack@eecs.umich.edu /** Parameters of communication monitor */ 686411Sgblack@eecs.umich.edu typedef CommMonitorParams Params; 696411Sgblack@eecs.umich.edu const Params* params() const 706411Sgblack@eecs.umich.edu { return reinterpret_cast<const Params*>(_params); } 716411Sgblack@eecs.umich.edu 726411Sgblack@eecs.umich.edu /** 736398Sgblack@eecs.umich.edu * Constructor based on the Python params 746411Sgblack@eecs.umich.edu * 756411Sgblack@eecs.umich.edu * @param params Python parameters 766411Sgblack@eecs.umich.edu */ 776411Sgblack@eecs.umich.edu CommMonitor(Params* params); 786411Sgblack@eecs.umich.edu 796411Sgblack@eecs.umich.edu /** Destructor */ 806411Sgblack@eecs.umich.edu ~CommMonitor(); 816411Sgblack@eecs.umich.edu 826411Sgblack@eecs.umich.edu /** 836411Sgblack@eecs.umich.edu * Callback to flush and close all open output streams on exit. If 846411Sgblack@eecs.umich.edu * we were calling the destructor it could be done there. 856411Sgblack@eecs.umich.edu */ 866411Sgblack@eecs.umich.edu void closeStreams(); 876411Sgblack@eecs.umich.edu 886411Sgblack@eecs.umich.edu virtual BaseMasterPort& getMasterPort(const std::string& if_name, 896411Sgblack@eecs.umich.edu PortID idx = InvalidPortID); 906411Sgblack@eecs.umich.edu 916398Sgblack@eecs.umich.edu virtual BaseSlavePort& getSlavePort(const std::string& if_name, 926398Sgblack@eecs.umich.edu PortID idx = InvalidPortID); 936398Sgblack@eecs.umich.edu 946398Sgblack@eecs.umich.edu virtual void init(); 956398Sgblack@eecs.umich.edu 966398Sgblack@eecs.umich.edu /** Register statistics */ 976398Sgblack@eecs.umich.edu void regStats(); 986398Sgblack@eecs.umich.edu 996398Sgblack@eecs.umich.edu private: 1006398Sgblack@eecs.umich.edu 1016398Sgblack@eecs.umich.edu /** 1026398Sgblack@eecs.umich.edu * Sender state class for the monitor so that we can annotate 1036398Sgblack@eecs.umich.edu * packets with a transmit time and receive time. 1046398Sgblack@eecs.umich.edu */ 1056398Sgblack@eecs.umich.edu class CommMonitorSenderState : public Packet::SenderState 1066398Sgblack@eecs.umich.edu { 1076398Sgblack@eecs.umich.edu 1086398Sgblack@eecs.umich.edu public: 1096398Sgblack@eecs.umich.edu 1106398Sgblack@eecs.umich.edu /** 1116398Sgblack@eecs.umich.edu * Construct a new sender state and store the time so we can 1126724Sgblack@eecs.umich.edu * calculate round-trip latency. 1136724Sgblack@eecs.umich.edu * 1146398Sgblack@eecs.umich.edu * @param _transmitTime Time of packet transmission 1156398Sgblack@eecs.umich.edu */ 1166365SN/A CommMonitorSenderState(Tick _transmitTime) 1176365SN/A : transmitTime(_transmitTime) 1186397Sgblack@eecs.umich.edu { } 1194776SN/A 1206417Sgblack@eecs.umich.edu /** Destructor */ 1216417Sgblack@eecs.umich.edu ~CommMonitorSenderState() { } 1226417Sgblack@eecs.umich.edu 1236417Sgblack@eecs.umich.edu /** Tick when request is transmitted */ 1246417Sgblack@eecs.umich.edu Tick transmitTime; 1256398Sgblack@eecs.umich.edu 1266417Sgblack@eecs.umich.edu }; 1275523SN/A 1287414SAli.Saidi@ARM.com /** 1297414SAli.Saidi@ARM.com * This is the master port of the communication monitor. All recv 1307414SAli.Saidi@ARM.com * functions call a function in CommMonitor, where the 1317414SAli.Saidi@ARM.com * send function of the slave port is called. Besides this, these 1327414SAli.Saidi@ARM.com * functions can also perform actions for capturing statistics. 1337414SAli.Saidi@ARM.com */ 1347414SAli.Saidi@ARM.com class MonitorMasterPort : public MasterPort 1357414SAli.Saidi@ARM.com { 1366409Sgblack@eecs.umich.edu 1376397Sgblack@eecs.umich.edu public: 1386398Sgblack@eecs.umich.edu 1396398Sgblack@eecs.umich.edu MonitorMasterPort(const std::string& _name, CommMonitor& _mon) 1406398Sgblack@eecs.umich.edu : MasterPort(_name, &_mon), mon(_mon) 1416410Sgblack@eecs.umich.edu { } 1426410Sgblack@eecs.umich.edu 1436410Sgblack@eecs.umich.edu protected: 1446410Sgblack@eecs.umich.edu 1456410Sgblack@eecs.umich.edu void recvFunctionalSnoop(PacketPtr pkt) 1466410Sgblack@eecs.umich.edu { 1476398Sgblack@eecs.umich.edu mon.recvFunctionalSnoop(pkt); 1486410Sgblack@eecs.umich.edu } 1496398Sgblack@eecs.umich.edu 1506398Sgblack@eecs.umich.edu Tick recvAtomicSnoop(PacketPtr pkt) 1516410Sgblack@eecs.umich.edu { 1526398Sgblack@eecs.umich.edu return mon.recvAtomicSnoop(pkt); 1536398Sgblack@eecs.umich.edu } 1546398Sgblack@eecs.umich.edu 1556398Sgblack@eecs.umich.edu bool recvTimingResp(PacketPtr pkt) 1566398Sgblack@eecs.umich.edu { 1576398Sgblack@eecs.umich.edu return mon.recvTimingResp(pkt); 1586398Sgblack@eecs.umich.edu } 1596398Sgblack@eecs.umich.edu 1606398Sgblack@eecs.umich.edu void recvTimingSnoopReq(PacketPtr pkt) 1616398Sgblack@eecs.umich.edu { 1626398Sgblack@eecs.umich.edu mon.recvTimingSnoopReq(pkt); 1636398Sgblack@eecs.umich.edu } 1646398Sgblack@eecs.umich.edu 1656398Sgblack@eecs.umich.edu void recvRangeChange() 1666410Sgblack@eecs.umich.edu { 1676398Sgblack@eecs.umich.edu mon.recvRangeChange(); 1686398Sgblack@eecs.umich.edu } 1696398Sgblack@eecs.umich.edu 1706398Sgblack@eecs.umich.edu bool isSnooping() const 1716398Sgblack@eecs.umich.edu { 1726398Sgblack@eecs.umich.edu return mon.isSnooping(); 1736398Sgblack@eecs.umich.edu } 1746398Sgblack@eecs.umich.edu 1754776SN/A void recvRetry() 1766409Sgblack@eecs.umich.edu { 1776409Sgblack@eecs.umich.edu mon.recvRetryMaster(); 1786409Sgblack@eecs.umich.edu } 1796409Sgblack@eecs.umich.edu 1806409Sgblack@eecs.umich.edu private: 1816409Sgblack@eecs.umich.edu 1826409Sgblack@eecs.umich.edu CommMonitor& mon; 1836409Sgblack@eecs.umich.edu 1846409Sgblack@eecs.umich.edu }; 1856409Sgblack@eecs.umich.edu 1866419Sgblack@eecs.umich.edu /** Instance of master port, facing the memory side */ 1876419Sgblack@eecs.umich.edu MonitorMasterPort masterPort; 1886419Sgblack@eecs.umich.edu 1896419Sgblack@eecs.umich.edu /** 1906419Sgblack@eecs.umich.edu * This is the slave port of the communication monitor. All recv 1916409Sgblack@eecs.umich.edu * functions call a function in CommMonitor, where the 1924776SN/A * send function of the master port is called. Besides this, these 1934776SN/A * functions can also perform actions for capturing statistics. 1946365SN/A */ 1954776SN/A class MonitorSlavePort : public SlavePort 1964776SN/A { 1974776SN/A 1984776SN/A public: 1994776SN/A 2006397Sgblack@eecs.umich.edu MonitorSlavePort(const std::string& _name, CommMonitor& _mon) 2016397Sgblack@eecs.umich.edu : SlavePort(_name, &_mon), mon(_mon) 2024776SN/A { } 2036397Sgblack@eecs.umich.edu 2044776SN/A protected: 205 206 void recvFunctional(PacketPtr pkt) 207 { 208 mon.recvFunctional(pkt); 209 } 210 211 Tick recvAtomic(PacketPtr pkt) 212 { 213 return mon.recvAtomic(pkt); 214 } 215 216 bool recvTimingReq(PacketPtr pkt) 217 { 218 return mon.recvTimingReq(pkt); 219 } 220 221 bool recvTimingSnoopResp(PacketPtr pkt) 222 { 223 return mon.recvTimingSnoopResp(pkt); 224 } 225 226 AddrRangeList getAddrRanges() const 227 { 228 return mon.getAddrRanges(); 229 } 230 231 void recvRetry() 232 { 233 mon.recvRetrySlave(); 234 } 235 236 private: 237 238 CommMonitor& mon; 239 240 }; 241 242 /** Instance of slave port, i.e. on the CPU side */ 243 MonitorSlavePort slavePort; 244 245 void recvFunctional(PacketPtr pkt); 246 247 void recvFunctionalSnoop(PacketPtr pkt); 248 249 Tick recvAtomic(PacketPtr pkt); 250 251 Tick recvAtomicSnoop(PacketPtr pkt); 252 253 bool recvTimingReq(PacketPtr pkt); 254 255 bool recvTimingResp(PacketPtr pkt); 256 257 void recvTimingSnoopReq(PacketPtr pkt); 258 259 bool recvTimingSnoopResp(PacketPtr pkt); 260 261 AddrRangeList getAddrRanges() const; 262 263 bool isSnooping() const; 264 265 void recvRetryMaster(); 266 267 void recvRetrySlave(); 268 269 void recvRangeChange(); 270 271 void periodicTraceDump(); 272 273 /** Stats declarations, all in a struct for convenience. */ 274 struct MonitorStats 275 { 276 277 /** Disable flag for burst length historgrams **/ 278 bool disableBurstLengthHists; 279 280 /** Histogram of read burst lengths */ 281 Stats::Histogram readBurstLengthHist; 282 283 /** Histogram of write burst lengths */ 284 Stats::Histogram writeBurstLengthHist; 285 286 /** Disable flag for the bandwidth histograms */ 287 bool disableBandwidthHists; 288 289 /** 290 * Histogram for read bandwidth per sample window. The 291 * internal counter is an unsigned int rather than a stat. 292 */ 293 unsigned int readBytes; 294 Stats::Histogram readBandwidthHist; 295 Stats::Formula averageReadBW; 296 Stats::Scalar totalReadBytes; 297 298 /** 299 * Histogram for write bandwidth per sample window. The 300 * internal counter is an unsigned int rather than a stat. 301 */ 302 unsigned int writtenBytes; 303 Stats::Histogram writeBandwidthHist; 304 Stats::Formula averageWriteBW; 305 Stats::Scalar totalWrittenBytes; 306 307 /** Disable flag for latency histograms. */ 308 bool disableLatencyHists; 309 310 /** Histogram of read request-to-response latencies */ 311 Stats::Histogram readLatencyHist; 312 313 /** Histogram of write request-to-response latencies */ 314 Stats::Histogram writeLatencyHist; 315 316 /** Disable flag for ITT distributions. */ 317 bool disableITTDists; 318 319 /** 320 * Inter transaction time (ITT) distributions. There are 321 * histograms of the time between two read, write or arbitrary 322 * accesses. The time of a request is the tick at which the 323 * request is forwarded by the monitor. 324 */ 325 Stats::Distribution ittReadRead; 326 Stats::Distribution ittWriteWrite; 327 Stats::Distribution ittReqReq; 328 Tick timeOfLastRead; 329 Tick timeOfLastWrite; 330 Tick timeOfLastReq; 331 332 /** Disable flag for outstanding histograms. */ 333 bool disableOutstandingHists; 334 335 /** 336 * Histogram of outstanding read requests. Counter for 337 * outstanding read requests is an unsigned integer because 338 * it should not be reset when stats are reset. 339 */ 340 Stats::Histogram outstandingReadsHist; 341 unsigned int outstandingReadReqs; 342 343 /** 344 * Histogram of outstanding write requests. Counter for 345 * outstanding write requests is an unsigned integer because 346 * it should not be reset when stats are reset. 347 */ 348 Stats::Histogram outstandingWritesHist; 349 unsigned int outstandingWriteReqs; 350 351 /** Disable flag for transaction histograms. */ 352 bool disableTransactionHists; 353 354 /** Histogram of number of read transactions per time bin */ 355 Stats::Histogram readTransHist; 356 unsigned int readTrans; 357 358 /** Histogram of number of timing write transactions per time bin */ 359 Stats::Histogram writeTransHist; 360 unsigned int writeTrans; 361 362 /** Disable flag for address distributions. */ 363 bool disableAddrDists; 364 365 /** 366 * Histogram of number of read accesses to addresses over 367 * time. 368 */ 369 Stats::SparseHistogram readAddrDist; 370 371 /** 372 * Histogram of number of write accesses to addresses over 373 * time. 374 */ 375 Stats::SparseHistogram writeAddrDist; 376 377 /** 378 * Create the monitor stats and initialise all the members 379 * that are not statistics themselves, but used to control the 380 * stats or track values during a sample period. 381 */ 382 MonitorStats(const CommMonitorParams* params) : 383 disableBurstLengthHists(params->disable_burst_length_hists), 384 disableBandwidthHists(params->disable_bandwidth_hists), 385 readBytes(0), writtenBytes(0), 386 disableLatencyHists(params->disable_latency_hists), 387 disableITTDists(params->disable_itt_dists), 388 timeOfLastRead(0), timeOfLastWrite(0), timeOfLastReq(0), 389 disableOutstandingHists(params->disable_outstanding_hists), 390 outstandingReadReqs(0), outstandingWriteReqs(0), 391 disableTransactionHists(params->disable_transaction_hists), 392 readTrans(0), writeTrans(0), 393 disableAddrDists(params->disable_addr_dists) 394 { } 395 396 }; 397 398 /** This function is called periodically at the end of each time bin */ 399 void samplePeriodic(); 400 401 /** Schedule the first periodic event */ 402 void startup(); 403 404 /** Periodic event called at the end of each simulation time bin */ 405 EventWrapper<CommMonitor, &CommMonitor::samplePeriodic> samplePeriodicEvent; 406 407 /** Length of simulation time bin*/ 408 Tick samplePeriodTicks; 409 Time samplePeriod; 410 411 /** Address mask for sources of read accesses to be captured */ 412 Addr readAddrMask; 413 414 /** Address mask for sources of write accesses to be captured */ 415 Addr writeAddrMask; 416 417 /** Instantiate stats */ 418 MonitorStats stats; 419 420 /** Output stream for a potential trace. */ 421 ProtoOutputStream* traceStream; 422 423 /** The system in which the monitor lives */ 424 System *system; 425}; 426 427#endif //__MEM_COMM_MONITOR_HH__ 428