Jui-min Lee has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/37075 )

Change subject: systemc: Make tlm/gem5 packet conversion flexible
......................................................................

systemc: Make tlm/gem5 packet conversion flexible

We used to have a hard-coded packet2payload and payload2packet in the
tlm_bridge implementation. However, as the conversion is operated on
generic tlm payload, we're not able to handle information stored in any
user defined SystemC extensions.

In this CL, we add a function to Tlm2Gem5BridgeBase/Gem52TlmBridgeBase
so we're able to register extra conversion steps between tlm payload and
gem5 packet. This decoupled the exact conversion logic and enable
SystemC users to register any necessary steps for their extensions.

Change-Id: I70b3405395fed0f757f0fb7e19136f47d84ac115
---
M src/systemc/tlm_bridge/gem5_to_tlm.cc
M src/systemc/tlm_bridge/gem5_to_tlm.hh
M src/systemc/tlm_bridge/tlm_to_gem5.cc
M src/systemc/tlm_bridge/tlm_to_gem5.hh
4 files changed, 65 insertions(+), 6 deletions(-)



diff --git a/src/systemc/tlm_bridge/gem5_to_tlm.cc b/src/systemc/tlm_bridge/gem5_to_tlm.cc
index ba8f121..511cd0d 100644
--- a/src/systemc/tlm_bridge/gem5_to_tlm.cc
+++ b/src/systemc/tlm_bridge/gem5_to_tlm.cc
@@ -74,11 +74,28 @@
 Gem5SystemC::MemoryManager mm;

 /**
+ * Hold all the callbacks necessary to convert a gem5 packet to tlm payload.
+ */
+std::vector<Gem5ToTlmBridgeBase::ConversionStep> extra_gem5_to_tlm_steps;
+
+/**
+ * Notify the Gem5ToTlm bridge that we need an extra step to properly convert a + * gem5 packet to tlm payload. This can be useful when there exists a SystemC + * extension that requires information in gem5 packet. For example, if a user + * defined a SystemC extension the carries stream_id, the user may add a step
+ * here to read stream_id out and set the extension properly.
+ */
+void Gem5ToTlmBridgeBase::addConversionStep(ConversionStep step)
+{
+    extra_gem5_to_tlm_steps.push_back(step);
+}
+
+/**
  * Convert a gem5 packet to a TLM payload by copying all the relevant
  * information to new tlm payload.
  */
 tlm::tlm_generic_payload *
-packet2payload(PacketPtr packet)
+Gem5ToTlmBridgeBase::packet2payload(PacketPtr packet)
 {
     tlm::tlm_generic_payload *trans = mm.allocate();
     trans->acquire();
@@ -110,6 +127,11 @@
     auto *extension = new Gem5SystemC::Gem5Extension(packet);
     trans->set_auto_extension(extension);

+    // Apply all conversion steps necessary in this specific setup.
+    for (auto& step : extra_gem5_to_tlm_steps) {
+        step(packet, *trans);
+    }
+
     return trans;
 }

diff --git a/src/systemc/tlm_bridge/gem5_to_tlm.hh b/src/systemc/tlm_bridge/gem5_to_tlm.hh
index 2572027..502931f 100644
--- a/src/systemc/tlm_bridge/gem5_to_tlm.hh
+++ b/src/systemc/tlm_bridge/gem5_to_tlm.hh
@@ -59,6 +59,7 @@
 #ifndef __SYSTEMC_TLM_BRIDGE_GEM5_TO_TLM_HH__
 #define __SYSTEMC_TLM_BRIDGE_GEM5_TO_TLM_HH__

+#include <functional>
 #include <string>

 #include "mem/port.hh"
@@ -73,12 +74,18 @@
 namespace sc_gem5
 {

-tlm::tlm_generic_payload *packet2payload(PacketPtr packet);
-
 class Gem5ToTlmBridgeBase : public sc_core::sc_module
 {
   protected:
     using sc_core::sc_module::sc_module;
+
+  public:
+    using ConversionStep =
+ std::function<void(PacketPtr pkt, tlm::tlm_generic_payload &trans)>;
+
+    static void addConversionStep(ConversionStep step);
+
+    static tlm::tlm_generic_payload *packet2payload(PacketPtr packet);
 };

 template <unsigned int BITWIDTH>
diff --git a/src/systemc/tlm_bridge/tlm_to_gem5.cc b/src/systemc/tlm_bridge/tlm_to_gem5.cc
index 0cc0d7f..330d5c9 100644
--- a/src/systemc/tlm_bridge/tlm_to_gem5.cc
+++ b/src/systemc/tlm_bridge/tlm_to_gem5.cc
@@ -66,8 +66,25 @@
 namespace sc_gem5
 {

+/**
+ * Hold all the callbacks necessary to convert a tlm payload to gem5 packet.
+ */
+std::vector<TlmToGem5BridgeBase::ConversionStep> extra_tlm_to_gem5_steps;
+
+/**
+ * Notify the Tlm2Gem5 bridge that we need an extra step to properly convert a + * tlm payload to gem5 packet. This can be useful when there exists a SystemC + * extension that carries extra information. For example, SystemC user might + * define an extension to store stream_id, the user may then add an extra step
+ * to set the generated request's stream_id accordingly.
+ */
+void TlmToGem5BridgeBase::addConversionStep(ConversionStep step)
+{
+    extra_tlm_to_gem5_steps.push_back(step);
+}
+
 PacketPtr
-payload2packet(RequestorID _id, tlm::tlm_generic_payload &trans)
+TlmToGem5BridgeBase::payload2packet(RequestorID _id, tlm::tlm_generic_payload &trans)
 {
     MemCmd cmd;

@@ -96,6 +113,11 @@
     auto pkt = new Packet(req, cmd);
     pkt->dataStatic(trans.get_data_ptr());

+    // Apply all conversion steps necessary in this specific setup.
+    for (auto& step : extra_tlm_to_gem5_steps) {
+        step(pkt, trans);
+    }
+
     return pkt;
 }

diff --git a/src/systemc/tlm_bridge/tlm_to_gem5.hh b/src/systemc/tlm_bridge/tlm_to_gem5.hh
index 279f76d..b280515 100644
--- a/src/systemc/tlm_bridge/tlm_to_gem5.hh
+++ b/src/systemc/tlm_bridge/tlm_to_gem5.hh
@@ -58,6 +58,8 @@
 #ifndef __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__
 #define __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__

+#include <functional>
+
 #include "mem/port.hh"
 #include "params/TlmToGem5BridgeBase.hh"
 #include "systemc/ext/core/sc_module.hh"
@@ -75,9 +77,15 @@
 {
   protected:
     using sc_core::sc_module::sc_module;
-};

-PacketPtr payload2packet(tlm::tlm_generic_payload &trans);
+  public:
+    using ConversionStep =
+ std::function<void(PacketPtr pkt, tlm::tlm_generic_payload &trans)>;
+
+    static void addConversionStep(ConversionStep step);
+
+ static PacketPtr payload2packet(RequestorID _id, tlm::tlm_generic_payload &trans);
+};

 template <unsigned int BITWIDTH>
 class TlmToGem5Bridge : public TlmToGem5BridgeBase

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/37075
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: I70b3405395fed0f757f0fb7e19136f47d84ac115
Gerrit-Change-Number: 37075
Gerrit-PatchSet: 1
Gerrit-Owner: Jui-min Lee <f...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
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