Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/30296 )

Change subject: mem: Use the new unbound port reporting mechanism in the mem ports.
......................................................................

mem: Use the new unbound port reporting mechanism in the mem ports.

There was an add-hoc check added to getAddrRanges, but the other methods
would just segfault if they tried to talk to their peers. This change
wraps all the calls in try blocks and catches the exception which the
peer will throw if it's the default and the port is not actually
connected to anything.

Change-Id: Ie46be0230f33f74305c599b251ca319a65ba008d
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/30296
Reviewed-by: Nikos Nikoleris <nikos.nikole...@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikole...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/mem/port.cc
M src/mem/port.hh
2 files changed, 137 insertions(+), 32 deletions(-)

Approvals:
  Nikos Nikoleris: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/mem/port.cc b/src/mem/port.cc
index 883b592..47e94f4 100644
--- a/src/mem/port.cc
+++ b/src/mem/port.cc
@@ -47,11 +47,72 @@
 #include "base/trace.hh"
 #include "sim/sim_object.hh"

+namespace
+{
+
+class DefaultMasterPort : public MasterPort
+{
+  protected:
+    [[noreturn]] void
+    blowUp() const
+    {
+        throw UnboundPortException();
+    }
+
+  public:
+    DefaultMasterPort() : MasterPort("default_master_port", nullptr) {}
+
+    // Atomic protocol.
+    Tick recvAtomicSnoop(PacketPtr) override { blowUp(); }
+
+    // Timing protocol.
+    bool recvTimingResp(PacketPtr) override { blowUp(); }
+    void recvTimingSnoopReq(PacketPtr) override { blowUp(); }
+    void recvReqRetry() override { blowUp(); }
+    void recvRetrySnoopResp() override { blowUp(); }
+
+    // Functional protocol.
+    void recvFunctionalSnoop(PacketPtr) override { blowUp(); }
+};
+
+class DefaultSlavePort : public SlavePort
+{
+  protected:
+    [[noreturn]] void
+    blowUp() const
+    {
+        throw UnboundPortException();
+    }
+
+  public:
+    DefaultSlavePort() : SlavePort("default_slave_port", nullptr) {}
+
+    // Atomic protocol.
+    Tick recvAtomic(PacketPtr) override { blowUp(); }
+
+    // Timing protocol.
+    bool recvTimingReq(PacketPtr) override { blowUp(); }
+    bool tryTiming(PacketPtr) override { blowUp(); }
+    bool recvTimingSnoopResp(PacketPtr) override { blowUp(); }
+    void recvRespRetry() override { blowUp(); }
+
+    // Functional protocol.
+    void recvFunctional(PacketPtr) override { blowUp(); }
+
+    // General.
+ AddrRangeList getAddrRanges() const override { return AddrRangeList(); }
+};
+
+DefaultMasterPort defaultMasterPort;
+DefaultSlavePort defaultSlavePort;
+
+} // anonymous namespace
+
 /**
  * Master port
  */
MasterPort::MasterPort(const std::string& name, SimObject* _owner, PortID _id)
-    : Port(name, _id), _slavePort(NULL), owner(*_owner)
+    : Port(name, _id), _slavePort(&defaultSlavePort), owner(*_owner)
 {
 }

