diff -r 920ca8183398 -r 5fb6386c07b4 src/mem/bus.hh --- a/src/mem/bus.hh Thu Jun 21 16:16:29 2012 +0100 +++ b/src/mem/bus.hh Thu Jun 21 16:17:54 2012 +0100 @@ -87,6 +87,7 @@ * has with one layer per connected slave port provides a full or * partial crossbar, like AXI, OCP, PCIe etc. */ + template class Layer { @@ -129,7 +130,7 @@ * * @return True if the bus layer accepts the packet */ - bool acceptTiming(Port* port); + bool acceptTiming(PORT* port); /** * Deal with a destination port accepting a packet by potentially @@ -148,7 +149,7 @@ * * @param busy_time Time to spend as a result of a failed send */ - void failedTiming(SlavePort* port, Tick busy_time); + void failedTiming(PORT* port, Tick busy_time); /** Occupy the bus layer until until */ void occupyLayer(Tick until); @@ -203,10 +204,10 @@ Event * drainEvent; /** - * An array of pointers to ports that retry should be called + * An array of ports that retry should be called * on because the original send failed for whatever reason. */ - std::list retryList; + std::list retryList; /** * Release the bus layer after being occupied and return to an diff -r 920ca8183398 -r 5fb6386c07b4 src/mem/bus.cc --- a/src/mem/bus.cc Thu Jun 21 16:16:29 2012 +0100 +++ b/src/mem/bus.cc Thu Jun 21 16:17:54 2012 +0100 @@ -136,13 +136,16 @@ return headerTime; } -BaseBus::Layer::Layer(BaseBus& _bus, const std::string& _name, Tick _clock) : +template +BaseBus::Layer::Layer(BaseBus& _bus, const std::string& _name, + Tick _clock) : bus(_bus), _name(_name), state(IDLE), clock(_clock), drainEvent(NULL), releaseEvent(this) { } -void BaseBus::Layer::occupyLayer(Tick until) +template +void BaseBus::Layer::occupyLayer(Tick until) { // ensure the state is busy or in retry and never idle at this // point, as the bus should transition from idle as soon as it has @@ -163,8 +166,9 @@ curTick(), until); } +template bool -BaseBus::Layer::acceptTiming(Port* port) +BaseBus::Layer::acceptTiming(PORT* port) { // first we see if the bus is busy, next we check if we are in a // retry with a port other than the current one @@ -184,8 +188,9 @@ return true; } +template void -BaseBus::Layer::succeededTiming(Tick busy_time) +BaseBus::Layer::succeededTiming(Tick busy_time) { // if a retrying port succeeded, also take it off the retry list if (state == RETRY) { @@ -203,8 +208,9 @@ occupyLayer(busy_time); } +template void -BaseBus::Layer::failedTiming(SlavePort* port, Tick busy_time) +BaseBus::Layer::failedTiming(PORT* port, Tick busy_time) { // if we are not in a retry, i.e. busy (but never idle), or we are // in a retry but not for the current port, then add the port at @@ -221,8 +227,9 @@ occupyLayer(busy_time); } +template void -BaseBus::Layer::releaseLayer() +BaseBus::Layer::releaseLayer() { // releasing the bus means we should now be idle assert(state == BUSY); @@ -246,8 +253,9 @@ } } +template void -BaseBus::Layer::retryWaiting() +BaseBus::Layer::retryWaiting() { // this should never be called with an empty retry list assert(!retryList.empty()); @@ -262,10 +270,7 @@ // note that we might have blocked on the receiving port being // busy (rather than the bus itself) and now call retry before the // destination called retry on the bus - if (dynamic_cast(retryList.front()) != NULL) - (dynamic_cast(retryList.front()))->sendRetry(); - else - (dynamic_cast(retryList.front()))->sendRetry(); + retryList.front()->sendRetry(); // If the bus is still in the retry state, sendTiming wasn't // called in zero time (e.g. the cache does this) @@ -286,8 +291,9 @@ } } +template void -BaseBus::Layer::recvRetry() +BaseBus::Layer::recvRetry() { // we got a retry from a peer that we tried to send something to // and failed, but we sent it on the account of someone else, and @@ -484,9 +490,9 @@ return max_bs; } - +template unsigned int -BaseBus::Layer::drain(Event * de) +BaseBus::Layer::drain(Event * de) { //We should check that we're not "doing" anything, and that noone is //waiting. We might be idle but have someone waiting if the device we @@ -497,3 +503,11 @@ } return 0; } + +/** + * Bus layer template instantiations. Could be removed with _impl.hh + * file, but since there are only two given options (MasterPort and + * SlavePort) it seems a bit excessive at this point. + */ +template class BaseBus::Layer; +template class BaseBus::Layer; diff -r 920ca8183398 -r 5fb6386c07b4 src/mem/coherent_bus.hh --- a/src/mem/coherent_bus.hh Thu Jun 21 16:16:29 2012 +0100 +++ b/src/mem/coherent_bus.hh Thu Jun 21 16:17:54 2012 +0100 @@ -70,9 +70,12 @@ protected: /** - * Declare the single layer of this bus. + * Declare the three layers of this bus, one for requests, one + * for responses, and one for snoop responses */ - Layer layer; + Layer reqLayer; + Layer respLayer; + Layer snoopRespLayer; /** * Declaration of the coherent bus slave port type, one will be diff -r 920ca8183398 -r 5fb6386c07b4 src/mem/coherent_bus.cc --- a/src/mem/coherent_bus.cc Thu Jun 21 16:16:29 2012 +0100 +++ b/src/mem/coherent_bus.cc Thu Jun 21 16:17:54 2012 +0100 @@ -54,7 +54,9 @@ #include "mem/coherent_bus.hh" CoherentBus::CoherentBus(const CoherentBusParams *p) - : BaseBus(p), layer(*this, ".layer", p->clock) + : BaseBus(p), reqLayer(*this, ".reqLayer", p->clock), + respLayer(*this, ".respLayer", p->clock), + snoopRespLayer(*this, ".snoopRespLayer", p->clock) { // create the ports based on the size of the master and slave // vector ports, and the presence of the default port, the ports @@ -115,7 +117,7 @@ // test if the bus should be considered occupied for the current // port, and exclude express snoops from the check - if (!is_express_snoop && !layer.acceptTiming(src_port)) { + if (!is_express_snoop && !reqLayer.acceptTiming(src_port)) { DPRINTF(CoherentBus, "recvTimingReq: src %s %s 0x%x BUSY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); return false; @@ -170,14 +172,14 @@ DPRINTF(CoherentBus, "recvTimingReq: src %s %s 0x%x RETRY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); - layer.failedTiming(src_port, headerFinishTime); + reqLayer.failedTiming(src_port, headerFinishTime); return false; } // update the bus state and schedule an idle even if (!is_express_snoop) - layer.succeededTiming(packetFinishTime); + reqLayer.succeededTiming(packetFinishTime); return true; } @@ -190,7 +192,7 @@ // test if the bus should be considered occupied for the current // port - if (!layer.acceptTiming(src_port)) { + if (!respLayer.acceptTiming(src_port)) { DPRINTF(CoherentBus, "recvTimingResp: src %s %s 0x%x BUSY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); return false; @@ -217,7 +219,7 @@ // deadlock assert(success); - layer.succeededTiming(packetFinishTime); + respLayer.succeededTiming(packetFinishTime); return true; } @@ -254,7 +256,7 @@ // test if the bus should be considered occupied for the current // port - if (!layer.acceptTiming(src_port)) { + if (!snoopRespLayer.acceptTiming(src_port)) { DPRINTF(CoherentBus, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); return false; @@ -305,7 +307,7 @@ assert(success); } - layer.succeededTiming(packetFinishTime); + snoopRespLayer.succeededTiming(packetFinishTime); return true; } @@ -331,8 +333,10 @@ void CoherentBus::recvRetry() { - // only one layer that can deal with it - layer.recvRetry(); + // responses and snoop responses never block on forwarding them, + // so the retry will always be coming from a port to which we + // tried to forward a request + reqLayer.recvRetry(); } Tick @@ -499,8 +503,8 @@ unsigned int CoherentBus::drain(Event *de) { - // only one layer to worry about at the moment - return layer.drain(de); + // sum up the individual layers + return reqLayer.drain(de) + respLayer.drain(de) + snoopRespLayer.drain(de); } CoherentBus * diff -r 920ca8183398 -r 5fb6386c07b4 src/mem/noncoherent_bus.hh --- a/src/mem/noncoherent_bus.hh Thu Jun 21 16:16:29 2012 +0100 +++ b/src/mem/noncoherent_bus.hh Thu Jun 21 16:17:54 2012 +0100 @@ -73,9 +73,11 @@ protected: /** - * Declare the single layer of this bus. + * Declare the two layers of this bus, one for requests and one + * for responses. */ - Layer layer; + Layer reqLayer; + Layer respLayer; /** * Declaration of the non-coherent bus slave port type, one will diff -r 920ca8183398 -r 5fb6386c07b4 src/mem/noncoherent_bus.cc --- a/src/mem/noncoherent_bus.cc Thu Jun 21 16:16:29 2012 +0100 +++ b/src/mem/noncoherent_bus.cc Thu Jun 21 16:17:54 2012 +0100 @@ -55,7 +55,8 @@ #include "mem/noncoherent_bus.hh" NoncoherentBus::NoncoherentBus(const NoncoherentBusParams *p) - : BaseBus(p), layer(*this, ".layer", p->clock) + : BaseBus(p), reqLayer(*this, ".reqLayer", p->clock), + respLayer(*this, ".respLayer", p->clock) { // create the ports based on the size of the master and slave // vector ports, and the presence of the default port, the ports @@ -97,7 +98,7 @@ // test if the bus should be considered occupied for the current // port - if (!layer.acceptTiming(src_port)) { + if (!reqLayer.acceptTiming(src_port)) { DPRINTF(NoncoherentBus, "recvTimingReq: src %s %s 0x%x BUSY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); return false; @@ -123,12 +124,12 @@ DPRINTF(NoncoherentBus, "recvTimingReq: src %s %s 0x%x RETRY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); - layer.failedTiming(src_port, headerFinishTime); + reqLayer.failedTiming(src_port, headerFinishTime); return false; } - layer.succeededTiming(packetFinishTime); + reqLayer.succeededTiming(packetFinishTime); return true; } @@ -141,7 +142,7 @@ // test if the bus should be considered occupied for the current // port - if (!layer.acceptTiming(src_port)) { + if (!respLayer.acceptTiming(src_port)) { DPRINTF(NoncoherentBus, "recvTimingResp: src %s %s 0x%x BUSY\n", src_port->name(), pkt->cmdString(), pkt->getAddr()); return false; @@ -161,7 +162,7 @@ // deadlock assert(success); - layer.succeededTiming(packetFinishTime); + respLayer.succeededTiming(packetFinishTime); return true; } @@ -169,8 +170,10 @@ void NoncoherentBus::recvRetry() { - // only one layer that can deal with it - layer.recvRetry(); + // responses never block on forwarding them, so the retry will + // always be coming from a port to which we tried to forward a + // request + reqLayer.recvRetry(); } Tick @@ -211,8 +214,8 @@ unsigned int NoncoherentBus::drain(Event *de) { - // only one layer to worry about at the moment - return layer.drain(de); + // sum up the individual layers + return reqLayer.drain(de) + respLayer.drain(de); } NoncoherentBus*