2 * Copyright (c) 2012-2013, 2015 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 #include "base/trace.hh"
42 #include "debug/CommMonitor.hh"
43 #include "mem/comm_monitor.hh"
44 #include "sim/stats.hh"
46 CommMonitor::CommMonitor(Params
* params
)
48 masterPort(name() + "-master", *this),
49 slavePort(name() + "-slave", *this),
50 samplePeriodicEvent(this),
51 samplePeriodTicks(params
->sample_period
),
52 samplePeriod(params
->sample_period
/ SimClock::Float::s
),
53 readAddrMask(params
->read_addr_mask
),
54 writeAddrMask(params
->write_addr_mask
),
58 "Created monitor %s with sample period %d ticks (%f ms)\n",
59 name(), samplePeriodTicks
, samplePeriod
* 1E3
);
63 CommMonitorParams::create()
65 return new CommMonitor(this);
71 // make sure both sides of the monitor are connected
72 if (!slavePort
.isConnected() || !masterPort
.isConnected())
73 fatal("Communication monitor is not connected on both sides.\n");
77 CommMonitor::regProbePoints()
79 ppPktReq
.reset(new ProbePoints::Packet(getProbeManager(), "PktRequest"));
80 ppPktResp
.reset(new ProbePoints::Packet(getProbeManager(), "PktResponse"));
84 CommMonitor::getMasterPort(const std::string
& if_name
, PortID idx
)
86 if (if_name
== "master") {
89 return MemObject::getMasterPort(if_name
, idx
);
94 CommMonitor::getSlavePort(const std::string
& if_name
, PortID idx
)
96 if (if_name
== "slave") {
99 return MemObject::getSlavePort(if_name
, idx
);
104 CommMonitor::recvFunctional(PacketPtr pkt
)
106 masterPort
.sendFunctional(pkt
);
110 CommMonitor::recvFunctionalSnoop(PacketPtr pkt
)
112 slavePort
.sendFunctionalSnoop(pkt
);
116 CommMonitor::recvAtomic(PacketPtr pkt
)
118 ProbePoints::PacketInfo
req_pkt_info(pkt
);
119 ppPktReq
->notify(req_pkt_info
);
121 const Tick
delay(masterPort
.sendAtomic(pkt
));
122 assert(pkt
->isResponse());
123 ProbePoints::PacketInfo
resp_pkt_info(pkt
);
124 ppPktResp
->notify(resp_pkt_info
);
129 CommMonitor::recvAtomicSnoop(PacketPtr pkt
)
131 return slavePort
.sendAtomicSnoop(pkt
);
135 CommMonitor::recvTimingReq(PacketPtr pkt
)
137 // should always see a request
138 assert(pkt
->isRequest());
140 // Store relevant fields of packet, because packet may be modified
141 // or even deleted when sendTiming() is called.
142 const ProbePoints::PacketInfo
pkt_info(pkt
);
144 const bool is_read
= pkt
->isRead();
145 const bool is_write
= pkt
->isWrite();
146 const bool expects_response(
147 pkt
->needsResponse() && !pkt
->cacheResponding());
149 // If a cache miss is served by a cache, a monitor near the memory
150 // would see a request which needs a response, but this response
151 // would not come back from the memory. Therefore we additionally
152 // have to check the cacheResponding flag
153 if (expects_response
&& !stats
.disableLatencyHists
) {
154 pkt
->pushSenderState(new CommMonitorSenderState(curTick()));
157 // Attempt to send the packet
158 bool successful
= masterPort
.sendTimingReq(pkt
);
160 // If not successful, restore the sender state
161 if (!successful
&& expects_response
&& !stats
.disableLatencyHists
) {
162 delete pkt
->popSenderState();
166 ppPktReq
->notify(pkt_info
);
169 if (successful
&& is_read
) {
170 DPRINTF(CommMonitor
, "Forwarded read request\n");
172 // Increment number of observed read transactions
173 if (!stats
.disableTransactionHists
) {
177 // Get sample of burst length
178 if (!stats
.disableBurstLengthHists
) {
179 stats
.readBurstLengthHist
.sample(pkt_info
.size
);
182 // Sample the masked address
183 if (!stats
.disableAddrDists
) {
184 stats
.readAddrDist
.sample(pkt_info
.addr
& readAddrMask
);
187 // If it needs a response increment number of outstanding read
189 if (!stats
.disableOutstandingHists
&& expects_response
) {
190 ++stats
.outstandingReadReqs
;
193 if (!stats
.disableITTDists
) {
194 // Sample value of read-read inter transaction time
195 if (stats
.timeOfLastRead
!= 0) {
196 stats
.ittReadRead
.sample(curTick() - stats
.timeOfLastRead
);
198 stats
.timeOfLastRead
= curTick();
200 // Sample value of req-req inter transaction time
201 if (stats
.timeOfLastReq
!= 0) {
202 stats
.ittReqReq
.sample(curTick() - stats
.timeOfLastReq
);
204 stats
.timeOfLastReq
= curTick();
206 } else if (successful
&& is_write
) {
207 DPRINTF(CommMonitor
, "Forwarded write request\n");
210 if (!stats
.disableTransactionHists
) {
214 if (!stats
.disableBurstLengthHists
) {
215 stats
.writeBurstLengthHist
.sample(pkt_info
.size
);
218 // Update the bandwidth stats on the request
219 if (!stats
.disableBandwidthHists
) {
220 stats
.writtenBytes
+= pkt_info
.size
;
221 stats
.totalWrittenBytes
+= pkt_info
.size
;
224 // Sample the masked write address
225 if (!stats
.disableAddrDists
) {
226 stats
.writeAddrDist
.sample(pkt_info
.addr
& writeAddrMask
);
229 if (!stats
.disableOutstandingHists
&& expects_response
) {
230 ++stats
.outstandingWriteReqs
;
233 if (!stats
.disableITTDists
) {
234 // Sample value of write-to-write inter transaction time
235 if (stats
.timeOfLastWrite
!= 0) {
236 stats
.ittWriteWrite
.sample(curTick() - stats
.timeOfLastWrite
);
238 stats
.timeOfLastWrite
= curTick();
240 // Sample value of req-to-req inter transaction time
241 if (stats
.timeOfLastReq
!= 0) {
242 stats
.ittReqReq
.sample(curTick() - stats
.timeOfLastReq
);
244 stats
.timeOfLastReq
= curTick();
246 } else if (successful
) {
247 DPRINTF(CommMonitor
, "Forwarded non read/write request\n");
254 CommMonitor::recvTimingResp(PacketPtr pkt
)
256 // should always see responses
257 assert(pkt
->isResponse());
259 // Store relevant fields of packet, because packet may be modified
260 // or even deleted when sendTiming() is called.
261 const ProbePoints::PacketInfo
pkt_info(pkt
);
263 bool is_read
= pkt
->isRead();
264 bool is_write
= pkt
->isWrite();
266 CommMonitorSenderState
* received_state
=
267 dynamic_cast<CommMonitorSenderState
*>(pkt
->senderState
);
269 if (!stats
.disableLatencyHists
) {
270 // Restore initial sender state
271 if (received_state
== NULL
)
272 panic("Monitor got a response without monitor sender state\n");
275 pkt
->senderState
= received_state
->predecessor
;
278 // Attempt to send the packet
279 bool successful
= slavePort
.sendTimingResp(pkt
);
281 if (!stats
.disableLatencyHists
) {
282 // If packet successfully send, sample value of latency,
283 // afterwards delete sender state, otherwise restore state
285 latency
= curTick() - received_state
->transmitTime
;
286 DPRINTF(CommMonitor
, "Latency: %d\n", latency
);
287 delete received_state
;
289 // Don't delete anything and let the packet look like we
291 pkt
->senderState
= received_state
;
296 ppPktResp
->notify(pkt_info
);
299 if (successful
&& is_read
) {
300 // Decrement number of outstanding read requests
301 DPRINTF(CommMonitor
, "Received read response\n");
302 if (!stats
.disableOutstandingHists
) {
303 assert(stats
.outstandingReadReqs
!= 0);
304 --stats
.outstandingReadReqs
;
307 if (!stats
.disableLatencyHists
) {
308 stats
.readLatencyHist
.sample(latency
);
311 // Update the bandwidth stats based on responses for reads
312 if (!stats
.disableBandwidthHists
) {
313 stats
.readBytes
+= pkt_info
.size
;
314 stats
.totalReadBytes
+= pkt_info
.size
;
317 } else if (successful
&& is_write
) {
318 // Decrement number of outstanding write requests
319 DPRINTF(CommMonitor
, "Received write response\n");
320 if (!stats
.disableOutstandingHists
) {
321 assert(stats
.outstandingWriteReqs
!= 0);
322 --stats
.outstandingWriteReqs
;
325 if (!stats
.disableLatencyHists
) {
326 stats
.writeLatencyHist
.sample(latency
);
328 } else if (successful
) {
329 DPRINTF(CommMonitor
, "Received non read/write response\n");
335 CommMonitor::recvTimingSnoopReq(PacketPtr pkt
)
337 slavePort
.sendTimingSnoopReq(pkt
);
341 CommMonitor::recvTimingSnoopResp(PacketPtr pkt
)
343 return masterPort
.sendTimingSnoopResp(pkt
);
347 CommMonitor::recvRetrySnoopResp()
349 slavePort
.sendRetrySnoopResp();
353 CommMonitor::isSnooping() const
355 // check if the connected master port is snooping
356 return slavePort
.isSnooping();
360 CommMonitor::getAddrRanges() const
362 // get the address ranges of the connected slave port
363 return masterPort
.getAddrRanges();
367 CommMonitor::recvReqRetry()
369 slavePort
.sendRetryReq();
373 CommMonitor::recvRespRetry()
375 masterPort
.sendRetryResp();
379 CommMonitor::recvRangeChange()
381 slavePort
.sendRangeChange();
385 CommMonitor::regStats()
387 // Initialise all the monitor stats
388 using namespace Stats
;
390 stats
.readBurstLengthHist
391 .init(params()->burst_length_bins
)
392 .name(name() + ".readBurstLengthHist")
393 .desc("Histogram of burst lengths of transmitted packets")
394 .flags(stats
.disableBurstLengthHists
? nozero
: pdf
);
396 stats
.writeBurstLengthHist
397 .init(params()->burst_length_bins
)
398 .name(name() + ".writeBurstLengthHist")
399 .desc("Histogram of burst lengths of transmitted packets")
400 .flags(stats
.disableBurstLengthHists
? nozero
: pdf
);
402 // Stats based on received responses
403 stats
.readBandwidthHist
404 .init(params()->bandwidth_bins
)
405 .name(name() + ".readBandwidthHist")
406 .desc("Histogram of read bandwidth per sample period (bytes/s)")
407 .flags(stats
.disableBandwidthHists
? nozero
: pdf
);
410 .name(name() + ".averageReadBandwidth")
411 .desc("Average read bandwidth (bytes/s)")
412 .flags(stats
.disableBandwidthHists
? nozero
: pdf
);
415 .name(name() + ".totalReadBytes")
416 .desc("Number of bytes read")
417 .flags(stats
.disableBandwidthHists
? nozero
: pdf
);
419 stats
.averageReadBW
= stats
.totalReadBytes
/ simSeconds
;
421 // Stats based on successfully sent requests
422 stats
.writeBandwidthHist
423 .init(params()->bandwidth_bins
)
424 .name(name() + ".writeBandwidthHist")
425 .desc("Histogram of write bandwidth (bytes/s)")
426 .flags(stats
.disableBandwidthHists
? (pdf
| nozero
) : pdf
);
429 .name(name() + ".averageWriteBandwidth")
430 .desc("Average write bandwidth (bytes/s)")
431 .flags(stats
.disableBandwidthHists
? nozero
: pdf
);
433 stats
.totalWrittenBytes
434 .name(name() + ".totalWrittenBytes")
435 .desc("Number of bytes written")
436 .flags(stats
.disableBandwidthHists
? nozero
: pdf
);
438 stats
.averageWriteBW
= stats
.totalWrittenBytes
/ simSeconds
;
440 stats
.readLatencyHist
441 .init(params()->latency_bins
)
442 .name(name() + ".readLatencyHist")
443 .desc("Read request-response latency")
444 .flags(stats
.disableLatencyHists
? nozero
: pdf
);
446 stats
.writeLatencyHist
447 .init(params()->latency_bins
)
448 .name(name() + ".writeLatencyHist")
449 .desc("Write request-response latency")
450 .flags(stats
.disableLatencyHists
? nozero
: pdf
);
453 .init(1, params()->itt_max_bin
, params()->itt_max_bin
/
455 .name(name() + ".ittReadRead")
456 .desc("Read-to-read inter transaction time")
457 .flags(stats
.disableITTDists
? nozero
: pdf
);
460 .init(1, params()->itt_max_bin
, params()->itt_max_bin
/
462 .name(name() + ".ittWriteWrite")
463 .desc("Write-to-write inter transaction time")
464 .flags(stats
.disableITTDists
? nozero
: pdf
);
467 .init(1, params()->itt_max_bin
, params()->itt_max_bin
/
469 .name(name() + ".ittReqReq")
470 .desc("Request-to-request inter transaction time")
471 .flags(stats
.disableITTDists
? nozero
: pdf
);
473 stats
.outstandingReadsHist
474 .init(params()->outstanding_bins
)
475 .name(name() + ".outstandingReadsHist")
476 .desc("Outstanding read transactions")
477 .flags(stats
.disableOutstandingHists
? nozero
: pdf
);
479 stats
.outstandingWritesHist
480 .init(params()->outstanding_bins
)
481 .name(name() + ".outstandingWritesHist")
482 .desc("Outstanding write transactions")
483 .flags(stats
.disableOutstandingHists
? nozero
: pdf
);
486 .init(params()->transaction_bins
)
487 .name(name() + ".readTransHist")
488 .desc("Histogram of read transactions per sample period")
489 .flags(stats
.disableTransactionHists
? nozero
: pdf
);
492 .init(params()->transaction_bins
)
493 .name(name() + ".writeTransHist")
494 .desc("Histogram of read transactions per sample period")
495 .flags(stats
.disableTransactionHists
? nozero
: pdf
);
499 .name(name() + ".readAddrDist")
500 .desc("Read address distribution")
501 .flags(stats
.disableAddrDists
? nozero
: pdf
);
505 .name(name() + ".writeAddrDist")
506 .desc("Write address distribution")
507 .flags(stats
.disableAddrDists
? nozero
: pdf
);
511 CommMonitor::samplePeriodic()
513 // the periodic stats update runs on the granularity of sample
514 // periods, but in combination with this there may also be a
515 // external resets and dumps of the stats (through schedStatEvent)
516 // causing the stats themselves to capture less than a sample
519 // only capture if we have not reset the stats during the last
521 if (simTicks
.value() >= samplePeriodTicks
) {
522 if (!stats
.disableTransactionHists
) {
523 stats
.readTransHist
.sample(stats
.readTrans
);
524 stats
.writeTransHist
.sample(stats
.writeTrans
);
527 if (!stats
.disableBandwidthHists
) {
528 stats
.readBandwidthHist
.sample(stats
.readBytes
/ samplePeriod
);
529 stats
.writeBandwidthHist
.sample(stats
.writtenBytes
/ samplePeriod
);
532 if (!stats
.disableOutstandingHists
) {
533 stats
.outstandingReadsHist
.sample(stats
.outstandingReadReqs
);
534 stats
.outstandingWritesHist
.sample(stats
.outstandingWriteReqs
);
538 // reset the sampled values
540 stats
.writeTrans
= 0;
543 stats
.writtenBytes
= 0;
545 schedule(samplePeriodicEvent
, curTick() + samplePeriodTicks
);
549 CommMonitor::startup()
551 schedule(samplePeriodicEvent
, curTick() + samplePeriodTicks
);