comm_monitor.cc (14084:9e60f14d5f0d) comm_monitor.cc (14208:1c8f93faf08f)
1/*
1/*
2 * Copyright (c) 2012-2013, 2015, 2018 ARM Limited
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
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#include "mem/comm_monitor.hh"
46
47#include "base/trace.hh"
48#include "debug/CommMonitor.hh"
49#include "sim/stats.hh"
50
51CommMonitor::CommMonitor(Params* params)
52 : SimObject(params),
53 masterPort(name() + "-master", *this),
54 slavePort(name() + "-slave", *this),
55 samplePeriodicEvent([this]{ samplePeriodic(); }, name()),
56 samplePeriodTicks(params->sample_period),
57 samplePeriod(params->sample_period / SimClock::Float::s),
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#include "mem/comm_monitor.hh"
46
47#include "base/trace.hh"
48#include "debug/CommMonitor.hh"
49#include "sim/stats.hh"
50
51CommMonitor::CommMonitor(Params* params)
52 : SimObject(params),
53 masterPort(name() + "-master", *this),
54 slavePort(name() + "-slave", *this),
55 samplePeriodicEvent([this]{ samplePeriodic(); }, name()),
56 samplePeriodTicks(params->sample_period),
57 samplePeriod(params->sample_period / SimClock::Float::s),
58 stats(params)
58 stats(this, params)
59{
60 DPRINTF(CommMonitor,
61 "Created monitor %s with sample period %d ticks (%f ms)\n",
62 name(), samplePeriodTicks, samplePeriod * 1E3);
63}
64
65CommMonitor*
66CommMonitorParams::create()
67{
68 return new CommMonitor(this);
69}
70
71void
72CommMonitor::init()
73{
74 // make sure both sides of the monitor are connected
75 if (!slavePort.isConnected() || !masterPort.isConnected())
76 fatal("Communication monitor is not connected on both sides.\n");
77}
78
79void
80CommMonitor::regProbePoints()
81{
82 ppPktReq.reset(new ProbePoints::Packet(getProbeManager(), "PktRequest"));
83 ppPktResp.reset(new ProbePoints::Packet(getProbeManager(), "PktResponse"));
84}
85
86Port &
87CommMonitor::getPort(const std::string &if_name, PortID idx)
88{
89 if (if_name == "master") {
90 return masterPort;
91 } else if (if_name == "slave") {
92 return slavePort;
93 } else {
94 return SimObject::getPort(if_name, idx);
95 }
96}
97
98void
99CommMonitor::recvFunctional(PacketPtr pkt)
100{
101 masterPort.sendFunctional(pkt);
102}
103
104void
105CommMonitor::recvFunctionalSnoop(PacketPtr pkt)
106{
107 slavePort.sendFunctionalSnoop(pkt);
108}
109
59{
60 DPRINTF(CommMonitor,
61 "Created monitor %s with sample period %d ticks (%f ms)\n",
62 name(), samplePeriodTicks, samplePeriod * 1E3);
63}
64
65CommMonitor*
66CommMonitorParams::create()
67{
68 return new CommMonitor(this);
69}
70
71void
72CommMonitor::init()
73{
74 // make sure both sides of the monitor are connected
75 if (!slavePort.isConnected() || !masterPort.isConnected())
76 fatal("Communication monitor is not connected on both sides.\n");
77}
78
79void
80CommMonitor::regProbePoints()
81{
82 ppPktReq.reset(new ProbePoints::Packet(getProbeManager(), "PktRequest"));
83 ppPktResp.reset(new ProbePoints::Packet(getProbeManager(), "PktResponse"));
84}
85
86Port &
87CommMonitor::getPort(const std::string &if_name, PortID idx)
88{
89 if (if_name == "master") {
90 return masterPort;
91 } else if (if_name == "slave") {
92 return slavePort;
93 } else {
94 return SimObject::getPort(if_name, idx);
95 }
96}
97
98void
99CommMonitor::recvFunctional(PacketPtr pkt)
100{
101 masterPort.sendFunctional(pkt);
102}
103
104void
105CommMonitor::recvFunctionalSnoop(PacketPtr pkt)
106{
107 slavePort.sendFunctionalSnoop(pkt);
108}
109
110CommMonitor::MonitorStats::MonitorStats(Stats::Group *parent,
111 const CommMonitorParams *params)
112 : Stats::Group(parent),
113
114 disableBurstLengthHists(params->disable_burst_length_hists),
115 ADD_STAT(readBurstLengthHist,
116 "Histogram of burst lengths of transmitted packets"),
117 ADD_STAT(writeBurstLengthHist,
118 "Histogram of burst lengths of transmitted packets"),
119
120 disableBandwidthHists(params->disable_bandwidth_hists),
121 readBytes(0),
122 ADD_STAT(readBandwidthHist,
123 "Histogram of read bandwidth per sample period (bytes/s)"),
124 ADD_STAT(totalReadBytes, "Number of bytes read"),
125 ADD_STAT(averageReadBandwidth, "Average read bandwidth (bytes/s)",
126 totalReadBytes / simSeconds),
127
128 writtenBytes(0),
129 ADD_STAT(writeBandwidthHist, "Histogram of write bandwidth (bytes/s)"),
130 ADD_STAT(totalWrittenBytes, "Number of bytes written"),
131 ADD_STAT(averageWriteBandwidth, "Average write bandwidth (bytes/s)",
132 totalWrittenBytes / simSeconds),
133
134 disableLatencyHists(params->disable_latency_hists),
135 ADD_STAT(readLatencyHist, "Read request-response latency"),
136 ADD_STAT(writeLatencyHist, "Write request-response latency"),
137
138 disableITTDists(params->disable_itt_dists),
139 ADD_STAT(ittReadRead, "Read-to-read inter transaction time"),
140 ADD_STAT(ittWriteWrite , "Write-to-write inter transaction time"),
141 ADD_STAT(ittReqReq, "Request-to-request inter transaction time"),
142 timeOfLastRead(0), timeOfLastWrite(0), timeOfLastReq(0),
143
144 disableOutstandingHists(params->disable_outstanding_hists),
145 ADD_STAT(outstandingReadsHist, "Outstanding read transactions"),
146 outstandingReadReqs(0),
147 ADD_STAT(outstandingWritesHist, "Outstanding write transactions"),
148 outstandingWriteReqs(0),
149
150 disableTransactionHists(params->disable_transaction_hists),
151 ADD_STAT(readTransHist,
152 "Histogram of read transactions per sample period"),
153 readTrans(0),
154 ADD_STAT(writeTransHist,
155 "Histogram of write transactions per sample period"),
156 writeTrans(0),
157
158 disableAddrDists(params->disable_addr_dists),
159 readAddrMask(params->read_addr_mask),
160 writeAddrMask(params->write_addr_mask),
161 ADD_STAT(readAddrDist, "Read address distribution"),
162 ADD_STAT(writeAddrDist, "Write address distribution")
163{
164 using namespace Stats;
165
166 readBurstLengthHist
167 .init(params->burst_length_bins)
168 .flags(disableBurstLengthHists ? nozero : pdf);
169
170 writeBurstLengthHist
171 .init(params->burst_length_bins)
172 .flags(disableBurstLengthHists ? nozero : pdf);
173
174 // Stats based on received responses
175 readBandwidthHist
176 .init(params->bandwidth_bins)
177 .flags(disableBandwidthHists ? nozero : pdf);
178
179 averageReadBandwidth
180 .flags(disableBandwidthHists ? nozero : pdf);
181
182 totalReadBytes
183 .flags(disableBandwidthHists ? nozero : pdf);
184
185 // Stats based on successfully sent requests
186 writeBandwidthHist
187 .init(params->bandwidth_bins)
188 .flags(disableBandwidthHists ? (pdf | nozero) : pdf);
189
190 averageWriteBandwidth
191 .flags(disableBandwidthHists ? nozero : pdf);
192
193 totalWrittenBytes
194 .flags(disableBandwidthHists ? nozero : pdf);
195
196
197 readLatencyHist
198 .init(params->latency_bins)
199 .flags(disableLatencyHists ? nozero : pdf);
200
201 writeLatencyHist
202 .init(params->latency_bins)
203 .flags(disableLatencyHists ? nozero : pdf);
204
205 ittReadRead
206 .init(1, params->itt_max_bin, params->itt_max_bin /
207 params->itt_bins)
208 .flags(disableITTDists ? nozero : pdf);
209
210 ittWriteWrite
211 .init(1, params->itt_max_bin, params->itt_max_bin /
212 params->itt_bins)
213 .flags(disableITTDists ? nozero : pdf);
214
215 ittReqReq
216 .init(1, params->itt_max_bin, params->itt_max_bin /
217 params->itt_bins)
218 .flags(disableITTDists ? nozero : pdf);
219
220 outstandingReadsHist
221 .init(params->outstanding_bins)
222 .flags(disableOutstandingHists ? nozero : pdf);
223
224 outstandingWritesHist
225 .init(params->outstanding_bins)
226 .flags(disableOutstandingHists ? nozero : pdf);
227
228 readTransHist
229 .init(params->transaction_bins)
230 .flags(disableTransactionHists ? nozero : pdf);
231
232 writeTransHist
233 .init(params->transaction_bins)
234 .flags(disableTransactionHists ? nozero : pdf);
235
236 readAddrDist
237 .init(0)
238 .flags(disableAddrDists ? nozero : pdf);
239
240 writeAddrDist
241 .init(0)
242 .flags(disableAddrDists ? nozero : pdf);
243}
244
110void
111CommMonitor::MonitorStats::updateReqStats(
112 const ProbePoints::PacketInfo& pkt_info, bool is_atomic,
113 bool expects_response)
114{
115 if (pkt_info.cmd.isRead()) {
116 // Increment number of observed read transactions
117 if (!disableTransactionHists)
118 ++readTrans;
119
120 // Get sample of burst length
121 if (!disableBurstLengthHists)
122 readBurstLengthHist.sample(pkt_info.size);
123
124 // Sample the masked address
125 if (!disableAddrDists)
126 readAddrDist.sample(pkt_info.addr & readAddrMask);
127
128 if (!disableITTDists) {
129 // Sample value of read-read inter transaction time
130 if (timeOfLastRead != 0)
131 ittReadRead.sample(curTick() - timeOfLastRead);
132 timeOfLastRead = curTick();
133
134 // Sample value of req-req inter transaction time
135 if (timeOfLastReq != 0)
136 ittReqReq.sample(curTick() - timeOfLastReq);
137 timeOfLastReq = curTick();
138 }
139 if (!is_atomic && !disableOutstandingHists && expects_response)
140 ++outstandingReadReqs;
141
142 } else if (pkt_info.cmd.isWrite()) {
143 // Same as for reads
144 if (!disableTransactionHists)
145 ++writeTrans;
146
147 if (!disableBurstLengthHists)
148 writeBurstLengthHist.sample(pkt_info.size);
149
150 // Update the bandwidth stats on the request
151 if (!disableBandwidthHists) {
152 writtenBytes += pkt_info.size;
153 totalWrittenBytes += pkt_info.size;
154 }
155
156 // Sample the masked write address
157 if (!disableAddrDists)
158 writeAddrDist.sample(pkt_info.addr & writeAddrMask);
159
160 if (!disableITTDists) {
161 // Sample value of write-to-write inter transaction time
162 if (timeOfLastWrite != 0)
163 ittWriteWrite.sample(curTick() - timeOfLastWrite);
164 timeOfLastWrite = curTick();
165
166 // Sample value of req-to-req inter transaction time
167 if (timeOfLastReq != 0)
168 ittReqReq.sample(curTick() - timeOfLastReq);
169 timeOfLastReq = curTick();
170 }
171
172 if (!is_atomic && !disableOutstandingHists && expects_response)
173 ++outstandingWriteReqs;
174 }
175}
176
177void
178CommMonitor::MonitorStats::updateRespStats(
179 const ProbePoints::PacketInfo& pkt_info, Tick latency, bool is_atomic)
180{
181 if (pkt_info.cmd.isRead()) {
182 // Decrement number of outstanding read requests
183 if (!is_atomic && !disableOutstandingHists) {
184 assert(outstandingReadReqs != 0);
185 --outstandingReadReqs;
186 }
187
188 if (!disableLatencyHists)
189 readLatencyHist.sample(latency);
190
191 // Update the bandwidth stats based on responses for reads
192 if (!disableBandwidthHists) {
193 readBytes += pkt_info.size;
194 totalReadBytes += pkt_info.size;
195 }
196
197 } else if (pkt_info.cmd.isWrite()) {
198 // Decrement number of outstanding write requests
199 if (!is_atomic && !disableOutstandingHists) {
200 assert(outstandingWriteReqs != 0);
201 --outstandingWriteReqs;
202 }
203
204 if (!disableLatencyHists)
205 writeLatencyHist.sample(latency);
206 }
207}
208
209Tick
210CommMonitor::recvAtomic(PacketPtr pkt)
211{
212 const bool expects_response(pkt->needsResponse() &&
213 !pkt->cacheResponding());
214 ProbePoints::PacketInfo req_pkt_info(pkt);
215 ppPktReq->notify(req_pkt_info);
216
217 const Tick delay(masterPort.sendAtomic(pkt));
218
219 stats.updateReqStats(req_pkt_info, true, expects_response);
220 if (expects_response)
221 stats.updateRespStats(req_pkt_info, delay, true);
222
223 // Some packets, such as WritebackDirty, don't need response.
224 assert(pkt->isResponse() || !expects_response);
225 ProbePoints::PacketInfo resp_pkt_info(pkt);
226 ppPktResp->notify(resp_pkt_info);
227 return delay;
228}
229
230Tick
231CommMonitor::recvAtomicSnoop(PacketPtr pkt)
232{
233 return slavePort.sendAtomicSnoop(pkt);
234}
235
236bool
237CommMonitor::recvTimingReq(PacketPtr pkt)
238{
239 // should always see a request
240 assert(pkt->isRequest());
241
242 // Store relevant fields of packet, because packet may be modified
243 // or even deleted when sendTiming() is called.
244 const ProbePoints::PacketInfo pkt_info(pkt);
245
246 const bool expects_response(pkt->needsResponse() &&
247 !pkt->cacheResponding());
248
249 // If a cache miss is served by a cache, a monitor near the memory
250 // would see a request which needs a response, but this response
251 // would not come back from the memory. Therefore we additionally
252 // have to check the cacheResponding flag
253 if (expects_response && !stats.disableLatencyHists) {
254 pkt->pushSenderState(new CommMonitorSenderState(curTick()));
255 }
256
257 // Attempt to send the packet
258 bool successful = masterPort.sendTimingReq(pkt);
259
260 // If not successful, restore the sender state
261 if (!successful && expects_response && !stats.disableLatencyHists) {
262 delete pkt->popSenderState();
263 }
264
265 if (successful) {
266 ppPktReq->notify(pkt_info);
267 }
268
269 if (successful) {
270 DPRINTF(CommMonitor, "Forwarded %s request\n", pkt->isRead() ? "read" :
271 pkt->isWrite() ? "write" : "non read/write");
272 stats.updateReqStats(pkt_info, false, expects_response);
273 }
274 return successful;
275}
276
277bool
278CommMonitor::recvTimingResp(PacketPtr pkt)
279{
280 // should always see responses
281 assert(pkt->isResponse());
282
283 // Store relevant fields of packet, because packet may be modified
284 // or even deleted when sendTiming() is called.
285 const ProbePoints::PacketInfo pkt_info(pkt);
286
287 Tick latency = 0;
288 CommMonitorSenderState* received_state =
289 dynamic_cast<CommMonitorSenderState*>(pkt->senderState);
290
291 if (!stats.disableLatencyHists) {
292 // Restore initial sender state
293 if (received_state == NULL)
294 panic("Monitor got a response without monitor sender state\n");
295
296 // Restore the sate
297 pkt->senderState = received_state->predecessor;
298 }
299
300 // Attempt to send the packet
301 bool successful = slavePort.sendTimingResp(pkt);
302
303 if (!stats.disableLatencyHists) {
304 // If packet successfully send, sample value of latency,
305 // afterwards delete sender state, otherwise restore state
306 if (successful) {
307 latency = curTick() - received_state->transmitTime;
308 DPRINTF(CommMonitor, "Latency: %d\n", latency);
309 delete received_state;
310 } else {
311 // Don't delete anything and let the packet look like we
312 // did not touch it
313 pkt->senderState = received_state;
314 }
315 }
316
317 if (successful) {
318 ppPktResp->notify(pkt_info);
319 DPRINTF(CommMonitor, "Received %s response\n", pkt->isRead() ? "read" :
320 pkt->isWrite() ? "write" : "non read/write");
321 stats.updateRespStats(pkt_info, latency, false);
322 }
323 return successful;
324}
325
326void
327CommMonitor::recvTimingSnoopReq(PacketPtr pkt)
328{
329 slavePort.sendTimingSnoopReq(pkt);
330}
331
332bool
333CommMonitor::recvTimingSnoopResp(PacketPtr pkt)
334{
335 return masterPort.sendTimingSnoopResp(pkt);
336}
337
338void
339CommMonitor::recvRetrySnoopResp()
340{
341 slavePort.sendRetrySnoopResp();
342}
343
344bool
345CommMonitor::isSnooping() const
346{
347 // check if the connected master port is snooping
348 return slavePort.isSnooping();
349}
350
351AddrRangeList
352CommMonitor::getAddrRanges() const
353{
354 // get the address ranges of the connected slave port
355 return masterPort.getAddrRanges();
356}
357
358void
359CommMonitor::recvReqRetry()
360{
361 slavePort.sendRetryReq();
362}
363
364void
365CommMonitor::recvRespRetry()
366{
367 masterPort.sendRetryResp();
368}
369
370bool
371CommMonitor::tryTiming(PacketPtr pkt)
372{
373 return masterPort.tryTiming(pkt);
374}
375
376void
377CommMonitor::recvRangeChange()
378{
379 slavePort.sendRangeChange();
380}
381
382void
245void
246CommMonitor::MonitorStats::updateReqStats(
247 const ProbePoints::PacketInfo& pkt_info, bool is_atomic,
248 bool expects_response)
249{
250 if (pkt_info.cmd.isRead()) {
251 // Increment number of observed read transactions
252 if (!disableTransactionHists)
253 ++readTrans;
254
255 // Get sample of burst length
256 if (!disableBurstLengthHists)
257 readBurstLengthHist.sample(pkt_info.size);
258
259 // Sample the masked address
260 if (!disableAddrDists)
261 readAddrDist.sample(pkt_info.addr & readAddrMask);
262
263 if (!disableITTDists) {
264 // Sample value of read-read inter transaction time
265 if (timeOfLastRead != 0)
266 ittReadRead.sample(curTick() - timeOfLastRead);
267 timeOfLastRead = curTick();
268
269 // Sample value of req-req inter transaction time
270 if (timeOfLastReq != 0)
271 ittReqReq.sample(curTick() - timeOfLastReq);
272 timeOfLastReq = curTick();
273 }
274 if (!is_atomic && !disableOutstandingHists && expects_response)
275 ++outstandingReadReqs;
276
277 } else if (pkt_info.cmd.isWrite()) {
278 // Same as for reads
279 if (!disableTransactionHists)
280 ++writeTrans;
281
282 if (!disableBurstLengthHists)
283 writeBurstLengthHist.sample(pkt_info.size);
284
285 // Update the bandwidth stats on the request
286 if (!disableBandwidthHists) {
287 writtenBytes += pkt_info.size;
288 totalWrittenBytes += pkt_info.size;
289 }
290
291 // Sample the masked write address
292 if (!disableAddrDists)
293 writeAddrDist.sample(pkt_info.addr & writeAddrMask);
294
295 if (!disableITTDists) {
296 // Sample value of write-to-write inter transaction time
297 if (timeOfLastWrite != 0)
298 ittWriteWrite.sample(curTick() - timeOfLastWrite);
299 timeOfLastWrite = curTick();
300
301 // Sample value of req-to-req inter transaction time
302 if (timeOfLastReq != 0)
303 ittReqReq.sample(curTick() - timeOfLastReq);
304 timeOfLastReq = curTick();
305 }
306
307 if (!is_atomic && !disableOutstandingHists && expects_response)
308 ++outstandingWriteReqs;
309 }
310}
311
312void
313CommMonitor::MonitorStats::updateRespStats(
314 const ProbePoints::PacketInfo& pkt_info, Tick latency, bool is_atomic)
315{
316 if (pkt_info.cmd.isRead()) {
317 // Decrement number of outstanding read requests
318 if (!is_atomic && !disableOutstandingHists) {
319 assert(outstandingReadReqs != 0);
320 --outstandingReadReqs;
321 }
322
323 if (!disableLatencyHists)
324 readLatencyHist.sample(latency);
325
326 // Update the bandwidth stats based on responses for reads
327 if (!disableBandwidthHists) {
328 readBytes += pkt_info.size;
329 totalReadBytes += pkt_info.size;
330 }
331
332 } else if (pkt_info.cmd.isWrite()) {
333 // Decrement number of outstanding write requests
334 if (!is_atomic && !disableOutstandingHists) {
335 assert(outstandingWriteReqs != 0);
336 --outstandingWriteReqs;
337 }
338
339 if (!disableLatencyHists)
340 writeLatencyHist.sample(latency);
341 }
342}
343
344Tick
345CommMonitor::recvAtomic(PacketPtr pkt)
346{
347 const bool expects_response(pkt->needsResponse() &&
348 !pkt->cacheResponding());
349 ProbePoints::PacketInfo req_pkt_info(pkt);
350 ppPktReq->notify(req_pkt_info);
351
352 const Tick delay(masterPort.sendAtomic(pkt));
353
354 stats.updateReqStats(req_pkt_info, true, expects_response);
355 if (expects_response)
356 stats.updateRespStats(req_pkt_info, delay, true);
357
358 // Some packets, such as WritebackDirty, don't need response.
359 assert(pkt->isResponse() || !expects_response);
360 ProbePoints::PacketInfo resp_pkt_info(pkt);
361 ppPktResp->notify(resp_pkt_info);
362 return delay;
363}
364
365Tick
366CommMonitor::recvAtomicSnoop(PacketPtr pkt)
367{
368 return slavePort.sendAtomicSnoop(pkt);
369}
370
371bool
372CommMonitor::recvTimingReq(PacketPtr pkt)
373{
374 // should always see a request
375 assert(pkt->isRequest());
376
377 // Store relevant fields of packet, because packet may be modified
378 // or even deleted when sendTiming() is called.
379 const ProbePoints::PacketInfo pkt_info(pkt);
380
381 const bool expects_response(pkt->needsResponse() &&
382 !pkt->cacheResponding());
383
384 // If a cache miss is served by a cache, a monitor near the memory
385 // would see a request which needs a response, but this response
386 // would not come back from the memory. Therefore we additionally
387 // have to check the cacheResponding flag
388 if (expects_response && !stats.disableLatencyHists) {
389 pkt->pushSenderState(new CommMonitorSenderState(curTick()));
390 }
391
392 // Attempt to send the packet
393 bool successful = masterPort.sendTimingReq(pkt);
394
395 // If not successful, restore the sender state
396 if (!successful && expects_response && !stats.disableLatencyHists) {
397 delete pkt->popSenderState();
398 }
399
400 if (successful) {
401 ppPktReq->notify(pkt_info);
402 }
403
404 if (successful) {
405 DPRINTF(CommMonitor, "Forwarded %s request\n", pkt->isRead() ? "read" :
406 pkt->isWrite() ? "write" : "non read/write");
407 stats.updateReqStats(pkt_info, false, expects_response);
408 }
409 return successful;
410}
411
412bool
413CommMonitor::recvTimingResp(PacketPtr pkt)
414{
415 // should always see responses
416 assert(pkt->isResponse());
417
418 // Store relevant fields of packet, because packet may be modified
419 // or even deleted when sendTiming() is called.
420 const ProbePoints::PacketInfo pkt_info(pkt);
421
422 Tick latency = 0;
423 CommMonitorSenderState* received_state =
424 dynamic_cast<CommMonitorSenderState*>(pkt->senderState);
425
426 if (!stats.disableLatencyHists) {
427 // Restore initial sender state
428 if (received_state == NULL)
429 panic("Monitor got a response without monitor sender state\n");
430
431 // Restore the sate
432 pkt->senderState = received_state->predecessor;
433 }
434
435 // Attempt to send the packet
436 bool successful = slavePort.sendTimingResp(pkt);
437
438 if (!stats.disableLatencyHists) {
439 // If packet successfully send, sample value of latency,
440 // afterwards delete sender state, otherwise restore state
441 if (successful) {
442 latency = curTick() - received_state->transmitTime;
443 DPRINTF(CommMonitor, "Latency: %d\n", latency);
444 delete received_state;
445 } else {
446 // Don't delete anything and let the packet look like we
447 // did not touch it
448 pkt->senderState = received_state;
449 }
450 }
451
452 if (successful) {
453 ppPktResp->notify(pkt_info);
454 DPRINTF(CommMonitor, "Received %s response\n", pkt->isRead() ? "read" :
455 pkt->isWrite() ? "write" : "non read/write");
456 stats.updateRespStats(pkt_info, latency, false);
457 }
458 return successful;
459}
460
461void
462CommMonitor::recvTimingSnoopReq(PacketPtr pkt)
463{
464 slavePort.sendTimingSnoopReq(pkt);
465}
466
467bool
468CommMonitor::recvTimingSnoopResp(PacketPtr pkt)
469{
470 return masterPort.sendTimingSnoopResp(pkt);
471}
472
473void
474CommMonitor::recvRetrySnoopResp()
475{
476 slavePort.sendRetrySnoopResp();
477}
478
479bool
480CommMonitor::isSnooping() const
481{
482 // check if the connected master port is snooping
483 return slavePort.isSnooping();
484}
485
486AddrRangeList
487CommMonitor::getAddrRanges() const
488{
489 // get the address ranges of the connected slave port
490 return masterPort.getAddrRanges();
491}
492
493void
494CommMonitor::recvReqRetry()
495{
496 slavePort.sendRetryReq();
497}
498
499void
500CommMonitor::recvRespRetry()
501{
502 masterPort.sendRetryResp();
503}
504
505bool
506CommMonitor::tryTiming(PacketPtr pkt)
507{
508 return masterPort.tryTiming(pkt);
509}
510
511void
512CommMonitor::recvRangeChange()
513{
514 slavePort.sendRangeChange();
515}
516
517void
383CommMonitor::regStats()
384{
385 SimObject::regStats();
386
387 // Initialise all the monitor stats
388 using namespace Stats;
389
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);
395
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);
401
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);
408
409 stats.averageReadBW
410 .name(name() + ".averageReadBandwidth")
411 .desc("Average read bandwidth (bytes/s)")
412 .flags(stats.disableBandwidthHists ? nozero : pdf);
413
414 stats.totalReadBytes
415 .name(name() + ".totalReadBytes")
416 .desc("Number of bytes read")
417 .flags(stats.disableBandwidthHists ? nozero : pdf);
418
419 stats.averageReadBW = stats.totalReadBytes / simSeconds;
420
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);
427
428 stats.averageWriteBW
429 .name(name() + ".averageWriteBandwidth")
430 .desc("Average write bandwidth (bytes/s)")
431 .flags(stats.disableBandwidthHists ? nozero : pdf);
432
433 stats.totalWrittenBytes
434 .name(name() + ".totalWrittenBytes")
435 .desc("Number of bytes written")
436 .flags(stats.disableBandwidthHists ? nozero : pdf);
437
438 stats.averageWriteBW = stats.totalWrittenBytes / simSeconds;
439
440 stats.readLatencyHist
441 .init(params()->latency_bins)
442 .name(name() + ".readLatencyHist")
443 .desc("Read request-response latency")
444 .flags(stats.disableLatencyHists ? nozero : pdf);
445
446 stats.writeLatencyHist
447 .init(params()->latency_bins)
448 .name(name() + ".writeLatencyHist")
449 .desc("Write request-response latency")
450 .flags(stats.disableLatencyHists ? nozero : pdf);
451
452 stats.ittReadRead
453 .init(1, params()->itt_max_bin, params()->itt_max_bin /
454 params()->itt_bins)
455 .name(name() + ".ittReadRead")
456 .desc("Read-to-read inter transaction time")
457 .flags(stats.disableITTDists ? nozero : pdf);
458
459 stats.ittWriteWrite
460 .init(1, params()->itt_max_bin, params()->itt_max_bin /
461 params()->itt_bins)
462 .name(name() + ".ittWriteWrite")
463 .desc("Write-to-write inter transaction time")
464 .flags(stats.disableITTDists ? nozero : pdf);
465
466 stats.ittReqReq
467 .init(1, params()->itt_max_bin, params()->itt_max_bin /
468 params()->itt_bins)
469 .name(name() + ".ittReqReq")
470 .desc("Request-to-request inter transaction time")
471 .flags(stats.disableITTDists ? nozero : pdf);
472
473 stats.outstandingReadsHist
474 .init(params()->outstanding_bins)
475 .name(name() + ".outstandingReadsHist")
476 .desc("Outstanding read transactions")
477 .flags(stats.disableOutstandingHists ? nozero : pdf);
478
479 stats.outstandingWritesHist
480 .init(params()->outstanding_bins)
481 .name(name() + ".outstandingWritesHist")
482 .desc("Outstanding write transactions")
483 .flags(stats.disableOutstandingHists ? nozero : pdf);
484
485 stats.readTransHist
486 .init(params()->transaction_bins)
487 .name(name() + ".readTransHist")
488 .desc("Histogram of read transactions per sample period")
489 .flags(stats.disableTransactionHists ? nozero : pdf);
490
491 stats.writeTransHist
492 .init(params()->transaction_bins)
493 .name(name() + ".writeTransHist")
494 .desc("Histogram of write transactions per sample period")
495 .flags(stats.disableTransactionHists ? nozero : pdf);
496
497 stats.readAddrDist
498 .init(0)
499 .name(name() + ".readAddrDist")
500 .desc("Read address distribution")
501 .flags(stats.disableAddrDists ? nozero : pdf);
502
503 stats.writeAddrDist
504 .init(0)
505 .name(name() + ".writeAddrDist")
506 .desc("Write address distribution")
507 .flags(stats.disableAddrDists ? nozero : pdf);
508}
509
510void
511CommMonitor::samplePeriodic()
512{
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
517 // period
518
519 // only capture if we have not reset the stats during the last
520 // sample period
521 if (simTicks.value() >= samplePeriodTicks) {
522 if (!stats.disableTransactionHists) {
523 stats.readTransHist.sample(stats.readTrans);
524 stats.writeTransHist.sample(stats.writeTrans);
525 }
526
527 if (!stats.disableBandwidthHists) {
528 stats.readBandwidthHist.sample(stats.readBytes / samplePeriod);
529 stats.writeBandwidthHist.sample(stats.writtenBytes / samplePeriod);
530 }
531
532 if (!stats.disableOutstandingHists) {
533 stats.outstandingReadsHist.sample(stats.outstandingReadReqs);
534 stats.outstandingWritesHist.sample(stats.outstandingWriteReqs);
535 }
536 }
537
538 // reset the sampled values
539 stats.readTrans = 0;
540 stats.writeTrans = 0;
541
542 stats.readBytes = 0;
543 stats.writtenBytes = 0;
544
545 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
546}
547
548void
549CommMonitor::startup()
550{
551 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
552}
518CommMonitor::samplePeriodic()
519{
520 // the periodic stats update runs on the granularity of sample
521 // periods, but in combination with this there may also be a
522 // external resets and dumps of the stats (through schedStatEvent)
523 // causing the stats themselves to capture less than a sample
524 // period
525
526 // only capture if we have not reset the stats during the last
527 // sample period
528 if (simTicks.value() >= samplePeriodTicks) {
529 if (!stats.disableTransactionHists) {
530 stats.readTransHist.sample(stats.readTrans);
531 stats.writeTransHist.sample(stats.writeTrans);
532 }
533
534 if (!stats.disableBandwidthHists) {
535 stats.readBandwidthHist.sample(stats.readBytes / samplePeriod);
536 stats.writeBandwidthHist.sample(stats.writtenBytes / samplePeriod);
537 }
538
539 if (!stats.disableOutstandingHists) {
540 stats.outstandingReadsHist.sample(stats.outstandingReadReqs);
541 stats.outstandingWritesHist.sample(stats.outstandingWriteReqs);
542 }
543 }
544
545 // reset the sampled values
546 stats.readTrans = 0;
547 stats.writeTrans = 0;
548
549 stats.readBytes = 0;
550 stats.writtenBytes = 0;
551
552 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
553}
554
555void
556CommMonitor::startup()
557{
558 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
559}