Network.cc revision 10311:ad9c042dce54
12101SN/A/*
22084SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32754Sksewell@umich.edu * All rights reserved.
42754Sksewell@umich.edu *
52754Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
62754Sksewell@umich.edu * modification, are permitted provided that the following conditions are
72754Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
82754Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
92754Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
102754Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
112754Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
122754Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
132754Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
142754Sksewell@umich.edu * this software without specific prior written permission.
152754Sksewell@umich.edu *
162754Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172754Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182754Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192754Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202754Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212754Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222754Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232754Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242754Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252754Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262754Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272754Sksewell@umich.edu */
282754Sksewell@umich.edu
292754Sksewell@umich.edu#include "base/misc.hh"
302754Sksewell@umich.edu#include "mem/ruby/network/BasicLink.hh"
312084SN/A#include "mem/ruby/network/Network.hh"
322084SN/A#include "mem/ruby/system/System.hh"
332084SN/A
342084SN/Auint32_t Network::m_virtual_networks;
352084SN/Auint32_t Network::m_control_msg_size;
362084SN/Auint32_t Network::m_data_msg_size;
372084SN/A
382084SN/ANetwork::Network(const Params *p)
392084SN/A    : ClockedObject(p)
402101SN/A{
412084SN/A    m_virtual_networks = p->number_of_virtual_networks;
422084SN/A    m_control_msg_size = p->control_msg_size;
432084SN/A
442084SN/A    // Total nodes/controllers in network
452084SN/A    // Must make sure this is called after the State Machine constructors
462084SN/A    m_nodes = MachineType_base_number(MachineType_NUM);
472084SN/A    assert(m_nodes != 0);
482101SN/A    assert(m_virtual_networks != 0);
492084SN/A
502084SN/A    m_topology_ptr = new Topology(p->routers.size(), p->ext_links,
512084SN/A                                  p->int_links);
522084SN/A
532084SN/A    // Allocate to and from queues
542084SN/A    // Queues that are getting messages from protocol
552084SN/A    m_toNetQueues.resize(m_nodes);
562084SN/A
572084SN/A    // Queues that are feeding the protocol
582084SN/A    m_fromNetQueues.resize(m_nodes);
592084SN/A
602084SN/A    m_in_use.resize(m_virtual_networks);
612084SN/A    m_ordered.resize(m_virtual_networks);
622084SN/A
632084SN/A    for (int i = 0; i < m_virtual_networks; i++) {
642084SN/A        m_in_use[i] = false;
652084SN/A        m_ordered[i] = false;
662084SN/A    }
672686Sksewell@umich.edu
682084SN/A    p->ruby_system->registerNetwork(this);
692084SN/A
702084SN/A    // Initialize the controller's network pointers
712084SN/A    for (std::vector<BasicExtLink*>::const_iterator i = p->ext_links.begin();
722084SN/A         i != p->ext_links.end(); ++i) {
732101SN/A        BasicExtLink *ext_link = (*i);
742101SN/A        AbstractController *abs_cntrl = ext_link->params()->ext_node;
752084SN/A        abs_cntrl->initNetworkPtr(this);
762750Sksewell@umich.edu    }
772750Sksewell@umich.edu
782084SN/A    // Register a callback function for combining the statistics
792084SN/A    Stats::registerDumpCallback(new StatsCallback(this));
802084SN/A}
812084SN/A
822084SN/ANetwork::~Network()
832084SN/A{
842084SN/A    for (int node = 0; node < m_nodes; node++) {
852084SN/A
862084SN/A        // Delete the Message Buffers
872239SN/A        for (auto& it : m_toNetQueues[node]) {
882084SN/A            delete it.second;
892084SN/A        }
902084SN/A
912750Sksewell@umich.edu        for (auto& it : m_fromNetQueues[node]) {
922750Sksewell@umich.edu            delete it.second;
932750Sksewell@umich.edu        }
942750Sksewell@umich.edu    }
952750Sksewell@umich.edu
962750Sksewell@umich.edu    delete m_topology_ptr;
972750Sksewell@umich.edu}
982750Sksewell@umich.edu
992750Sksewell@umich.eduvoid
1002750Sksewell@umich.eduNetwork::init()
1012750Sksewell@umich.edu{
1022750Sksewell@umich.edu    m_data_msg_size = RubySystem::getBlockSizeBytes() + m_control_msg_size;
1032084SN/A}
1042084SN/A
1052101SN/Auint32_t
1062750Sksewell@umich.eduNetwork::MessageSizeType_to_int(MessageSizeType size_type)
1072750Sksewell@umich.edu{
1082750Sksewell@umich.edu    switch(size_type) {
1092750Sksewell@umich.edu      case MessageSizeType_Control:
1102750Sksewell@umich.edu      case MessageSizeType_Request_Control:
1112750Sksewell@umich.edu      case MessageSizeType_Reissue_Control:
1122239SN/A      case MessageSizeType_Response_Control:
1132750Sksewell@umich.edu      case MessageSizeType_Writeback_Control:
1142750Sksewell@umich.edu      case MessageSizeType_Broadcast_Control:
1152750Sksewell@umich.edu      case MessageSizeType_Multicast_Control:
1162750Sksewell@umich.edu      case MessageSizeType_Forwarded_Control:
1172750Sksewell@umich.edu      case MessageSizeType_Invalidate_Control:
1182750Sksewell@umich.edu      case MessageSizeType_Unblock_Control:
1192750Sksewell@umich.edu      case MessageSizeType_Persistent_Control:
1202750Sksewell@umich.edu      case MessageSizeType_Completion_Control:
1212084SN/A        return m_control_msg_size;
1222084SN/A      case MessageSizeType_Data:
1232084SN/A      case MessageSizeType_Response_Data:
1242084SN/A      case MessageSizeType_ResponseLocal_Data:
1252084SN/A      case MessageSizeType_ResponseL2hit_Data:
1262084SN/A      case MessageSizeType_Writeback_Data:
1272084SN/A        return m_data_msg_size;
1282101SN/A      default:
1292084SN/A        panic("Invalid range for type MessageSizeType");
1302084SN/A        break;
1312084SN/A    }
1322084SN/A}
1332084SN/A