mem-garnet: Use static allocation in CrossbarSwitch
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Sun, 26 Jan 2020 11:38:54 +0000 (12:38 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 16 Mar 2020 22:23:16 +0000 (22:23 +0000)
There is no need to dynamically allocate these variables.

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

index dba3474b7ac86e1cfbc5087e89bcb779e81c9a03..eda9e9edb02f41d8946add9f02e66e1d8e380f40 100644 (file)
 #include "mem/ruby/network/garnet2.0/Router.hh"
 
 CrossbarSwitch::CrossbarSwitch(Router *router)
-    : Consumer(router)
+  : Consumer(router), m_router(router), m_num_vcs(m_router->get_num_vcs()),
+    m_crossbar_activity(0), switchBuffers(0)
 {
-    m_router = router;
-    m_num_vcs = m_router->get_num_vcs();
-    m_crossbar_activity = 0;
 }
 
 void
 CrossbarSwitch::init()
 {
-    m_num_inports = m_router->get_num_inports();
-    m_switch_buffer.resize(m_num_inports);
-    for (int i = 0; i < m_num_inports; i++) {
-        m_switch_buffer[i].reset(new flitBuffer());
-    }
+    switchBuffers.resize(m_router->get_num_inports());
 }
 
 /*
@@ -66,11 +60,12 @@ CrossbarSwitch::wakeup()
             "at time: %lld\n",
             m_router->get_id(), m_router->curCycle());
 
-    for (int inport = 0; inport < m_num_inports; inport++) {
-        if (!m_switch_buffer[inport]->isReady(m_router->curCycle()))
+    for (auto& switch_buffer : switchBuffers) {
+        if (!switch_buffer.isReady(m_router->curCycle())) {
             continue;
+        }
 
-        flit *t_flit = m_switch_buffer[inport]->peekTopFlit();
+        flit *t_flit = switch_buffer.peekTopFlit();
         if (t_flit->is_stage(ST_, m_router->curCycle())) {
             int outport = t_flit->get_outport();
 
@@ -81,7 +76,7 @@ CrossbarSwitch::wakeup()
             // This will take care of waking up the Network Link
             // in the next cycle
             m_router->getOutputUnit(outport)->insert_flit(t_flit);
-            m_switch_buffer[inport]->getTopFlit();
+            switch_buffer.getTopFlit();
             m_crossbar_activity++;
         }
     }
@@ -92,8 +87,8 @@ CrossbarSwitch::functionalWrite(Packet *pkt)
 {
    uint32_t num_functional_writes = 0;
 
-   for (uint32_t i = 0; i < m_switch_buffer.size(); ++i) {
-       num_functional_writes += m_switch_buffer[i]->functionalWrite(pkt);
+   for (auto& switch_buffer : switchBuffers) {
+       num_functional_writes += switch_buffer.functionalWrite(pkt);
    }
 
    return num_functional_writes;
index 95418d82b0aa97b4e92d50ae1a200acc4ba26527..7dee784396118829dcce24ebb4342852c1a9ed6d 100644 (file)
@@ -33,7 +33,6 @@
 #define __MEM_RUBY_NETWORK_GARNET2_0_CROSSBARSWITCH_HH__
 
 #include <iostream>
-#include <memory>
 #include <vector>
 
 #include "mem/ruby/common/Consumer.hh"
@@ -41,7 +40,6 @@
 #include "mem/ruby/network/garnet2.0/flitBuffer.hh"
 
 class Router;
-class OutputUnit;
 
 class CrossbarSwitch : public Consumer
 {
@@ -52,8 +50,11 @@ class CrossbarSwitch : public Consumer
     void init();
     void print(std::ostream& out) const {};
 
-    inline void update_sw_winner(int inport, flit *t_flit)
-    { m_switch_buffer[inport]->insert(t_flit); }
+    inline void
+    update_sw_winner(int inport, flit *t_flit)
+    {
+        switchBuffers[inport].insert(t_flit);
+    }
 
     inline double get_crossbar_activity() { return m_crossbar_activity; }
 
@@ -61,11 +62,10 @@ class CrossbarSwitch : public Consumer
     void resetStats();
 
   private:
+    Router *m_router;
     int m_num_vcs;
-    int m_num_inports;
     double m_crossbar_activity;
-    Router *m_router;
-    std::vector<std::unique_ptr<flitBuffer>> m_switch_buffer;
+    std::vector<flitBuffer> switchBuffers;
 };
 
 #endif // __MEM_RUBY_NETWORK_GARNET2_0_CROSSBARSWITCH_HH__