* Andreas Hansson
*/
+#include "base/trace.hh"
+#include "debug/Drain.hh"
#include "debug/PacketQueue.hh"
#include "mem/packet_queue.hh"
using namespace std;
-PacketQueue::PacketQueue(EventManager& _em, Port& _port,
- const std::string _label)
- : em(_em), label(_label), sendEvent(this), drainEvent(NULL), port(_port),
+PacketQueue::PacketQueue(EventManager& _em, const std::string& _label)
+ : em(_em), sendEvent(this), drainManager(NULL), label(_label),
waitingOnRetry(false)
{
}
}
void
-PacketQueue::schedSendTiming(PacketPtr pkt, Tick when)
+PacketQueue::schedSendTiming(PacketPtr pkt, Tick when, bool send_as_snoop)
{
- assert(when > curTick());
+ // we can still send a packet before the end of this tick
+ assert(when >= curTick());
+
+ // express snoops should never be queued
+ assert(!pkt->isExpressSnoop());
+
+ // add a very basic sanity check on the port to ensure the
+ // invisible buffer is not growing beyond reasonable limits
+ if (transmitList.size() > 100) {
+ panic("Packet queue %s has grown beyond 100 packets\n",
+ name());
+ }
// nothing on the list, or earlier than current front element,
// schedule an event
// note that currently we ignore a potentially outstanding retry
// and could in theory put a new packet at the head of the
// transmit list before retrying the existing packet
- transmitList.push_front(DeferredPacket(when, pkt));
+ transmitList.push_front(DeferredPacket(when, pkt, send_as_snoop));
schedSendEvent(when);
return;
}
// list is non-empty and this belongs at the end
if (when >= transmitList.back().tick) {
- transmitList.push_back(DeferredPacket(when, pkt));
+ transmitList.push_back(DeferredPacket(when, pkt, send_as_snoop));
return;
}
++i; // already checked for insertion at front
while (i != transmitList.end() && when >= i->tick)
++i;
- transmitList.insert(i, DeferredPacket(when, pkt));
+ transmitList.insert(i, DeferredPacket(when, pkt, send_as_snoop));
}
void PacketQueue::trySendTiming()
DeferredPacket dp = transmitList.front();
transmitList.pop_front();
- // attempt to send the packet and remember the outcome
- waitingOnRetry = !port.sendTiming(dp.pkt);
+ // use the appropriate implementation of sendTiming based on the
+ // type of port associated with the queue, and whether the packet
+ // is to be sent as a snoop or not
+ waitingOnRetry = !sendTiming(dp.pkt, dp.sendAsSnoop);
if (waitingOnRetry) {
// put the packet back at the front of the list (packet should
em.schedule(&sendEvent, std::max(nextReady, curTick() + 1));
} else {
// no more to send, so if we're draining, we may be done
- if (drainEvent && !sendEvent.scheduled()) {
- drainEvent->process();
- drainEvent = NULL;
+ if (drainManager && transmitList.empty() && !sendEvent.scheduled()) {
+ DPRINTF(Drain, "PacketQueue done draining,"
+ "processing drain event\n");
+ drainManager->signalDrainDone();
+ drainManager = NULL;
}
}
}
}
unsigned int
-PacketQueue::drain(Event *de)
+PacketQueue::drain(DrainManager *dm)
{
if (transmitList.empty() && !sendEvent.scheduled())
return 0;
- drainEvent = de;
+ DPRINTF(Drain, "PacketQueue not drained\n");
+ drainManager = dm;
return 1;
}
+
+MasterPacketQueue::MasterPacketQueue(EventManager& _em, MasterPort& _masterPort,
+ const std::string _label)
+ : PacketQueue(_em, _label), masterPort(_masterPort)
+{
+}
+
+bool
+MasterPacketQueue::sendTiming(PacketPtr pkt, bool send_as_snoop)
+{
+ // attempt to send the packet and return according to the outcome
+ if (!send_as_snoop)
+ return masterPort.sendTimingReq(pkt);
+ else
+ return masterPort.sendTimingSnoopResp(pkt);
+}
+
+SlavePacketQueue::SlavePacketQueue(EventManager& _em, SlavePort& _slavePort,
+ const std::string _label)
+ : PacketQueue(_em, _label), slavePort(_slavePort)
+{
+}
+
+bool
+SlavePacketQueue::sendTiming(PacketPtr pkt, bool send_as_snoop)
+{
+ // we should never have queued snoop requests
+ assert(!send_as_snoop);
+ return slavePort.sendTimingResp(pkt);
+}