Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/24250 )

Change subject: mem-garnet: Use static allocation in Switch
......................................................................

mem-garnet: Use static allocation in Switch

Make pointers non pointers when possible.

Change-Id: I272387c2ac1fd77deef06feb637127e232910e30
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24250
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/ruby/network/simple/Switch.cc
M src/mem/ruby/network/simple/Switch.hh
2 files changed, 39 insertions(+), 58 deletions(-)

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



diff --git a/src/mem/ruby/network/simple/Switch.cc b/src/mem/ruby/network/simple/Switch.cc
index 7cc635d..71b6636 100644
--- a/src/mem/ruby/network/simple/Switch.cc
+++ b/src/mem/ruby/network/simple/Switch.cc
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2020 Inria
  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
  * All rights reserved.
  *
@@ -33,43 +34,32 @@
 #include "base/cast.hh"
 #include "base/stl_helpers.hh"
 #include "mem/ruby/network/MessageBuffer.hh"
-#include "mem/ruby/network/simple/PerfectSwitch.hh"
 #include "mem/ruby/network/simple/SimpleNetwork.hh"
-#include "mem/ruby/network/simple/Throttle.hh"

 using namespace std;
-using m5::stl_helpers::deletePointers;
 using m5::stl_helpers::operator<<;

-Switch::Switch(const Params *p) : BasicRouter(p)
+Switch::Switch(const Params *p)
+  : BasicRouter(p), perfectSwitch(m_id, this, p->virt_nets),
+    m_num_connected_buffers(0)
 {
-    m_perfect_switch = new PerfectSwitch(m_id, this, p->virt_nets);
-    m_port_buffers = p->port_buffers;
-    m_num_connected_buffers = 0;
-}
-
-Switch::~Switch()
-{
-    delete m_perfect_switch;
-
-    // Delete throttles (one per output port)
-    deletePointers(m_throttles);
-
-    // Delete MessageBuffers
-    deletePointers(m_port_buffers);
+    m_port_buffers.reserve(p->port_buffers.size());
+    for (auto& buffer : p->port_buffers) {
+        m_port_buffers.emplace_back(buffer);
+    }
 }

 void
 Switch::init()
 {
     BasicRouter::init();
-    m_perfect_switch->init(m_network_ptr);
+    perfectSwitch.init(m_network_ptr);
 }

 void
 Switch::addInPort(const vector<MessageBuffer*>& in)
 {
-    m_perfect_switch->addInPort(in);
+    perfectSwitch.addInPort(in);
 }

 void
@@ -78,36 +68,26 @@
                    Cycles link_latency, int bw_multiplier)
 {
     // Create a throttle
-    RubySystem *rs = m_network_ptr->params()->ruby_system;
-    Throttle* throttle_ptr = new Throttle(m_id, rs, m_throttles.size(),
-                                          link_latency, bw_multiplier,
- m_network_ptr->getEndpointBandwidth(),
-                                          this);
-
-    m_throttles.push_back(throttle_ptr);
+    throttles.emplace_back(m_id, m_network_ptr->params()->ruby_system,
+        throttles.size(), link_latency, bw_multiplier,
+        m_network_ptr->getEndpointBandwidth(), this);

     // Create one buffer per vnet (these are intermediaryQueues)
     vector<MessageBuffer*> intermediateBuffers;

     for (int i = 0; i < out.size(); ++i) {
         assert(m_num_connected_buffers < m_port_buffers.size());
- MessageBuffer* buffer_ptr = m_port_buffers[m_num_connected_buffers];
+        MessageBuffer* buffer_ptr =
+            m_port_buffers[m_num_connected_buffers];
         m_num_connected_buffers++;
         intermediateBuffers.push_back(buffer_ptr);
     }

     // Hook the queues to the PerfectSwitch
-    m_perfect_switch->addOutPort(intermediateBuffers, routing_table_entry);
+    perfectSwitch.addOutPort(intermediateBuffers, routing_table_entry);

     // Hook the queues to the Throttle
-    throttle_ptr->addLinks(intermediateBuffers, out);
-}
-
-const Throttle*
-Switch::getThrottle(LinkID link_number) const
-{
-    assert(m_throttles[link_number] != NULL);
-    return m_throttles[link_number];
+    throttles.back().addLinks(intermediateBuffers, out);
 }

 void
