/*
+ * Copyright (c) 2020 Inria
* Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
* All rights reserved.
*
#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
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
{
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) {
.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)));
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();
}
}
/*
+ * Copyright (c) 2020 Inria
* Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
* All rights reserved.
*
#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);
const NetDest& routing_table_entry,
Cycles link_latency, int bw_multiplier);
- const Throttle* getThrottle(LinkID link_number) const;
-
void resetStats();
void collateStats();
void regStats();
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;