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_ROUTER_HH__ 35#define __MEM_RUBY_NETWORK_GARNET2_0_ROUTER_HH__ 36 37#include <iostream> 38#include <vector> 39 40#include "mem/ruby/common/Consumer.hh" 41#include "mem/ruby/common/NetDest.hh" 42#include "mem/ruby/network/BasicRouter.hh" 43#include "mem/ruby/network/garnet2.0/CommonTypes.hh" 44#include "mem/ruby/network/garnet2.0/GarnetNetwork.hh" 45#include "mem/ruby/network/garnet2.0/flit.hh" 46#include "params/GarnetRouter.hh" 47 48class NetworkLink; 49class CreditLink; 50class InputUnit; 51class OutputUnit; 52class RoutingUnit; 53class SwitchAllocator; 54class CrossbarSwitch; 55class FaultModel; 56 57class Router : public BasicRouter, public Consumer 58{ 59 public: 60 typedef GarnetRouterParams Params; 61 Router(const Params *p); 62 63 ~Router(); 64 65 void wakeup(); 66 void print(std::ostream& out) const {}; 67 68 void init(); 69 void addInPort(PortDirection inport_dirn, NetworkLink *link, 70 CreditLink *credit_link); 71 void addOutPort(PortDirection outport_dirn, NetworkLink *link, 72 const NetDest& routing_table_entry, 73 int link_weight, CreditLink *credit_link); 74 75 Cycles get_pipe_stages(){ return m_latency; } 76 int get_num_vcs() { return m_num_vcs; } 77 int get_num_vnets() { return m_virtual_networks; } 78 int get_vc_per_vnet() { return m_vc_per_vnet; } 79 int get_num_inports() { return m_input_unit.size(); } 80 int get_num_outports() { return m_output_unit.size(); } 81 int get_id() { return m_id; } 82 83 void init_net_ptr(GarnetNetwork* net_ptr) 84 { 85 m_network_ptr = net_ptr; 86 } 87 88 GarnetNetwork* get_net_ptr() { return m_network_ptr; } 89 std::vector<InputUnit *>& get_inputUnit_ref() { return m_input_unit; } 90 std::vector<OutputUnit *>& get_outputUnit_ref() { return m_output_unit; } 91 PortDirection getOutportDirection(int outport); 92 PortDirection getInportDirection(int inport); 93 94 int route_compute(RouteInfo route, int inport, PortDirection direction); 95 void grant_switch(int inport, flit *t_flit); 96 void schedule_wakeup(Cycles time); 97 98 std::string getPortDirectionName(PortDirection direction); 99 void printFaultVector(std::ostream& out); 100 void printAggregateFaultProbability(std::ostream& out); 101 102 void regStats(); 103 void collateStats(); 104 void resetStats(); 105 106 // For Fault Model: 107 bool get_fault_vector(int temperature, float fault_vector[]) { 108 return m_network_ptr->fault_model->fault_vector(m_id, temperature, 109 fault_vector); 110 } 111 bool get_aggregate_fault_probability(int temperature, 112 float *aggregate_fault_prob) { 113 return m_network_ptr->fault_model->fault_prob(m_id, temperature, 114 aggregate_fault_prob); 115 } 116 117 uint32_t functionalWrite(Packet *); 118 119 private: 120 Cycles m_latency; 121 int m_virtual_networks, m_num_vcs, m_vc_per_vnet; 122 GarnetNetwork *m_network_ptr; 123 124 std::vector<InputUnit *> m_input_unit; 125 std::vector<OutputUnit *> m_output_unit; 126 RoutingUnit *m_routing_unit; 127 SwitchAllocator *m_sw_alloc; 128 CrossbarSwitch *m_switch; 129 130 // Statistical variables required for power computations 131 Stats::Scalar m_buffer_reads; 132 Stats::Scalar m_buffer_writes; 133 134 Stats::Scalar m_sw_input_arbiter_activity; 135 Stats::Scalar m_sw_output_arbiter_activity; 136 137 Stats::Scalar m_crossbar_activity; 138}; 139 140#endif // __MEM_RUBY_NETWORK_GARNET2_0_ROUTER_HH__ 141