/*
- * Copyright (c) 2012-2013 ARM Limited
- * All rights reserved
+ * Copyright (c) 2012-2013, 2015, 2018 ARM Limited
+ * Copyright (c) 2016 Google Inc.
+ * Copyright (c) 2017, Centre National de la Recherche Scientifique
+ * All rights reserved.
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
*
* Authors: Thomas Grass
* Andreas Hansson
+ * Rahul Thakur
+ * Pierre-Yves Peneau
*/
-#include "base/callback.hh"
-#include "base/output.hh"
+#include "mem/comm_monitor.hh"
+
#include "base/trace.hh"
#include "debug/CommMonitor.hh"
-#include "mem/comm_monitor.hh"
-#include "proto/packet.pb.h"
#include "sim/stats.hh"
CommMonitor::CommMonitor(Params* params)
: MemObject(params),
masterPort(name() + "-master", *this),
slavePort(name() + "-slave", *this),
- samplePeriodicEvent(this),
+ samplePeriodicEvent([this]{ samplePeriodic(); }, name()),
samplePeriodTicks(params->sample_period),
- readAddrMask(params->read_addr_mask),
- writeAddrMask(params->write_addr_mask),
- stats(params),
- traceStream(NULL)
+ samplePeriod(params->sample_period / SimClock::Float::s),
+ stats(params)
{
- // If we are using a trace file, then open the file,
- if (params->trace_file != "") {
- // If the trace file is not specified as an absolute path,
- // append the current simulation output directory
- std::string filename = simout.resolve(params->trace_file);
- traceStream = new ProtoOutputStream(filename);
-
- // Create a protobuf message for the header and write it to
- // the stream
- Message::PacketHeader header_msg;
- header_msg.set_obj_id(name());
- header_msg.set_tick_freq(SimClock::Frequency);
- traceStream->write(header_msg);
-
- // Register a callback to compensate for the destructor not
- // being called. The callback forces the stream to flush and
- // closes the output file.
- Callback* cb = new MakeCallback<CommMonitor,
- &CommMonitor::closeStreams>(this);
- registerExitCallback(cb);
- }
-
- // keep track of the sample period both in ticks and absolute time
- samplePeriod.setTick(params->sample_period);
-
DPRINTF(CommMonitor,
- "Created monitor %s with sample period %d ticks (%f s)\n",
- name(), samplePeriodTicks, samplePeriod);
-}
-
-void
-CommMonitor::closeStreams()
-{
- if (traceStream != NULL)
- delete traceStream;
+ "Created monitor %s with sample period %d ticks (%f ms)\n",
+ name(), samplePeriodTicks, samplePeriod * 1E3);
}
CommMonitor*
fatal("Communication monitor is not connected on both sides.\n");
}
-BaseMasterPort&
-CommMonitor::getMasterPort(const std::string& if_name, PortID idx)
+void
+CommMonitor::regProbePoints()
{
- if (if_name == "master") {
- return masterPort;
- } else {
- return MemObject::getMasterPort(if_name, idx);
- }
+ ppPktReq.reset(new ProbePoints::Packet(getProbeManager(), "PktRequest"));
+ ppPktResp.reset(new ProbePoints::Packet(getProbeManager(), "PktResponse"));
}
-BaseSlavePort&
-CommMonitor::getSlavePort(const std::string& if_name, PortID idx)
+Port &
+CommMonitor::getPort(const std::string &if_name, PortID idx)
{
- if (if_name == "slave") {
+ if (if_name == "master") {
+ return masterPort;
+ } else if (if_name == "slave") {
return slavePort;
} else {
- return MemObject::getSlavePort(if_name, idx);
+ return MemObject::getPort(if_name, idx);
}
}
slavePort.sendFunctionalSnoop(pkt);
}
+void
+CommMonitor::MonitorStats::updateReqStats(
+ const ProbePoints::PacketInfo& pkt_info, bool is_atomic,
+ bool expects_response)
+{
+ if (pkt_info.cmd.isRead()) {
+ // Increment number of observed read transactions
+ if (!disableTransactionHists)
+ ++readTrans;
+
+ // Get sample of burst length
+ if (!disableBurstLengthHists)
+ readBurstLengthHist.sample(pkt_info.size);
+
+ // Sample the masked address
+ if (!disableAddrDists)
+ readAddrDist.sample(pkt_info.addr & readAddrMask);
+
+ if (!disableITTDists) {
+ // Sample value of read-read inter transaction time
+ if (timeOfLastRead != 0)
+ ittReadRead.sample(curTick() - timeOfLastRead);
+ timeOfLastRead = curTick();
+
+ // Sample value of req-req inter transaction time
+ if (timeOfLastReq != 0)
+ ittReqReq.sample(curTick() - timeOfLastReq);
+ timeOfLastReq = curTick();
+ }
+ if (!is_atomic && !disableOutstandingHists && expects_response)
+ ++outstandingReadReqs;
+
+ } else if (pkt_info.cmd.isWrite()) {
+ // Same as for reads
+ if (!disableTransactionHists)
+ ++writeTrans;
+
+ if (!disableBurstLengthHists)
+ writeBurstLengthHist.sample(pkt_info.size);
+
+ // Update the bandwidth stats on the request
+ if (!disableBandwidthHists) {
+ writtenBytes += pkt_info.size;
+ totalWrittenBytes += pkt_info.size;
+ }
+
+ // Sample the masked write address
+ if (!disableAddrDists)
+ writeAddrDist.sample(pkt_info.addr & writeAddrMask);
+
+ if (!disableITTDists) {
+ // Sample value of write-to-write inter transaction time
+ if (timeOfLastWrite != 0)
+ ittWriteWrite.sample(curTick() - timeOfLastWrite);
+ timeOfLastWrite = curTick();
+
+ // Sample value of req-to-req inter transaction time
+ if (timeOfLastReq != 0)
+ ittReqReq.sample(curTick() - timeOfLastReq);
+ timeOfLastReq = curTick();
+ }
+
+ if (!is_atomic && !disableOutstandingHists && expects_response)
+ ++outstandingWriteReqs;
+ }
+}
+
+void
+CommMonitor::MonitorStats::updateRespStats(
+ const ProbePoints::PacketInfo& pkt_info, Tick latency, bool is_atomic)
+{
+ if (pkt_info.cmd.isRead()) {
+ // Decrement number of outstanding read requests
+ if (!is_atomic && !disableOutstandingHists) {
+ assert(outstandingReadReqs != 0);
+ --outstandingReadReqs;
+ }
+
+ if (!disableLatencyHists)
+ readLatencyHist.sample(latency);
+
+ // Update the bandwidth stats based on responses for reads
+ if (!disableBandwidthHists) {
+ readBytes += pkt_info.size;
+ totalReadBytes += pkt_info.size;
+ }
+
+ } else if (pkt_info.cmd.isWrite()) {
+ // Decrement number of outstanding write requests
+ if (!is_atomic && !disableOutstandingHists) {
+ assert(outstandingWriteReqs != 0);
+ --outstandingWriteReqs;
+ }
+
+ if (!disableLatencyHists)
+ writeLatencyHist.sample(latency);
+ }
+}
+
Tick
CommMonitor::recvAtomic(PacketPtr pkt)
{
- return masterPort.sendAtomic(pkt);
+ const bool expects_response(pkt->needsResponse() &&
+ !pkt->cacheResponding());
+ ProbePoints::PacketInfo req_pkt_info(pkt);
+ ppPktReq->notify(req_pkt_info);
+
+ const Tick delay(masterPort.sendAtomic(pkt));
+
+ stats.updateReqStats(req_pkt_info, true, expects_response);
+ if (expects_response)
+ stats.updateRespStats(req_pkt_info, delay, true);
+
+ assert(pkt->isResponse());
+ ProbePoints::PacketInfo resp_pkt_info(pkt);
+ ppPktResp->notify(resp_pkt_info);
+ return delay;
}
Tick
// Store relevant fields of packet, because packet may be modified
// or even deleted when sendTiming() is called.
- bool isRead = pkt->isRead();
- bool isWrite = pkt->isWrite();
- int cmd = pkt->cmdToIndex();
- unsigned size = pkt->getSize();
- Addr addr = pkt->getAddr();
- bool needsResponse = pkt->needsResponse();
- bool memInhibitAsserted = pkt->memInhibitAsserted();
+ const ProbePoints::PacketInfo pkt_info(pkt);
+
+ const bool expects_response(pkt->needsResponse() &&
+ !pkt->cacheResponding());
// If a cache miss is served by a cache, a monitor near the memory
// would see a request which needs a response, but this response
- // would be inhibited and not come back from the memory. Therefore
- // we additionally have to check the inhibit flag.
- if (needsResponse && !memInhibitAsserted && !stats.disableLatencyHists) {
+ // would not come back from the memory. Therefore we additionally
+ // have to check the cacheResponding flag
+ if (expects_response && !stats.disableLatencyHists) {
pkt->pushSenderState(new CommMonitorSenderState(curTick()));
}
- // Attempt to send the packet (always succeeds for inhibited
- // packets)
+ // Attempt to send the packet
bool successful = masterPort.sendTimingReq(pkt);
// If not successful, restore the sender state
- if (!successful && needsResponse && !stats.disableLatencyHists) {
+ if (!successful && expects_response && !stats.disableLatencyHists) {
delete pkt->popSenderState();
}
- if (successful && traceStream != NULL) {
- // Create a protobuf message representing the
- // packet. Currently we do not preserve the flags in the
- // trace.
- Message::Packet pkt_msg;
- pkt_msg.set_tick(curTick());
- pkt_msg.set_cmd(cmd);
- pkt_msg.set_addr(addr);
- pkt_msg.set_size(size);
-
- traceStream->write(pkt_msg);
+ if (successful) {
+ ppPktReq->notify(pkt_info);
}
- if (successful && isRead) {
- DPRINTF(CommMonitor, "Forwarded read request\n");
-
- // Increment number of observed read transactions
- if (!stats.disableTransactionHists) {
- ++stats.readTrans;
- }
-
- // Get sample of burst length
- if (!stats.disableBurstLengthHists) {
- stats.readBurstLengthHist.sample(size);
- }
-
- // Sample the masked address
- if (!stats.disableAddrDists) {
- stats.readAddrDist.sample(addr & readAddrMask);
- }
-
- // If it needs a response increment number of outstanding read
- // requests
- if (!stats.disableOutstandingHists && needsResponse) {
- ++stats.outstandingReadReqs;
- }
-
- if (!stats.disableITTDists) {
- // Sample value of read-read inter transaction time
- if (stats.timeOfLastRead != 0) {
- stats.ittReadRead.sample(curTick() - stats.timeOfLastRead);
- }
- stats.timeOfLastRead = curTick();
-
- // Sample value of req-req inter transaction time
- if (stats.timeOfLastReq != 0) {
- stats.ittReqReq.sample(curTick() - stats.timeOfLastReq);
- }
- stats.timeOfLastReq = curTick();
- }
- } else if (successful && isWrite) {
- DPRINTF(CommMonitor, "Forwarded write request\n");
-
- // Same as for reads
- if (!stats.disableTransactionHists) {
- ++stats.writeTrans;
- }
-
- if (!stats.disableBurstLengthHists) {
- stats.writeBurstLengthHist.sample(size);
- }
-
- // Update the bandwidth stats on the request
- if (!stats.disableBandwidthHists) {
- stats.writtenBytes += size;
- stats.totalWrittenBytes += size;
- }
-
- // Sample the masked write address
- if (!stats.disableAddrDists) {
- stats.writeAddrDist.sample(addr & writeAddrMask);
- }
-
- if (!stats.disableOutstandingHists && needsResponse) {
- ++stats.outstandingWriteReqs;
- }
-
- if (!stats.disableITTDists) {
- // Sample value of write-to-write inter transaction time
- if (stats.timeOfLastWrite != 0) {
- stats.ittWriteWrite.sample(curTick() - stats.timeOfLastWrite);
- }
- stats.timeOfLastWrite = curTick();
-
- // Sample value of req-to-req inter transaction time
- if (stats.timeOfLastReq != 0) {
- stats.ittReqReq.sample(curTick() - stats.timeOfLastReq);
- }
- stats.timeOfLastReq = curTick();
- }
- } else if (successful) {
- DPRINTF(CommMonitor, "Forwarded non read/write request\n");
+ if (successful) {
+ DPRINTF(CommMonitor, "Forwarded %s request\n", pkt->isRead() ? "read" :
+ pkt->isWrite() ? "write" : "non read/write");
+ stats.updateReqStats(pkt_info, false, expects_response);
}
-
return successful;
}
// Store relevant fields of packet, because packet may be modified
// or even deleted when sendTiming() is called.
- bool isRead = pkt->isRead();
- bool isWrite = pkt->isWrite();
- unsigned size = pkt->getSize();
+ const ProbePoints::PacketInfo pkt_info(pkt);
+
Tick latency = 0;
- CommMonitorSenderState* commReceivedState =
+ CommMonitorSenderState* received_state =
dynamic_cast<CommMonitorSenderState*>(pkt->senderState);
if (!stats.disableLatencyHists) {
// Restore initial sender state
- if (commReceivedState == NULL)
+ if (received_state == NULL)
panic("Monitor got a response without monitor sender state\n");
// Restore the sate
- pkt->senderState = commReceivedState->predecessor;
+ pkt->senderState = received_state->predecessor;
}
// Attempt to send the packet
// If packet successfully send, sample value of latency,
// afterwards delete sender state, otherwise restore state
if (successful) {
- latency = curTick() - commReceivedState->transmitTime;
+ latency = curTick() - received_state->transmitTime;
DPRINTF(CommMonitor, "Latency: %d\n", latency);
- delete commReceivedState;
+ delete received_state;
} else {
// Don't delete anything and let the packet look like we
// did not touch it
- pkt->senderState = commReceivedState;
+ pkt->senderState = received_state;
}
}
- if (successful && isRead) {
- // Decrement number of outstanding read requests
- DPRINTF(CommMonitor, "Received read response\n");
- if (!stats.disableOutstandingHists) {
- assert(stats.outstandingReadReqs != 0);
- --stats.outstandingReadReqs;
- }
-
- if (!stats.disableLatencyHists) {
- stats.readLatencyHist.sample(latency);
- }
-
- // Update the bandwidth stats based on responses for reads
- if (!stats.disableBandwidthHists) {
- stats.readBytes += size;
- stats.totalReadBytes += size;
- }
-
- } else if (successful && isWrite) {
- // Decrement number of outstanding write requests
- DPRINTF(CommMonitor, "Received write response\n");
- if (!stats.disableOutstandingHists) {
- assert(stats.outstandingWriteReqs != 0);
- --stats.outstandingWriteReqs;
- }
-
- if (!stats.disableLatencyHists) {
- stats.writeLatencyHist.sample(latency);
- }
- } else if (successful) {
- DPRINTF(CommMonitor, "Received non read/write response\n");
+ if (successful) {
+ ppPktResp->notify(pkt_info);
+ DPRINTF(CommMonitor, "Received %s response\n", pkt->isRead() ? "read" :
+ pkt->isWrite() ? "write" : "non read/write");
+ stats.updateRespStats(pkt_info, latency, false);
}
return successful;
}
return masterPort.sendTimingSnoopResp(pkt);
}
+void
+CommMonitor::recvRetrySnoopResp()
+{
+ slavePort.sendRetrySnoopResp();
+}
+
bool
CommMonitor::isSnooping() const
{
return slavePort.isSnooping();
}
-unsigned
-CommMonitor::deviceBlockSizeMaster()
-{
- return slavePort.peerBlockSize();
-}
-
-unsigned
-CommMonitor::deviceBlockSizeSlave()
-{
- return masterPort.peerBlockSize();
-}
-
AddrRangeList
CommMonitor::getAddrRanges() const
{
}
void
-CommMonitor::recvRetryMaster()
+CommMonitor::recvReqRetry()
{
- slavePort.sendRetry();
+ slavePort.sendRetryReq();
}
void
-CommMonitor::recvRetrySlave()
+CommMonitor::recvRespRetry()
+{
+ masterPort.sendRetryResp();
+}
+
+bool
+CommMonitor::tryTiming(PacketPtr pkt)
{
- masterPort.sendRetry();
+ return masterPort.tryTiming(pkt);
}
void
void
CommMonitor::regStats()
{
+ MemObject::regStats();
+
// Initialise all the monitor stats
using namespace Stats;
stats.writeTransHist
.init(params()->transaction_bins)
.name(name() + ".writeTransHist")
- .desc("Histogram of read transactions per sample period")
+ .desc("Histogram of write transactions per sample period")
.flags(stats.disableTransactionHists ? nozero : pdf);
stats.readAddrDist