2 * Copyright (c) 2012-2013, 2015, 2018 ARM Limited
3 * Copyright (c) 2016 Google Inc.
4 * Copyright (c) 2017, Centre National de la Recherche Scientifique
7 * The license below extends only to copyright in the software and shall
8 * not be construed as granting a license to any other intellectual
9 * property including but not limited to intellectual property relating
10 * to a hardware implementation of the functionality of the software
11 * licensed hereunder. You may use the software subject to the license
12 * terms below provided that you ensure that this notice is replicated
13 * unmodified and in its entirety in all distributions of the software,
14 * modified or unmodified, in source code or in binary form.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
18 * met: redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer;
20 * redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution;
23 * neither the name of the copyright holders nor the names of its
24 * contributors may be used to endorse or promote products derived from
25 * this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * Authors: Thomas Grass
45 #ifndef __MEM_COMM_MONITOR_HH__
46 #define __MEM_COMM_MONITOR_HH__
48 #include "base/statistics.hh"
49 #include "mem/port.hh"
50 #include "params/CommMonitor.hh"
51 #include "sim/probe/mem.hh"
52 #include "sim/sim_object.hh"
55 * The communication monitor is a SimObject which can monitor statistics of
56 * the communication happening between two ports in the memory system.
58 * Currently the following stats are implemented: Histograms of read/write
59 * transactions, read/write burst lengths, read/write bandwidth,
60 * outstanding read/write requests, read latency and inter transaction time
61 * (read-read, write-write, read/write-read/write). Furthermore it allows
62 * to capture the number of accesses to an address over time ("heat map").
63 * All stats can be disabled from Python.
65 class CommMonitor : public SimObject
68 public: // Construction & SimObject interfaces
70 /** Parameters of communication monitor */
71 typedef CommMonitorParams Params;
72 const Params* params() const
73 { return reinterpret_cast<const Params*>(_params); }
76 * Constructor based on the Python params
78 * @param params Python parameters
80 CommMonitor(Params* params);
83 void regStats() override;
84 void startup() override;
85 void regProbePoints() override;
87 public: // SimObject interfaces
88 Port &getPort(const std::string &if_name,
89 PortID idx=InvalidPortID) override;
94 * Sender state class for the monitor so that we can annotate
95 * packets with a transmit time and receive time.
97 class CommMonitorSenderState : public Packet::SenderState
103 * Construct a new sender state and store the time so we can
104 * calculate round-trip latency.
106 * @param _transmitTime Time of packet transmission
108 CommMonitorSenderState(Tick _transmitTime)
109 : transmitTime(_transmitTime)
113 ~CommMonitorSenderState() { }
115 /** Tick when request is transmitted */
121 * This is the master port of the communication monitor. All recv
122 * functions call a function in CommMonitor, where the
123 * send function of the slave port is called. Besides this, these
124 * functions can also perform actions for capturing statistics.
126 class MonitorMasterPort : public MasterPort
131 MonitorMasterPort(const std::string& _name, CommMonitor& _mon)
132 : MasterPort(_name, &_mon), mon(_mon)
137 void recvFunctionalSnoop(PacketPtr pkt)
139 mon.recvFunctionalSnoop(pkt);
142 Tick recvAtomicSnoop(PacketPtr pkt)
144 return mon.recvAtomicSnoop(pkt);
147 bool recvTimingResp(PacketPtr pkt)
149 return mon.recvTimingResp(pkt);
152 void recvTimingSnoopReq(PacketPtr pkt)
154 mon.recvTimingSnoopReq(pkt);
157 void recvRangeChange()
159 mon.recvRangeChange();
162 bool isSnooping() const
164 return mon.isSnooping();
172 void recvRetrySnoopResp()
174 mon.recvRetrySnoopResp();
183 /** Instance of master port, facing the memory side */
184 MonitorMasterPort masterPort;
187 * This is the slave port of the communication monitor. All recv
188 * functions call a function in CommMonitor, where the
189 * send function of the master port is called. Besides this, these
190 * functions can also perform actions for capturing statistics.
192 class MonitorSlavePort : public SlavePort
197 MonitorSlavePort(const std::string& _name, CommMonitor& _mon)
198 : SlavePort(_name, &_mon), mon(_mon)
203 void recvFunctional(PacketPtr pkt)
205 mon.recvFunctional(pkt);
208 Tick recvAtomic(PacketPtr pkt)
210 return mon.recvAtomic(pkt);
213 bool recvTimingReq(PacketPtr pkt)
215 return mon.recvTimingReq(pkt);
218 bool recvTimingSnoopResp(PacketPtr pkt)
220 return mon.recvTimingSnoopResp(pkt);
223 AddrRangeList getAddrRanges() const
225 return mon.getAddrRanges();
233 bool tryTiming(PacketPtr pkt)
235 return mon.tryTiming(pkt);
244 /** Instance of slave port, i.e. on the CPU side */
245 MonitorSlavePort slavePort;
247 void recvFunctional(PacketPtr pkt);
249 void recvFunctionalSnoop(PacketPtr pkt);
251 Tick recvAtomic(PacketPtr pkt);
253 Tick recvAtomicSnoop(PacketPtr pkt);
255 bool recvTimingReq(PacketPtr pkt);
257 bool recvTimingResp(PacketPtr pkt);
259 void recvTimingSnoopReq(PacketPtr pkt);
261 bool recvTimingSnoopResp(PacketPtr pkt);
263 void recvRetrySnoopResp();
265 AddrRangeList getAddrRanges() const;
267 bool isSnooping() const;
271 void recvRespRetry();
273 void recvRangeChange();
275 bool tryTiming(PacketPtr pkt);
277 /** Stats declarations, all in a struct for convenience. */
281 /** Disable flag for burst length histograms **/
282 bool disableBurstLengthHists;
284 /** Histogram of read burst lengths */
285 Stats::Histogram readBurstLengthHist;
287 /** Histogram of write burst lengths */
288 Stats::Histogram writeBurstLengthHist;
290 /** Disable flag for the bandwidth histograms */
291 bool disableBandwidthHists;
294 * Histogram for read bandwidth per sample window. The
295 * internal counter is an unsigned int rather than a stat.
297 unsigned int readBytes;
298 Stats::Histogram readBandwidthHist;
299 Stats::Formula averageReadBW;
300 Stats::Scalar totalReadBytes;
303 * Histogram for write bandwidth per sample window. The
304 * internal counter is an unsigned int rather than a stat.
306 unsigned int writtenBytes;
307 Stats::Histogram writeBandwidthHist;
308 Stats::Formula averageWriteBW;
309 Stats::Scalar totalWrittenBytes;
311 /** Disable flag for latency histograms. */
312 bool disableLatencyHists;
314 /** Histogram of read request-to-response latencies */
315 Stats::Histogram readLatencyHist;
317 /** Histogram of write request-to-response latencies */
318 Stats::Histogram writeLatencyHist;
320 /** Disable flag for ITT distributions. */
321 bool disableITTDists;
324 * Inter transaction time (ITT) distributions. There are
325 * histograms of the time between two read, write or arbitrary
326 * accesses. The time of a request is the tick at which the
327 * request is forwarded by the monitor.
329 Stats::Distribution ittReadRead;
330 Stats::Distribution ittWriteWrite;
331 Stats::Distribution ittReqReq;
333 Tick timeOfLastWrite;
336 /** Disable flag for outstanding histograms. */
337 bool disableOutstandingHists;
340 * Histogram of outstanding read requests. Counter for
341 * outstanding read requests is an unsigned integer because
342 * it should not be reset when stats are reset.
344 Stats::Histogram outstandingReadsHist;
345 unsigned int outstandingReadReqs;
348 * Histogram of outstanding write requests. Counter for
349 * outstanding write requests is an unsigned integer because
350 * it should not be reset when stats are reset.
352 Stats::Histogram outstandingWritesHist;
353 unsigned int outstandingWriteReqs;
355 /** Disable flag for transaction histograms. */
356 bool disableTransactionHists;
358 /** Histogram of number of read transactions per time bin */
359 Stats::Histogram readTransHist;
360 unsigned int readTrans;
362 /** Histogram of number of timing write transactions per time bin */
363 Stats::Histogram writeTransHist;
364 unsigned int writeTrans;
366 /** Disable flag for address distributions. */
367 bool disableAddrDists;
369 /** Address mask for sources of read accesses to be captured */
370 const Addr readAddrMask;
372 /** Address mask for sources of write accesses to be captured */
373 const Addr writeAddrMask;
376 * Histogram of number of read accesses to addresses over
379 Stats::SparseHistogram readAddrDist;
382 * Histogram of number of write accesses to addresses over
385 Stats::SparseHistogram writeAddrDist;
388 * Create the monitor stats and initialise all the members
389 * that are not statistics themselves, but used to control the
390 * stats or track values during a sample period.
392 MonitorStats(const CommMonitorParams* params) :
393 disableBurstLengthHists(params->disable_burst_length_hists),
394 disableBandwidthHists(params->disable_bandwidth_hists),
395 readBytes(0), writtenBytes(0),
396 disableLatencyHists(params->disable_latency_hists),
397 disableITTDists(params->disable_itt_dists),
398 timeOfLastRead(0), timeOfLastWrite(0), timeOfLastReq(0),
399 disableOutstandingHists(params->disable_outstanding_hists),
400 outstandingReadReqs(0), outstandingWriteReqs(0),
401 disableTransactionHists(params->disable_transaction_hists),
402 readTrans(0), writeTrans(0),
403 disableAddrDists(params->disable_addr_dists),
404 readAddrMask(params->read_addr_mask),
405 writeAddrMask(params->write_addr_mask)
408 void updateReqStats(const ProbePoints::PacketInfo& pkt, bool is_atomic,
409 bool expects_response);
410 void updateRespStats(const ProbePoints::PacketInfo& pkt, Tick latency,
414 /** This function is called periodically at the end of each time bin */
415 void samplePeriodic();
417 /** Periodic event called at the end of each simulation time bin */
418 EventFunctionWrapper samplePeriodicEvent;
422 * @name Configuration
425 /** Length of simulation time bin*/
426 const Tick samplePeriodTicks;
427 /** Sample period in seconds */
428 const double samplePeriod;
432 /** Instantiate stats */
435 protected: // Probe points
438 * @name Memory system probe points
441 /** Successfully forwarded request packet */
442 ProbePoints::PacketUPtr ppPktReq;
444 /** Successfully forwarded response packet */
445 ProbePoints::PacketUPtr ppPktResp;
450 #endif //__MEM_COMM_MONITOR_HH__