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