2 * Copyright (c) 2012-2013, 2015, 2018-2019 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.
40 #ifndef __MEM_COMM_MONITOR_HH__
41 #define __MEM_COMM_MONITOR_HH__
43 #include "base/statistics.hh"
44 #include "mem/port.hh"
45 #include "params/CommMonitor.hh"
46 #include "sim/probe/mem.hh"
47 #include "sim/sim_object.hh"
50 * The communication monitor is a SimObject which can monitor statistics of
51 * the communication happening between two ports in the memory system.
53 * Currently the following stats are implemented: Histograms of read/write
54 * transactions, read/write burst lengths, read/write bandwidth,
55 * outstanding read/write requests, read latency and inter transaction time
56 * (read-read, write-write, read/write-read/write). Furthermore it allows
57 * to capture the number of accesses to an address over time ("heat map").
58 * All stats can be disabled from Python.
60 class CommMonitor : public SimObject
63 public: // Construction & SimObject interfaces
65 /** Parameters of communication monitor */
66 typedef CommMonitorParams Params;
67 const Params* params() const
68 { return reinterpret_cast<const Params*>(_params); }
71 * Constructor based on the Python params
73 * @param params Python parameters
75 CommMonitor(Params* params);
78 void startup() override;
79 void regProbePoints() override;
81 public: // SimObject interfaces
82 Port &getPort(const std::string &if_name,
83 PortID idx=InvalidPortID) override;
88 * Sender state class for the monitor so that we can annotate
89 * packets with a transmit time and receive time.
91 class CommMonitorSenderState : public Packet::SenderState
97 * Construct a new sender state and store the time so we can
98 * calculate round-trip latency.
100 * @param _transmitTime Time of packet transmission
102 CommMonitorSenderState(Tick _transmitTime)
103 : transmitTime(_transmitTime)
107 ~CommMonitorSenderState() { }
109 /** Tick when request is transmitted */
115 * This is the request port of the communication monitor. All recv
116 * functions call a function in CommMonitor, where the
117 * send function of the CPU-side port is called. Besides this, these
118 * functions can also perform actions for capturing statistics.
120 class MonitorRequestPort : public RequestPort
125 MonitorRequestPort(const std::string& _name, CommMonitor& _mon)
126 : RequestPort(_name, &_mon), mon(_mon)
131 void recvFunctionalSnoop(PacketPtr pkt)
133 mon.recvFunctionalSnoop(pkt);
136 Tick recvAtomicSnoop(PacketPtr pkt)
138 return mon.recvAtomicSnoop(pkt);
141 bool recvTimingResp(PacketPtr pkt)
143 return mon.recvTimingResp(pkt);
146 void recvTimingSnoopReq(PacketPtr pkt)
148 mon.recvTimingSnoopReq(pkt);
151 void recvRangeChange()
153 mon.recvRangeChange();
156 bool isSnooping() const
158 return mon.isSnooping();
166 void recvRetrySnoopResp()
168 mon.recvRetrySnoopResp();
177 /** Instance of request port, facing the memory side */
178 MonitorRequestPort memSidePort;
181 * This is the CPU-side port of the communication monitor. All recv
182 * functions call a function in CommMonitor, where the
183 * send function of the request port is called. Besides this, these
184 * functions can also perform actions for capturing statistics.
186 class MonitorResponsePort : public ResponsePort
191 MonitorResponsePort(const std::string& _name, CommMonitor& _mon)
192 : ResponsePort(_name, &_mon), mon(_mon)
197 void recvFunctional(PacketPtr pkt)
199 mon.recvFunctional(pkt);
202 Tick recvAtomic(PacketPtr pkt)
204 return mon.recvAtomic(pkt);
207 bool recvTimingReq(PacketPtr pkt)
209 return mon.recvTimingReq(pkt);
212 bool recvTimingSnoopResp(PacketPtr pkt)
214 return mon.recvTimingSnoopResp(pkt);
217 AddrRangeList getAddrRanges() const
219 return mon.getAddrRanges();
227 bool tryTiming(PacketPtr pkt)
229 return mon.tryTiming(pkt);
238 /** Instance of response port, i.e. on the CPU side */
239 MonitorResponsePort cpuSidePort;
241 void recvFunctional(PacketPtr pkt);
243 void recvFunctionalSnoop(PacketPtr pkt);
245 Tick recvAtomic(PacketPtr pkt);
247 Tick recvAtomicSnoop(PacketPtr pkt);
249 bool recvTimingReq(PacketPtr pkt);
251 bool recvTimingResp(PacketPtr pkt);
253 void recvTimingSnoopReq(PacketPtr pkt);
255 bool recvTimingSnoopResp(PacketPtr pkt);
257 void recvRetrySnoopResp();
259 AddrRangeList getAddrRanges() const;
261 bool isSnooping() const;
265 void recvRespRetry();
267 void recvRangeChange();
269 bool tryTiming(PacketPtr pkt);
271 /** Stats declarations, all in a struct for convenience. */
272 struct MonitorStats : public Stats::Group
274 /** Disable flag for burst length histograms **/
275 bool disableBurstLengthHists;
277 /** Histogram of read burst lengths */
278 Stats::Histogram readBurstLengthHist;
280 /** Histogram of write burst lengths */
281 Stats::Histogram writeBurstLengthHist;
283 /** Disable flag for the bandwidth histograms */
284 bool disableBandwidthHists;
287 * Histogram for read bandwidth per sample window. The
288 * internal counter is an unsigned int rather than a stat.
290 unsigned int readBytes;
291 Stats::Histogram readBandwidthHist;
292 Stats::Scalar totalReadBytes;
293 Stats::Formula averageReadBandwidth;
296 * Histogram for write bandwidth per sample window. The
297 * internal counter is an unsigned int rather than a stat.
299 unsigned int writtenBytes;
300 Stats::Histogram writeBandwidthHist;
301 Stats::Scalar totalWrittenBytes;
302 Stats::Formula averageWriteBandwidth;
304 /** Disable flag for latency histograms. */
305 bool disableLatencyHists;
307 /** Histogram of read request-to-response latencies */
308 Stats::Histogram readLatencyHist;
310 /** Histogram of write request-to-response latencies */
311 Stats::Histogram writeLatencyHist;
313 /** Disable flag for ITT distributions. */
314 bool disableITTDists;
317 * Inter transaction time (ITT) distributions. There are
318 * histograms of the time between two read, write or arbitrary
319 * accesses. The time of a request is the tick at which the
320 * request is forwarded by the monitor.
322 Stats::Distribution ittReadRead;
323 Stats::Distribution ittWriteWrite;
324 Stats::Distribution ittReqReq;
326 Tick timeOfLastWrite;
329 /** Disable flag for outstanding histograms. */
330 bool disableOutstandingHists;
333 * Histogram of outstanding read requests. Counter for
334 * outstanding read requests is an unsigned integer because
335 * it should not be reset when stats are reset.
337 Stats::Histogram outstandingReadsHist;
338 unsigned int outstandingReadReqs;
341 * Histogram of outstanding write requests. Counter for
342 * outstanding write requests is an unsigned integer because
343 * it should not be reset when stats are reset.
345 Stats::Histogram outstandingWritesHist;
346 unsigned int outstandingWriteReqs;
348 /** Disable flag for transaction histograms. */
349 bool disableTransactionHists;
351 /** Histogram of number of read transactions per time bin */
352 Stats::Histogram readTransHist;
353 unsigned int readTrans;
355 /** Histogram of number of timing write transactions per time bin */
356 Stats::Histogram writeTransHist;
357 unsigned int writeTrans;
359 /** Disable flag for address distributions. */
360 bool disableAddrDists;
362 /** Address mask for sources of read accesses to be captured */
363 const Addr readAddrMask;
365 /** Address mask for sources of write accesses to be captured */
366 const Addr writeAddrMask;
369 * Histogram of number of read accesses to addresses over
372 Stats::SparseHistogram readAddrDist;
375 * Histogram of number of write accesses to addresses over
378 Stats::SparseHistogram writeAddrDist;
381 * Create the monitor stats and initialise all the members
382 * that are not statistics themselves, but used to control the
383 * stats or track values during a sample period.
385 MonitorStats(Stats::Group *parent, const CommMonitorParams* params);
387 void updateReqStats(const ProbePoints::PacketInfo& pkt, bool is_atomic,
388 bool expects_response);
389 void updateRespStats(const ProbePoints::PacketInfo& pkt, Tick latency,
393 /** This function is called periodically at the end of each time bin */
394 void samplePeriodic();
396 /** Periodic event called at the end of each simulation time bin */
397 EventFunctionWrapper samplePeriodicEvent;
401 * @name Configuration
404 /** Length of simulation time bin*/
405 const Tick samplePeriodTicks;
406 /** Sample period in seconds */
407 const double samplePeriod;
411 /** Instantiate stats */
414 protected: // Probe points
417 * @name Memory system probe points
420 /** Successfully forwarded request packet */
421 ProbePoints::PacketUPtr ppPktReq;
423 /** Successfully forwarded response packet */
424 ProbePoints::PacketUPtr ppPktResp;
429 #endif //__MEM_COMM_MONITOR_HH__