@@ -63,10 +124,8 @@
 MasterPort::bind(Port &peer)
 {
     auto *slave_port = dynamic_cast<SlavePort *>(&peer);
-    if (!slave_port) {
-        fatal("Attempt to bind port %s to non-slave port %s.",
-                name(), peer.name());
-    }
+    fatal_if(!slave_port, "Can't bind port %s to non-slave port %s.",
+             name(), peer.name());
     // master port keeps track of the slave port
     _slavePort = slave_port;
     Port::bind(peer);
@@ -77,11 +136,10 @@
 void
 MasterPort::unbind()
 {
-    if (_slavePort == NULL)
- panic("Attempting to unbind master port %s that is not connected\n",
-              name());
+ panic_if(!isConnected(), "Can't unbind master port %s which is not bound.",
+             name());
     _slavePort->slaveUnbind();
-    _slavePort = nullptr;
+    _slavePort = &defaultSlavePort;
     Port::unbind();
 }

@@ -108,8 +166,8 @@
  * Slave port
  */
 SlavePort::SlavePort(const std::string& name, SimObject* _owner, PortID id)
-    : Port(name, id), _masterPort(NULL), defaultBackdoorWarned(false),
-    owner(*_owner)
+    : Port(name, id), _masterPort(&defaultMasterPort),
+    defaultBackdoorWarned(false), owner(*_owner)
 {
 }

@@ -120,7 +178,7 @@
 void
 SlavePort::slaveUnbind()
 {
-    _masterPort = NULL;
+    _masterPort = &defaultMasterPort;
     Port::unbind();
 }

diff --git a/src/mem/port.hh b/src/mem/port.hh
index d84e46f..eadf7f4 100644
--- a/src/mem/port.hh
+++ b/src/mem/port.hh
@@ -258,6 +258,7 @@

   private:
     MasterPort* _masterPort;
+
     bool defaultBackdoorWarned;

   protected:
@@ -278,13 +279,7 @@
     /**
      * Called by the owner to send a range change
      */
-    void
-    sendRangeChange() const
-    {
-        fatal_if(!_masterPort,
- "%s cannot sendRangeChange() without master port.", name());
-        _masterPort->recvRangeChange();
-    }
+    void sendRangeChange() const { _masterPort->recvRangeChange(); }

     /**
      * Get a list of the non-overlapping address ranges the owner is
@@ -316,7 +311,11 @@
     Tick
     sendAtomicSnoop(PacketPtr pkt)
     {
-        return AtomicResponseProtocol::sendSnoop(_masterPort, pkt);
+        try {
+            return AtomicResponseProtocol::sendSnoop(_masterPort, pkt);
+        } catch (UnboundPortException) {
+            reportUnbound();
+        }
     }

   public:
@@ -332,7 +331,11 @@
     void
     sendFunctionalSnoop(PacketPtr pkt) const
     {
-        FunctionalResponseProtocol::sendSnoop(_masterPort, pkt);
+        try {
+            FunctionalResponseProtocol::sendSnoop(_masterPort, pkt);
+        } catch (UnboundPortException) {
+            reportUnbound();
+        }
     }

   public:
@@ -352,7 +355,11 @@
     bool
     sendTimingResp(PacketPtr pkt)
     {
-        return TimingResponseProtocol::sendResp(_masterPort, pkt);
+        try {
+            return TimingResponseProtocol::sendResp(_masterPort, pkt);
+        } catch (UnboundPortException) {
+            reportUnbound();
+        }
     }

     /**
@@ -365,7 +372,11 @@
     void
     sendTimingSnoopReq(PacketPtr pkt)
     {
-        TimingResponseProtocol::sendSnoopReq(_masterPort, pkt);
+        try {
+            TimingResponseProtocol::sendSnoopReq(_masterPort, pkt);
+        } catch (UnboundPortException) {
+            reportUnbound();
+        }
     }

     /**
@@ -375,7 +386,11 @@
     void
     sendRetryReq()
     {
-        TimingResponseProtocol::sendRetryReq(_masterPort);
+        try {
+            TimingResponseProtocol::sendRetryReq(_masterPort);
+        } catch (UnboundPortException) {
+            reportUnbound();
+        }
     }

     /**
@@ -385,7 +400,11 @@
     void
     sendRetrySnoopResp()
     {
-        TimingResponseProtocol::sendRetrySnoopResp(_masterPort);
+        try {
+            TimingResponseProtocol::sendRetrySnoopResp(_masterPort);
+        } catch (UnboundPortException) {
+            reportUnbound();
+        }
     }

   protected:
@@ -422,43 +441,71 @@
 inline Tick
 MasterPort::sendAtomic(PacketPtr pkt)
 {
-    return AtomicRequestProtocol::send(_slavePort, pkt);
+    try {
+        return AtomicRequestProtocol::send(_slavePort, pkt);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 inline Tick
 MasterPort::sendAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
 {
-    return AtomicRequestProtocol::sendBackdoor(_slavePort, pkt, backdoor);
+    try {
+ return AtomicRequestProtocol::sendBackdoor(_slavePort, pkt, backdoor);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 inline void
 MasterPort::sendFunctional(PacketPtr pkt) const
 {
-    return FunctionalRequestProtocol::send(_slavePort, pkt);
+    try {
+        return FunctionalRequestProtocol::send(_slavePort, pkt);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 inline bool
 MasterPort::sendTimingReq(PacketPtr pkt)
 {
-    return TimingRequestProtocol::sendReq(_slavePort, pkt);
+    try {
+        return TimingRequestProtocol::sendReq(_slavePort, pkt);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 inline bool
 MasterPort::tryTiming(PacketPtr pkt) const
 {
-    return TimingRequestProtocol::trySend(_slavePort, pkt);
+    try {
+        return TimingRequestProtocol::trySend(_slavePort, pkt);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 inline bool
 MasterPort::sendTimingSnoopResp(PacketPtr pkt)
 {
-    return TimingRequestProtocol::sendSnoopResp(_slavePort, pkt);
+    try {
+        return TimingRequestProtocol::sendSnoopResp(_slavePort, pkt);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 inline void
 MasterPort::sendRetryResp()
 {
-    TimingRequestProtocol::sendRetryResp(_slavePort);
+    try {
+        TimingRequestProtocol::sendRetryResp(_slavePort);
+    } catch (UnboundPortException) {
+        reportUnbound();
+    }
 }

 #endif //__MEM_PORT_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/30296
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ie46be0230f33f74305c599b251ca319a65ba008d
Gerrit-Change-Number: 30296
Gerrit-PatchSet: 2
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Matthew Poremba <matthew.pore...@amd.com>
Gerrit-Reviewer: Nikos Nikoleris <nikos.nikole...@arm.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to