Deleted Added
sdiff udiff text old ( 7780:42da07116e12 ) new ( 7973:e5550966464a )
full compact
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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;

--- 40 unchanged lines hidden (view full) ---

49
50PerfectSwitch::PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr)
51{
52 m_virtual_networks = network_ptr->getNumberOfVirtualNetworks();
53 m_switch_id = sid;
54 m_round_robin_start = 0;
55 m_network_ptr = network_ptr;
56 m_wakeups_wo_switch = 0;
57
58 for(int i = 0;i < m_virtual_networks;++i)
59 {
60 m_pending_message_count.push_back(0);
61 }
62}
63
64void
65PerfectSwitch::addInPort(const vector<MessageBuffer*>& in)
66{
67 assert(in.size() == m_virtual_networks);
68 NodeID port = m_in.size();
69 m_in.push_back(in);
70
71 for (int j = 0; j < m_virtual_networks; j++) {
72 m_in[port][j]->setConsumer(this);
73 string desc = csprintf("[Queue from port %s %s %s to PerfectSwitch]",
74 NodeIDToString(m_switch_id), NodeIDToString(port),
75 NodeIDToString(j));
76 m_in[port][j]->setDescription(desc);
77 m_in[port][j]->setIncomingLink(port);
78 m_in[port][j]->setVnet(j);
79 }
80}
81
82void
83PerfectSwitch::addOutPort(const vector<MessageBuffer*>& out,
84 const NetDest& routing_table_entry)
85{
86 assert(out.size() == m_virtual_networks);

--- 70 unchanged lines hidden (view full) ---

157
158 // This is for round-robin scheduling
159 int incoming = m_round_robin_start;
160 m_round_robin_start++;
161 if (m_round_robin_start >= m_in.size()) {
162 m_round_robin_start = 0;
163 }
164
165 if(m_pending_message_count[vnet] > 0) {
166 // for all input ports, use round robin scheduling
167 for (int counter = 0; counter < m_in.size(); counter++) {
168 // Round robin scheduling
169 incoming++;
170 if (incoming >= m_in.size()) {
171 incoming = 0;
172 }
173
174 // temporary vectors to store the routing results
175 vector<LinkID> output_links;
176 vector<NetDest> output_link_destinations;
177
178 // Is there a message waiting?
179 while (m_in[incoming][vnet]->isReady()) {
180 DPRINTF(RubyNetwork, "incoming: %d\n", incoming);
181
182 // Peek at message
183 msg_ptr = m_in[incoming][vnet]->peekMsgPtr();
184 net_msg_ptr = safe_cast<NetworkMessage*>(msg_ptr.get());
185 DPRINTF(RubyNetwork, "Message: %s\n", (*net_msg_ptr));
186
187 output_links.clear();
188 output_link_destinations.clear();
189 NetDest msg_dsts =
190 net_msg_ptr->getInternalDestination();
191
192 // Unfortunately, the token-protocol sends some
193 // zero-destination messages, so this assert isn't valid
194 // assert(msg_dsts.count() > 0);
195
196 assert(m_link_order.size() == m_routing_table.size());
197 assert(m_link_order.size() == m_out.size());
198
199 if (m_network_ptr->getAdaptiveRouting()) {
200 if (m_network_ptr->isVNetOrdered(vnet)) {
201 // Don't adaptively route
202 for (int out = 0; out < m_out.size(); out++) {
203 m_link_order[out].m_link = out;
204 m_link_order[out].m_value = 0;
205 }
206 } else {
207 // Find how clogged each link is
208 for (int out = 0; out < m_out.size(); out++) {
209 int out_queue_length = 0;
210 for (int v = 0; v < m_virtual_networks; v++) {
211 out_queue_length += m_out[out][v]->getSize();
212 }
213 int value =
214 (out_queue_length << 8) | (random() & 0xff);
215 m_link_order[out].m_link = out;
216 m_link_order[out].m_value = value;
217 }
218
219 // Look at the most empty link first
220 sort(m_link_order.begin(), m_link_order.end());
221 }
222 }
223
224 for (int i = 0; i < m_routing_table.size(); i++) {
225 // pick the next link to look at
226 int link = m_link_order[i].m_link;
227 NetDest dst = m_routing_table[link];
228 DPRINTF(RubyNetwork, "dst: %s\n", dst);
229
230 if (!msg_dsts.intersectionIsNotEmpty(dst))
231 continue;
232
233 // Remember what link we're using
234 output_links.push_back(link);
235
236 // Need to remember which destinations need this
237 // message in another vector. This Set is the
238 // intersection of the routing_table entry and the
239 // current destination set. The intersection must
240 // not be empty, since we are inside "if"
241 output_link_destinations.push_back(msg_dsts.AND(dst));
242
243 // Next, we update the msg_destination not to
244 // include those nodes that were already handled
245 // by this link
246 msg_dsts.removeNetDest(dst);
247 }
248
249 assert(msg_dsts.count() == 0);
250 //assert(output_links.size() > 0);
251
252 // Check for resources - for all outgoing queues
253 bool enough = true;
254 for (int i = 0; i < output_links.size(); i++) {
255 int outgoing = output_links[i];
256 if (!m_out[outgoing][vnet]->areNSlotsAvailable(1))
257 enough = false;
258 DPRINTF(RubyNetwork, "Checking if node is blocked\n"
259 "outgoing: %d, vnet: %d, enough: %d\n",
260 outgoing, vnet, enough);
261 }
262
263 // There were not enough resources
264 if (!enough) {
265 g_eventQueue_ptr->scheduleEvent(this, 1);
266 DPRINTF(RubyNetwork, "Can't deliver message since a node "
267 "is blocked\n"
268 "Message: %s\n", (*net_msg_ptr));
269 break; // go to next incoming port
270 }
271
272 MsgPtr unmodified_msg_ptr;
273
274 if (output_links.size() > 1) {
275 // If we are sending this message down more than
276 // one link (size>1), we need to make a copy of
277 // the message so each branch can have a different
278 // internal destination we need to create an
279 // unmodified MsgPtr because the MessageBuffer
280 // enqueue func will modify the message
281
282 // This magic line creates a private copy of the
283 // message
284 unmodified_msg_ptr = msg_ptr->clone();
285 }
286
287 // Enqueue it - for all outgoing queues
288 for (int i=0; i<output_links.size(); i++) {
289 int outgoing = output_links[i];
290
291 if (i > 0) {
292 // create a private copy of the unmodified
293 // message
294 msg_ptr = unmodified_msg_ptr->clone();
295 }
296
297 // Change the internal destination set of the
298 // message so it knows which destinations this
299 // link is responsible for.
300 net_msg_ptr = safe_cast<NetworkMessage*>(msg_ptr.get());
301 net_msg_ptr->getInternalDestination() =
302 output_link_destinations[i];
303
304 // Enqeue msg
305 DPRINTF(RubyNetwork, "Switch: %d enqueuing net msg from "
306 "inport[%d][%d] to outport [%d][%d] time: %lld.\n",
307 m_switch_id, incoming, vnet, outgoing, vnet,
308 g_eventQueue_ptr->getTime());
309
310 m_out[outgoing][vnet]->enqueue(msg_ptr);
311 }
312
313 // Dequeue msg
314 m_in[incoming][vnet]->pop();
315 m_pending_message_count[vnet]--;
316 }
317 }
318 }
319 }
320}
321
322void
323PerfectSwitch::storeEventInfo(int info)
324{
325 m_pending_message_count[info]++;
326}
327
328void
329PerfectSwitch::printStats(std::ostream& out) const
330{
331 out << "PerfectSwitch printStats" << endl;
332}
333
334void
335PerfectSwitch::clearStats()
336{

--- 13 unchanged lines hidden ---