@@ -115,15 +95,15 @@
 {
     BasicRouter::regStats();

-    for (int link = 0; link < m_throttles.size(); link++) {
-        m_throttles[link]->regStats(name());
+    for (auto& throttle : throttles) {
+        throttle.regStats(name());
     }

     m_avg_utilization.name(name() + ".percent_links_utilized");
-    for (unsigned int i = 0; i < m_throttles.size(); i++) {
-        m_avg_utilization += m_throttles[i]->getUtilization();
+    for (const auto& throttle : throttles) {
+        m_avg_utilization += throttle.getUtilization();
     }
-    m_avg_utilization /= Stats::constant(m_throttles.size());
+    m_avg_utilization /= Stats::constant(throttles.size());

     for (unsigned int type = MessageSizeType_FIRST;
          type < MessageSizeType_NUM; ++type) {
@@ -138,8 +118,8 @@
             .flags(Stats::nozero)
             ;

-        for (unsigned int i = 0; i < m_throttles.size(); i++) {
-            m_msg_counts[type] += m_throttles[i]->getMsgCount(type);
+        for (const auto& throttle : throttles) {
+            m_msg_counts[type] += throttle.getMsgCount(type);
         }
         m_msg_bytes[type] = m_msg_counts[type] * Stats::constant(
                 Network::MessageSizeType_to_int(MessageSizeType(type)));
@@ -149,18 +129,18 @@
 void
 Switch::resetStats()
 {
-    m_perfect_switch->clearStats();
-    for (int i = 0; i < m_throttles.size(); i++) {
-        m_throttles[i]->clearStats();
+    perfectSwitch.clearStats();
+    for (auto& throttle : throttles) {
+        throttle.clearStats();
     }
 }

 void
 Switch::collateStats()
 {
-    m_perfect_switch->collateStats();
-    for (int i = 0; i < m_throttles.size(); i++) {
-        m_throttles[i]->collateStats();
+    perfectSwitch.collateStats();
+    for (auto& throttle : throttles) {
+        throttle.collateStats();
     }
 }

diff --git a/src/mem/ruby/network/simple/Switch.hh b/src/mem/ruby/network/simple/Switch.hh
index b481ed5..5d26906 100644
--- a/src/mem/ruby/network/simple/Switch.hh
+++ b/src/mem/ruby/network/simple/Switch.hh
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2020 Inria
  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
  * All rights reserved.
  *
@@ -40,26 +41,27 @@
 #define __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__

 #include <iostream>
+#include <list>
 #include <vector>

 #include "mem/packet.hh"
 #include "mem/ruby/common/TypeDefines.hh"
 #include "mem/ruby/network/BasicRouter.hh"
+#include "mem/ruby/network/simple/PerfectSwitch.hh"
+#include "mem/ruby/network/simple/Throttle.hh"
 #include "mem/ruby/protocol/MessageSizeType.hh"
 #include "params/Switch.hh"

 class MessageBuffer;
-class PerfectSwitch;
 class NetDest;
 class SimpleNetwork;
-class Throttle;

 class Switch : public BasicRouter
 {
   public:
     typedef SwitchParams Params;
     Switch(const Params *p);
-    ~Switch();
+    ~Switch() = default;
     void init();

     void addInPort(const std::vector<MessageBuffer*>& in);
@@ -67,8 +69,6 @@
                     const NetDest& routing_table_entry,
                     Cycles link_latency, int bw_multiplier);

-    const Throttle* getThrottle(LinkID link_number) const;
-
     void resetStats();
     void collateStats();
     void regStats();
@@ -86,11 +86,12 @@
     Switch(const Switch& obj);
     Switch& operator=(const Switch& obj);

-    PerfectSwitch* m_perfect_switch;
+    PerfectSwitch perfectSwitch;
     SimpleNetwork* m_network_ptr;
-    std::vector<Throttle*> m_throttles;
-    std::vector<MessageBuffer*> m_port_buffers;
+    std::list<Throttle> throttles;
+
     unsigned m_num_connected_buffers;
+    std::vector<MessageBuffer*> m_port_buffers;

     // Statistical variables
     Stats::Formula m_avg_utilization;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/24250
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: I272387c2ac1fd77deef06feb637127e232910e30
Gerrit-Change-Number: 24250
Gerrit-PatchSet: 5
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
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
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to