1/* 2 * Copyright (c) 2008 Princeton University 3 * Copyright (c) 2016 Georgia Institute of Technology 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Niket Agarwal 30 * Tushar Krishna 31 */ 32 33 34#ifndef __MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__ 35#define __MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__ 36 37#include <iostream> 38#include <vector> 39 40#include "mem/ruby/network/Network.hh" 41#include "mem/ruby/network/fault_model/FaultModel.hh" 42#include "mem/ruby/network/garnet2.0/CommonTypes.hh" 43#include "params/GarnetNetwork.hh" 44 45class FaultModel; 46class NetworkInterface; 47class Router; 48class NetDest; 49class NetworkLink; 50class CreditLink; 51 52class GarnetNetwork : public Network 53{ 54 public: 55 typedef GarnetNetworkParams Params; 56 GarnetNetwork(const Params *p); 57 58 ~GarnetNetwork(); 59 void init(); 60 61 // Configuration (set externally) 62 63 // for 2D topology 64 int getNumRows() const { return m_num_rows; } 65 int getNumCols() { return m_num_cols; } 66 67 // for network 68 uint32_t getNiFlitSize() const { return m_ni_flit_size; } 69 uint32_t getVCsPerVnet() const { return m_vcs_per_vnet; } 70 uint32_t getBuffersPerDataVC() { return m_buffers_per_data_vc; } 71 uint32_t getBuffersPerCtrlVC() { return m_buffers_per_ctrl_vc; } 72 int getRoutingAlgorithm() const { return m_routing_algorithm; } 73 74 bool isFaultModelEnabled() const { return m_enable_fault_model; } 75 FaultModel* fault_model; 76 77 78 // Internal configuration 79 bool isVNetOrdered(int vnet) const { return m_ordered[vnet]; } 80 VNET_type 81 get_vnet_type(int vc) 82 { 83 int vnet = vc/getVCsPerVnet(); 84 return m_vnet_type[vnet]; 85 } 86 int getNumRouters(); 87 int get_router_id(int ni); 88 89 90 // Methods used by Topology to setup the network 91 void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link, 92 const NetDest& routing_table_entry); 93 void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link, 94 const NetDest& routing_table_entry); 95 void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 96 const NetDest& routing_table_entry, 97 PortDirection src_outport_dirn, 98 PortDirection dest_inport_dirn); 99 100 //! Function for performing a functional write. The return value 101 //! indicates the number of messages that were written. 102 uint32_t functionalWrite(Packet *pkt); 103 104 // Stats 105 void collateStats(); 106 void regStats(); 107 void print(std::ostream& out) const; 108 109 // increment counters 110 void increment_injected_packets(int vnet) { m_packets_injected[vnet]++; } 111 void increment_received_packets(int vnet) { m_packets_received[vnet]++; } 112 113 void 114 increment_packet_network_latency(Cycles latency, int vnet) 115 { 116 m_packet_network_latency[vnet] += latency; 117 } 118 119 void 120 increment_packet_queueing_latency(Cycles latency, int vnet) 121 { 122 m_packet_queueing_latency[vnet] += latency; 123 } 124 125 void increment_injected_flits(int vnet) { m_flits_injected[vnet]++; } 126 void increment_received_flits(int vnet) { m_flits_received[vnet]++; } 127 128 void 129 increment_flit_network_latency(Cycles latency, int vnet) 130 { 131 m_flit_network_latency[vnet] += latency; 132 } 133 134 void 135 increment_flit_queueing_latency(Cycles latency, int vnet) 136 { 137 m_flit_queueing_latency[vnet] += latency; 138 } 139 140 void 141 increment_total_hops(int hops) 142 { 143 m_total_hops += hops; 144 } 145 146 protected: 147 // Configuration 148 int m_num_rows; 149 int m_num_cols; 150 uint32_t m_ni_flit_size; 151 uint32_t m_vcs_per_vnet; 152 uint32_t m_buffers_per_ctrl_vc; 153 uint32_t m_buffers_per_data_vc; 154 int m_routing_algorithm; 155 bool m_enable_fault_model; 156 157 // Statistical variables 158 Stats::Vector m_packets_received; 159 Stats::Vector m_packets_injected; 160 Stats::Vector m_packet_network_latency; 161 Stats::Vector m_packet_queueing_latency; 162 163 Stats::Formula m_avg_packet_vnet_latency; 164 Stats::Formula m_avg_packet_vqueue_latency; 165 Stats::Formula m_avg_packet_network_latency; 166 Stats::Formula m_avg_packet_queueing_latency; 167 Stats::Formula m_avg_packet_latency; 168 169 Stats::Vector m_flits_received; 170 Stats::Vector m_flits_injected; 171 Stats::Vector m_flit_network_latency; 172 Stats::Vector m_flit_queueing_latency; 173 174 Stats::Formula m_avg_flit_vnet_latency; 175 Stats::Formula m_avg_flit_vqueue_latency; 176 Stats::Formula m_avg_flit_network_latency; 177 Stats::Formula m_avg_flit_queueing_latency; 178 Stats::Formula m_avg_flit_latency; 179 180 Stats::Scalar m_total_ext_in_link_utilization; 181 Stats::Scalar m_total_ext_out_link_utilization; 182 Stats::Scalar m_total_int_link_utilization; 183 Stats::Scalar m_average_link_utilization; 184 Stats::Vector m_average_vc_load; 185 186 Stats::Scalar m_total_hops; 187 Stats::Formula m_avg_hops; 188 189 private: 190 GarnetNetwork(const GarnetNetwork& obj); 191 GarnetNetwork& operator=(const GarnetNetwork& obj); 192 193 std::vector<VNET_type > m_vnet_type; 194 std::vector<Router *> m_routers; // All Routers in Network 195 std::vector<NetworkLink *> m_networklinks; // All flit links in the network 196 std::vector<CreditLink *> m_creditlinks; // All credit links in the network 197 std::vector<NetworkInterface *> m_nis; // All NI's in Network 198}; 199 200inline std::ostream& 201operator<<(std::ostream& out, const GarnetNetwork& obj) 202{ 203 obj.print(out); 204 out << std::flush; 205 return out; 206} 207 208#endif //__MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__ 209