mem-garnet: Use static allocation in OutputUnit
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Tue, 7 Jan 2020 22:44:08 +0000 (23:44 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 16 Mar 2020 22:23:16 +0000 (22:23 +0000)
Use static allocation for the pointers created by OutputUnit.

Change-Id: Ica4fd5d4994078764769702311520c9daf8dba72
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24243
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/ruby/network/garnet2.0/OutputUnit.cc
src/mem/ruby/network/garnet2.0/OutputUnit.hh

index bdb9f9a71035fae382783730bbb1c4ae15652c2e..2270feaf345e9c9f95f6ccf8d50c593a0b4997ed 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * Copyright (c) 2008 Princeton University
+ * Copyright (c) 2020 Inria
  * Copyright (c) 2016 Georgia Institute of Technology
+ * Copyright (c) 2008 Princeton University
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include "mem/ruby/network/garnet2.0/OutputUnit.hh"
 
-#include "base/stl_helpers.hh"
 #include "debug/RubyNetwork.hh"
 #include "mem/ruby/network/garnet2.0/Credit.hh"
+#include "mem/ruby/network/garnet2.0/CreditLink.hh"
 #include "mem/ruby/network/garnet2.0/Router.hh"
-
-using namespace std;
-using m5::stl_helpers::deletePointers;
+#include "mem/ruby/network/garnet2.0/flitBuffer.hh"
 
 OutputUnit::OutputUnit(int id, PortDirection direction, Router *router)
-    : Consumer(router)
+  : Consumer(router), m_router(router), m_id(id), m_direction(direction),
+    m_vc_per_vnet(m_router->get_vc_per_vnet())
 {
-    m_id = id;
-    m_direction = direction;
-    m_router = router;
-    m_num_vcs = m_router->get_num_vcs();
-    m_vc_per_vnet = m_router->get_vc_per_vnet();
-    m_out_buffer = new flitBuffer();
-
+    const int m_num_vcs = m_router->get_num_vcs();
+    outVcState.reserve(m_num_vcs);
     for (int i = 0; i < m_num_vcs; i++) {
-        m_outvc_state.push_back(new OutVcState(i, m_router->get_net_ptr()));
+        outVcState.emplace_back(i, m_router->get_net_ptr());
     }
 }
 
-OutputUnit::~OutputUnit()
-{
-    delete m_out_buffer;
-    deletePointers(m_outvc_state);
-}
-
 void
 OutputUnit::decrement_credit(int out_vc)
 {
@@ -66,7 +55,7 @@ OutputUnit::decrement_credit(int out_vc)
             "outvc %d at time: %lld\n",
             m_router->get_id(), m_id, out_vc, m_router->curCycle());
 
-    m_outvc_state[out_vc]->decrement_credit();
+    outVcState[out_vc].decrement_credit();
 }
 
 void
@@ -76,7 +65,7 @@ OutputUnit::increment_credit(int out_vc)
             "outvc %d at time: %lld\n",
             m_router->get_id(), m_id, out_vc, m_router->curCycle());
 
-    m_outvc_state[out_vc]->increment_credit();
+    outVcState[out_vc].increment_credit();
 }
 
 // Check if the output VC (i.e., input VC at next router)
@@ -85,8 +74,8 @@ OutputUnit::increment_credit(int out_vc)
 bool
 OutputUnit::has_credit(int out_vc)
 {
-    assert(m_outvc_state[out_vc]->isInState(ACTIVE_, m_router->curCycle()));
-    return m_outvc_state[out_vc]->has_credit();
+    assert(outVcState[out_vc].isInState(ACTIVE_, m_router->curCycle()));
+    return outVcState[out_vc].has_credit();
 }
 
 
@@ -110,7 +99,7 @@ OutputUnit::select_free_vc(int vnet)
     int vc_base = vnet*m_vc_per_vnet;
     for (int vc = vc_base; vc < vc_base + m_vc_per_vnet; vc++) {
         if (is_vc_idle(vc, m_router->curCycle())) {
-            m_outvc_state[vc]->setState(ACTIVE_, m_router->curCycle());
+            outVcState[vc].setState(ACTIVE_, m_router->curCycle());
             return vc;
         }
     }
