2 * Copyright (c) 2012-2013 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Authors: Thomas Grass
41 #ifndef __MEM_COMM_MONITOR_HH__
42 #define __MEM_COMM_MONITOR_HH__
44 #include "base/statistics.hh"
45 #include "base/time.hh"
46 #include "mem/mem_object.hh"
47 #include "params/CommMonitor.hh"
48 #include "proto/protoio.hh"
51 * The communication monitor is a MemObject which can monitor statistics of
52 * the communication happening between two ports in the memory system.
54 * Currently the following stats are implemented: Histograms of read/write
55 * transactions, read/write burst lengths, read/write bandwidth,
56 * outstanding read/write requests, read latency and inter transaction time
57 * (read-read, write-write, read/write-read/write). Furthermore it allows
58 * to capture the number of accesses to an address over time ("heat map").
59 * All stats can be disabled from Python.
61 class CommMonitor : public MemObject
66 /** Parameters of communication monitor */
67 typedef CommMonitorParams Params;
68 const Params* params() const
69 { return reinterpret_cast<const Params*>(_params); }
72 * Constructor based on the Python params
74 * @param params Python parameters
76 CommMonitor(Params* params);
82 * Callback to flush and close all open output streams on exit. If
83 * we were calling the destructor it could be done there.
87 virtual BaseMasterPort& getMasterPort(const std::string& if_name,
88 PortID idx = InvalidPortID);
90 virtual BaseSlavePort& getSlavePort(const std::string& if_name,
91 PortID idx = InvalidPortID);
95 /** Register statistics */
101 * Sender state class for the monitor so that we can annotate
102 * packets with a transmit time and receive time.
104 class CommMonitorSenderState : public Packet::SenderState
110 * Construct a new sender state and store the time so we can
111 * calculate round-trip latency.
113 * @param _transmitTime Time of packet transmission
115 CommMonitorSenderState(Tick _transmitTime)
116 : transmitTime(_transmitTime)
120 ~CommMonitorSenderState() { }
122 /** Tick when request is transmitted */
128 * This is the master port of the communication monitor. All recv
129 * functions call a function in CommMonitor, where the
130 * send function of the slave port is called. Besides this, these
131 * functions can also perform actions for capturing statistics.
133 class MonitorMasterPort : public MasterPort
138 MonitorMasterPort(const std::string& _name, CommMonitor& _mon)
139 : MasterPort(_name, &_mon), mon(_mon)
144 void recvFunctionalSnoop(PacketPtr pkt)
146 mon.recvFunctionalSnoop(pkt);
149 Tick recvAtomicSnoop(PacketPtr pkt)
151 return mon.recvAtomicSnoop(pkt);
154 bool recvTimingResp(PacketPtr pkt)
156 return mon.recvTimingResp(pkt);
159 void recvTimingSnoopReq(PacketPtr pkt)
161 mon.recvTimingSnoopReq(pkt);
164 void recvRangeChange()
166 mon.recvRangeChange();
169 bool isSnooping() const
171 return mon.isSnooping();
174 unsigned deviceBlockSize() const
176 return mon.deviceBlockSizeMaster();
181 mon.recvRetryMaster();
190 /** Instance of master port, facing the memory side */
191 MonitorMasterPort masterPort;
194 * This is the slave port of the communication monitor. All recv
195 * functions call a function in CommMonitor, where the
196 * send function of the master port is called. Besides this, these
197 * functions can also perform actions for capturing statistics.
199 class MonitorSlavePort : public SlavePort
204 MonitorSlavePort(const std::string& _name, CommMonitor& _mon)
205 : SlavePort(_name, &_mon), mon(_mon)
210 void recvFunctional(PacketPtr pkt)
212 mon.recvFunctional(pkt);
215 Tick recvAtomic(PacketPtr pkt)
217 return mon.recvAtomic(pkt);
220 bool recvTimingReq(PacketPtr pkt)
222 return mon.recvTimingReq(pkt);
225 bool recvTimingSnoopResp(PacketPtr pkt)
227 return mon.recvTimingSnoopResp(pkt);
230 unsigned deviceBlockSize() const
232 return mon.deviceBlockSizeSlave();
235 AddrRangeList getAddrRanges() const
237 return mon.getAddrRanges();
242 mon.recvRetrySlave();
251 /** Instance of slave port, i.e. on the CPU side */
252 MonitorSlavePort slavePort;
254 void recvFunctional(PacketPtr pkt);
256 void recvFunctionalSnoop(PacketPtr pkt);
258 Tick recvAtomic(PacketPtr pkt);
260 Tick recvAtomicSnoop(PacketPtr pkt);
262 bool recvTimingReq(PacketPtr pkt);
264 bool recvTimingResp(PacketPtr pkt);
266 void recvTimingSnoopReq(PacketPtr pkt);
268 bool recvTimingSnoopResp(PacketPtr pkt);
270 unsigned deviceBlockSizeMaster();
272 unsigned deviceBlockSizeSlave();
274 AddrRangeList getAddrRanges() const;
276 bool isSnooping() const;
278 void recvRetryMaster();
280 void recvRetrySlave();
282 void recvRangeChange();
284 void periodicTraceDump();
286 /** Stats declarations, all in a struct for convenience. */
290 /** Disable flag for burst length historgrams **/
291 bool disableBurstLengthHists;
293 /** Histogram of read burst lengths */
294 Stats::Histogram readBurstLengthHist;
296 /** Histogram of write burst lengths */
297 Stats::Histogram writeBurstLengthHist;
299 /** Disable flag for the bandwidth histograms */
300 bool disableBandwidthHists;
303 * Histogram for read bandwidth per sample window. The
304 * internal counter is an unsigned int rather than a stat.
306 unsigned int readBytes;
307 Stats::Histogram readBandwidthHist;
308 Stats::Formula averageReadBW;
309 Stats::Scalar totalReadBytes;
312 * Histogram for write bandwidth per sample window. The
313 * internal counter is an unsigned int rather than a stat.
315 unsigned int writtenBytes;
316 Stats::Histogram writeBandwidthHist;
317 Stats::Formula averageWriteBW;
318 Stats::Scalar totalWrittenBytes;
320 /** Disable flag for latency histograms. */
321 bool disableLatencyHists;
323 /** Histogram of read request-to-response latencies */
324 Stats::Histogram readLatencyHist;
326 /** Histogram of write request-to-response latencies */
327 Stats::Histogram writeLatencyHist;
329 /** Disable flag for ITT distributions. */
330 bool disableITTDists;
333 * Inter transaction time (ITT) distributions. There are
334 * histograms of the time between two read, write or arbitrary
335 * accesses. The time of a request is the tick at which the
336 * request is forwarded by the monitor.
338 Stats::Distribution ittReadRead;
339 Stats::Distribution ittWriteWrite;
340 Stats::Distribution ittReqReq;
342 Tick timeOfLastWrite;
345 /** Disable flag for outstanding histograms. */
346 bool disableOutstandingHists;
349 * Histogram of outstanding read requests. Counter for
350 * outstanding read requests is an unsigned integer because
351 * it should not be reset when stats are reset.
353 Stats::Histogram outstandingReadsHist;
354 unsigned int outstandingReadReqs;
357 * Histogram of outstanding write requests. Counter for
358 * outstanding write requests is an unsigned integer because
359 * it should not be reset when stats are reset.
361 Stats::Histogram outstandingWritesHist;
362 unsigned int outstandingWriteReqs;
364 /** Disable flag for transaction histograms. */
365 bool disableTransactionHists;
367 /** Histogram of number of read transactions per time bin */
368 Stats::Histogram readTransHist;
369 unsigned int readTrans;
371 /** Histogram of number of timing write transactions per time bin */
372 Stats::Histogram writeTransHist;
373 unsigned int writeTrans;
375 /** Disable flag for address distributions. */
376 bool disableAddrDists;
379 * Histogram of number of read accesses to addresses over
382 Stats::SparseHistogram readAddrDist;
385 * Histogram of number of write accesses to addresses over
388 Stats::SparseHistogram writeAddrDist;
391 * Create the monitor stats and initialise all the members
392 * that are not statistics themselves, but used to control the
393 * stats or track values during a sample period.
395 MonitorStats(const CommMonitorParams* params) :
396 disableBurstLengthHists(params->disable_burst_length_hists),
397 disableBandwidthHists(params->disable_bandwidth_hists),
398 readBytes(0), writtenBytes(0),
399 disableLatencyHists(params->disable_latency_hists),
400 disableITTDists(params->disable_itt_dists),
401 timeOfLastRead(0), timeOfLastWrite(0), timeOfLastReq(0),
402 disableOutstandingHists(params->disable_outstanding_hists),
403 outstandingReadReqs(0), outstandingWriteReqs(0),
404 disableTransactionHists(params->disable_transaction_hists),
405 readTrans(0), writeTrans(0),
406 disableAddrDists(params->disable_addr_dists)
411 /** This function is called periodically at the end of each time bin */
412 void samplePeriodic();
414 /** Schedule the first periodic event */
417 /** Periodic event called at the end of each simulation time bin */
418 EventWrapper<CommMonitor, &CommMonitor::samplePeriodic> samplePeriodicEvent;
420 /** Length of simulation time bin*/
421 Tick samplePeriodTicks;
424 /** Address mask for sources of read accesses to be captured */
427 /** Address mask for sources of write accesses to be captured */
430 /** Instantiate stats */
433 /** Output stream for a potential trace. */
434 ProtoOutputStream* traceStream;
437 #endif //__MEM_COMM_MONITOR_HH__