cpu, dev, mem: Use the new Port methods.
authorGabe Black <gabeblack@google.com>
Sat, 17 Aug 2019 06:21:56 +0000 (23:21 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 27 Aug 2019 22:18:28 +0000 (22:18 +0000)
Use getPeer, takeOverFrom, and << to simplify the use of ports in some
areas.

Change-Id: Idfbda27411b5d6b742f5e4927894302ea6d6a53d
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20235
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/cpu/base.cc
src/cpu/trace/trace_cpu.cc
src/dev/arm/smmu_v3_slaveifc.cc
src/mem/coherent_xbar.cc
src/mem/mport.cc
src/mem/xbar.cc

index a9f68bb26618a94aaf7ddf0ecb95a3c0c963c41b..5bc3fe7c75b21d3322ffd0b26c4d835fd0418b73 100644 (file)
@@ -628,24 +628,10 @@ BaseCPU::takeOverFrom(BaseCPU *oldCPU)
         Port *new_dtb_port = newTC->getDTBPtr()->getTableWalkerPort();
 
         // Move over any table walker ports if they exist
-        if (new_itb_port) {
-            assert(!new_itb_port->isConnected());
-            assert(old_itb_port);
-            assert(old_itb_port->isConnected());
-            auto &slavePort =
-                dynamic_cast<BaseMasterPort *>(old_itb_port)->getSlavePort();
-            old_itb_port->unbind();
-            new_itb_port->bind(slavePort);
-        }
-        if (new_dtb_port) {
-            assert(!new_dtb_port->isConnected());
-            assert(old_dtb_port);
-            assert(old_dtb_port->isConnected());
-            auto &slavePort =
-                dynamic_cast<BaseMasterPort *>(old_dtb_port)->getSlavePort();
-            old_dtb_port->unbind();
-            new_dtb_port->bind(slavePort);
-        }
+        if (new_itb_port)
+            new_itb_port->takeOverFrom(old_itb_port);
+        if (new_dtb_port)
+            new_dtb_port->takeOverFrom(old_dtb_port);
         newTC->getITBPtr()->takeOverFrom(oldTC->getITBPtr());
         newTC->getDTBPtr()->takeOverFrom(oldTC->getDTBPtr());
 
@@ -667,26 +653,10 @@ BaseCPU::takeOverFrom(BaseCPU *oldCPU)
             newChecker->getDTBPtr()->takeOverFrom(oldChecker->getDTBPtr());
 
             // Move over any table walker ports if they exist for checker
-            if (new_checker_itb_port) {
-                assert(!new_checker_itb_port->isConnected());
-                assert(old_checker_itb_port);
-                assert(old_checker_itb_port->isConnected());
-                auto &slavePort =
-                    dynamic_cast<BaseMasterPort *>(old_checker_itb_port)->
-                    getSlavePort();
-                old_checker_itb_port->unbind();
-                new_checker_itb_port->bind(slavePort);
-            }
-            if (new_checker_dtb_port) {
-                assert(!new_checker_dtb_port->isConnected());
-                assert(old_checker_dtb_port);
-                assert(old_checker_dtb_port->isConnected());
-                auto &slavePort =
-                    dynamic_cast<BaseMasterPort *>(old_checker_dtb_port)->
-                    getSlavePort();
-                old_checker_dtb_port->unbind();
-                new_checker_dtb_port->bind(slavePort);
-            }
+            if (new_checker_itb_port)
+                new_checker_itb_port->takeOverFrom(old_checker_itb_port);
+            if (new_checker_dtb_port)
+                new_checker_dtb_port->takeOverFrom(old_checker_dtb_port);
         }
     }
 
@@ -708,19 +678,8 @@ BaseCPU::takeOverFrom(BaseCPU *oldCPU)
     // ports are dangling while the old CPU has its ports connected
     // already. Unbind the old CPU and then bind the ports of the one
     // we are switching to.
-    assert(!getInstPort().isConnected());
-    assert(oldCPU->getInstPort().isConnected());
-    auto &inst_peer_port =
-        dynamic_cast<BaseMasterPort &>(oldCPU->getInstPort()).getSlavePort();
-    oldCPU->getInstPort().unbind();
-    getInstPort().bind(inst_peer_port);
-
-    assert(!getDataPort().isConnected());
-    assert(oldCPU->getDataPort().isConnected());
-    auto &data_peer_port =
-        dynamic_cast<BaseMasterPort &>(oldCPU->getDataPort()).getSlavePort();
-    oldCPU->getDataPort().unbind();
-    getDataPort().bind(data_peer_port);
+    getInstPort().takeOverFrom(&oldCPU->getInstPort());
+    getDataPort().takeOverFrom(&oldCPU->getDataPort());
 }
 
 void
index 6e499dbaccc0198e87e082054352b5fd799c8364..2d26ed0627d306ff7599d0bf1b66a861d37278c0 100644 (file)
@@ -106,17 +106,8 @@ void
 TraceCPU::takeOverFrom(BaseCPU *oldCPU)
 {
     // Unbind the ports of the old CPU and bind the ports of the TraceCPU.
-    assert(!getInstPort().isConnected());
-    assert(oldCPU->getInstPort().isConnected());
-    Port &inst_peer_port = oldCPU->getInstPort().getSlavePort();
-    oldCPU->getInstPort().unbind();
-    getInstPort().bind(inst_peer_port);
-
-    assert(!getDataPort().isConnected());
-    assert(oldCPU->getDataPort().isConnected());
-    Port &data_peer_port = oldCPU->getDataPort().getSlavePort();
-    oldCPU->getDataPort().unbind();
-    getDataPort().bind(data_peer_port);
+    getInstPort().takeOverFrom(&oldCPU->getInstPort());
+    getDataPort().takeOverFrom(&oldCPU->getDataPort());
 }
 
 void
index 0a53ed0ba4f9c4775daddce9ccb760e6d8ae9929..fec480da2e4b741f9c15cf24cae94fd81d9ced4d 100644 (file)
@@ -80,8 +80,7 @@ void
 SMMUv3SlaveInterface::sendRange()
 {
     if (slavePort->isConnected()) {
-        inform("Slave port is connected to %d\n",
-                slavePort->getMasterPort().name());
+        inform("Slave port is connected to %s\n", slavePort->getPeer());
 
         slavePort->sendRangeChange();
     } else {
@@ -124,8 +123,7 @@ Tick
 SMMUv3SlaveInterface::recvAtomic(PacketPtr pkt)
 {
     DPRINTF(SMMUv3, "[a] req from %s addr=%#x size=%#x\n",
-            slavePort->getMasterPort().name(),
-            pkt->getAddr(), pkt->getSize());
+            slavePort->getPeer(), pkt->getAddr(), pkt->getSize());
 
     std::string proc_name = csprintf("%s.port", name());
     SMMUTranslationProcess proc(proc_name, *smmu, *this);
@@ -141,8 +139,7 @@ bool
 SMMUv3SlaveInterface::recvTimingReq(PacketPtr pkt)
 {
     DPRINTF(SMMUv3, "[t] req from %s addr=%#x size=%#x\n",
-            slavePort->getMasterPort().name(),
-            pkt->getAddr(), pkt->getSize());
+            slavePort->getPeer(), pkt->getAddr(), pkt->getSize());
 
     // @todo: We need to pay for this and not just zero it out
     pkt->headerDelay = pkt->payloadDelay = 0;
index 74c93be0f3ebe9ca95b41d6bf8df89db7bf0984d..a339500a874250da27f8e7efdea46e8bed8def10 100644 (file)
@@ -125,8 +125,7 @@ CoherentXBar::init()
     for (const auto& p: slavePorts) {
         // check if the connected master port is snooping
         if (p->isSnooping()) {
-            DPRINTF(AddrRanges, "Adding snooping master %s\n",
-                    p->getMasterPort().name());
+            DPRINTF(AddrRanges, "Adding snooping master %s\n", p->getPeer());
             snoopPorts.push_back(p);
         }
     }
index 5678f87d79b2b7ce034147010901192073cb9f63..6b5ae774ba969917793917368c81bf78d559f64e 100644 (file)
@@ -49,6 +49,6 @@ MessageSlavePort::recvAtomic(PacketPtr pkt)
         return recvMessage(pkt);
     } else {
         panic("%s received unexpected atomic command %s from %s.\n",
-              name(), pkt->cmd.toString(), getMasterPort().name());
+              name(), pkt->cmd.toString(), getPeer());
     }
 }
index de32c0b32b7ceeac683475c41ec1145496c411a1..16f0e21dd31b78e41dc03c0b69ff333807abfdb7 100644 (file)
@@ -344,7 +344,7 @@ void
 BaseXBar::recvRangeChange(PortID master_port_id)
 {
     DPRINTF(AddrRanges, "Received range change from slave port %s\n",
-            masterPorts[master_port_id]->getSlavePort().name());
+            masterPorts[master_port_id]->getPeer());
 
     // remember that we got a range from this master port and thus the
     // connected slave module
@@ -405,8 +405,8 @@ BaseXBar::recvRangeChange(PortID master_port_id)
                       "%s:\n\t%s\n\t%s\n",
                       name(),
                       r.to_string(),
-                      masterPorts[master_port_id]->getSlavePort().name(),
-                      masterPorts[conflict_id]->getSlavePort().name());
+                      masterPorts[master_port_id]->getPeer(),
+                      masterPorts[conflict_id]->getPeer());
             }
         }
     }
@@ -557,11 +557,11 @@ BaseXBar::regStats()
     // and snoop responses) and what came from the slave and was
     // forwarded to the master (responses and snoop requests)
     for (int i = 0; i < slavePorts.size(); i++) {
-        pktCount.subname(i, slavePorts[i]->getMasterPort().name());
-        pktSize.subname(i, slavePorts[i]->getMasterPort().name());
+        pktCount.subname(i, slavePorts[i]->getPeer().name());
+        pktSize.subname(i, slavePorts[i]->getPeer().name());
         for (int j = 0; j < masterPorts.size(); j++) {
-            pktCount.ysubname(j, masterPorts[j]->getSlavePort().name());
-            pktSize.ysubname(j, masterPorts[j]->getSlavePort().name());
+            pktCount.ysubname(j, masterPorts[j]->getPeer().name());
+            pktSize.ysubname(j, masterPorts[j]->getPeer().name());
         }
     }
 }