Deleted Added
sdiff udiff text old ( 11037:91d6a2d95cf8 ) new ( 11049:dfb0aa3f0649 )
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;

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

44// Operator for helper class
45bool
46operator<(const LinkOrder& l1, const LinkOrder& l2)
47{
48 return (l1.m_value < l2.m_value);
49}
50
51PerfectSwitch::PerfectSwitch(SwitchID sid, Switch *sw, uint32_t virt_nets)
52 : Consumer(sw)
53{
54 m_switch_id = sid;
55 m_round_robin_start = 0;
56 m_wakeups_wo_switch = 0;
57 m_virtual_networks = virt_nets;
58}
59
60void
61PerfectSwitch::init(SimpleNetwork *network_ptr)
62{

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

99
100PerfectSwitch::~PerfectSwitch()
101{
102}
103
104void
105PerfectSwitch::operateVnet(int vnet)
106{
107 MsgPtr msg_ptr;
108 Message *net_msg_ptr = NULL;
109
110 // This is for round-robin scheduling
111 int incoming = m_round_robin_start;
112 m_round_robin_start++;
113 if (m_round_robin_start >= m_in.size()) {
114 m_round_robin_start = 0;
115 }
116
117 if(m_pending_message_count[vnet] > 0) {
118 // for all input ports, use round robin scheduling
119 for (int counter = 0; counter < m_in.size(); counter++) {
120 // Round robin scheduling
121 incoming++;
122 if (incoming >= m_in.size()) {
123 incoming = 0;
124 }
125
126 // temporary vectors to store the routing results
127 vector<LinkID> output_links;
128 vector<NetDest> output_link_destinations;
129
130 // Is there a message waiting?
131 if (m_in[incoming].size() <= vnet) {
132 continue;
133 }
134
135 MessageBuffer *buffer = m_in[incoming][vnet];
136 if (buffer == nullptr) {
137 continue;
138 }
139
140 while (buffer->isReady()) {
141 DPRINTF(RubyNetwork, "incoming: %d\n", incoming);
142
143 // Peek at message
144 msg_ptr = buffer->peekMsgPtr();
145 net_msg_ptr = msg_ptr.get();
146 DPRINTF(RubyNetwork, "Message: %s\n", (*net_msg_ptr));
147
148 output_links.clear();
149 output_link_destinations.clear();
150 NetDest msg_dsts = net_msg_ptr->getDestination();
151
152 // Unfortunately, the token-protocol sends some
153 // zero-destination messages, so this assert isn't valid
154 // assert(msg_dsts.count() > 0);
155
156 assert(m_link_order.size() == m_routing_table.size());
157 assert(m_link_order.size() == m_out.size());
158
159 if (m_network_ptr->getAdaptiveRouting()) {
160 if (m_network_ptr->isVNetOrdered(vnet)) {
161 // Don't adaptively route
162 for (int out = 0; out < m_out.size(); out++) {
163 m_link_order[out].m_link = out;
164 m_link_order[out].m_value = 0;
165 }
166 } else {
167 // Find how clogged each link is
168 for (int out = 0; out < m_out.size(); out++) {
169 int out_queue_length = 0;
170 for (int v = 0; v < m_virtual_networks; v++) {
171 out_queue_length += m_out[out][v]->getSize();
172 }
173 int value =
174 (out_queue_length << 8) |
175 random_mt.random(0, 0xff);
176 m_link_order[out].m_link = out;
177 m_link_order[out].m_value = value;
178 }
179
180 // Look at the most empty link first
181 sort(m_link_order.begin(), m_link_order.end());
182 }
183 }
184
185 for (int i = 0; i < m_routing_table.size(); i++) {
186 // pick the next link to look at
187 int link = m_link_order[i].m_link;
188 NetDest dst = m_routing_table[link];
189 DPRINTF(RubyNetwork, "dst: %s\n", dst);
190
191 if (!msg_dsts.intersectionIsNotEmpty(dst))
192 continue;
193
194 // Remember what link we're using
195 output_links.push_back(link);
196
197 // Need to remember which destinations need this message in
198 // another vector. This Set is the intersection of the
199 // routing_table entry and the current destination set. The
200 // intersection must not be empty, since we are inside "if"
201 output_link_destinations.push_back(msg_dsts.AND(dst));
202
203 // Next, we update the msg_destination not to include
204 // those nodes that were already handled by this link
205 msg_dsts.removeNetDest(dst);
206 }
207
208 assert(msg_dsts.count() == 0);
209
210 // Check for resources - for all outgoing queues
211 bool enough = true;
212 for (int i = 0; i < output_links.size(); i++) {
213 int outgoing = output_links[i];
214
215 if (!m_out[outgoing][vnet]->areNSlotsAvailable(1))
216 enough = false;
217
218 DPRINTF(RubyNetwork, "Checking if node is blocked ..."
219 "outgoing: %d, vnet: %d, enough: %d\n",
220 outgoing, vnet, enough);
221 }
222
223 // There were not enough resources
224 if (!enough) {
225 scheduleEvent(Cycles(1));
226 DPRINTF(RubyNetwork, "Can't deliver message since a node "
227 "is blocked\n");
228 DPRINTF(RubyNetwork, "Message: %s\n", (*net_msg_ptr));
229 break; // go to next incoming port
230 }
231
232 MsgPtr unmodified_msg_ptr;
233
234 if (output_links.size() > 1) {
235 // If we are sending this message down more than one link
236 // (size>1), we need to make a copy of the message so each
237 // branch can have a different internal destination we need
238 // to create an unmodified MsgPtr because the MessageBuffer
239 // enqueue func will modify the message
240
241 // This magic line creates a private copy of the message
242 unmodified_msg_ptr = msg_ptr->clone();
243 }
244
245 // Dequeue msg
246 buffer->dequeue();
247 m_pending_message_count[vnet]--;
248
249 // Enqueue it - for all outgoing queues
250 for (int i=0; i<output_links.size(); i++) {
251 int outgoing = output_links[i];
252
253 if (i > 0) {
254 // create a private copy of the unmodified message
255 msg_ptr = unmodified_msg_ptr->clone();
256 }
257
258 // Change the internal destination set of the message so it
259 // knows which destinations this link is responsible for.
260 net_msg_ptr = msg_ptr.get();
261 net_msg_ptr->getDestination() =
262 output_link_destinations[i];
263
264 // Enqeue msg
265 DPRINTF(RubyNetwork, "Enqueuing net msg from "
266 "inport[%d][%d] to outport [%d][%d].\n",
267 incoming, vnet, outgoing, vnet);
268
269 m_out[outgoing][vnet]->enqueue(msg_ptr);
270 }
271 }
272 }
273 }
274}
275
276void
277PerfectSwitch::wakeup()
278{
279 // Give the highest numbered link priority most of the time

--- 42 unchanged lines hidden ---