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_NETWORKINTERFACE_HH__ 35#define __MEM_RUBY_NETWORK_GARNET2_0_NETWORKINTERFACE_HH__ 36 37#include <iostream> 38#include <vector> 39 40#include "mem/ruby/common/Consumer.hh" 41#include "mem/ruby/network/garnet2.0/CommonTypes.hh" 42#include "mem/ruby/network/garnet2.0/CreditLink.hh" 43#include "mem/ruby/network/garnet2.0/GarnetNetwork.hh" 44#include "mem/ruby/network/garnet2.0/NetworkLink.hh" 45#include "mem/ruby/network/garnet2.0/OutVcState.hh" 46#include "mem/ruby/slicc_interface/Message.hh" 47#include "params/GarnetNetworkInterface.hh" 48 49class MessageBuffer; 50class flitBuffer; 51 52class NetworkInterface : public ClockedObject, public Consumer 53{ 54 public: 55 typedef GarnetNetworkInterfaceParams Params; 56 NetworkInterface(const Params *p); 57 ~NetworkInterface(); 58 59 void init(); 60 61 void addInPort(NetworkLink *in_link, CreditLink *credit_link); 62 void addOutPort(NetworkLink *out_link, CreditLink *credit_link, 63 SwitchID router_id); 64 65 void dequeueCallback(); 66 void wakeup(); 67 void addNode(std::vector<MessageBuffer *> &inNode, 68 std::vector<MessageBuffer *> &outNode); 69 70 void print(std::ostream& out) const; 71 int get_vnet(int vc); 72 int get_router_id() { return m_router_id; } 73 void init_net_ptr(GarnetNetwork *net_ptr) { m_net_ptr = net_ptr; } 74 75 uint32_t functionalWrite(Packet *); 76 77 private: 78 GarnetNetwork *m_net_ptr; 79 const NodeID m_id; 80 const int m_virtual_networks, m_vc_per_vnet, m_num_vcs; 81 int m_router_id; // id of my router 82 std::vector<OutVcState *> m_out_vc_state; 83 std::vector<int> m_vc_allocator; 84 int m_vc_round_robin; // For round robin scheduling 85 flitBuffer *outFlitQueue; // For modeling link contention 86 flitBuffer *outCreditQueue; 87 int m_deadlock_threshold; 88 89 NetworkLink *inNetLink; 90 NetworkLink *outNetLink; 91 CreditLink *inCreditLink; 92 CreditLink *outCreditLink; 93 94 // Queue for stalled flits 95 std::deque<flit *> m_stall_queue; 96 std::vector<int> m_stall_count; 97 98 // Input Flit Buffers 99 // The flit buffers which will serve the Consumer 100 std::vector<flitBuffer *> m_ni_out_vcs; 101 std::vector<Cycles> m_ni_out_vcs_enqueue_time; 102 103 // The Message buffers that takes messages from the protocol 104 std::vector<MessageBuffer *> inNode_ptr; 105 // The Message buffers that provides messages to the protocol 106 std::vector<MessageBuffer *> outNode_ptr; 107 // When a vc stays busy for a long time, it indicates a deadlock 108 std::vector<int> vc_busy_counter; 109 110 bool checkStallQueue(); 111 bool flitisizeMessage(MsgPtr msg_ptr, int vnet); 112 int calculateVC(int vnet); 113 114 void scheduleOutputLink(); 115 void checkReschedule(); 116 void sendCredit(flit *t_flit, bool is_free); 117 118 void incrementStats(flit *t_flit); 119}; 120 121#endif // __MEM_RUBY_NETWORK_GARNET2_0_NETWORKINTERFACE_HH__ 122