ruby: network: move message buffers to base network class.
[gem5.git] / src / mem / ruby / network / garnet / BaseGarnetNetwork.cc
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 #include "mem/ruby/buffers/MessageBuffer.hh"
32 #include "mem/ruby/network/garnet/BaseGarnetNetwork.hh"
33
34 using namespace std;
35
36 BaseGarnetNetwork::BaseGarnetNetwork(const Params *p)
37 : Network(p)
38 {
39 m_ni_flit_size = p->ni_flit_size;
40 m_vcs_per_vnet = p->vcs_per_vnet;
41 m_enable_fault_model = p->enable_fault_model;
42 if (m_enable_fault_model)
43 fault_model = p->fault_model;
44
45 // Currently Garnet only supports uniform bandwidth for all
46 // links and network interfaces.
47 for (std::vector<BasicExtLink*>::const_iterator i = p->ext_links.begin();
48 i != p->ext_links.end(); ++i) {
49 BasicExtLink* ext_link = (*i);
50 if (ext_link->params()->bandwidth_factor != m_ni_flit_size) {
51 fatal("Garnet only supports uniform bw across all links and NIs\n");
52 }
53 }
54 for (std::vector<BasicIntLink*>::const_iterator i = p->int_links.begin();
55 i != p->int_links.end(); ++i) {
56 BasicIntLink* int_link = (*i);
57 if (int_link->params()->bandwidth_factor != m_ni_flit_size) {
58 fatal("Garnet only supports uniform bw across all links and NIs\n");
59 }
60 }
61
62 // Allocate to and from queues
63
64 // Queues that are getting messages from protocol
65 m_toNetQueues.resize(m_nodes);
66
67 // Queues that are feeding the protocol
68 m_fromNetQueues.resize(m_nodes);
69
70 m_in_use.resize(m_virtual_networks);
71 m_ordered.resize(m_virtual_networks);
72 for (int i = 0; i < m_virtual_networks; i++) {
73 m_in_use[i] = false;
74 m_ordered[i] = false;
75 }
76
77 for (int node = 0; node < m_nodes; node++) {
78 // Setting number of virtual message buffers per Network Queue
79 m_toNetQueues[node].resize(m_virtual_networks);
80 m_fromNetQueues[node].resize(m_virtual_networks);
81
82 // Instantiating the Message Buffers that
83 // interact with the coherence protocol
84 for (int j = 0; j < m_virtual_networks; j++) {
85 m_toNetQueues[node][j] = new MessageBuffer();
86 m_fromNetQueues[node][j] = new MessageBuffer();
87 }
88 }
89 }
90
91 void
92 BaseGarnetNetwork::init()
93 {
94 Network::init();
95 }
96
97 MessageBuffer*
98 BaseGarnetNetwork::getToNetQueue(NodeID id, bool ordered, int network_num,
99 string vnet_type)
100 {
101 checkNetworkAllocation(id, ordered, network_num, vnet_type);
102 return m_toNetQueues[id][network_num];
103 }
104
105 MessageBuffer*
106 BaseGarnetNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num,
107 string vnet_type)
108 {
109 checkNetworkAllocation(id, ordered, network_num, vnet_type);
110 return m_fromNetQueues[id][network_num];
111 }
112
113 void
114 BaseGarnetNetwork::regStats()
115 {
116 m_flits_received
117 .init(m_virtual_networks)
118 .name(name() + ".flits_received")
119 .flags(Stats::pdf | Stats::total | Stats::nozero | Stats::oneline)
120 ;
121
122 m_flits_injected
123 .init(m_virtual_networks)
124 .name(name() + ".flits_injected")
125 .flags(Stats::pdf | Stats::total | Stats::nozero | Stats::oneline)
126 ;
127
128 m_network_latency
129 .init(m_virtual_networks)
130 .name(name() + ".network_latency")
131 .flags(Stats::oneline)
132 ;
133
134 m_queueing_latency
135 .init(m_virtual_networks)
136 .name(name() + ".queueing_latency")
137 .flags(Stats::oneline)
138 ;
139
140 for (int i = 0; i < m_virtual_networks; i++) {
141 m_flits_received.subname(i, csprintf("vnet-%i", i));
142 m_flits_injected.subname(i, csprintf("vnet-%i", i));
143 m_network_latency.subname(i, csprintf("vnet-%i", i));
144 m_queueing_latency.subname(i, csprintf("vnet-%i", i));
145 }
146
147 m_avg_vnet_latency
148 .name(name() + ".average_vnet_latency")
149 .flags(Stats::oneline);
150 m_avg_vnet_latency = m_network_latency / m_flits_received;
151
152 m_avg_vqueue_latency
153 .name(name() + ".average_vqueue_latency")
154 .flags(Stats::oneline);
155 m_avg_vqueue_latency = m_queueing_latency / m_flits_received;
156
157 m_avg_network_latency.name(name() + ".average_network_latency");
158 m_avg_network_latency = sum(m_network_latency) / sum(m_flits_received);
159
160 m_avg_queueing_latency.name(name() + ".average_queueing_latency");
161 m_avg_queueing_latency = sum(m_queueing_latency) / sum(m_flits_received);
162
163 m_avg_latency.name(name() + ".average_latency");
164 m_avg_latency = m_avg_network_latency + m_avg_queueing_latency;
165 }