Only issue responses if we aren;t already blocked
[gem5.git] / src / mem / bus.cc
index 66cd581e7fbdf0f0ccefd48995eecc0b0725d5d8..03c1a42094bbe08692979e4558d224f2ac1a0010 100644 (file)
@@ -61,20 +61,18 @@ Bus::getPort(const std::string &if_name, int idx)
 void
 Bus::init()
 {
-    std::vector<Port*>::iterator intIter;
+    std::vector<BusPort*>::iterator intIter;
 
     for (intIter = interfaces.begin(); intIter != interfaces.end(); intIter++)
         (*intIter)->sendStatusChange(Port::RangeChange);
 }
 
 Bus::BusFreeEvent::BusFreeEvent(Bus *_bus) : Event(&mainEventQueue), bus(_bus)
-{
-    assert(!scheduled());
-}
+{}
 
 void Bus::BusFreeEvent::process()
 {
-    bus->recvRetry(0);
+    bus->recvRetry(-1);
 }
 
 const char * Bus::BusFreeEvent::description()
@@ -82,51 +80,8 @@ const char * Bus::BusFreeEvent::description()
     return "bus became available";
 }
 
-/** Function called by the port when the bus is receiving a Timing
- * transaction.*/
-bool
-Bus::recvTiming(Packet *pkt)
+void Bus::occupyBus(PacketPtr pkt)
 {
-    Port *port;
-    DPRINTF(Bus, "recvTiming: packet src %d dest %d addr 0x%x cmd %s\n",
-            pkt->getSrc(), pkt->getDest(), pkt->getAddr(), pkt->cmdString());
-
-    Port *pktPort = interfaces[pkt->getSrc()];
-
-    // If the bus is busy, or other devices are in line ahead of the current
-    // one, put this device on the retry list.
-    if (tickNextIdle > curTick ||
-            (retryList.size() && pktPort != retryingPort)) {
-        addToRetryList(pktPort);
-        return false;
-    }
-
-    short dest = pkt->getDest();
-    if (dest == Packet::Broadcast) {
-        if (timingSnoop(pkt)) {
-            pkt->flags |= SNOOP_COMMIT;
-            bool success = timingSnoop(pkt);
-            assert(success);
-            if (pkt->flags & SATISFIED) {
-                //Cache-Cache transfer occuring
-                if (retryingPort) {
-                    retryList.pop_front();
-                    retryingPort = NULL;
-                }
-                return true;
-            }
-            port = findPort(pkt->getAddr(), pkt->getSrc());
-        } else {
-            //Snoop didn't succeed
-            addToRetryList(pktPort);
-            return false;
-        }
-    } else {
-        assert(dest >= 0 && dest < interfaces.size());
-        assert(dest != pkt->getSrc()); // catch infinite loops
-        port = interfaces[dest];
-    }
-
     //Bring tickNextIdle up to the present tick
     //There is some potential ambiguity where a cycle starts, which might make
     //a difference when devices are acting right around a cycle boundary. Using
@@ -178,18 +133,71 @@ Bus::recvTiming(Packet *pkt)
 
     // The bus will become idle once the current packet is delivered.
     pkt->finishTime = tickNextIdle;
+}
+
+/** Function called by the port when the bus is receiving a Timing
+ * transaction.*/
+bool
+Bus::recvTiming(Packet *pkt)
+{
+    Port *port;
+    DPRINTF(Bus, "recvTiming: packet src %d dest %d addr 0x%x cmd %s\n",
+            pkt->getSrc(), pkt->getDest(), pkt->getAddr(), pkt->cmdString());
+
+    BusPort *pktPort = interfaces[pkt->getSrc()];
+
+    // If the bus is busy, or other devices are in line ahead of the current
+    // one, put this device on the retry list.
+    if (tickNextIdle > curTick ||
+            (retryList.size() && (!inRetry || pktPort != retryList.front()))) {
+        addToRetryList(pktPort);
+        return false;
+    }
+
+    short dest = pkt->getDest();
+    if (dest == Packet::Broadcast) {
+        if (timingSnoop(pkt)) {
+            pkt->flags |= SNOOP_COMMIT;
+            bool success = timingSnoop(pkt);
+            assert(success);
+            if (pkt->flags & SATISFIED) {
+                //Cache-Cache transfer occuring
+                if (inRetry) {
+                    retryList.front()->onRetryList(false);
+                    retryList.pop_front();
+                    inRetry = false;
+                }
+                occupyBus(pkt);
+                return true;
+            }
+            port = findPort(pkt->getAddr(), pkt->getSrc());
+        } else {
+            //Snoop didn't succeed
+            addToRetryList(pktPort);
+            return false;
+        }
+    } else {
+        assert(dest >= 0 && dest < interfaces.size());
+        assert(dest != pkt->getSrc()); // catch infinite loops
+        port = interfaces[dest];
+    }
+
+    occupyBus(pkt);
 
     if (port->sendTiming(pkt))  {
         // Packet was successfully sent. Return true.
         // Also take care of retries
-        if (retryingPort) {
+        if (inRetry) {
+            DPRINTF(Bus, "Remove retry from list %i\n", retryList.front());
+            retryList.front()->onRetryList(false);
             retryList.pop_front();
-            retryingPort = NULL;
+            inRetry = false;
         }
         return true;
     }
 
     // Packet not successfully sent. Leave or put it on the retry list.
+    DPRINTF(Bus, "Adding a retry to RETRY list %i\n", pktPort);
     addToRetryList(pktPort);
     return false;
 }
@@ -197,16 +205,18 @@ Bus::recvTiming(Packet *pkt)
 void
 Bus::recvRetry(int id)
 {
+    DPRINTF(Bus, "Received a retry\n");
     // If there's anything waiting...
     if (retryList.size()) {
-        retryingPort = retryList.front();
-        retryingPort->sendRetry();
-        // If the retryingPort pointer isn't null, sendTiming wasn't called
-        if (retryingPort) {
-            warn("sendRetry didn't call sendTiming\n");
-            retryList.pop_front();
-            retryingPort = NULL;
-        }
+        //retryingPort = retryList.front();
+        inRetry = true;
+        DPRINTF(Bus, "Sending a retry\n");
+        retryList.front()->sendRetry();
+        // If inRetry is still true, sendTiming wasn't called
+        if (inRetry)
+            panic("Port %s didn't call sendTiming in it's recvRetry\n",\
+                    retryList.front()->getPeer()->name());
+        //assert(!inRetry);
     }
 }
 
@@ -260,8 +270,8 @@ Bus::findSnoopPorts(Addr addr, int id)
             //Careful  to not overlap ranges
             //or snoop will be called more than once on the port
             ports.push_back(portSnoopList[i].portId);
-            DPRINTF(Bus, "  found snoop addr %#llx on device%d\n", addr,
-                    portSnoopList[i].portId);
+//            DPRINTF(Bus, "  found snoop addr %#llx on device%d\n", addr,
+//                    portSnoopList[i].portId);
         }
         i++;
     }