Restructure SimpleTimingPort a bit:

- factor out checkFunctional() code so it can be
called from derived classes
- use EventWrapper for sendEvent, move event handling
code from event to port where it belongs
- make sendEvent a pointer so derived classes can
override it
- replace std::pair with new class for readability

--HG--
extra : convert_revision : 5709de2daacfb751a440144ecaab5f9fc02e6b7a
This commit is contained in:
Steve Reinhardt 2007-05-28 08:11:43 -07:00
parent 04ac944920
commit 41f6cbce9a
3 changed files with 76 additions and 70 deletions

View file

@ -414,20 +414,7 @@ PhysicalMemory::MemoryPort::recvAtomic(PacketPtr pkt)
void void
PhysicalMemory::MemoryPort::recvFunctional(PacketPtr pkt) PhysicalMemory::MemoryPort::recvFunctional(PacketPtr pkt)
{ {
//Since we are overriding the function, make sure to have the impl of the checkFunctional(pkt);
//check or functional accesses here.
std::list<std::pair<Tick,PacketPtr> >::iterator i = transmitList.begin();
std::list<std::pair<Tick,PacketPtr> >::iterator end = transmitList.end();
bool notDone = true;
while (i != end && notDone) {
PacketPtr target = i->second;
// If the target contains data, and it overlaps the
// probed request, need to update data
if (target->intersect(pkt))
notDone = fixPacket(pkt, target);
i++;
}
// Default implementation of SimpleTimingPort::recvFunctional() // Default implementation of SimpleTimingPort::recvFunctional()
// calls recvAtomic() and throws away the latency; we can save a // calls recvAtomic() and throws away the latency; we can save a

View file

@ -31,23 +31,32 @@
#include "mem/tport.hh" #include "mem/tport.hh"
void void
SimpleTimingPort::recvFunctional(PacketPtr pkt) SimpleTimingPort::checkFunctional(PacketPtr pkt)
{ {
std::list<std::pair<Tick,PacketPtr> >::iterator i = transmitList.begin(); DeferredPacketIterator i = transmitList.begin();
std::list<std::pair<Tick,PacketPtr> >::iterator end = transmitList.end(); DeferredPacketIterator end = transmitList.end();
bool notDone = true;
while (i != end && notDone) { while (i != end) {
PacketPtr target = i->second; PacketPtr target = i->pkt;
// If the target contains data, and it overlaps the // If the target contains data, and it overlaps the
// probed request, need to update data // probed request, need to update data
if (target->intersect(pkt)) if (target->intersect(pkt)) {
notDone = fixPacket(pkt, target); if (!fixPacket(pkt, target)) {
// fixPacket returns true for continue, false for done
return;
}
}
i++; i++;
} }
}
//Then just do an atomic access and throw away the returned latency void
SimpleTimingPort::recvFunctional(PacketPtr pkt)
{
checkFunctional(pkt);
// Just do an atomic access and throw away the returned latency
if (pkt->result != Packet::Success) if (pkt->result != Packet::Success)
recvAtomic(pkt); recvAtomic(pkt);
} }
@ -67,12 +76,9 @@ SimpleTimingPort::recvTiming(PacketPtr pkt)
pkt->makeTimingResponse(); pkt->makeTimingResponse();
sendTiming(pkt, latency); sendTiming(pkt, latency);
} }
else { else if (pkt->cmd != MemCmd::UpgradeReq) {
if (pkt->cmd != MemCmd::UpgradeReq) delete pkt->req;
{ delete pkt;
delete pkt->req;
delete pkt;
}
} }
return true; return true;
} }
@ -81,12 +87,12 @@ void
SimpleTimingPort::recvRetry() SimpleTimingPort::recvRetry()
{ {
assert(!transmitList.empty()); assert(!transmitList.empty());
if (Port::sendTiming(transmitList.front().second)) { if (Port::sendTiming(transmitList.front().pkt)) {
transmitList.pop_front(); transmitList.pop_front();
DPRINTF(Bus, "No Longer waiting on retry\n"); DPRINTF(Bus, "No Longer waiting on retry\n");
if (!transmitList.empty()) { if (!transmitList.empty()) {
Tick time = transmitList.front().first; Tick time = transmitList.front().tick;
sendEvent.schedule(time <= curTick ? curTick+1 : time); sendEvent->schedule(time <= curTick ? curTick+1 : time);
} }
} }
@ -101,29 +107,29 @@ SimpleTimingPort::sendTiming(PacketPtr pkt, Tick time)
{ {
// Nothing is on the list: add it and schedule an event // Nothing is on the list: add it and schedule an event
if (transmitList.empty()) { if (transmitList.empty()) {
assert(!sendEvent.scheduled()); assert(!sendEvent->scheduled());
sendEvent.schedule(curTick+time); sendEvent->schedule(curTick+time);
transmitList.push_back(std::pair<Tick,PacketPtr>(time+curTick,pkt)); transmitList.push_back(DeferredPacket(time+curTick, pkt));
return; return;
} }
// something is on the list and this belongs at the end // something is on the list and this belongs at the end
if (time+curTick >= transmitList.back().first) { if (time+curTick >= transmitList.back().tick) {
transmitList.push_back(std::pair<Tick,PacketPtr>(time+curTick,pkt)); transmitList.push_back(DeferredPacket(time+curTick, pkt));
return; return;
} }
// Something is on the list and this belongs somewhere else // Something is on the list and this belongs somewhere else
std::list<std::pair<Tick,PacketPtr> >::iterator i = transmitList.begin(); DeferredPacketIterator i = transmitList.begin();
std::list<std::pair<Tick,PacketPtr> >::iterator end = transmitList.end(); DeferredPacketIterator end = transmitList.end();
bool done = false; bool done = false;
while (i != end && !done) { while (i != end && !done) {
if (time+curTick < i->first) { if (time+curTick < i->tick) {
if (i == transmitList.begin()) { if (i == transmitList.begin()) {
//Inserting at begining, reschedule //Inserting at begining, reschedule
sendEvent.reschedule(time+curTick); sendEvent->reschedule(time+curTick);
} }
transmitList.insert(i,std::pair<Tick,PacketPtr>(time+curTick,pkt)); transmitList.insert(i, DeferredPacket(time+curTick, pkt));
done = true; done = true;
} }
i++; i++;
@ -132,20 +138,20 @@ SimpleTimingPort::sendTiming(PacketPtr pkt, Tick time)
} }
void void
SimpleTimingPort::SendEvent::process() SimpleTimingPort::processSendEvent()
{ {
assert(port->transmitList.size()); assert(transmitList.size());
assert(port->transmitList.front().first <= curTick); assert(transmitList.front().tick <= curTick);
if (port->Port::sendTiming(port->transmitList.front().second)) { if (Port::sendTiming(transmitList.front().pkt)) {
//send successful, remove packet //send successful, remove packet
port->transmitList.pop_front(); transmitList.pop_front();
if (!port->transmitList.empty()) { if (!transmitList.empty()) {
Tick time = port->transmitList.front().first; Tick time = transmitList.front().tick;
schedule(time <= curTick ? curTick+1 : time); sendEvent->schedule(time <= curTick ? curTick+1 : time);
} }
if (port->transmitList.empty() && port->drainEvent) { if (transmitList.empty() && drainEvent) {
port->drainEvent->process(); drainEvent->process();
port->drainEvent = NULL; drainEvent = NULL;
} }
return; return;
} }

View file

@ -58,9 +58,26 @@
class SimpleTimingPort : public Port class SimpleTimingPort : public Port
{ {
protected: protected:
/** A deferred packet, buffered to transmit later. */
class DeferredPacket {
public:
Tick tick; ///< The tick when the packet is ready to transmit
PacketPtr pkt; ///< Pointer to the packet to transmit
DeferredPacket(Tick t, PacketPtr p)
: tick(t), pkt(p)
{}
};
typedef std::list<DeferredPacket> DeferredPacketList;
typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
/** A list of outgoing timing response packets that haven't been /** A list of outgoing timing response packets that haven't been
* serviced yet. */ * serviced yet. */
std::list<std::pair<Tick,PacketPtr> > transmitList; DeferredPacketList transmitList;
/** This function attempts to send deferred packets. Scheduled to
* be called in the future via SendEvent. */
void processSendEvent();
/** /**
* This class is used to implemented sendTiming() with a delay. When * This class is used to implemented sendTiming() with a delay. When
@ -68,27 +85,19 @@ class SimpleTimingPort : public Port
* When the event time expires it attempts to send the packet. * When the event time expires it attempts to send the packet.
* If it cannot, the packet sent when recvRetry() is called. * If it cannot, the packet sent when recvRetry() is called.
**/ **/
class SendEvent : public Event typedef EventWrapper<SimpleTimingPort, &SimpleTimingPort::processSendEvent>
{ SendEvent;
SimpleTimingPort *port;
public: Event *sendEvent;
SendEvent(SimpleTimingPort *p)
: Event(&mainEventQueue), port(p)
{ }
virtual void process();
virtual const char *description()
{ return "Future scheduled sendTiming event"; }
};
SendEvent sendEvent;
/** If we need to drain, keep the drain event around until we're done /** If we need to drain, keep the drain event around until we're done
* here.*/ * here.*/
Event *drainEvent; Event *drainEvent;
/** Check the list of buffered packets against the supplied
* functional request. */
void checkFunctional(PacketPtr funcPkt);
/** Schedule a sendTiming() event to be called in the future. /** Schedule a sendTiming() event to be called in the future.
* @param pkt packet to send * @param pkt packet to send
* @param time increment from now (in ticks) to send packet * @param time increment from now (in ticks) to send packet
@ -115,9 +124,13 @@ class SimpleTimingPort : public Port
public: public:
SimpleTimingPort(std::string pname, MemObject *_owner = NULL) SimpleTimingPort(std::string pname, MemObject *_owner = NULL)
: Port(pname, _owner), sendEvent(this), drainEvent(NULL) : Port(pname, _owner),
sendEvent(new SendEvent(this)),
drainEvent(NULL)
{} {}
~SimpleTimingPort() { delete sendEvent; }
/** Hook for draining timing accesses from the system. The /** Hook for draining timing accesses from the system. The
* associated SimObject's drain() functions should be implemented * associated SimObject's drain() functions should be implemented
* something like this when this class is used: * something like this when this class is used: