comm_monitor.cc (10994:51ff41f6a4a5) comm_monitor.cc (10995:a114e2712642)
1/*
2 * Copyright (c) 2012-2013, 2015 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Thomas Grass
38 * Andreas Hansson
39 */
40
41#include "base/callback.hh"
42#include "base/output.hh"
43#include "base/trace.hh"
44#include "debug/CommMonitor.hh"
45#include "mem/comm_monitor.hh"
46#include "proto/packet.pb.h"
47#include "sim/stats.hh"
48
49CommMonitor::CommMonitor(Params* params)
50 : MemObject(params),
51 masterPort(name() + "-master", *this),
52 slavePort(name() + "-slave", *this),
53 samplePeriodicEvent(this),
54 samplePeriodTicks(params->sample_period),
55 samplePeriod(params->sample_period / SimClock::Float::s),
56 readAddrMask(params->read_addr_mask),
57 writeAddrMask(params->write_addr_mask),
1/*
2 * Copyright (c) 2012-2013, 2015 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Thomas Grass
38 * Andreas Hansson
39 */
40
41#include "base/callback.hh"
42#include "base/output.hh"
43#include "base/trace.hh"
44#include "debug/CommMonitor.hh"
45#include "mem/comm_monitor.hh"
46#include "proto/packet.pb.h"
47#include "sim/stats.hh"
48
49CommMonitor::CommMonitor(Params* params)
50 : MemObject(params),
51 masterPort(name() + "-master", *this),
52 slavePort(name() + "-slave", *this),
53 samplePeriodicEvent(this),
54 samplePeriodTicks(params->sample_period),
55 samplePeriod(params->sample_period / SimClock::Float::s),
56 readAddrMask(params->read_addr_mask),
57 writeAddrMask(params->write_addr_mask),
58 stackDistCalc(params->stack_dist_calc),
59 system(params->system),
60 traceStream(nullptr),
61 stats(params)
62{
63 // If we are using a trace file, then open the file
64 if (params->trace_enable) {
65 std::string filename;
66 if (params->trace_file != "") {
67 // If the trace file is not specified as an absolute path,
68 // append the current simulation output directory
69 filename = simout.resolve(params->trace_file);
70
71 std::string suffix = ".gz";
72 // If trace_compress has been set, check the suffix. Append
73 // accordingly.
74 if (params->trace_compress &&
75 filename.compare(filename.size() - suffix.size(), suffix.size(),
76 suffix) != 0)
77 filename = filename + suffix;
78 } else {
79 // Generate a filename from the name of the SimObject. Append .trc
80 // and .gz if we want compression enabled.
81 filename = simout.resolve(name() + ".trc" +
82 (params->trace_compress ? ".gz" : ""));
83 }
84
85 traceStream = new ProtoOutputStream(filename);
86
87 // Create a protobuf message for the header and write it to
88 // the stream
89 ProtoMessage::PacketHeader header_msg;
90 header_msg.set_obj_id(name());
91 header_msg.set_tick_freq(SimClock::Frequency);
92 traceStream->write(header_msg);
93
94 // Register a callback to compensate for the destructor not
95 // being called. The callback forces the stream to flush and
96 // closes the output file.
97 Callback* cb = new MakeCallback<CommMonitor,
98 &CommMonitor::closeStreams>(this);
99 registerExitCallback(cb);
100 }
101
102 DPRINTF(CommMonitor,
103 "Created monitor %s with sample period %d ticks (%f ms)\n",
104 name(), samplePeriodTicks, samplePeriod * 1E3);
105}
106
107CommMonitor::~CommMonitor()
108{
109 // if not already done, close the stream
110 closeStreams();
111}
112
113void
114CommMonitor::closeStreams()
115{
116 if (traceStream != NULL)
117 delete traceStream;
118}
119
120CommMonitor*
121CommMonitorParams::create()
122{
123 return new CommMonitor(this);
124}
125
126void
127CommMonitor::init()
128{
129 // make sure both sides of the monitor are connected
130 if (!slavePort.isConnected() || !masterPort.isConnected())
131 fatal("Communication monitor is not connected on both sides.\n");
132
133 if (traceStream != NULL) {
134 // Check the memory mode. We only record something when in
135 // timing mode. Warn accordingly.
136 if (!system->isTimingMode())
137 warn("%s: Not in timing mode. No trace will be recorded.", name());
138 }
139
140}
141
142void
143CommMonitor::regProbePoints()
144{
145 ppPktReq.reset(new ProbePoints::Packet(getProbeManager(), "PktRequest"));
146 ppPktResp.reset(new ProbePoints::Packet(getProbeManager(), "PktResponse"));
147}
148
149BaseMasterPort&
150CommMonitor::getMasterPort(const std::string& if_name, PortID idx)
151{
152 if (if_name == "master") {
153 return masterPort;
154 } else {
155 return MemObject::getMasterPort(if_name, idx);
156 }
157}
158
159BaseSlavePort&
160CommMonitor::getSlavePort(const std::string& if_name, PortID idx)
161{
162 if (if_name == "slave") {
163 return slavePort;
164 } else {
165 return MemObject::getSlavePort(if_name, idx);
166 }
167}
168
169void
170CommMonitor::recvFunctional(PacketPtr pkt)
171{
172 masterPort.sendFunctional(pkt);
173}
174
175void
176CommMonitor::recvFunctionalSnoop(PacketPtr pkt)
177{
178 slavePort.sendFunctionalSnoop(pkt);
179}
180
181Tick
182CommMonitor::recvAtomic(PacketPtr pkt)
183{
184 ppPktReq->notify(pkt);
185
58 system(params->system),
59 traceStream(nullptr),
60 stats(params)
61{
62 // If we are using a trace file, then open the file
63 if (params->trace_enable) {
64 std::string filename;
65 if (params->trace_file != "") {
66 // If the trace file is not specified as an absolute path,
67 // append the current simulation output directory
68 filename = simout.resolve(params->trace_file);
69
70 std::string suffix = ".gz";
71 // If trace_compress has been set, check the suffix. Append
72 // accordingly.
73 if (params->trace_compress &&
74 filename.compare(filename.size() - suffix.size(), suffix.size(),
75 suffix) != 0)
76 filename = filename + suffix;
77 } else {
78 // Generate a filename from the name of the SimObject. Append .trc
79 // and .gz if we want compression enabled.
80 filename = simout.resolve(name() + ".trc" +
81 (params->trace_compress ? ".gz" : ""));
82 }
83
84 traceStream = new ProtoOutputStream(filename);
85
86 // Create a protobuf message for the header and write it to
87 // the stream
88 ProtoMessage::PacketHeader header_msg;
89 header_msg.set_obj_id(name());
90 header_msg.set_tick_freq(SimClock::Frequency);
91 traceStream->write(header_msg);
92
93 // Register a callback to compensate for the destructor not
94 // being called. The callback forces the stream to flush and
95 // closes the output file.
96 Callback* cb = new MakeCallback<CommMonitor,
97 &CommMonitor::closeStreams>(this);
98 registerExitCallback(cb);
99 }
100
101 DPRINTF(CommMonitor,
102 "Created monitor %s with sample period %d ticks (%f ms)\n",
103 name(), samplePeriodTicks, samplePeriod * 1E3);
104}
105
106CommMonitor::~CommMonitor()
107{
108 // if not already done, close the stream
109 closeStreams();
110}
111
112void
113CommMonitor::closeStreams()
114{
115 if (traceStream != NULL)
116 delete traceStream;
117}
118
119CommMonitor*
120CommMonitorParams::create()
121{
122 return new CommMonitor(this);
123}
124
125void
126CommMonitor::init()
127{
128 // make sure both sides of the monitor are connected
129 if (!slavePort.isConnected() || !masterPort.isConnected())
130 fatal("Communication monitor is not connected on both sides.\n");
131
132 if (traceStream != NULL) {
133 // Check the memory mode. We only record something when in
134 // timing mode. Warn accordingly.
135 if (!system->isTimingMode())
136 warn("%s: Not in timing mode. No trace will be recorded.", name());
137 }
138
139}
140
141void
142CommMonitor::regProbePoints()
143{
144 ppPktReq.reset(new ProbePoints::Packet(getProbeManager(), "PktRequest"));
145 ppPktResp.reset(new ProbePoints::Packet(getProbeManager(), "PktResponse"));
146}
147
148BaseMasterPort&
149CommMonitor::getMasterPort(const std::string& if_name, PortID idx)
150{
151 if (if_name == "master") {
152 return masterPort;
153 } else {
154 return MemObject::getMasterPort(if_name, idx);
155 }
156}
157
158BaseSlavePort&
159CommMonitor::getSlavePort(const std::string& if_name, PortID idx)
160{
161 if (if_name == "slave") {
162 return slavePort;
163 } else {
164 return MemObject::getSlavePort(if_name, idx);
165 }
166}
167
168void
169CommMonitor::recvFunctional(PacketPtr pkt)
170{
171 masterPort.sendFunctional(pkt);
172}
173
174void
175CommMonitor::recvFunctionalSnoop(PacketPtr pkt)
176{
177 slavePort.sendFunctionalSnoop(pkt);
178}
179
180Tick
181CommMonitor::recvAtomic(PacketPtr pkt)
182{
183 ppPktReq->notify(pkt);
184
186 // do stack distance calculations if enabled
187 if (stackDistCalc)
188 stackDistCalc->update(pkt->cmd, pkt->getAddr());
189
190 // if tracing enabled, store the packet information
191 // to the trace stream
192 if (traceStream != NULL) {
193 ProtoMessage::Packet pkt_msg;
194 pkt_msg.set_tick(curTick());
195 pkt_msg.set_cmd(pkt->cmdToIndex());
196 pkt_msg.set_flags(pkt->req->getFlags());
197 pkt_msg.set_addr(pkt->getAddr());
198 pkt_msg.set_size(pkt->getSize());
199
200 traceStream->write(pkt_msg);
201 }
202
203 const Tick delay(masterPort.sendAtomic(pkt));
204 assert(pkt->isResponse());
205 ppPktResp->notify(pkt);
206 return delay;
207}
208
209Tick
210CommMonitor::recvAtomicSnoop(PacketPtr pkt)
211{
212 return slavePort.sendAtomicSnoop(pkt);
213}
214
215bool
216CommMonitor::recvTimingReq(PacketPtr pkt)
217{
218 // should always see a request
219 assert(pkt->isRequest());
220
221 // Store relevant fields of packet, because packet may be modified
222 // or even deleted when sendTiming() is called.
223 const bool is_read = pkt->isRead();
224 const bool is_write = pkt->isWrite();
225 const MemCmd cmd = pkt->cmd;
226 const int cmd_idx = pkt->cmdToIndex();
227 const Request::FlagsType req_flags = pkt->req->getFlags();
228 const unsigned size = pkt->getSize();
229 const Addr addr = pkt->getAddr();
230 const bool expects_response(
231 pkt->needsResponse() && !pkt->memInhibitAsserted());
232
233 // If a cache miss is served by a cache, a monitor near the memory
234 // would see a request which needs a response, but this response
235 // would be inhibited and not come back from the memory. Therefore
236 // we additionally have to check the inhibit flag.
237 if (expects_response && !stats.disableLatencyHists) {
238 pkt->pushSenderState(new CommMonitorSenderState(curTick()));
239 }
240
241 // Attempt to send the packet (always succeeds for inhibited
242 // packets)
243 bool successful = masterPort.sendTimingReq(pkt);
244
245 // If not successful, restore the sender state
246 if (!successful && expects_response && !stats.disableLatencyHists) {
247 delete pkt->popSenderState();
248 }
249
250 if (successful) {
251 // The receiver might already have modified the packet. We
252 // want to give the probe access to the original packet, which
253 // means we need to fake the original packet by temporarily
254 // restoring the command.
255 const MemCmd response_cmd(pkt->cmd);
256 pkt->cmd = cmd;
257 ppPktReq->notify(pkt);
258 pkt->cmd = response_cmd;
259 }
260
185 // if tracing enabled, store the packet information
186 // to the trace stream
187 if (traceStream != NULL) {
188 ProtoMessage::Packet pkt_msg;
189 pkt_msg.set_tick(curTick());
190 pkt_msg.set_cmd(pkt->cmdToIndex());
191 pkt_msg.set_flags(pkt->req->getFlags());
192 pkt_msg.set_addr(pkt->getAddr());
193 pkt_msg.set_size(pkt->getSize());
194
195 traceStream->write(pkt_msg);
196 }
197
198 const Tick delay(masterPort.sendAtomic(pkt));
199 assert(pkt->isResponse());
200 ppPktResp->notify(pkt);
201 return delay;
202}
203
204Tick
205CommMonitor::recvAtomicSnoop(PacketPtr pkt)
206{
207 return slavePort.sendAtomicSnoop(pkt);
208}
209
210bool
211CommMonitor::recvTimingReq(PacketPtr pkt)
212{
213 // should always see a request
214 assert(pkt->isRequest());
215
216 // Store relevant fields of packet, because packet may be modified
217 // or even deleted when sendTiming() is called.
218 const bool is_read = pkt->isRead();
219 const bool is_write = pkt->isWrite();
220 const MemCmd cmd = pkt->cmd;
221 const int cmd_idx = pkt->cmdToIndex();
222 const Request::FlagsType req_flags = pkt->req->getFlags();
223 const unsigned size = pkt->getSize();
224 const Addr addr = pkt->getAddr();
225 const bool expects_response(
226 pkt->needsResponse() && !pkt->memInhibitAsserted());
227
228 // If a cache miss is served by a cache, a monitor near the memory
229 // would see a request which needs a response, but this response
230 // would be inhibited and not come back from the memory. Therefore
231 // we additionally have to check the inhibit flag.
232 if (expects_response && !stats.disableLatencyHists) {
233 pkt->pushSenderState(new CommMonitorSenderState(curTick()));
234 }
235
236 // Attempt to send the packet (always succeeds for inhibited
237 // packets)
238 bool successful = masterPort.sendTimingReq(pkt);
239
240 // If not successful, restore the sender state
241 if (!successful && expects_response && !stats.disableLatencyHists) {
242 delete pkt->popSenderState();
243 }
244
245 if (successful) {
246 // The receiver might already have modified the packet. We
247 // want to give the probe access to the original packet, which
248 // means we need to fake the original packet by temporarily
249 // restoring the command.
250 const MemCmd response_cmd(pkt->cmd);
251 pkt->cmd = cmd;
252 ppPktReq->notify(pkt);
253 pkt->cmd = response_cmd;
254 }
255
261 // If successful and we are calculating stack distances, update
262 // the calculator
263 if (successful && stackDistCalc)
264 stackDistCalc->update(cmd, addr);
265
266 if (successful && traceStream != NULL) {
267 // Create a protobuf message representing the
268 // packet. Currently we do not preserve the flags in the
269 // trace.
270 ProtoMessage::Packet pkt_msg;
271 pkt_msg.set_tick(curTick());
272 pkt_msg.set_cmd(cmd_idx);
273 pkt_msg.set_flags(req_flags);
274 pkt_msg.set_addr(addr);
275 pkt_msg.set_size(size);
276
277 traceStream->write(pkt_msg);
278 }
279
280 if (successful && is_read) {
281 DPRINTF(CommMonitor, "Forwarded read request\n");
282
283 // Increment number of observed read transactions
284 if (!stats.disableTransactionHists) {
285 ++stats.readTrans;
286 }
287
288 // Get sample of burst length
289 if (!stats.disableBurstLengthHists) {
290 stats.readBurstLengthHist.sample(size);
291 }
292
293 // Sample the masked address
294 if (!stats.disableAddrDists) {
295 stats.readAddrDist.sample(addr & readAddrMask);
296 }
297
298 // If it needs a response increment number of outstanding read
299 // requests
300 if (!stats.disableOutstandingHists && expects_response) {
301 ++stats.outstandingReadReqs;
302 }
303
304 if (!stats.disableITTDists) {
305 // Sample value of read-read inter transaction time
306 if (stats.timeOfLastRead != 0) {
307 stats.ittReadRead.sample(curTick() - stats.timeOfLastRead);
308 }
309 stats.timeOfLastRead = curTick();
310
311 // Sample value of req-req inter transaction time
312 if (stats.timeOfLastReq != 0) {
313 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq);
314 }
315 stats.timeOfLastReq = curTick();
316 }
317 } else if (successful && is_write) {
318 DPRINTF(CommMonitor, "Forwarded write request\n");
319
320 // Same as for reads
321 if (!stats.disableTransactionHists) {
322 ++stats.writeTrans;
323 }
324
325 if (!stats.disableBurstLengthHists) {
326 stats.writeBurstLengthHist.sample(size);
327 }
328
329 // Update the bandwidth stats on the request
330 if (!stats.disableBandwidthHists) {
331 stats.writtenBytes += size;
332 stats.totalWrittenBytes += size;
333 }
334
335 // Sample the masked write address
336 if (!stats.disableAddrDists) {
337 stats.writeAddrDist.sample(addr & writeAddrMask);
338 }
339
340 if (!stats.disableOutstandingHists && expects_response) {
341 ++stats.outstandingWriteReqs;
342 }
343
344 if (!stats.disableITTDists) {
345 // Sample value of write-to-write inter transaction time
346 if (stats.timeOfLastWrite != 0) {
347 stats.ittWriteWrite.sample(curTick() - stats.timeOfLastWrite);
348 }
349 stats.timeOfLastWrite = curTick();
350
351 // Sample value of req-to-req inter transaction time
352 if (stats.timeOfLastReq != 0) {
353 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq);
354 }
355 stats.timeOfLastReq = curTick();
356 }
357 } else if (successful) {
358 DPRINTF(CommMonitor, "Forwarded non read/write request\n");
359 }
360
361 return successful;
362}
363
364bool
365CommMonitor::recvTimingResp(PacketPtr pkt)
366{
367 // should always see responses
368 assert(pkt->isResponse());
369
370 // Store relevant fields of packet, because packet may be modified
371 // or even deleted when sendTiming() is called.
372 bool is_read = pkt->isRead();
373 bool is_write = pkt->isWrite();
374 unsigned size = pkt->getSize();
375 Tick latency = 0;
376 CommMonitorSenderState* received_state =
377 dynamic_cast<CommMonitorSenderState*>(pkt->senderState);
378
379 if (!stats.disableLatencyHists) {
380 // Restore initial sender state
381 if (received_state == NULL)
382 panic("Monitor got a response without monitor sender state\n");
383
384 // Restore the sate
385 pkt->senderState = received_state->predecessor;
386 }
387
388 // Attempt to send the packet
389 bool successful = slavePort.sendTimingResp(pkt);
390
391 if (!stats.disableLatencyHists) {
392 // If packet successfully send, sample value of latency,
393 // afterwards delete sender state, otherwise restore state
394 if (successful) {
395 latency = curTick() - received_state->transmitTime;
396 DPRINTF(CommMonitor, "Latency: %d\n", latency);
397 delete received_state;
398 } else {
399 // Don't delete anything and let the packet look like we
400 // did not touch it
401 pkt->senderState = received_state;
402 }
403 }
404
405 if (successful) {
406 assert(pkt->isResponse());
407 ppPktResp->notify(pkt);
408 }
409
410 if (successful && is_read) {
411 // Decrement number of outstanding read requests
412 DPRINTF(CommMonitor, "Received read response\n");
413 if (!stats.disableOutstandingHists) {
414 assert(stats.outstandingReadReqs != 0);
415 --stats.outstandingReadReqs;
416 }
417
418 if (!stats.disableLatencyHists) {
419 stats.readLatencyHist.sample(latency);
420 }
421
422 // Update the bandwidth stats based on responses for reads
423 if (!stats.disableBandwidthHists) {
424 stats.readBytes += size;
425 stats.totalReadBytes += size;
426 }
427
428 } else if (successful && is_write) {
429 // Decrement number of outstanding write requests
430 DPRINTF(CommMonitor, "Received write response\n");
431 if (!stats.disableOutstandingHists) {
432 assert(stats.outstandingWriteReqs != 0);
433 --stats.outstandingWriteReqs;
434 }
435
436 if (!stats.disableLatencyHists) {
437 stats.writeLatencyHist.sample(latency);
438 }
439 } else if (successful) {
440 DPRINTF(CommMonitor, "Received non read/write response\n");
441 }
442 return successful;
443}
444
445void
446CommMonitor::recvTimingSnoopReq(PacketPtr pkt)
447{
448 slavePort.sendTimingSnoopReq(pkt);
449}
450
451bool
452CommMonitor::recvTimingSnoopResp(PacketPtr pkt)
453{
454 return masterPort.sendTimingSnoopResp(pkt);
455}
456
457bool
458CommMonitor::isSnooping() const
459{
460 // check if the connected master port is snooping
461 return slavePort.isSnooping();
462}
463
464AddrRangeList
465CommMonitor::getAddrRanges() const
466{
467 // get the address ranges of the connected slave port
468 return masterPort.getAddrRanges();
469}
470
471void
472CommMonitor::recvReqRetry()
473{
474 slavePort.sendRetryReq();
475}
476
477void
478CommMonitor::recvRespRetry()
479{
480 masterPort.sendRetryResp();
481}
482
483void
484CommMonitor::recvRangeChange()
485{
486 slavePort.sendRangeChange();
487}
488
489void
490CommMonitor::regStats()
491{
492 // Initialise all the monitor stats
493 using namespace Stats;
494
495 stats.readBurstLengthHist
496 .init(params()->burst_length_bins)
497 .name(name() + ".readBurstLengthHist")
498 .desc("Histogram of burst lengths of transmitted packets")
499 .flags(stats.disableBurstLengthHists ? nozero : pdf);
500
501 stats.writeBurstLengthHist
502 .init(params()->burst_length_bins)
503 .name(name() + ".writeBurstLengthHist")
504 .desc("Histogram of burst lengths of transmitted packets")
505 .flags(stats.disableBurstLengthHists ? nozero : pdf);
506
507 // Stats based on received responses
508 stats.readBandwidthHist
509 .init(params()->bandwidth_bins)
510 .name(name() + ".readBandwidthHist")
511 .desc("Histogram of read bandwidth per sample period (bytes/s)")
512 .flags(stats.disableBandwidthHists ? nozero : pdf);
513
514 stats.averageReadBW
515 .name(name() + ".averageReadBandwidth")
516 .desc("Average read bandwidth (bytes/s)")
517 .flags(stats.disableBandwidthHists ? nozero : pdf);
518
519 stats.totalReadBytes
520 .name(name() + ".totalReadBytes")
521 .desc("Number of bytes read")
522 .flags(stats.disableBandwidthHists ? nozero : pdf);
523
524 stats.averageReadBW = stats.totalReadBytes / simSeconds;
525
526 // Stats based on successfully sent requests
527 stats.writeBandwidthHist
528 .init(params()->bandwidth_bins)
529 .name(name() + ".writeBandwidthHist")
530 .desc("Histogram of write bandwidth (bytes/s)")
531 .flags(stats.disableBandwidthHists ? (pdf | nozero) : pdf);
532
533 stats.averageWriteBW
534 .name(name() + ".averageWriteBandwidth")
535 .desc("Average write bandwidth (bytes/s)")
536 .flags(stats.disableBandwidthHists ? nozero : pdf);
537
538 stats.totalWrittenBytes
539 .name(name() + ".totalWrittenBytes")
540 .desc("Number of bytes written")
541 .flags(stats.disableBandwidthHists ? nozero : pdf);
542
543 stats.averageWriteBW = stats.totalWrittenBytes / simSeconds;
544
545 stats.readLatencyHist
546 .init(params()->latency_bins)
547 .name(name() + ".readLatencyHist")
548 .desc("Read request-response latency")
549 .flags(stats.disableLatencyHists ? nozero : pdf);
550
551 stats.writeLatencyHist
552 .init(params()->latency_bins)
553 .name(name() + ".writeLatencyHist")
554 .desc("Write request-response latency")
555 .flags(stats.disableLatencyHists ? nozero : pdf);
556
557 stats.ittReadRead
558 .init(1, params()->itt_max_bin, params()->itt_max_bin /
559 params()->itt_bins)
560 .name(name() + ".ittReadRead")
561 .desc("Read-to-read inter transaction time")
562 .flags(stats.disableITTDists ? nozero : pdf);
563
564 stats.ittWriteWrite
565 .init(1, params()->itt_max_bin, params()->itt_max_bin /
566 params()->itt_bins)
567 .name(name() + ".ittWriteWrite")
568 .desc("Write-to-write inter transaction time")
569 .flags(stats.disableITTDists ? nozero : pdf);
570
571 stats.ittReqReq
572 .init(1, params()->itt_max_bin, params()->itt_max_bin /
573 params()->itt_bins)
574 .name(name() + ".ittReqReq")
575 .desc("Request-to-request inter transaction time")
576 .flags(stats.disableITTDists ? nozero : pdf);
577
578 stats.outstandingReadsHist
579 .init(params()->outstanding_bins)
580 .name(name() + ".outstandingReadsHist")
581 .desc("Outstanding read transactions")
582 .flags(stats.disableOutstandingHists ? nozero : pdf);
583
584 stats.outstandingWritesHist
585 .init(params()->outstanding_bins)
586 .name(name() + ".outstandingWritesHist")
587 .desc("Outstanding write transactions")
588 .flags(stats.disableOutstandingHists ? nozero : pdf);
589
590 stats.readTransHist
591 .init(params()->transaction_bins)
592 .name(name() + ".readTransHist")
593 .desc("Histogram of read transactions per sample period")
594 .flags(stats.disableTransactionHists ? nozero : pdf);
595
596 stats.writeTransHist
597 .init(params()->transaction_bins)
598 .name(name() + ".writeTransHist")
599 .desc("Histogram of read transactions per sample period")
600 .flags(stats.disableTransactionHists ? nozero : pdf);
601
602 stats.readAddrDist
603 .init(0)
604 .name(name() + ".readAddrDist")
605 .desc("Read address distribution")
606 .flags(stats.disableAddrDists ? nozero : pdf);
607
608 stats.writeAddrDist
609 .init(0)
610 .name(name() + ".writeAddrDist")
611 .desc("Write address distribution")
612 .flags(stats.disableAddrDists ? nozero : pdf);
613}
614
615void
616CommMonitor::samplePeriodic()
617{
618 // the periodic stats update runs on the granularity of sample
619 // periods, but in combination with this there may also be a
620 // external resets and dumps of the stats (through schedStatEvent)
621 // causing the stats themselves to capture less than a sample
622 // period
623
624 // only capture if we have not reset the stats during the last
625 // sample period
626 if (simTicks.value() >= samplePeriodTicks) {
627 if (!stats.disableTransactionHists) {
628 stats.readTransHist.sample(stats.readTrans);
629 stats.writeTransHist.sample(stats.writeTrans);
630 }
631
632 if (!stats.disableBandwidthHists) {
633 stats.readBandwidthHist.sample(stats.readBytes / samplePeriod);
634 stats.writeBandwidthHist.sample(stats.writtenBytes / samplePeriod);
635 }
636
637 if (!stats.disableOutstandingHists) {
638 stats.outstandingReadsHist.sample(stats.outstandingReadReqs);
639 stats.outstandingWritesHist.sample(stats.outstandingWriteReqs);
640 }
641 }
642
643 // reset the sampled values
644 stats.readTrans = 0;
645 stats.writeTrans = 0;
646
647 stats.readBytes = 0;
648 stats.writtenBytes = 0;
649
650 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
651}
652
653void
654CommMonitor::startup()
655{
656 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
657}
256 if (successful && traceStream != NULL) {
257 // Create a protobuf message representing the
258 // packet. Currently we do not preserve the flags in the
259 // trace.
260 ProtoMessage::Packet pkt_msg;
261 pkt_msg.set_tick(curTick());
262 pkt_msg.set_cmd(cmd_idx);
263 pkt_msg.set_flags(req_flags);
264 pkt_msg.set_addr(addr);
265 pkt_msg.set_size(size);
266
267 traceStream->write(pkt_msg);
268 }
269
270 if (successful && is_read) {
271 DPRINTF(CommMonitor, "Forwarded read request\n");
272
273 // Increment number of observed read transactions
274 if (!stats.disableTransactionHists) {
275 ++stats.readTrans;
276 }
277
278 // Get sample of burst length
279 if (!stats.disableBurstLengthHists) {
280 stats.readBurstLengthHist.sample(size);
281 }
282
283 // Sample the masked address
284 if (!stats.disableAddrDists) {
285 stats.readAddrDist.sample(addr & readAddrMask);
286 }
287
288 // If it needs a response increment number of outstanding read
289 // requests
290 if (!stats.disableOutstandingHists && expects_response) {
291 ++stats.outstandingReadReqs;
292 }
293
294 if (!stats.disableITTDists) {
295 // Sample value of read-read inter transaction time
296 if (stats.timeOfLastRead != 0) {
297 stats.ittReadRead.sample(curTick() - stats.timeOfLastRead);
298 }
299 stats.timeOfLastRead = curTick();
300
301 // Sample value of req-req inter transaction time
302 if (stats.timeOfLastReq != 0) {
303 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq);
304 }
305 stats.timeOfLastReq = curTick();
306 }
307 } else if (successful && is_write) {
308 DPRINTF(CommMonitor, "Forwarded write request\n");
309
310 // Same as for reads
311 if (!stats.disableTransactionHists) {
312 ++stats.writeTrans;
313 }
314
315 if (!stats.disableBurstLengthHists) {
316 stats.writeBurstLengthHist.sample(size);
317 }
318
319 // Update the bandwidth stats on the request
320 if (!stats.disableBandwidthHists) {
321 stats.writtenBytes += size;
322 stats.totalWrittenBytes += size;
323 }
324
325 // Sample the masked write address
326 if (!stats.disableAddrDists) {
327 stats.writeAddrDist.sample(addr & writeAddrMask);
328 }
329
330 if (!stats.disableOutstandingHists && expects_response) {
331 ++stats.outstandingWriteReqs;
332 }
333
334 if (!stats.disableITTDists) {
335 // Sample value of write-to-write inter transaction time
336 if (stats.timeOfLastWrite != 0) {
337 stats.ittWriteWrite.sample(curTick() - stats.timeOfLastWrite);
338 }
339 stats.timeOfLastWrite = curTick();
340
341 // Sample value of req-to-req inter transaction time
342 if (stats.timeOfLastReq != 0) {
343 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq);
344 }
345 stats.timeOfLastReq = curTick();
346 }
347 } else if (successful) {
348 DPRINTF(CommMonitor, "Forwarded non read/write request\n");
349 }
350
351 return successful;
352}
353
354bool
355CommMonitor::recvTimingResp(PacketPtr pkt)
356{
357 // should always see responses
358 assert(pkt->isResponse());
359
360 // Store relevant fields of packet, because packet may be modified
361 // or even deleted when sendTiming() is called.
362 bool is_read = pkt->isRead();
363 bool is_write = pkt->isWrite();
364 unsigned size = pkt->getSize();
365 Tick latency = 0;
366 CommMonitorSenderState* received_state =
367 dynamic_cast<CommMonitorSenderState*>(pkt->senderState);
368
369 if (!stats.disableLatencyHists) {
370 // Restore initial sender state
371 if (received_state == NULL)
372 panic("Monitor got a response without monitor sender state\n");
373
374 // Restore the sate
375 pkt->senderState = received_state->predecessor;
376 }
377
378 // Attempt to send the packet
379 bool successful = slavePort.sendTimingResp(pkt);
380
381 if (!stats.disableLatencyHists) {
382 // If packet successfully send, sample value of latency,
383 // afterwards delete sender state, otherwise restore state
384 if (successful) {
385 latency = curTick() - received_state->transmitTime;
386 DPRINTF(CommMonitor, "Latency: %d\n", latency);
387 delete received_state;
388 } else {
389 // Don't delete anything and let the packet look like we
390 // did not touch it
391 pkt->senderState = received_state;
392 }
393 }
394
395 if (successful) {
396 assert(pkt->isResponse());
397 ppPktResp->notify(pkt);
398 }
399
400 if (successful && is_read) {
401 // Decrement number of outstanding read requests
402 DPRINTF(CommMonitor, "Received read response\n");
403 if (!stats.disableOutstandingHists) {
404 assert(stats.outstandingReadReqs != 0);
405 --stats.outstandingReadReqs;
406 }
407
408 if (!stats.disableLatencyHists) {
409 stats.readLatencyHist.sample(latency);
410 }
411
412 // Update the bandwidth stats based on responses for reads
413 if (!stats.disableBandwidthHists) {
414 stats.readBytes += size;
415 stats.totalReadBytes += size;
416 }
417
418 } else if (successful && is_write) {
419 // Decrement number of outstanding write requests
420 DPRINTF(CommMonitor, "Received write response\n");
421 if (!stats.disableOutstandingHists) {
422 assert(stats.outstandingWriteReqs != 0);
423 --stats.outstandingWriteReqs;
424 }
425
426 if (!stats.disableLatencyHists) {
427 stats.writeLatencyHist.sample(latency);
428 }
429 } else if (successful) {
430 DPRINTF(CommMonitor, "Received non read/write response\n");
431 }
432 return successful;
433}
434
435void
436CommMonitor::recvTimingSnoopReq(PacketPtr pkt)
437{
438 slavePort.sendTimingSnoopReq(pkt);
439}
440
441bool
442CommMonitor::recvTimingSnoopResp(PacketPtr pkt)
443{
444 return masterPort.sendTimingSnoopResp(pkt);
445}
446
447bool
448CommMonitor::isSnooping() const
449{
450 // check if the connected master port is snooping
451 return slavePort.isSnooping();
452}
453
454AddrRangeList
455CommMonitor::getAddrRanges() const
456{
457 // get the address ranges of the connected slave port
458 return masterPort.getAddrRanges();
459}
460
461void
462CommMonitor::recvReqRetry()
463{
464 slavePort.sendRetryReq();
465}
466
467void
468CommMonitor::recvRespRetry()
469{
470 masterPort.sendRetryResp();
471}
472
473void
474CommMonitor::recvRangeChange()
475{
476 slavePort.sendRangeChange();
477}
478
479void
480CommMonitor::regStats()
481{
482 // Initialise all the monitor stats
483 using namespace Stats;
484
485 stats.readBurstLengthHist
486 .init(params()->burst_length_bins)
487 .name(name() + ".readBurstLengthHist")
488 .desc("Histogram of burst lengths of transmitted packets")
489 .flags(stats.disableBurstLengthHists ? nozero : pdf);
490
491 stats.writeBurstLengthHist
492 .init(params()->burst_length_bins)
493 .name(name() + ".writeBurstLengthHist")
494 .desc("Histogram of burst lengths of transmitted packets")
495 .flags(stats.disableBurstLengthHists ? nozero : pdf);
496
497 // Stats based on received responses
498 stats.readBandwidthHist
499 .init(params()->bandwidth_bins)
500 .name(name() + ".readBandwidthHist")
501 .desc("Histogram of read bandwidth per sample period (bytes/s)")
502 .flags(stats.disableBandwidthHists ? nozero : pdf);
503
504 stats.averageReadBW
505 .name(name() + ".averageReadBandwidth")
506 .desc("Average read bandwidth (bytes/s)")
507 .flags(stats.disableBandwidthHists ? nozero : pdf);
508
509 stats.totalReadBytes
510 .name(name() + ".totalReadBytes")
511 .desc("Number of bytes read")
512 .flags(stats.disableBandwidthHists ? nozero : pdf);
513
514 stats.averageReadBW = stats.totalReadBytes / simSeconds;
515
516 // Stats based on successfully sent requests
517 stats.writeBandwidthHist
518 .init(params()->bandwidth_bins)
519 .name(name() + ".writeBandwidthHist")
520 .desc("Histogram of write bandwidth (bytes/s)")
521 .flags(stats.disableBandwidthHists ? (pdf | nozero) : pdf);
522
523 stats.averageWriteBW
524 .name(name() + ".averageWriteBandwidth")
525 .desc("Average write bandwidth (bytes/s)")
526 .flags(stats.disableBandwidthHists ? nozero : pdf);
527
528 stats.totalWrittenBytes
529 .name(name() + ".totalWrittenBytes")
530 .desc("Number of bytes written")
531 .flags(stats.disableBandwidthHists ? nozero : pdf);
532
533 stats.averageWriteBW = stats.totalWrittenBytes / simSeconds;
534
535 stats.readLatencyHist
536 .init(params()->latency_bins)
537 .name(name() + ".readLatencyHist")
538 .desc("Read request-response latency")
539 .flags(stats.disableLatencyHists ? nozero : pdf);
540
541 stats.writeLatencyHist
542 .init(params()->latency_bins)
543 .name(name() + ".writeLatencyHist")
544 .desc("Write request-response latency")
545 .flags(stats.disableLatencyHists ? nozero : pdf);
546
547 stats.ittReadRead
548 .init(1, params()->itt_max_bin, params()->itt_max_bin /
549 params()->itt_bins)
550 .name(name() + ".ittReadRead")
551 .desc("Read-to-read inter transaction time")
552 .flags(stats.disableITTDists ? nozero : pdf);
553
554 stats.ittWriteWrite
555 .init(1, params()->itt_max_bin, params()->itt_max_bin /
556 params()->itt_bins)
557 .name(name() + ".ittWriteWrite")
558 .desc("Write-to-write inter transaction time")
559 .flags(stats.disableITTDists ? nozero : pdf);
560
561 stats.ittReqReq
562 .init(1, params()->itt_max_bin, params()->itt_max_bin /
563 params()->itt_bins)
564 .name(name() + ".ittReqReq")
565 .desc("Request-to-request inter transaction time")
566 .flags(stats.disableITTDists ? nozero : pdf);
567
568 stats.outstandingReadsHist
569 .init(params()->outstanding_bins)
570 .name(name() + ".outstandingReadsHist")
571 .desc("Outstanding read transactions")
572 .flags(stats.disableOutstandingHists ? nozero : pdf);
573
574 stats.outstandingWritesHist
575 .init(params()->outstanding_bins)
576 .name(name() + ".outstandingWritesHist")
577 .desc("Outstanding write transactions")
578 .flags(stats.disableOutstandingHists ? nozero : pdf);
579
580 stats.readTransHist
581 .init(params()->transaction_bins)
582 .name(name() + ".readTransHist")
583 .desc("Histogram of read transactions per sample period")
584 .flags(stats.disableTransactionHists ? nozero : pdf);
585
586 stats.writeTransHist
587 .init(params()->transaction_bins)
588 .name(name() + ".writeTransHist")
589 .desc("Histogram of read transactions per sample period")
590 .flags(stats.disableTransactionHists ? nozero : pdf);
591
592 stats.readAddrDist
593 .init(0)
594 .name(name() + ".readAddrDist")
595 .desc("Read address distribution")
596 .flags(stats.disableAddrDists ? nozero : pdf);
597
598 stats.writeAddrDist
599 .init(0)
600 .name(name() + ".writeAddrDist")
601 .desc("Write address distribution")
602 .flags(stats.disableAddrDists ? nozero : pdf);
603}
604
605void
606CommMonitor::samplePeriodic()
607{
608 // the periodic stats update runs on the granularity of sample
609 // periods, but in combination with this there may also be a
610 // external resets and dumps of the stats (through schedStatEvent)
611 // causing the stats themselves to capture less than a sample
612 // period
613
614 // only capture if we have not reset the stats during the last
615 // sample period
616 if (simTicks.value() >= samplePeriodTicks) {
617 if (!stats.disableTransactionHists) {
618 stats.readTransHist.sample(stats.readTrans);
619 stats.writeTransHist.sample(stats.writeTrans);
620 }
621
622 if (!stats.disableBandwidthHists) {
623 stats.readBandwidthHist.sample(stats.readBytes / samplePeriod);
624 stats.writeBandwidthHist.sample(stats.writtenBytes / samplePeriod);
625 }
626
627 if (!stats.disableOutstandingHists) {
628 stats.outstandingReadsHist.sample(stats.outstandingReadReqs);
629 stats.outstandingWritesHist.sample(stats.outstandingWriteReqs);
630 }
631 }
632
633 // reset the sampled values
634 stats.readTrans = 0;
635 stats.writeTrans = 0;
636
637 stats.readBytes = 0;
638 stats.writtenBytes = 0;
639
640 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
641}
642
643void
644CommMonitor::startup()
645{
646 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks);
647}