Network.cc revision 11113
16700Snate@binkert.org/*
26700Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36700Snate@binkert.org * All rights reserved.
46700Snate@binkert.org *
56700Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66700Snate@binkert.org * modification, are permitted provided that the following conditions are
76700Snate@binkert.org * met: redistributions of source code must retain the above copyright
86700Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96700Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106700Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116700Snate@binkert.org * documentation and/or other materials provided with the distribution;
126700Snate@binkert.org * neither the name of the copyright holders nor the names of its
136700Snate@binkert.org * contributors may be used to endorse or promote products derived from
146700Snate@binkert.org * this software without specific prior written permission.
156700Snate@binkert.org *
166700Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176700Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186700Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196700Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206700Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216700Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226700Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236700Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246700Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256700Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266700Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276700Snate@binkert.org */
286285Snate@binkert.org
297805Snilay@cs.wisc.edu#include "base/misc.hh"
309594Snilay@cs.wisc.edu#include "mem/ruby/network/BasicLink.hh"
316285Snate@binkert.org#include "mem/ruby/network/Network.hh"
3211108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh"
336285Snate@binkert.org
349275Snilay@cs.wisc.eduuint32_t Network::m_virtual_networks;
359275Snilay@cs.wisc.eduuint32_t Network::m_control_msg_size;
369275Snilay@cs.wisc.eduuint32_t Network::m_data_msg_size;
379275Snilay@cs.wisc.edu
386876Ssteve.reinhardt@amd.comNetwork::Network(const Params *p)
399465Snilay@cs.wisc.edu    : ClockedObject(p)
406285Snate@binkert.org{
416876Ssteve.reinhardt@amd.com    m_virtual_networks = p->number_of_virtual_networks;
426876Ssteve.reinhardt@amd.com    m_control_msg_size = p->control_msg_size;
436876Ssteve.reinhardt@amd.com
446881SBrad.Beckmann@amd.com    // Total nodes/controllers in network
456881SBrad.Beckmann@amd.com    // Must make sure this is called after the State Machine constructors
467054Snate@binkert.org    m_nodes = MachineType_base_number(MachineType_NUM);
476881SBrad.Beckmann@amd.com    assert(m_nodes != 0);
489594Snilay@cs.wisc.edu    assert(m_virtual_networks != 0);
496881SBrad.Beckmann@amd.com
509594Snilay@cs.wisc.edu    m_topology_ptr = new Topology(p->routers.size(), p->ext_links,
519594Snilay@cs.wisc.edu                                  p->int_links);
5210303Snilay@cs.wisc.edu
5310303Snilay@cs.wisc.edu    // Allocate to and from queues
5410303Snilay@cs.wisc.edu    // Queues that are getting messages from protocol
5510303Snilay@cs.wisc.edu    m_toNetQueues.resize(m_nodes);
5610303Snilay@cs.wisc.edu
5710303Snilay@cs.wisc.edu    // Queues that are feeding the protocol
5810303Snilay@cs.wisc.edu    m_fromNetQueues.resize(m_nodes);
5910303Snilay@cs.wisc.edu
6010303Snilay@cs.wisc.edu    m_ordered.resize(m_virtual_networks);
6111113Sjoe.gross@amd.com    m_vnet_type_names.resize(m_virtual_networks);
6210303Snilay@cs.wisc.edu
6310303Snilay@cs.wisc.edu    for (int i = 0; i < m_virtual_networks; i++) {
6410303Snilay@cs.wisc.edu        m_ordered[i] = false;
6510303Snilay@cs.wisc.edu    }
6610303Snilay@cs.wisc.edu
6710918Sbrandon.potter@amd.com    params()->ruby_system->registerNetwork(this);
686881SBrad.Beckmann@amd.com
696881SBrad.Beckmann@amd.com    // Initialize the controller's network pointers
709594Snilay@cs.wisc.edu    for (std::vector<BasicExtLink*>::const_iterator i = p->ext_links.begin();
719594Snilay@cs.wisc.edu         i != p->ext_links.end(); ++i) {
729594Snilay@cs.wisc.edu        BasicExtLink *ext_link = (*i);
739594Snilay@cs.wisc.edu        AbstractController *abs_cntrl = ext_link->params()->ext_node;
749594Snilay@cs.wisc.edu        abs_cntrl->initNetworkPtr(this);
759594Snilay@cs.wisc.edu    }
769863Snilay@cs.wisc.edu
779863Snilay@cs.wisc.edu    // Register a callback function for combining the statistics
789863Snilay@cs.wisc.edu    Stats::registerDumpCallback(new StatsCallback(this));
7911113Sjoe.gross@amd.com
8011113Sjoe.gross@amd.com    for (auto &it : dynamic_cast<Network *>(this)->params()->ext_links) {
8111113Sjoe.gross@amd.com        it->params()->ext_node->initNetQueues();
8211113Sjoe.gross@amd.com    }
836285Snate@binkert.org}
846285Snate@binkert.org
8510303Snilay@cs.wisc.eduNetwork::~Network()
8610303Snilay@cs.wisc.edu{
8710303Snilay@cs.wisc.edu    for (int node = 0; node < m_nodes; node++) {
8810311Snilay@cs.wisc.edu
8910303Snilay@cs.wisc.edu        // Delete the Message Buffers
9010311Snilay@cs.wisc.edu        for (auto& it : m_toNetQueues[node]) {
9110370Snilay@cs.wisc.edu            delete it;
9210311Snilay@cs.wisc.edu        }
9310311Snilay@cs.wisc.edu
9410311Snilay@cs.wisc.edu        for (auto& it : m_fromNetQueues[node]) {
9510370Snilay@cs.wisc.edu            delete it;
9610303Snilay@cs.wisc.edu        }
9710303Snilay@cs.wisc.edu    }
9810303Snilay@cs.wisc.edu
9910303Snilay@cs.wisc.edu    delete m_topology_ptr;
10010303Snilay@cs.wisc.edu}
10110303Snilay@cs.wisc.edu
1027054Snate@binkert.orgvoid
1037054Snate@binkert.orgNetwork::init()
1046285Snate@binkert.org{
1057054Snate@binkert.org    m_data_msg_size = RubySystem::getBlockSizeBytes() + m_control_msg_size;
1066285Snate@binkert.org}
1076493STushar.Krishna@amd.com
1089275Snilay@cs.wisc.eduuint32_t
1097054Snate@binkert.orgNetwork::MessageSizeType_to_int(MessageSizeType size_type)
1106493STushar.Krishna@amd.com{
1117054Snate@binkert.org    switch(size_type) {
1127054Snate@binkert.org      case MessageSizeType_Control:
1137054Snate@binkert.org      case MessageSizeType_Request_Control:
1147054Snate@binkert.org      case MessageSizeType_Reissue_Control:
1157054Snate@binkert.org      case MessageSizeType_Response_Control:
1167054Snate@binkert.org      case MessageSizeType_Writeback_Control:
1177548SBrad.Beckmann@amd.com      case MessageSizeType_Broadcast_Control:
1187904SBrad.Beckmann@amd.com      case MessageSizeType_Multicast_Control:
1197054Snate@binkert.org      case MessageSizeType_Forwarded_Control:
1207054Snate@binkert.org      case MessageSizeType_Invalidate_Control:
1217054Snate@binkert.org      case MessageSizeType_Unblock_Control:
1227054Snate@binkert.org      case MessageSizeType_Persistent_Control:
1237054Snate@binkert.org      case MessageSizeType_Completion_Control:
1247054Snate@binkert.org        return m_control_msg_size;
1257054Snate@binkert.org      case MessageSizeType_Data:
1267054Snate@binkert.org      case MessageSizeType_Response_Data:
1277054Snate@binkert.org      case MessageSizeType_ResponseLocal_Data:
1287054Snate@binkert.org      case MessageSizeType_ResponseL2hit_Data:
1297054Snate@binkert.org      case MessageSizeType_Writeback_Data:
1307054Snate@binkert.org        return m_data_msg_size;
1317054Snate@binkert.org      default:
1327805Snilay@cs.wisc.edu        panic("Invalid range for type MessageSizeType");
1337054Snate@binkert.org        break;
1347054Snate@binkert.org    }
1356493STushar.Krishna@amd.com}
13611113Sjoe.gross@amd.com
13711113Sjoe.gross@amd.comvoid
13811113Sjoe.gross@amd.comNetwork::checkNetworkAllocation(NodeID id, bool ordered,
13911113Sjoe.gross@amd.com                                        int network_num,
14011113Sjoe.gross@amd.com                                        std::string vnet_type)
14111113Sjoe.gross@amd.com{
14211113Sjoe.gross@amd.com    fatal_if(id >= m_nodes, "Node ID is out of range");
14311113Sjoe.gross@amd.com    fatal_if(network_num >= m_virtual_networks, "Network id is out of range");
14411113Sjoe.gross@amd.com
14511113Sjoe.gross@amd.com    if (ordered) {
14611113Sjoe.gross@amd.com        m_ordered[network_num] = true;
14711113Sjoe.gross@amd.com    }
14811113Sjoe.gross@amd.com
14911113Sjoe.gross@amd.com    m_vnet_type_names[network_num] = vnet_type;
15011113Sjoe.gross@amd.com}
15111113Sjoe.gross@amd.com
15211113Sjoe.gross@amd.com
15311113Sjoe.gross@amd.comvoid
15411113Sjoe.gross@amd.comNetwork::setToNetQueue(NodeID id, bool ordered, int network_num,
15511113Sjoe.gross@amd.com                                 std::string vnet_type, MessageBuffer *b)
15611113Sjoe.gross@amd.com{
15711113Sjoe.gross@amd.com    checkNetworkAllocation(id, ordered, network_num, vnet_type);
15811113Sjoe.gross@amd.com    while (m_toNetQueues[id].size() <= network_num) {
15911113Sjoe.gross@amd.com        m_toNetQueues[id].push_back(nullptr);
16011113Sjoe.gross@amd.com    }
16111113Sjoe.gross@amd.com    m_toNetQueues[id][network_num] = b;
16211113Sjoe.gross@amd.com}
16311113Sjoe.gross@amd.com
16411113Sjoe.gross@amd.comvoid
16511113Sjoe.gross@amd.comNetwork::setFromNetQueue(NodeID id, bool ordered, int network_num,
16611113Sjoe.gross@amd.com                                   std::string vnet_type, MessageBuffer *b)
16711113Sjoe.gross@amd.com{
16811113Sjoe.gross@amd.com    checkNetworkAllocation(id, ordered, network_num, vnet_type);
16911113Sjoe.gross@amd.com    while (m_fromNetQueues[id].size() <= network_num) {
17011113Sjoe.gross@amd.com        m_fromNetQueues[id].push_back(nullptr);
17111113Sjoe.gross@amd.com    }
17211113Sjoe.gross@amd.com    m_fromNetQueues[id][network_num] = b;
17311113Sjoe.gross@amd.com}
174