d3fb9f39b3ab135af0b74a0e5bc60ec8188b653a
[gem5.git] / src / mem / ruby / network / garnet / fixed-pipeline / GarnetNetwork_d.hh
1 /*
2 * Copyright (c) 2008 Princeton University
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Niket Agarwal
29 */
30
31 #ifndef __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_GARNETNETWORK_D_HH__
32 #define __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_GARNETNETWORK_D_HH__
33
34 #include <iostream>
35 #include <vector>
36
37 #include "mem/ruby/network/garnet/NetworkHeader.hh"
38 #include "mem/ruby/network/garnet/BaseGarnetNetwork.hh"
39 #include "mem/ruby/network/Network.hh"
40 #include "params/GarnetNetwork_d.hh"
41
42 class NetworkInterface_d;
43 class MessageBuffer;
44 class Router_d;
45 class Topology;
46 class NetDest;
47 class NetworkLink_d;
48 class CreditLink_d;
49
50 class GarnetNetwork_d : public BaseGarnetNetwork
51 {
52 public:
53 typedef GarnetNetwork_dParams Params;
54 GarnetNetwork_d(const Params *p);
55
56 ~GarnetNetwork_d();
57
58 void init();
59
60 int getNumNodes() { return m_nodes; }
61
62 // returns the queue requested for the given component
63 MessageBuffer* getToNetQueue(NodeID id, bool ordered, int network_num);
64 MessageBuffer* getFromNetQueue(NodeID id, bool ordered, int network_num);
65
66 void clearStats();
67 void printStats(std::ostream& out) const;
68 void printConfig(std::ostream& out) const;
69 void print(std::ostream& out) const;
70
71 inline void increment_injected_flits() { m_flits_injected++; }
72 inline void increment_received_flits() { m_flits_received++; }
73
74 inline void
75 increment_network_latency(Time latency)
76 {
77 m_network_latency += latency;
78 }
79
80 inline void
81 increment_queueing_latency(Time latency)
82 {
83 m_queueing_latency += latency;
84 }
85
86 bool isVNetOrdered(int vnet) { return m_ordered[vnet]; }
87 bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; }
88 Time getRubyStartTime();
89
90 void reset();
91
92 // Methods used by Topology to setup the network
93 void makeOutLink(SwitchID src, NodeID dest,
94 const NetDest& routing_table_entry, int link_latency, int link_weight,
95 int bw_multiplier, bool isReconfiguration);
96 void makeInLink(SwitchID src, NodeID dest,
97 const NetDest& routing_table_entry, int link_latency,
98 int bw_multiplier, bool isReconfiguration);
99 void makeInternalLink(SwitchID src, NodeID dest,
100 const NetDest& routing_table_entry, int link_latency, int link_weight,
101 int bw_multiplier, bool isReconfiguration);
102
103 private:
104 void checkNetworkAllocation(NodeID id, bool ordered, int network_num);
105
106 GarnetNetwork_d(const GarnetNetwork_d& obj);
107 GarnetNetwork_d& operator=(const GarnetNetwork_d& obj);
108
109 // int m_virtual_networks;
110 // int m_nodes;
111 int m_flits_received, m_flits_injected;
112 double m_network_latency, m_queueing_latency;
113
114 std::vector<bool> m_in_use;
115 std::vector<bool> m_ordered;
116
117 std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
118 std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
119
120 std::vector<Router_d *> m_router_ptr_vector; // All Routers in Network
121 std::vector<NetworkLink_d *> m_link_ptr_vector; // All links in the network
122 std::vector<CreditLink_d *> m_creditlink_ptr_vector; // All links in net
123 std::vector<NetworkInterface_d *> m_ni_ptr_vector; // All NI's in Network
124
125 // Topology* m_topology_ptr;
126 Time m_ruby_start;
127 };
128
129 inline std::ostream&
130 operator<<(std::ostream& out, const GarnetNetwork_d& obj)
131 {
132 obj.print(out);
133 out << std::flush;
134 return out;
135 }
136
137 #endif // __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_GARNETNETWORK_D_HH__