Network.cc revision 6700
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
296285Snate@binkert.org#include "mem/protocol/MachineType.hh"
306285Snate@binkert.org#include "mem/ruby/network/Network.hh"
316285Snate@binkert.org
326285Snate@binkert.orgNetwork::Network(const string & name)
336285Snate@binkert.org  :  m_name(name)
346285Snate@binkert.org{
356285Snate@binkert.org  m_virtual_networks = 0;
366285Snate@binkert.org  m_topology_ptr = NULL;
376285Snate@binkert.org}
386285Snate@binkert.org
396285Snate@binkert.orgvoid Network::init(const vector<string> & argv)
406285Snate@binkert.org{
416285Snate@binkert.org  m_nodes = MachineType_base_number(MachineType_NUM); // Total nodes in network
426285Snate@binkert.org
436285Snate@binkert.org  for (size_t i=0; i<argv.size(); i+=2) {
446285Snate@binkert.org   if (argv[i] == "number_of_virtual_networks")
456285Snate@binkert.org     m_virtual_networks = atoi(argv[i+1].c_str());
466285Snate@binkert.org   else if (argv[i] == "topology")
476285Snate@binkert.org     m_topology_ptr = RubySystem::getTopology(argv[i+1]);
486285Snate@binkert.org   else if (argv[i] == "buffer_size")
496285Snate@binkert.org     m_buffer_size = atoi(argv[i+1].c_str());
506285Snate@binkert.org   else if (argv[i] == "endpoint_bandwidth")
516285Snate@binkert.org     m_endpoint_bandwidth = atoi(argv[i+1].c_str());
526285Snate@binkert.org   else if (argv[i] == "adaptive_routing")
536285Snate@binkert.org     m_adaptive_routing = (argv[i+1]=="true");
546285Snate@binkert.org   else if (argv[i] == "link_latency")
556285Snate@binkert.org     m_link_latency = atoi(argv[i+1].c_str());
566493STushar.Krishna@amd.com   else if (argv[i] == "control_msg_size")
576493STushar.Krishna@amd.com     m_control_msg_size = atoi(argv[i+1].c_str());
586493STushar.Krishna@amd.com  }
596285Snate@binkert.org
606493STushar.Krishna@amd.com  m_data_msg_size = RubySystem::getBlockSizeBytes() + m_control_msg_size;
616493STushar.Krishna@amd.com
626285Snate@binkert.org  assert(m_virtual_networks != 0);
636285Snate@binkert.org  assert(m_topology_ptr != NULL);
646285Snate@binkert.org}
656493STushar.Krishna@amd.com
666493STushar.Krishna@amd.comint Network::MessageSizeType_to_int(MessageSizeType size_type)
676493STushar.Krishna@amd.com{
686493STushar.Krishna@amd.com  switch(size_type) {
696493STushar.Krishna@amd.com  case MessageSizeType_Undefined:
706493STushar.Krishna@amd.com    ERROR_MSG("Can't convert Undefined MessageSizeType to integer");
716493STushar.Krishna@amd.com    break;
726493STushar.Krishna@amd.com  case MessageSizeType_Control:
736493STushar.Krishna@amd.com  case MessageSizeType_Request_Control:
746493STushar.Krishna@amd.com  case MessageSizeType_Reissue_Control:
756493STushar.Krishna@amd.com  case MessageSizeType_Response_Control:
766493STushar.Krishna@amd.com  case MessageSizeType_Writeback_Control:
776493STushar.Krishna@amd.com  case MessageSizeType_Forwarded_Control:
786493STushar.Krishna@amd.com  case MessageSizeType_Invalidate_Control:
796493STushar.Krishna@amd.com  case MessageSizeType_Unblock_Control:
806493STushar.Krishna@amd.com  case MessageSizeType_Persistent_Control:
816493STushar.Krishna@amd.com  case MessageSizeType_Completion_Control:
826493STushar.Krishna@amd.com    return m_control_msg_size;
836493STushar.Krishna@amd.com    break;
846493STushar.Krishna@amd.com  case MessageSizeType_Data:
856493STushar.Krishna@amd.com  case MessageSizeType_Response_Data:
866493STushar.Krishna@amd.com  case MessageSizeType_ResponseLocal_Data:
876493STushar.Krishna@amd.com  case MessageSizeType_ResponseL2hit_Data:
886493STushar.Krishna@amd.com  case MessageSizeType_Writeback_Data:
896493STushar.Krishna@amd.com    return m_data_msg_size;
906493STushar.Krishna@amd.com    break;
916493STushar.Krishna@amd.com  default:
926493STushar.Krishna@amd.com    ERROR_MSG("Invalid range for type MessageSizeType");
936493STushar.Krishna@amd.com    break;
946493STushar.Krishna@amd.com  }
956493STushar.Krishna@amd.com  return 0;
966493STushar.Krishna@amd.com}
97