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;
70 return reinterpret_cast<const Params &>(_params);
74 * Constructor based on the Python params
76 * @param params Python parameters
78 CommMonitor(const Params ¶ms);
81 void startup() override;
82 void regProbePoints() override;
84 public: // SimObject interfaces
85 Port &getPort(const std::string &if_name,
86 PortID idx=InvalidPortID) override;
91 * Sender state class for the monitor so that we can annotate
92 * packets with a transmit time and receive time.
94 class CommMonitorSenderState : public Packet::SenderState
100 * Construct a new sender state and store the time so we can
101 * calculate round-trip latency.
103 * @param _transmitTime Time of packet transmission
105 CommMonitorSenderState(Tick _transmitTime)
106 : transmitTime(_transmitTime)
110 ~CommMonitorSenderState() { }
112 /** Tick when request is transmitted */
118 * This is the request port of the communication monitor. All recv
119 * functions call a function in CommMonitor, where the
120 * send function of the CPU-side port is called. Besides this, these
121 * functions can also perform actions for capturing statistics.
123 class MonitorRequestPort : public RequestPort
128 MonitorRequestPort(const std::string& _name, CommMonitor& _mon)
129 : RequestPort(_name, &_mon), mon(_mon)
134 void recvFunctionalSnoop(PacketPtr pkt)
136 mon.recvFunctionalSnoop(pkt);
139 Tick recvAtomicSnoop(PacketPtr pkt)
141 return mon.recvAtomicSnoop(pkt);
144 bool recvTimingResp(PacketPtr pkt)
146 return mon.recvTimingResp(pkt);
149 void recvTimingSnoopReq(PacketPtr pkt)
151 mon.recvTimingSnoopReq(pkt);
154 void recvRangeChange()
156 mon.recvRangeChange();
159 bool isSnooping() const
161 return mon.isSnooping();
169 void recvRetrySnoopResp()
171 mon.recvRetrySnoopResp();
180 /** Instance of request port, facing the memory side */
181 MonitorRequestPort memSidePort;
184 * This is the CPU-side port of the communication monitor. All recv
185 * functions call a function in CommMonitor, where the
186 * send function of the request port is called. Besides this, these
187 * functions can also perform actions for capturing statistics.
189 class MonitorResponsePort : public ResponsePort
194 MonitorResponsePort(const std::string& _name, CommMonitor& _mon)
195 : ResponsePort(_name, &_mon), mon(_mon)
200 void recvFunctional(PacketPtr pkt)
202 mon.recvFunctional(pkt);
205 Tick recvAtomic(PacketPtr pkt)
207 return mon.recvAtomic(pkt);
210 bool recvTimingReq(PacketPtr pkt)
212 return mon.recvTimingReq(pkt);
215 bool recvTimingSnoopResp(PacketPtr pkt)
217 return mon.recvTimingSnoopResp(pkt);
220 AddrRangeList getAddrRanges() const
222 return mon.getAddrRanges();
230 bool tryTiming(PacketPtr pkt)
232 return mon.tryTiming(pkt);
241 /** Instance of response port, i.e. on the CPU side */
242 MonitorResponsePort cpuSidePort;
244 void recvFunctional(PacketPtr pkt);
246 void recvFunctionalSnoop(PacketPtr pkt);
248 Tick recvAtomic(PacketPtr pkt);
250 Tick recvAtomicSnoop(PacketPtr pkt);
252 bool recvTimingReq(PacketPtr pkt);
254 bool recvTimingResp(PacketPtr pkt);
256 void recvTimingSnoopReq(PacketPtr pkt);
258 bool recvTimingSnoopResp(PacketPtr pkt);
260 void recvRetrySnoopResp();
262 AddrRangeList getAddrRanges() const;
264 bool isSnooping() const;
268 void recvRespRetry();
270 void recvRangeChange();
272 bool tryTiming(PacketPtr pkt);
274 /** Stats declarations, all in a struct for convenience. */
275 struct MonitorStats : public Stats::Group
277 /** Disable flag for burst length histograms **/
278 bool disableBurstLengthHists;
280 /** Histogram of read burst lengths */
281 Stats::Histogram readBurstLengthHist;
283 /** Histogram of write burst lengths */
284 Stats::Histogram writeBurstLengthHist;
286 /** Disable flag for the bandwidth histograms */
287 bool disableBandwidthHists;
290 * Histogram for read bandwidth per sample window. The
291 * internal counter is an unsigned int rather than a stat.
293 unsigned int readBytes;
294 Stats::Histogram readBandwidthHist;
295 Stats::Scalar totalReadBytes;
296 Stats::Formula averageReadBandwidth;
299 * Histogram for write bandwidth per sample window. The
300 * internal counter is an unsigned int rather than a stat.
302 unsigned int writtenBytes;
303 Stats::Histogram writeBandwidthHist;
304 Stats::Scalar totalWrittenBytes;
305 Stats::Formula averageWriteBandwidth;
307 /** Disable flag for latency histograms. */
308 bool disableLatencyHists;
310 /** Histogram of read request-to-response latencies */
311 Stats::Histogram readLatencyHist;
313 /** Histogram of write request-to-response latencies */
314 Stats::Histogram writeLatencyHist;
316 /** Disable flag for ITT distributions. */
317 bool disableITTDists;
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.
325 Stats::Distribution ittReadRead;
326 Stats::Distribution ittWriteWrite;
327 Stats::Distribution ittReqReq;
329 Tick timeOfLastWrite;
332 /** Disable flag for outstanding histograms. */
333 bool disableOutstandingHists;
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.
340 Stats::Histogram outstandingReadsHist;
341 unsigned int outstandingReadReqs;
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.
348 Stats::Histogram outstandingWritesHist;
349 unsigned int outstandingWriteReqs;
351 /** Disable flag for transaction histograms. */
352 bool disableTransactionHists;
354 /** Histogram of number of read transactions per time bin */
355 Stats::Histogram readTransHist;
356 unsigned int readTrans;
358 /** Histogram of number of timing write transactions per time bin */
359 Stats::Histogram writeTransHist;
360 unsigned int writeTrans;
362 /** Disable flag for address distributions. */
363 bool disableAddrDists;
365 /** Address mask for sources of read accesses to be captured */
366 const Addr readAddrMask;
368 /** Address mask for sources of write accesses to be captured */
369 const Addr writeAddrMask;
372 * Histogram of number of read accesses to addresses over
375 Stats::SparseHistogram readAddrDist;
378 * Histogram of number of write accesses to addresses over
381 Stats::SparseHistogram writeAddrDist;
384 * Create the monitor stats and initialise all the members
385 * that are not statistics themselves, but used to control the
386 * stats or track values during a sample period.
388 MonitorStats(Stats::Group *parent, const CommMonitorParams ¶ms);
390 void updateReqStats(const ProbePoints::PacketInfo& pkt, bool is_atomic,
391 bool expects_response);
392 void updateRespStats(const ProbePoints::PacketInfo& pkt, Tick latency,
396 /** This function is called periodically at the end of each time bin */
397 void samplePeriodic();
399 /** Periodic event called at the end of each simulation time bin */
400 EventFunctionWrapper samplePeriodicEvent;
404 * @name Configuration
407 /** Length of simulation time bin*/
408 const Tick samplePeriodTicks;
409 /** Sample period in seconds */
410 const double samplePeriod;
414 /** Instantiate stats */
417 protected: // Probe points
420 * @name Memory system probe points
423 /** Successfully forwarded request packet */
424 ProbePoints::PacketUPtr ppPktReq;
426 /** Successfully forwarded response packet */
427 ProbePoints::PacketUPtr ppPktResp;
432 #endif //__MEM_COMM_MONITOR_HH__