Deleted Added
sdiff udiff text old ( 13784:1941dc118243 ) new ( 13892:0182a0601f66 )
full compact
1/*
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
5 * All rights reserved.
6 *
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.
15 *
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.
26 *
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.
38 *
39 * Authors: Thomas Grass
40 * Andreas Hansson
41 * Rahul Thakur
42 * Pierre-Yves Peneau
43 */
44
45#ifndef __MEM_COMM_MONITOR_HH__
46#define __MEM_COMM_MONITOR_HH__
47
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"
53
54/**
55 * The communication monitor is a SimObject which can monitor statistics of
56 * the communication happening between two ports in the memory system.
57 *
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.
64 */
65class CommMonitor : public SimObject
66{
67
68 public: // Construction & SimObject interfaces
69
70 /** Parameters of communication monitor */
71 typedef CommMonitorParams Params;
72 const Params* params() const
73 { return reinterpret_cast<const Params*>(_params); }
74
75 /**
76 * Constructor based on the Python params
77 *
78 * @param params Python parameters
79 */
80 CommMonitor(Params* params);
81
82 void init() override;
83 void regStats() override;
84 void startup() override;
85 void regProbePoints() override;
86
87 public: // SimObject interfaces
88 Port &getPort(const std::string &if_name,
89 PortID idx=InvalidPortID) override;
90
91 private:
92
93 /**
94 * Sender state class for the monitor so that we can annotate
95 * packets with a transmit time and receive time.
96 */
97 class CommMonitorSenderState : public Packet::SenderState
98 {
99
100 public:
101
102 /**
103 * Construct a new sender state and store the time so we can
104 * calculate round-trip latency.
105 *
106 * @param _transmitTime Time of packet transmission
107 */
108 CommMonitorSenderState(Tick _transmitTime)
109 : transmitTime(_transmitTime)
110 { }
111
112 /** Destructor */
113 ~CommMonitorSenderState() { }
114
115 /** Tick when request is transmitted */
116 Tick transmitTime;
117
118 };
119
120 /**
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.
125 */
126 class MonitorMasterPort : public MasterPort
127 {
128
129 public:
130
131 MonitorMasterPort(const std::string& _name, CommMonitor& _mon)
132 : MasterPort(_name, &_mon), mon(_mon)
133 { }
134
135 protected:
136
137 void recvFunctionalSnoop(PacketPtr pkt)
138 {
139 mon.recvFunctionalSnoop(pkt);
140 }
141
142 Tick recvAtomicSnoop(PacketPtr pkt)
143 {
144 return mon.recvAtomicSnoop(pkt);
145 }
146
147 bool recvTimingResp(PacketPtr pkt)
148 {
149 return mon.recvTimingResp(pkt);
150 }
151
152 void recvTimingSnoopReq(PacketPtr pkt)
153 {
154 mon.recvTimingSnoopReq(pkt);
155 }
156
157 void recvRangeChange()
158 {
159 mon.recvRangeChange();
160 }
161
162 bool isSnooping() const
163 {
164 return mon.isSnooping();
165 }
166
167 void recvReqRetry()
168 {
169 mon.recvReqRetry();
170 }
171
172 void recvRetrySnoopResp()
173 {
174 mon.recvRetrySnoopResp();
175 }
176
177 private:
178
179 CommMonitor& mon;
180
181 };
182
183 /** Instance of master port, facing the memory side */
184 MonitorMasterPort masterPort;
185
186 /**
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.
191 */
192 class MonitorSlavePort : public SlavePort
193 {
194
195 public:
196
197 MonitorSlavePort(const std::string& _name, CommMonitor& _mon)
198 : SlavePort(_name, &_mon), mon(_mon)
199 { }
200
201 protected:
202
203 void recvFunctional(PacketPtr pkt)
204 {
205 mon.recvFunctional(pkt);
206 }
207
208 Tick recvAtomic(PacketPtr pkt)
209 {
210 return mon.recvAtomic(pkt);
211 }
212
213 bool recvTimingReq(PacketPtr pkt)
214 {
215 return mon.recvTimingReq(pkt);
216 }
217
218 bool recvTimingSnoopResp(PacketPtr pkt)
219 {
220 return mon.recvTimingSnoopResp(pkt);
221 }
222
223 AddrRangeList getAddrRanges() const
224 {
225 return mon.getAddrRanges();
226 }
227
228 void recvRespRetry()
229 {
230 mon.recvRespRetry();
231 }
232
233 bool tryTiming(PacketPtr pkt)
234 {
235 return mon.tryTiming(pkt);
236 }
237
238 private:
239
240 CommMonitor& mon;
241
242 };
243
244 /** Instance of slave port, i.e. on the CPU side */
245 MonitorSlavePort slavePort;
246
247 void recvFunctional(PacketPtr pkt);
248
249 void recvFunctionalSnoop(PacketPtr pkt);
250
251 Tick recvAtomic(PacketPtr pkt);
252
253 Tick recvAtomicSnoop(PacketPtr pkt);
254
255 bool recvTimingReq(PacketPtr pkt);
256
257 bool recvTimingResp(PacketPtr pkt);
258
259 void recvTimingSnoopReq(PacketPtr pkt);
260
261 bool recvTimingSnoopResp(PacketPtr pkt);
262
263 void recvRetrySnoopResp();
264
265 AddrRangeList getAddrRanges() const;
266
267 bool isSnooping() const;
268
269 void recvReqRetry();
270
271 void recvRespRetry();
272
273 void recvRangeChange();
274
275 bool tryTiming(PacketPtr pkt);
276
277 /** Stats declarations, all in a struct for convenience. */
278 struct MonitorStats
279 {
280
281 /** Disable flag for burst length histograms **/
282 bool disableBurstLengthHists;
283
284 /** Histogram of read burst lengths */
285 Stats::Histogram readBurstLengthHist;
286
287 /** Histogram of write burst lengths */
288 Stats::Histogram writeBurstLengthHist;
289
290 /** Disable flag for the bandwidth histograms */
291 bool disableBandwidthHists;
292
293 /**
294 * Histogram for read bandwidth per sample window. The
295 * internal counter is an unsigned int rather than a stat.
296 */
297 unsigned int readBytes;
298 Stats::Histogram readBandwidthHist;
299 Stats::Formula averageReadBW;
300 Stats::Scalar totalReadBytes;
301
302 /**
303 * Histogram for write bandwidth per sample window. The
304 * internal counter is an unsigned int rather than a stat.
305 */
306 unsigned int writtenBytes;
307 Stats::Histogram writeBandwidthHist;
308 Stats::Formula averageWriteBW;
309 Stats::Scalar totalWrittenBytes;
310
311 /** Disable flag for latency histograms. */
312 bool disableLatencyHists;
313
314 /** Histogram of read request-to-response latencies */
315 Stats::Histogram readLatencyHist;
316
317 /** Histogram of write request-to-response latencies */
318 Stats::Histogram writeLatencyHist;
319
320 /** Disable flag for ITT distributions. */
321 bool disableITTDists;
322
323 /**
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.
328 */
329 Stats::Distribution ittReadRead;
330 Stats::Distribution ittWriteWrite;
331 Stats::Distribution ittReqReq;
332 Tick timeOfLastRead;
333 Tick timeOfLastWrite;
334 Tick timeOfLastReq;
335
336 /** Disable flag for outstanding histograms. */
337 bool disableOutstandingHists;
338
339 /**
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.
343 */
344 Stats::Histogram outstandingReadsHist;
345 unsigned int outstandingReadReqs;
346
347 /**
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.
351 */
352 Stats::Histogram outstandingWritesHist;
353 unsigned int outstandingWriteReqs;
354
355 /** Disable flag for transaction histograms. */
356 bool disableTransactionHists;
357
358 /** Histogram of number of read transactions per time bin */
359 Stats::Histogram readTransHist;
360 unsigned int readTrans;
361
362 /** Histogram of number of timing write transactions per time bin */
363 Stats::Histogram writeTransHist;
364 unsigned int writeTrans;
365
366 /** Disable flag for address distributions. */
367 bool disableAddrDists;
368
369 /** Address mask for sources of read accesses to be captured */
370 const Addr readAddrMask;
371
372 /** Address mask for sources of write accesses to be captured */
373 const Addr writeAddrMask;
374
375 /**
376 * Histogram of number of read accesses to addresses over
377 * time.
378 */
379 Stats::SparseHistogram readAddrDist;
380
381 /**
382 * Histogram of number of write accesses to addresses over
383 * time.
384 */
385 Stats::SparseHistogram writeAddrDist;
386
387 /**
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.
391 */
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)
406 { }
407
408 void updateReqStats(const ProbePoints::PacketInfo& pkt, bool is_atomic,
409 bool expects_response);
410 void updateRespStats(const ProbePoints::PacketInfo& pkt, Tick latency,
411 bool is_atomic);
412 };
413
414 /** This function is called periodically at the end of each time bin */
415 void samplePeriodic();
416
417 /** Periodic event called at the end of each simulation time bin */
418 EventFunctionWrapper samplePeriodicEvent;
419
420 /**
421 *@{
422 * @name Configuration
423 */
424
425 /** Length of simulation time bin*/
426 const Tick samplePeriodTicks;
427 /** Sample period in seconds */
428 const double samplePeriod;
429
430 /** @} */
431
432 /** Instantiate stats */
433 MonitorStats stats;
434
435 protected: // Probe points
436 /**
437 * @{
438 * @name Memory system probe points
439 */
440
441 /** Successfully forwarded request packet */
442 ProbePoints::PacketUPtr ppPktReq;
443
444 /** Successfully forwarded response packet */
445 ProbePoints::PacketUPtr ppPktResp;
446
447 /** @} */
448};
449
450#endif //__MEM_COMM_MONITOR_HH__