1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/*
* Copyright (c) 2008 Princeton University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Niket Agarwal
*/
#include "mem/ruby/network/garnet-flexible-pipeline/NetworkConfig.hh"
#include "mem/ruby/network/garnet/fixed-pipeline/VCallocator_d.hh"
#include "mem/ruby/network/garnet/fixed-pipeline/Router_d.hh"
#include "mem/ruby/network/garnet/fixed-pipeline/InputUnit_d.hh"
#include "mem/ruby/network/garnet/fixed-pipeline/OutputUnit_d.hh"
#include "mem/ruby/network/garnet/fixed-pipeline/GarnetNetwork_d.hh"
VCallocator_d::VCallocator_d(Router_d *router)
{
m_router = router;
m_num_vcs = m_router->get_num_vcs();
m_vc_per_vnet = m_router->get_vc_per_vnet();
m_local_arbiter_activity = 0;
m_global_arbiter_activity = 0;
}
void VCallocator_d::init()
{
m_input_unit = m_router->get_inputUnit_ref();
m_output_unit = m_router->get_outputUnit_ref();
m_num_inports = m_router->get_num_inports();
m_num_outports = m_router->get_num_outports();
m_round_robin_invc.setSize(m_num_inports);
m_round_robin_outvc.setSize(m_num_outports);
m_outvc_req.setSize(m_num_outports);
m_outvc_is_req.setSize(m_num_outports);
for(int i = 0; i < m_num_inports; i++)
{
m_round_robin_invc[i].setSize(m_num_vcs);
for(int j = 0; j < m_num_vcs; j++)
{
m_round_robin_invc[i][j] = 0;
}
}
for(int i = 0; i < m_num_outports; i++)
{
m_round_robin_outvc[i].setSize(m_num_vcs);
m_outvc_req[i].setSize(m_num_vcs);
m_outvc_is_req[i].setSize(m_num_vcs);
for(int j = 0; j < m_num_vcs; j++)
{
m_round_robin_outvc[i][j].first = 0;
m_round_robin_outvc[i][j].second = 0;
m_outvc_is_req[i][j] = false;
m_outvc_req[i][j].setSize(m_num_inports);
for(int k = 0; k < m_num_inports; k++)
{
m_outvc_req[i][j][k].setSize(m_num_vcs);
for(int l = 0; l < m_num_vcs; l++)
{
m_outvc_req[i][j][k][l] = false;
}
}
}
}
}
void VCallocator_d::clear_request_vector()
{
for(int i = 0; i < m_num_outports; i++)
{
for(int j = 0; j < m_num_vcs; j++)
{
if(!m_outvc_is_req[i][j])
continue;
m_outvc_is_req[i][j] = false;
for(int k = 0; k < m_num_inports; k++)
{
for(int l = 0; l < m_num_vcs; l++)
{
m_outvc_req[i][j][k][l] = false;
}
}
}
}
}
void VCallocator_d::wakeup()
{
arbitrate_invcs(); // First stage of allocation
arbitrate_outvcs(); // Second stage of allocation
clear_request_vector();
check_for_wakeup();
}
bool VCallocator_d::is_invc_candidate(int inport_iter, int invc_iter)
{
int outport = m_input_unit[inport_iter]->get_route(invc_iter);
int vnet = get_vnet(invc_iter);
int t_enqueue_time = m_input_unit[inport_iter]->get_enqueue_time(invc_iter);
int invc_base = vnet*m_vc_per_vnet;
if((m_router->get_net_ptr())->isVNetOrdered(vnet))
{
for(int vc_offset = 0; vc_offset < m_vc_per_vnet; vc_offset++)
{
int temp_vc = invc_base + vc_offset;
if(m_input_unit[inport_iter]->need_stage(temp_vc, VC_AB_, VA_) && (m_input_unit[inport_iter]->get_route(temp_vc) == outport) && (m_input_unit[inport_iter]->get_enqueue_time(temp_vc) < t_enqueue_time))
{
return false;
}
}
}
return true;
}
void VCallocator_d::select_outvc(int inport_iter, int invc_iter)
{
int outport = m_input_unit[inport_iter]->get_route(invc_iter);
int vnet = get_vnet(invc_iter);
int outvc_base = vnet*m_vc_per_vnet;
int num_vcs_per_vnet = m_vc_per_vnet;
int outvc_offset = m_round_robin_invc[inport_iter][invc_iter];
m_round_robin_invc[inport_iter][invc_iter]++;
if(m_round_robin_invc[inport_iter][invc_iter] >= num_vcs_per_vnet)
m_round_robin_invc[inport_iter][invc_iter] = 0;
for(int outvc_offset_iter = 0; outvc_offset_iter < num_vcs_per_vnet; outvc_offset_iter++)
{
outvc_offset++;
if(outvc_offset >= num_vcs_per_vnet)
outvc_offset = 0;
int outvc = outvc_base + outvc_offset;
if(m_output_unit[outport]->is_vc_idle(outvc))
{
m_local_arbiter_activity++;
m_outvc_req[outport][outvc][inport_iter][invc_iter] = true;
if(!m_outvc_is_req[outport][outvc])
m_outvc_is_req[outport][outvc] = true;
return; // out vc acquired
}
}
}
void VCallocator_d::arbitrate_invcs()
{
for(int inport_iter = 0; inport_iter < m_num_inports; inport_iter++)
{
for(int invc_iter = 0; invc_iter < m_num_vcs; invc_iter++)
{
if(m_input_unit[inport_iter]->need_stage(invc_iter, VC_AB_, VA_))
{
if(!is_invc_candidate(inport_iter, invc_iter))
continue;
select_outvc(inport_iter, invc_iter);
}
}
}
}
void VCallocator_d::arbitrate_outvcs()
{
for(int outport_iter = 0; outport_iter < m_num_outports; outport_iter++)
{
for(int outvc_iter = 0; outvc_iter < m_num_vcs; outvc_iter++)
{
if(!m_outvc_is_req[outport_iter][outvc_iter]) // No requests for this outvc in this cycle
continue;
int inport = m_round_robin_outvc[outport_iter][outvc_iter].first;
int invc_offset = m_round_robin_outvc[outport_iter][outvc_iter].second;
int vnet = get_vnet(outvc_iter);
int invc_base = vnet*m_vc_per_vnet;
int num_vcs_per_vnet = m_vc_per_vnet;
m_round_robin_outvc[outport_iter][outvc_iter].second++;
if(m_round_robin_outvc[outport_iter][outvc_iter].second >= num_vcs_per_vnet)
{
m_round_robin_outvc[outport_iter][outvc_iter].second = 0;
m_round_robin_outvc[outport_iter][outvc_iter].first++;
if(m_round_robin_outvc[outport_iter][outvc_iter].first >= m_num_inports)
m_round_robin_outvc[outport_iter][outvc_iter].first = 0;
}
for(int in_iter = 0; in_iter < m_num_inports*num_vcs_per_vnet; in_iter++)
{
invc_offset++;
if(invc_offset >= num_vcs_per_vnet)
{
invc_offset = 0;
inport++;
if(inport >= m_num_inports)
inport = 0;
}
int invc = invc_base + invc_offset;
if(m_outvc_req[outport_iter][outvc_iter][inport][invc])
{
m_global_arbiter_activity++;
m_input_unit[inport]->grant_vc(invc, outvc_iter);
m_output_unit[outport_iter]->update_vc(outvc_iter, inport, invc);
m_router->swarb_req();
break;
}
}
}
}
}
int VCallocator_d::get_vnet(int invc)
{
for(int i = 0; i < RubySystem::getNetwork()->getNumberOfVirtualNetworks(); i++)
{
if(invc >= (i*m_vc_per_vnet) && invc < ((i+1)*m_vc_per_vnet))
{
return i;
}
}
ERROR_MSG("Could not determine vc");
return -1;
}
void VCallocator_d::check_for_wakeup()
{
for(int i = 0; i < m_num_inports; i++)
{
for(int j = 0; j < m_num_vcs; j++)
{
if(m_input_unit[i]->need_stage_nextcycle(j, VC_AB_, VA_))
{
g_eventQueue_ptr->scheduleEvent(this, 1);
return;
}
}
}
}
|