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 readAddrMask(params->read_addr_mask), 56 writeAddrMask(params->write_addr_mask), 57 stats(params), 58 traceStream(NULL) 59{ 60 // If we are using a trace file, then open the file, 61 if (params->trace_file != "") { 62 // If the trace file is not specified as an absolute path, 63 // append the current simulation output directory 64 std::string filename = simout.resolve(params->trace_file); 65 traceStream = new ProtoOutputStream(filename); 66 67 // Create a protobuf message for the header and write it to 68 // the stream 69 Message::PacketHeader header_msg; 70 header_msg.set_obj_id(name()); 71 header_msg.set_tick_freq(SimClock::Frequency); 72 traceStream->write(header_msg); 73 74 // Register a callback to compensate for the destructor not 75 // being called. The callback forces the stream to flush and 76 // closes the output file. 77 Callback* cb = new MakeCallback<CommMonitor, 78 &CommMonitor::closeStreams>(this); 79 registerExitCallback(cb); 80 } 81 82 // keep track of the sample period both in ticks and absolute time 83 samplePeriod.setTick(params->sample_period); 84 85 DPRINTF(CommMonitor, 86 "Created monitor %s with sample period %d ticks (%f s)\n", 87 name(), samplePeriodTicks, samplePeriod); 88} 89 90void 91CommMonitor::closeStreams() 92{ 93 if (traceStream != NULL) 94 delete traceStream; 95} 96 97CommMonitor* 98CommMonitorParams::create() 99{ 100 return new CommMonitor(this); 101} 102 103void 104CommMonitor::init() 105{ 106 // make sure both sides of the monitor are connected 107 if (!slavePort.isConnected() || !masterPort.isConnected()) 108 fatal("Communication monitor is not connected on both sides.\n"); 109} 110 111BaseMasterPort& 112CommMonitor::getMasterPort(const std::string& if_name, PortID idx) 113{ 114 if (if_name == "master") { 115 return masterPort; 116 } else { 117 return MemObject::getMasterPort(if_name, idx); 118 } 119} 120 121BaseSlavePort& 122CommMonitor::getSlavePort(const std::string& if_name, PortID idx) 123{ 124 if (if_name == "slave") { 125 return slavePort; 126 } else { 127 return MemObject::getSlavePort(if_name, idx); 128 } 129} 130 131void 132CommMonitor::recvFunctional(PacketPtr pkt) 133{ 134 masterPort.sendFunctional(pkt); 135} 136 137void 138CommMonitor::recvFunctionalSnoop(PacketPtr pkt) 139{ 140 slavePort.sendFunctionalSnoop(pkt); 141} 142 143Tick 144CommMonitor::recvAtomic(PacketPtr pkt) 145{ 146 return masterPort.sendAtomic(pkt); 147} 148 149Tick 150CommMonitor::recvAtomicSnoop(PacketPtr pkt) 151{ 152 return slavePort.sendAtomicSnoop(pkt); 153} 154 155bool 156CommMonitor::recvTimingReq(PacketPtr pkt) 157{ 158 // should always see a request 159 assert(pkt->isRequest()); 160 161 // Store relevant fields of packet, because packet may be modified 162 // or even deleted when sendTiming() is called. 163 bool isRead = pkt->isRead(); 164 bool isWrite = pkt->isWrite();
| 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 readAddrMask(params->read_addr_mask), 56 writeAddrMask(params->write_addr_mask), 57 stats(params), 58 traceStream(NULL) 59{ 60 // If we are using a trace file, then open the file, 61 if (params->trace_file != "") { 62 // If the trace file is not specified as an absolute path, 63 // append the current simulation output directory 64 std::string filename = simout.resolve(params->trace_file); 65 traceStream = new ProtoOutputStream(filename); 66 67 // Create a protobuf message for the header and write it to 68 // the stream 69 Message::PacketHeader header_msg; 70 header_msg.set_obj_id(name()); 71 header_msg.set_tick_freq(SimClock::Frequency); 72 traceStream->write(header_msg); 73 74 // Register a callback to compensate for the destructor not 75 // being called. The callback forces the stream to flush and 76 // closes the output file. 77 Callback* cb = new MakeCallback<CommMonitor, 78 &CommMonitor::closeStreams>(this); 79 registerExitCallback(cb); 80 } 81 82 // keep track of the sample period both in ticks and absolute time 83 samplePeriod.setTick(params->sample_period); 84 85 DPRINTF(CommMonitor, 86 "Created monitor %s with sample period %d ticks (%f s)\n", 87 name(), samplePeriodTicks, samplePeriod); 88} 89 90void 91CommMonitor::closeStreams() 92{ 93 if (traceStream != NULL) 94 delete traceStream; 95} 96 97CommMonitor* 98CommMonitorParams::create() 99{ 100 return new CommMonitor(this); 101} 102 103void 104CommMonitor::init() 105{ 106 // make sure both sides of the monitor are connected 107 if (!slavePort.isConnected() || !masterPort.isConnected()) 108 fatal("Communication monitor is not connected on both sides.\n"); 109} 110 111BaseMasterPort& 112CommMonitor::getMasterPort(const std::string& if_name, PortID idx) 113{ 114 if (if_name == "master") { 115 return masterPort; 116 } else { 117 return MemObject::getMasterPort(if_name, idx); 118 } 119} 120 121BaseSlavePort& 122CommMonitor::getSlavePort(const std::string& if_name, PortID idx) 123{ 124 if (if_name == "slave") { 125 return slavePort; 126 } else { 127 return MemObject::getSlavePort(if_name, idx); 128 } 129} 130 131void 132CommMonitor::recvFunctional(PacketPtr pkt) 133{ 134 masterPort.sendFunctional(pkt); 135} 136 137void 138CommMonitor::recvFunctionalSnoop(PacketPtr pkt) 139{ 140 slavePort.sendFunctionalSnoop(pkt); 141} 142 143Tick 144CommMonitor::recvAtomic(PacketPtr pkt) 145{ 146 return masterPort.sendAtomic(pkt); 147} 148 149Tick 150CommMonitor::recvAtomicSnoop(PacketPtr pkt) 151{ 152 return slavePort.sendAtomicSnoop(pkt); 153} 154 155bool 156CommMonitor::recvTimingReq(PacketPtr pkt) 157{ 158 // should always see a request 159 assert(pkt->isRequest()); 160 161 // Store relevant fields of packet, because packet may be modified 162 // or even deleted when sendTiming() is called. 163 bool isRead = pkt->isRead(); 164 bool isWrite = pkt->isWrite();
|
199 200 traceStream->write(pkt_msg); 201 } 202 203 if (successful && isRead) { 204 DPRINTF(CommMonitor, "Forwarded read request\n"); 205 206 // Increment number of observed read transactions 207 if (!stats.disableTransactionHists) { 208 ++stats.readTrans; 209 } 210 211 // Get sample of burst length 212 if (!stats.disableBurstLengthHists) { 213 stats.readBurstLengthHist.sample(size); 214 } 215 216 // Sample the masked address 217 if (!stats.disableAddrDists) { 218 stats.readAddrDist.sample(addr & readAddrMask); 219 } 220 221 // If it needs a response increment number of outstanding read 222 // requests 223 if (!stats.disableOutstandingHists && needsResponse) { 224 ++stats.outstandingReadReqs; 225 } 226 227 if (!stats.disableITTDists) { 228 // Sample value of read-read inter transaction time 229 if (stats.timeOfLastRead != 0) { 230 stats.ittReadRead.sample(curTick() - stats.timeOfLastRead); 231 } 232 stats.timeOfLastRead = curTick(); 233 234 // Sample value of req-req inter transaction time 235 if (stats.timeOfLastReq != 0) { 236 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq); 237 } 238 stats.timeOfLastReq = curTick(); 239 } 240 } else if (successful && isWrite) { 241 DPRINTF(CommMonitor, "Forwarded write request\n"); 242 243 // Same as for reads 244 if (!stats.disableTransactionHists) { 245 ++stats.writeTrans; 246 } 247 248 if (!stats.disableBurstLengthHists) { 249 stats.writeBurstLengthHist.sample(size); 250 } 251 252 // Update the bandwidth stats on the request 253 if (!stats.disableBandwidthHists) { 254 stats.writtenBytes += size; 255 stats.totalWrittenBytes += size; 256 } 257 258 // Sample the masked write address 259 if (!stats.disableAddrDists) { 260 stats.writeAddrDist.sample(addr & writeAddrMask); 261 } 262 263 if (!stats.disableOutstandingHists && needsResponse) { 264 ++stats.outstandingWriteReqs; 265 } 266 267 if (!stats.disableITTDists) { 268 // Sample value of write-to-write inter transaction time 269 if (stats.timeOfLastWrite != 0) { 270 stats.ittWriteWrite.sample(curTick() - stats.timeOfLastWrite); 271 } 272 stats.timeOfLastWrite = curTick(); 273 274 // Sample value of req-to-req inter transaction time 275 if (stats.timeOfLastReq != 0) { 276 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq); 277 } 278 stats.timeOfLastReq = curTick(); 279 } 280 } else if (successful) { 281 DPRINTF(CommMonitor, "Forwarded non read/write request\n"); 282 } 283 284 return successful; 285} 286 287bool 288CommMonitor::recvTimingResp(PacketPtr pkt) 289{ 290 // should always see responses 291 assert(pkt->isResponse()); 292 293 // Store relevant fields of packet, because packet may be modified 294 // or even deleted when sendTiming() is called. 295 bool isRead = pkt->isRead(); 296 bool isWrite = pkt->isWrite(); 297 unsigned size = pkt->getSize(); 298 Tick latency = 0; 299 CommMonitorSenderState* commReceivedState = 300 dynamic_cast<CommMonitorSenderState*>(pkt->senderState); 301 302 if (!stats.disableLatencyHists) { 303 // Restore initial sender state 304 if (commReceivedState == NULL) 305 panic("Monitor got a response without monitor sender state\n"); 306 307 // Restore the sate 308 pkt->senderState = commReceivedState->origSenderState; 309 } 310 311 // Attempt to send the packet 312 bool successful = slavePort.sendTimingResp(pkt); 313 314 if (!stats.disableLatencyHists) { 315 // If packet successfully send, sample value of latency, 316 // afterwards delete sender state, otherwise restore state 317 if (successful) { 318 latency = curTick() - commReceivedState->transmitTime; 319 DPRINTF(CommMonitor, "Latency: %d\n", latency); 320 delete commReceivedState; 321 } else { 322 // Don't delete anything and let the packet look like we 323 // did not touch it 324 pkt->senderState = commReceivedState; 325 } 326 } 327 328 if (successful && isRead) { 329 // Decrement number of outstanding read requests 330 DPRINTF(CommMonitor, "Received read response\n"); 331 if (!stats.disableOutstandingHists) { 332 assert(stats.outstandingReadReqs != 0); 333 --stats.outstandingReadReqs; 334 } 335 336 if (!stats.disableLatencyHists) { 337 stats.readLatencyHist.sample(latency); 338 } 339 340 // Update the bandwidth stats based on responses for reads 341 if (!stats.disableBandwidthHists) { 342 stats.readBytes += size; 343 stats.totalReadBytes += size; 344 } 345 346 } else if (successful && isWrite) { 347 // Decrement number of outstanding write requests 348 DPRINTF(CommMonitor, "Received write response\n"); 349 if (!stats.disableOutstandingHists) { 350 assert(stats.outstandingWriteReqs != 0); 351 --stats.outstandingWriteReqs; 352 } 353 354 if (!stats.disableLatencyHists) { 355 stats.writeLatencyHist.sample(latency); 356 } 357 } else if (successful) { 358 DPRINTF(CommMonitor, "Received non read/write response\n"); 359 } 360 return successful; 361} 362 363void 364CommMonitor::recvTimingSnoopReq(PacketPtr pkt) 365{ 366 slavePort.sendTimingSnoopReq(pkt); 367} 368 369bool 370CommMonitor::recvTimingSnoopResp(PacketPtr pkt) 371{ 372 return masterPort.sendTimingSnoopResp(pkt); 373} 374 375bool 376CommMonitor::isSnooping() const 377{ 378 // check if the connected master port is snooping 379 return slavePort.isSnooping(); 380} 381 382unsigned 383CommMonitor::deviceBlockSizeMaster() 384{ 385 return slavePort.peerBlockSize(); 386} 387 388unsigned 389CommMonitor::deviceBlockSizeSlave() 390{ 391 return masterPort.peerBlockSize(); 392} 393 394AddrRangeList 395CommMonitor::getAddrRanges() const 396{ 397 // get the address ranges of the connected slave port 398 return masterPort.getAddrRanges(); 399} 400 401void 402CommMonitor::recvRetryMaster() 403{ 404 slavePort.sendRetry(); 405} 406 407void 408CommMonitor::recvRetrySlave() 409{ 410 masterPort.sendRetry(); 411} 412 413void 414CommMonitor::recvRangeChange() 415{ 416 slavePort.sendRangeChange(); 417} 418 419void 420CommMonitor::regStats() 421{ 422 // Initialise all the monitor stats 423 using namespace Stats; 424 425 stats.readBurstLengthHist 426 .init(params()->burst_length_bins) 427 .name(name() + ".readBurstLengthHist") 428 .desc("Histogram of burst lengths of transmitted packets") 429 .flags(stats.disableBurstLengthHists ? nozero : pdf); 430 431 stats.writeBurstLengthHist 432 .init(params()->burst_length_bins) 433 .name(name() + ".writeBurstLengthHist") 434 .desc("Histogram of burst lengths of transmitted packets") 435 .flags(stats.disableBurstLengthHists ? nozero : pdf); 436 437 // Stats based on received responses 438 stats.readBandwidthHist 439 .init(params()->bandwidth_bins) 440 .name(name() + ".readBandwidthHist") 441 .desc("Histogram of read bandwidth per sample period (bytes/s)") 442 .flags(stats.disableBandwidthHists ? nozero : pdf); 443 444 stats.averageReadBW 445 .name(name() + ".averageReadBandwidth") 446 .desc("Average read bandwidth (bytes/s)") 447 .flags(stats.disableBandwidthHists ? nozero : pdf); 448 449 stats.totalReadBytes 450 .name(name() + ".totalReadBytes") 451 .desc("Number of bytes read") 452 .flags(stats.disableBandwidthHists ? nozero : pdf); 453 454 stats.averageReadBW = stats.totalReadBytes / simSeconds; 455 456 // Stats based on successfully sent requests 457 stats.writeBandwidthHist 458 .init(params()->bandwidth_bins) 459 .name(name() + ".writeBandwidthHist") 460 .desc("Histogram of write bandwidth (bytes/s)") 461 .flags(stats.disableBandwidthHists ? (pdf | nozero) : pdf); 462 463 stats.averageWriteBW 464 .name(name() + ".averageWriteBandwidth") 465 .desc("Average write bandwidth (bytes/s)") 466 .flags(stats.disableBandwidthHists ? nozero : pdf); 467 468 stats.totalWrittenBytes 469 .name(name() + ".totalWrittenBytes") 470 .desc("Number of bytes written") 471 .flags(stats.disableBandwidthHists ? nozero : pdf); 472 473 stats.averageWriteBW = stats.totalWrittenBytes / simSeconds; 474 475 stats.readLatencyHist 476 .init(params()->latency_bins) 477 .name(name() + ".readLatencyHist") 478 .desc("Read request-response latency") 479 .flags(stats.disableLatencyHists ? nozero : pdf); 480 481 stats.writeLatencyHist 482 .init(params()->latency_bins) 483 .name(name() + ".writeLatencyHist") 484 .desc("Write request-response latency") 485 .flags(stats.disableLatencyHists ? nozero : pdf); 486 487 stats.ittReadRead 488 .init(1, params()->itt_max_bin, params()->itt_max_bin / 489 params()->itt_bins) 490 .name(name() + ".ittReadRead") 491 .desc("Read-to-read inter transaction time") 492 .flags(stats.disableITTDists ? nozero : pdf); 493 494 stats.ittWriteWrite 495 .init(1, params()->itt_max_bin, params()->itt_max_bin / 496 params()->itt_bins) 497 .name(name() + ".ittWriteWrite") 498 .desc("Write-to-write inter transaction time") 499 .flags(stats.disableITTDists ? nozero : pdf); 500 501 stats.ittReqReq 502 .init(1, params()->itt_max_bin, params()->itt_max_bin / 503 params()->itt_bins) 504 .name(name() + ".ittReqReq") 505 .desc("Request-to-request inter transaction time") 506 .flags(stats.disableITTDists ? nozero : pdf); 507 508 stats.outstandingReadsHist 509 .init(params()->outstanding_bins) 510 .name(name() + ".outstandingReadsHist") 511 .desc("Outstanding read transactions") 512 .flags(stats.disableOutstandingHists ? nozero : pdf); 513 514 stats.outstandingWritesHist 515 .init(params()->outstanding_bins) 516 .name(name() + ".outstandingWritesHist") 517 .desc("Outstanding write transactions") 518 .flags(stats.disableOutstandingHists ? nozero : pdf); 519 520 stats.readTransHist 521 .init(params()->transaction_bins) 522 .name(name() + ".readTransHist") 523 .desc("Histogram of read transactions per sample period") 524 .flags(stats.disableTransactionHists ? nozero : pdf); 525 526 stats.writeTransHist 527 .init(params()->transaction_bins) 528 .name(name() + ".writeTransHist") 529 .desc("Histogram of read transactions per sample period") 530 .flags(stats.disableTransactionHists ? nozero : pdf); 531 532 stats.readAddrDist 533 .init(0) 534 .name(name() + ".readAddrDist") 535 .desc("Read address distribution") 536 .flags(stats.disableAddrDists ? nozero : pdf); 537 538 stats.writeAddrDist 539 .init(0) 540 .name(name() + ".writeAddrDist") 541 .desc("Write address distribution") 542 .flags(stats.disableAddrDists ? nozero : pdf); 543} 544 545void 546CommMonitor::samplePeriodic() 547{ 548 // the periodic stats update runs on the granularity of sample 549 // periods, but in combination with this there may also be a 550 // external resets and dumps of the stats (through schedStatEvent) 551 // causing the stats themselves to capture less than a sample 552 // period 553 554 // only capture if we have not reset the stats during the last 555 // sample period 556 if (simTicks.value() >= samplePeriodTicks) { 557 if (!stats.disableTransactionHists) { 558 stats.readTransHist.sample(stats.readTrans); 559 stats.writeTransHist.sample(stats.writeTrans); 560 } 561 562 if (!stats.disableBandwidthHists) { 563 stats.readBandwidthHist.sample(stats.readBytes / samplePeriod); 564 stats.writeBandwidthHist.sample(stats.writtenBytes / samplePeriod); 565 } 566 567 if (!stats.disableOutstandingHists) { 568 stats.outstandingReadsHist.sample(stats.outstandingReadReqs); 569 stats.outstandingWritesHist.sample(stats.outstandingWriteReqs); 570 } 571 } 572 573 // reset the sampled values 574 stats.readTrans = 0; 575 stats.writeTrans = 0; 576 577 stats.readBytes = 0; 578 stats.writtenBytes = 0; 579 580 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks); 581} 582 583void 584CommMonitor::startup() 585{ 586 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks); 587}
| 200 201 traceStream->write(pkt_msg); 202 } 203 204 if (successful && isRead) { 205 DPRINTF(CommMonitor, "Forwarded read request\n"); 206 207 // Increment number of observed read transactions 208 if (!stats.disableTransactionHists) { 209 ++stats.readTrans; 210 } 211 212 // Get sample of burst length 213 if (!stats.disableBurstLengthHists) { 214 stats.readBurstLengthHist.sample(size); 215 } 216 217 // Sample the masked address 218 if (!stats.disableAddrDists) { 219 stats.readAddrDist.sample(addr & readAddrMask); 220 } 221 222 // If it needs a response increment number of outstanding read 223 // requests 224 if (!stats.disableOutstandingHists && needsResponse) { 225 ++stats.outstandingReadReqs; 226 } 227 228 if (!stats.disableITTDists) { 229 // Sample value of read-read inter transaction time 230 if (stats.timeOfLastRead != 0) { 231 stats.ittReadRead.sample(curTick() - stats.timeOfLastRead); 232 } 233 stats.timeOfLastRead = curTick(); 234 235 // Sample value of req-req inter transaction time 236 if (stats.timeOfLastReq != 0) { 237 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq); 238 } 239 stats.timeOfLastReq = curTick(); 240 } 241 } else if (successful && isWrite) { 242 DPRINTF(CommMonitor, "Forwarded write request\n"); 243 244 // Same as for reads 245 if (!stats.disableTransactionHists) { 246 ++stats.writeTrans; 247 } 248 249 if (!stats.disableBurstLengthHists) { 250 stats.writeBurstLengthHist.sample(size); 251 } 252 253 // Update the bandwidth stats on the request 254 if (!stats.disableBandwidthHists) { 255 stats.writtenBytes += size; 256 stats.totalWrittenBytes += size; 257 } 258 259 // Sample the masked write address 260 if (!stats.disableAddrDists) { 261 stats.writeAddrDist.sample(addr & writeAddrMask); 262 } 263 264 if (!stats.disableOutstandingHists && needsResponse) { 265 ++stats.outstandingWriteReqs; 266 } 267 268 if (!stats.disableITTDists) { 269 // Sample value of write-to-write inter transaction time 270 if (stats.timeOfLastWrite != 0) { 271 stats.ittWriteWrite.sample(curTick() - stats.timeOfLastWrite); 272 } 273 stats.timeOfLastWrite = curTick(); 274 275 // Sample value of req-to-req inter transaction time 276 if (stats.timeOfLastReq != 0) { 277 stats.ittReqReq.sample(curTick() - stats.timeOfLastReq); 278 } 279 stats.timeOfLastReq = curTick(); 280 } 281 } else if (successful) { 282 DPRINTF(CommMonitor, "Forwarded non read/write request\n"); 283 } 284 285 return successful; 286} 287 288bool 289CommMonitor::recvTimingResp(PacketPtr pkt) 290{ 291 // should always see responses 292 assert(pkt->isResponse()); 293 294 // Store relevant fields of packet, because packet may be modified 295 // or even deleted when sendTiming() is called. 296 bool isRead = pkt->isRead(); 297 bool isWrite = pkt->isWrite(); 298 unsigned size = pkt->getSize(); 299 Tick latency = 0; 300 CommMonitorSenderState* commReceivedState = 301 dynamic_cast<CommMonitorSenderState*>(pkt->senderState); 302 303 if (!stats.disableLatencyHists) { 304 // Restore initial sender state 305 if (commReceivedState == NULL) 306 panic("Monitor got a response without monitor sender state\n"); 307 308 // Restore the sate 309 pkt->senderState = commReceivedState->origSenderState; 310 } 311 312 // Attempt to send the packet 313 bool successful = slavePort.sendTimingResp(pkt); 314 315 if (!stats.disableLatencyHists) { 316 // If packet successfully send, sample value of latency, 317 // afterwards delete sender state, otherwise restore state 318 if (successful) { 319 latency = curTick() - commReceivedState->transmitTime; 320 DPRINTF(CommMonitor, "Latency: %d\n", latency); 321 delete commReceivedState; 322 } else { 323 // Don't delete anything and let the packet look like we 324 // did not touch it 325 pkt->senderState = commReceivedState; 326 } 327 } 328 329 if (successful && isRead) { 330 // Decrement number of outstanding read requests 331 DPRINTF(CommMonitor, "Received read response\n"); 332 if (!stats.disableOutstandingHists) { 333 assert(stats.outstandingReadReqs != 0); 334 --stats.outstandingReadReqs; 335 } 336 337 if (!stats.disableLatencyHists) { 338 stats.readLatencyHist.sample(latency); 339 } 340 341 // Update the bandwidth stats based on responses for reads 342 if (!stats.disableBandwidthHists) { 343 stats.readBytes += size; 344 stats.totalReadBytes += size; 345 } 346 347 } else if (successful && isWrite) { 348 // Decrement number of outstanding write requests 349 DPRINTF(CommMonitor, "Received write response\n"); 350 if (!stats.disableOutstandingHists) { 351 assert(stats.outstandingWriteReqs != 0); 352 --stats.outstandingWriteReqs; 353 } 354 355 if (!stats.disableLatencyHists) { 356 stats.writeLatencyHist.sample(latency); 357 } 358 } else if (successful) { 359 DPRINTF(CommMonitor, "Received non read/write response\n"); 360 } 361 return successful; 362} 363 364void 365CommMonitor::recvTimingSnoopReq(PacketPtr pkt) 366{ 367 slavePort.sendTimingSnoopReq(pkt); 368} 369 370bool 371CommMonitor::recvTimingSnoopResp(PacketPtr pkt) 372{ 373 return masterPort.sendTimingSnoopResp(pkt); 374} 375 376bool 377CommMonitor::isSnooping() const 378{ 379 // check if the connected master port is snooping 380 return slavePort.isSnooping(); 381} 382 383unsigned 384CommMonitor::deviceBlockSizeMaster() 385{ 386 return slavePort.peerBlockSize(); 387} 388 389unsigned 390CommMonitor::deviceBlockSizeSlave() 391{ 392 return masterPort.peerBlockSize(); 393} 394 395AddrRangeList 396CommMonitor::getAddrRanges() const 397{ 398 // get the address ranges of the connected slave port 399 return masterPort.getAddrRanges(); 400} 401 402void 403CommMonitor::recvRetryMaster() 404{ 405 slavePort.sendRetry(); 406} 407 408void 409CommMonitor::recvRetrySlave() 410{ 411 masterPort.sendRetry(); 412} 413 414void 415CommMonitor::recvRangeChange() 416{ 417 slavePort.sendRangeChange(); 418} 419 420void 421CommMonitor::regStats() 422{ 423 // Initialise all the monitor stats 424 using namespace Stats; 425 426 stats.readBurstLengthHist 427 .init(params()->burst_length_bins) 428 .name(name() + ".readBurstLengthHist") 429 .desc("Histogram of burst lengths of transmitted packets") 430 .flags(stats.disableBurstLengthHists ? nozero : pdf); 431 432 stats.writeBurstLengthHist 433 .init(params()->burst_length_bins) 434 .name(name() + ".writeBurstLengthHist") 435 .desc("Histogram of burst lengths of transmitted packets") 436 .flags(stats.disableBurstLengthHists ? nozero : pdf); 437 438 // Stats based on received responses 439 stats.readBandwidthHist 440 .init(params()->bandwidth_bins) 441 .name(name() + ".readBandwidthHist") 442 .desc("Histogram of read bandwidth per sample period (bytes/s)") 443 .flags(stats.disableBandwidthHists ? nozero : pdf); 444 445 stats.averageReadBW 446 .name(name() + ".averageReadBandwidth") 447 .desc("Average read bandwidth (bytes/s)") 448 .flags(stats.disableBandwidthHists ? nozero : pdf); 449 450 stats.totalReadBytes 451 .name(name() + ".totalReadBytes") 452 .desc("Number of bytes read") 453 .flags(stats.disableBandwidthHists ? nozero : pdf); 454 455 stats.averageReadBW = stats.totalReadBytes / simSeconds; 456 457 // Stats based on successfully sent requests 458 stats.writeBandwidthHist 459 .init(params()->bandwidth_bins) 460 .name(name() + ".writeBandwidthHist") 461 .desc("Histogram of write bandwidth (bytes/s)") 462 .flags(stats.disableBandwidthHists ? (pdf | nozero) : pdf); 463 464 stats.averageWriteBW 465 .name(name() + ".averageWriteBandwidth") 466 .desc("Average write bandwidth (bytes/s)") 467 .flags(stats.disableBandwidthHists ? nozero : pdf); 468 469 stats.totalWrittenBytes 470 .name(name() + ".totalWrittenBytes") 471 .desc("Number of bytes written") 472 .flags(stats.disableBandwidthHists ? nozero : pdf); 473 474 stats.averageWriteBW = stats.totalWrittenBytes / simSeconds; 475 476 stats.readLatencyHist 477 .init(params()->latency_bins) 478 .name(name() + ".readLatencyHist") 479 .desc("Read request-response latency") 480 .flags(stats.disableLatencyHists ? nozero : pdf); 481 482 stats.writeLatencyHist 483 .init(params()->latency_bins) 484 .name(name() + ".writeLatencyHist") 485 .desc("Write request-response latency") 486 .flags(stats.disableLatencyHists ? nozero : pdf); 487 488 stats.ittReadRead 489 .init(1, params()->itt_max_bin, params()->itt_max_bin / 490 params()->itt_bins) 491 .name(name() + ".ittReadRead") 492 .desc("Read-to-read inter transaction time") 493 .flags(stats.disableITTDists ? nozero : pdf); 494 495 stats.ittWriteWrite 496 .init(1, params()->itt_max_bin, params()->itt_max_bin / 497 params()->itt_bins) 498 .name(name() + ".ittWriteWrite") 499 .desc("Write-to-write inter transaction time") 500 .flags(stats.disableITTDists ? nozero : pdf); 501 502 stats.ittReqReq 503 .init(1, params()->itt_max_bin, params()->itt_max_bin / 504 params()->itt_bins) 505 .name(name() + ".ittReqReq") 506 .desc("Request-to-request inter transaction time") 507 .flags(stats.disableITTDists ? nozero : pdf); 508 509 stats.outstandingReadsHist 510 .init(params()->outstanding_bins) 511 .name(name() + ".outstandingReadsHist") 512 .desc("Outstanding read transactions") 513 .flags(stats.disableOutstandingHists ? nozero : pdf); 514 515 stats.outstandingWritesHist 516 .init(params()->outstanding_bins) 517 .name(name() + ".outstandingWritesHist") 518 .desc("Outstanding write transactions") 519 .flags(stats.disableOutstandingHists ? nozero : pdf); 520 521 stats.readTransHist 522 .init(params()->transaction_bins) 523 .name(name() + ".readTransHist") 524 .desc("Histogram of read transactions per sample period") 525 .flags(stats.disableTransactionHists ? nozero : pdf); 526 527 stats.writeTransHist 528 .init(params()->transaction_bins) 529 .name(name() + ".writeTransHist") 530 .desc("Histogram of read transactions per sample period") 531 .flags(stats.disableTransactionHists ? nozero : pdf); 532 533 stats.readAddrDist 534 .init(0) 535 .name(name() + ".readAddrDist") 536 .desc("Read address distribution") 537 .flags(stats.disableAddrDists ? nozero : pdf); 538 539 stats.writeAddrDist 540 .init(0) 541 .name(name() + ".writeAddrDist") 542 .desc("Write address distribution") 543 .flags(stats.disableAddrDists ? nozero : pdf); 544} 545 546void 547CommMonitor::samplePeriodic() 548{ 549 // the periodic stats update runs on the granularity of sample 550 // periods, but in combination with this there may also be a 551 // external resets and dumps of the stats (through schedStatEvent) 552 // causing the stats themselves to capture less than a sample 553 // period 554 555 // only capture if we have not reset the stats during the last 556 // sample period 557 if (simTicks.value() >= samplePeriodTicks) { 558 if (!stats.disableTransactionHists) { 559 stats.readTransHist.sample(stats.readTrans); 560 stats.writeTransHist.sample(stats.writeTrans); 561 } 562 563 if (!stats.disableBandwidthHists) { 564 stats.readBandwidthHist.sample(stats.readBytes / samplePeriod); 565 stats.writeBandwidthHist.sample(stats.writtenBytes / samplePeriod); 566 } 567 568 if (!stats.disableOutstandingHists) { 569 stats.outstandingReadsHist.sample(stats.outstandingReadReqs); 570 stats.outstandingWritesHist.sample(stats.outstandingWriteReqs); 571 } 572 } 573 574 // reset the sampled values 575 stats.readTrans = 0; 576 stats.writeTrans = 0; 577 578 stats.readBytes = 0; 579 stats.writtenBytes = 0; 580 581 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks); 582} 583 584void 585CommMonitor::startup() 586{ 587 schedule(samplePeriodicEvent, curTick() + samplePeriodTicks); 588}
|