From 7539c69c4e8e130a4e3bd0125d957aee106b0bd5 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Sun, 26 Jan 2020 12:38:54 +0100 Subject: [PATCH] mem-garnet: Use static allocation in CrossbarSwitch There is no need to dynamically allocate these variables. Change-Id: I6efeaffe75f2b4ba706c26d2a12c42c07dc7c7ee Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24983 Reviewed-by: Srikant Bharadwaj Maintainer: Nikos Nikoleris Tested-by: kokoro --- .../ruby/network/garnet2.0/CrossbarSwitch.cc | 25 ++++++++----------- .../ruby/network/garnet2.0/CrossbarSwitch.hh | 14 +++++------ 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/mem/ruby/network/garnet2.0/CrossbarSwitch.cc b/src/mem/ruby/network/garnet2.0/CrossbarSwitch.cc index dba3474b7..eda9e9edb 100644 --- a/src/mem/ruby/network/garnet2.0/CrossbarSwitch.cc +++ b/src/mem/ruby/network/garnet2.0/CrossbarSwitch.cc @@ -36,21 +36,15 @@ #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; diff --git a/src/mem/ruby/network/garnet2.0/CrossbarSwitch.hh b/src/mem/ruby/network/garnet2.0/CrossbarSwitch.hh index 95418d82b..7dee78439 100644 --- a/src/mem/ruby/network/garnet2.0/CrossbarSwitch.hh +++ b/src/mem/ruby/network/garnet2.0/CrossbarSwitch.hh @@ -33,7 +33,6 @@ #define __MEM_RUBY_NETWORK_GARNET2_0_CROSSBARSWITCH_HH__ #include -#include #include #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> m_switch_buffer; + std::vector switchBuffers; }; #endif // __MEM_RUBY_NETWORK_GARNET2_0_CROSSBARSWITCH_HH__ -- 2.30.2