@@ -143,7 +132,7 @@ OutputUnit::wakeup()
 flitBuffer*
 OutputUnit::getOutQueue()
 {
-    return m_out_buffer;
+    return &outBuffer;
 }
 
 void
@@ -158,8 +147,15 @@ OutputUnit::set_credit_link(CreditLink *credit_link)
     m_credit_link = credit_link;
 }
 
+void
+OutputUnit::insert_flit(flit *t_flit)
+{
+    outBuffer.insert(t_flit);
+    m_out_link->scheduleEventAbsolute(m_router->clockEdge(Cycles(1)));
+}
+
 uint32_t
 OutputUnit::functionalWrite(Packet *pkt)
 {
-    return m_out_buffer->functionalWrite(pkt);
+    return outBuffer.functionalWrite(pkt);
 }
index a10539cf947d9a6552d34b0bf61520fd22f64d62..c720888c126304aec566f00b27e2083af7869645 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * Copyright (c) 2008 Princeton University
+ * Copyright (c) 2020 Inria
  * Copyright (c) 2016 Georgia Institute of Technology
+ * Copyright (c) 2008 Princeton University
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include "mem/ruby/common/Consumer.hh"
 #include "mem/ruby/network/garnet2.0/CommonTypes.hh"
-#include "mem/ruby/network/garnet2.0/CreditLink.hh"
 #include "mem/ruby/network/garnet2.0/NetworkLink.hh"
 #include "mem/ruby/network/garnet2.0/OutVcState.hh"
-#include "mem/ruby/network/garnet2.0/Router.hh"
-#include "mem/ruby/network/garnet2.0/flitBuffer.hh"
+
+class CreditLink;
+class Router;
 
 class OutputUnit : public Consumer
 {
   public:
     OutputUnit(int id, PortDirection direction, Router *router);
-    ~OutputUnit();
+    ~OutputUnit() = default;
     void set_out_link(NetworkLink *link);
     void set_credit_link(CreditLink *credit_link);
     void wakeup();
@@ -63,7 +64,7 @@ class OutputUnit : public Consumer
     int
     get_credit_count(int vc)
     {
-        return m_outvc_state[vc]->get_credit_count();
+        return outVcState[vc].get_credit_count();
     }
 
     inline int
@@ -75,36 +76,31 @@ class OutputUnit : public Consumer
     inline void
     set_vc_state(VC_state_type state, int vc, Cycles curTime)
     {
-      m_outvc_state[vc]->setState(state, curTime);
+      outVcState[vc].setState(state, curTime);
     }
 
     inline bool
     is_vc_idle(int vc, Cycles curTime)
     {
-        return (m_outvc_state[vc]->isInState(IDLE_, curTime));
+        return (outVcState[vc].isInState(IDLE_, curTime));
     }
 
-    inline void
-    insert_flit(flit *t_flit)
-    {
-        m_out_buffer->insert(t_flit);
-        m_out_link->scheduleEventAbsolute(m_router->clockEdge(Cycles(1)));
-    }
+    void insert_flit(flit *t_flit);
 
     uint32_t functionalWrite(Packet *pkt);
 
   private:
+    Router *m_router;
     int m_id;
     PortDirection m_direction;
-    int m_num_vcs;
     int m_vc_per_vnet;
-    Router *m_router;
     NetworkLink *m_out_link;
     CreditLink *m_credit_link;
 
-    flitBuffer *m_out_buffer; // This is for the network link to consume
-    std::vector<OutVcState *> m_outvc_state; // vc state of downstream router
-
+    // This is for the network link to consume
+    flitBuffer outBuffer;
+    // vc state of downstream router
+    std::vector<OutVcState> outVcState;
 };
 
 #endif // __MEM_RUBY_NETWORK_GARNET2_0_OUTPUTUNIT_HH__