From 21e12a0d0eefbf57ff21dd298ef3524b02546932 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Wed, 8 Jan 2020 23:30:13 +0100 Subject: [PATCH] mem-garnet: Use static allocation in Switch Make pointers non pointers when possible. Change-Id: I272387c2ac1fd77deef06feb637127e232910e30 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24250 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- src/mem/ruby/network/simple/Switch.cc | 80 ++++++++++----------------- src/mem/ruby/network/simple/Switch.hh | 17 +++--- 2 files changed, 39 insertions(+), 58 deletions(-) diff --git a/src/mem/ruby/network/simple/Switch.cc b/src/mem/ruby/network/simple/Switch.cc index 7cc635d2a..71b66365c 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& in) { - m_perfect_switch->addInPort(in); + perfectSwitch.addInPort(in); } void @@ -78,36 +68,26 @@ Switch::addOutPort(const vector& out, 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 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 @@ Switch::regStats() { 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 @@ Switch::regStats() .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 @@ Switch::regStats() 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 b481ed53e..5d2690621 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 +#include #include #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& in); @@ -67,8 +69,6 @@ class Switch : public BasicRouter 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 @@ class Switch : public BasicRouter Switch(const Switch& obj); Switch& operator=(const Switch& obj); - PerfectSwitch* m_perfect_switch; + PerfectSwitch perfectSwitch; SimpleNetwork* m_network_ptr; - std::vector m_throttles; - std::vector m_port_buffers; + std::list throttles; + unsigned m_num_connected_buffers; + std::vector m_port_buffers; // Statistical variables Stats::Formula m_avg_utilization; -- 2.30.2