flit.hh revision 11666:10d59d546ea2
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_GARNET_FLIT_HH__ 35#define __MEM_RUBY_NETWORK_GARNET_FLIT_HH__ 36 37#include <cassert> 38#include <iostream> 39 40#include "base/types.hh" 41#include "mem/ruby/network/garnet2.0/CommonTypes.hh" 42#include "mem/ruby/slicc_interface/Message.hh" 43 44class flit 45{ 46 public: 47 flit() {} 48 flit(int id, int vc, int vnet, RouteInfo route, int size, 49 MsgPtr msg_ptr, Cycles curTime); 50 51 int get_outport() {return m_outport; } 52 int get_size() { return m_size; } 53 Cycles get_enqueue_time() { return m_enqueue_time; } 54 int get_id() { return m_id; } 55 Cycles get_time() { return m_time; } 56 int get_vnet() { return m_vnet; } 57 int get_vc() { return m_vc; } 58 RouteInfo get_route() { return m_route; } 59 MsgPtr& get_msg_ptr() { return m_msg_ptr; } 60 flit_type get_type() { return m_type; } 61 std::pair<flit_stage, Cycles> get_stage() { return m_stage; } 62 Cycles get_src_delay() { return src_delay; } 63 64 void set_outport(int port) { m_outport = port; } 65 void set_time(Cycles time) { m_time = time; } 66 void set_vc(int vc) { m_vc = vc; } 67 void set_route(RouteInfo route) { m_route = route; } 68 void set_src_delay(Cycles delay) { src_delay = delay; } 69 70 void increment_hops() { m_route.hops_traversed++; } 71 void print(std::ostream& out) const; 72 73 bool 74 is_stage(flit_stage stage, Cycles time) 75 { 76 return (stage == m_stage.first && 77 time >= m_stage.second); 78 } 79 80 void 81 advance_stage(flit_stage t_stage, Cycles newTime) 82 { 83 m_stage.first = t_stage; 84 m_stage.second = newTime; 85 } 86 87 static bool 88 greater(flit* n1, flit* n2) 89 { 90 if (n1->get_time() == n2->get_time()) { 91 //assert(n1->flit_id != n2->flit_id); 92 return (n1->get_id() > n2->get_id()); 93 } else { 94 return (n1->get_time() > n2->get_time()); 95 } 96 } 97 98 bool functionalWrite(Packet *pkt); 99 100 protected: 101 int m_id; 102 int m_vnet; 103 int m_vc; 104 RouteInfo m_route; 105 int m_size; 106 Cycles m_enqueue_time, m_time; 107 flit_type m_type; 108 MsgPtr m_msg_ptr; 109 int m_outport; 110 Cycles src_delay; 111 std::pair<flit_stage, Cycles> m_stage; 112}; 113 114inline std::ostream& 115operator<<(std::ostream& out, const flit& obj) 116{ 117 obj.print(out); 118 out << std::flush; 119 return out; 120} 121 122#endif // __MEM_RUBY_NETWORK_GARNET_FLIT_HH__ 123