bridge.cc (8975:7f36d4436074) | bridge.cc (9029:120ba616606e) |
---|---|
1/* 2 * Copyright (c) 2011-2012 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 188 unchanged lines hidden (view full) --- 197 // The Nack packets are stored in the response queue just like any 198 // other response, but they do not occupy any space as this is 199 // tracked by the outstandingResponses, this guarantees space for 200 // the Nack packets, but implicitly means we have an (unrealistic) 201 // unbounded Nack queue. 202 203 // put it on the list to send 204 Tick readyTime = curTick() + nackDelay; | 1/* 2 * Copyright (c) 2011-2012 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 188 unchanged lines hidden (view full) --- 197 // The Nack packets are stored in the response queue just like any 198 // other response, but they do not occupy any space as this is 199 // tracked by the outstandingResponses, this guarantees space for 200 // the Nack packets, but implicitly means we have an (unrealistic) 201 // unbounded Nack queue. 202 203 // put it on the list to send 204 Tick readyTime = curTick() + nackDelay; |
205 PacketBuffer *buf = new PacketBuffer(pkt, readyTime, true); | 205 DeferredResponse resp(pkt, readyTime, true); |
206 207 // nothing on the list, add it and we're done 208 if (responseQueue.empty()) { 209 assert(!sendEvent.scheduled()); 210 bridge->schedule(sendEvent, readyTime); | 206 207 // nothing on the list, add it and we're done 208 if (responseQueue.empty()) { 209 assert(!sendEvent.scheduled()); 210 bridge->schedule(sendEvent, readyTime); |
211 responseQueue.push_back(buf); | 211 responseQueue.push_back(resp); |
212 return; 213 } 214 215 assert(sendEvent.scheduled() || inRetry); 216 217 // does it go at the end? | 212 return; 213 } 214 215 assert(sendEvent.scheduled() || inRetry); 216 217 // does it go at the end? |
218 if (readyTime >= responseQueue.back()->ready) { 219 responseQueue.push_back(buf); | 218 if (readyTime >= responseQueue.back().ready) { 219 responseQueue.push_back(resp); |
220 return; 221 } 222 223 // ok, somewhere in the middle, fun | 220 return; 221 } 222 223 // ok, somewhere in the middle, fun |
224 std::list<PacketBuffer*>::iterator i = responseQueue.begin(); 225 std::list<PacketBuffer*>::iterator end = responseQueue.end(); 226 std::list<PacketBuffer*>::iterator begin = responseQueue.begin(); | 224 std::list<DeferredResponse>::iterator i = responseQueue.begin(); 225 std::list<DeferredResponse>::iterator end = responseQueue.end(); 226 std::list<DeferredResponse>::iterator begin = responseQueue.begin(); |
227 bool done = false; 228 229 while (i != end && !done) { | 227 bool done = false; 228 229 while (i != end && !done) { |
230 if (readyTime < (*i)->ready) { | 230 if (readyTime < (*i).ready) { |
231 if (i == begin) 232 bridge->reschedule(sendEvent, readyTime); | 231 if (i == begin) 232 bridge->reschedule(sendEvent, readyTime); |
233 responseQueue.insert(i,buf); | 233 responseQueue.insert(i, resp); |
234 done = true; 235 } 236 i++; 237 } 238 assert(done); 239} 240 241void 242Bridge::BridgeMasterPort::queueForSendTiming(PacketPtr pkt) 243{ 244 Tick readyTime = curTick() + delay; | 234 done = true; 235 } 236 i++; 237 } 238 assert(done); 239} 240 241void 242Bridge::BridgeMasterPort::queueForSendTiming(PacketPtr pkt) 243{ 244 Tick readyTime = curTick() + delay; |
245 PacketBuffer *buf = new PacketBuffer(pkt, readyTime); | |
246 | 245 |
246 // If we expect to see a response, we need to restore the source 247 // and destination field that is potentially changed by a second 248 // bus 249 if (!pkt->memInhibitAsserted() && pkt->needsResponse()) { 250 // Update the sender state so we can deal with the response 251 // appropriately 252 RequestState *req_state = new RequestState(pkt); 253 pkt->senderState = req_state; 254 } 255 |
|
247 // If we're about to put this packet at the head of the queue, we 248 // need to schedule an event to do the transmit. Otherwise there 249 // should already be an event scheduled for sending the head 250 // packet. 251 if (requestQueue.empty()) { 252 bridge->schedule(sendEvent, readyTime); 253 } 254 255 assert(requestQueue.size() != reqQueueLimit); 256 | 256 // If we're about to put this packet at the head of the queue, we 257 // need to schedule an event to do the transmit. Otherwise there 258 // should already be an event scheduled for sending the head 259 // packet. 260 if (requestQueue.empty()) { 261 bridge->schedule(sendEvent, readyTime); 262 } 263 264 assert(requestQueue.size() != reqQueueLimit); 265 |
257 requestQueue.push_back(buf); | 266 requestQueue.push_back(DeferredRequest(pkt, readyTime)); |
258} 259 260 261void 262Bridge::BridgeSlavePort::queueForSendTiming(PacketPtr pkt) 263{ 264 // This is a response for a request we forwarded earlier. The | 267} 268 269 270void 271Bridge::BridgeSlavePort::queueForSendTiming(PacketPtr pkt) 272{ 273 // This is a response for a request we forwarded earlier. The |
265 // corresponding PacketBuffer should be stored in the packet's | 274 // corresponding request state should be stored in the packet's |
266 // senderState field. | 275 // senderState field. |
267 PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState); 268 assert(buf != NULL); | 276 RequestState *req_state = dynamic_cast<RequestState*>(pkt->senderState); 277 assert(req_state != NULL); |
269 // set up new packet dest & senderState based on values saved 270 // from original request | 278 // set up new packet dest & senderState based on values saved 279 // from original request |
271 buf->fixResponse(pkt); | 280 req_state->fixResponse(pkt); |
272 273 // the bridge assumes that at least one bus has set the 274 // destination field of the packet 275 assert(pkt->isDestValid()); 276 DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest()); | 281 282 // the bridge assumes that at least one bus has set the 283 // destination field of the packet 284 assert(pkt->isDestValid()); 285 DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest()); |
277 delete buf; | 286 delete req_state; |
278 279 Tick readyTime = curTick() + delay; | 287 288 Tick readyTime = curTick() + delay; |
280 buf = new PacketBuffer(pkt, readyTime); | |
281 282 // If we're about to put this packet at the head of the queue, we 283 // need to schedule an event to do the transmit. Otherwise there 284 // should already be an event scheduled for sending the head 285 // packet. 286 if (responseQueue.empty()) { 287 bridge->schedule(sendEvent, readyTime); 288 } | 289 290 // If we're about to put this packet at the head of the queue, we 291 // need to schedule an event to do the transmit. Otherwise there 292 // should already be an event scheduled for sending the head 293 // packet. 294 if (responseQueue.empty()) { 295 bridge->schedule(sendEvent, readyTime); 296 } |
289 responseQueue.push_back(buf); | 297 responseQueue.push_back(DeferredResponse(pkt, readyTime)); |
290} 291 292void 293Bridge::BridgeMasterPort::trySend() 294{ 295 assert(!requestQueue.empty()); 296 | 298} 299 300void 301Bridge::BridgeMasterPort::trySend() 302{ 303 assert(!requestQueue.empty()); 304 |
297 PacketBuffer *buf = requestQueue.front(); | 305 DeferredRequest req = requestQueue.front(); |
298 | 306 |
299 assert(buf->ready <= curTick()); | 307 assert(req.ready <= curTick()); |
300 | 308 |
301 PacketPtr pkt = buf->pkt; | 309 PacketPtr pkt = req.pkt; |
302 | 310 |
303 DPRINTF(BusBridge, "trySend: origSrc %d addr 0x%x\n", 304 buf->origSrc, pkt->getAddr()); | 311 DPRINTF(BusBridge, "trySend request: addr 0x%x\n", pkt->getAddr()); |
305 | 312 |
306 // If the send was successful, make sure sender state was set to NULL 307 // otherwise we could get a NACK back of a packet that didn't expect a 308 // response and we would try to use freed memory. 309 310 Packet::SenderState *old_sender_state = pkt->senderState; 311 if (!buf->expectResponse) 312 pkt->senderState = NULL; 313 | |
314 if (sendTimingReq(pkt)) { 315 // send successful 316 requestQueue.pop_front(); | 313 if (sendTimingReq(pkt)) { 314 // send successful 315 requestQueue.pop_front(); |
317 // we no longer own packet, so it's not safe to look at it 318 buf->pkt = NULL; | |
319 | 316 |
320 if (!buf->expectResponse) { 321 // no response expected... deallocate packet buffer now. 322 DPRINTF(BusBridge, " successful: no response expected\n"); 323 delete buf; 324 } 325 | |
326 // If there are more packets to send, schedule event to try again. 327 if (!requestQueue.empty()) { | 317 // If there are more packets to send, schedule event to try again. 318 if (!requestQueue.empty()) { |
328 buf = requestQueue.front(); | 319 req = requestQueue.front(); |
329 DPRINTF(BusBridge, "Scheduling next send\n"); | 320 DPRINTF(BusBridge, "Scheduling next send\n"); |
330 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1)); | 321 bridge->schedule(sendEvent, 322 std::max(req.ready, curTick() + 1)); |
331 } 332 } else { | 323 } 324 } else { |
333 DPRINTF(BusBridge, " unsuccessful\n"); 334 pkt->senderState = old_sender_state; | |
335 inRetry = true; 336 } 337 338 DPRINTF(BusBridge, "trySend: request queue size: %d\n", 339 requestQueue.size()); 340} 341 342void 343Bridge::BridgeSlavePort::trySend() 344{ 345 assert(!responseQueue.empty()); 346 | 325 inRetry = true; 326 } 327 328 DPRINTF(BusBridge, "trySend: request queue size: %d\n", 329 requestQueue.size()); 330} 331 332void 333Bridge::BridgeSlavePort::trySend() 334{ 335 assert(!responseQueue.empty()); 336 |
347 PacketBuffer *buf = responseQueue.front(); | 337 DeferredResponse resp = responseQueue.front(); |
348 | 338 |
349 assert(buf->ready <= curTick()); | 339 assert(resp.ready <= curTick()); |
350 | 340 |
351 PacketPtr pkt = buf->pkt; | 341 PacketPtr pkt = resp.pkt; |
352 | 342 |
353 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 354 buf->origSrc, pkt->getDest(), pkt->getAddr()); | 343 DPRINTF(BusBridge, "trySend response: dest %d addr 0x%x\n", 344 pkt->getDest(), pkt->getAddr()); |
355 | 345 |
356 bool was_nacked_here = buf->nackedHere; | 346 bool was_nacked_here = resp.nackedHere; |
357 | 347 |
358 // no need to worry about the sender state since we are not 359 // modifying it 360 | |
361 if (sendTimingResp(pkt)) { 362 DPRINTF(BusBridge, " successful\n"); 363 // send successful 364 responseQueue.pop_front(); | 348 if (sendTimingResp(pkt)) { 349 DPRINTF(BusBridge, " successful\n"); 350 // send successful 351 responseQueue.pop_front(); |
365 // this is a response... deallocate packet buffer now. 366 delete buf; | |
367 368 if (!was_nacked_here) { 369 assert(outstandingResponses != 0); 370 --outstandingResponses; 371 } 372 373 // If there are more packets to send, schedule event to try again. 374 if (!responseQueue.empty()) { | 352 353 if (!was_nacked_here) { 354 assert(outstandingResponses != 0); 355 --outstandingResponses; 356 } 357 358 // If there are more packets to send, schedule event to try again. 359 if (!responseQueue.empty()) { |
375 buf = responseQueue.front(); | 360 resp = responseQueue.front(); |
376 DPRINTF(BusBridge, "Scheduling next send\n"); | 361 DPRINTF(BusBridge, "Scheduling next send\n"); |
377 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1)); | 362 bridge->schedule(sendEvent, 363 std::max(resp.ready, curTick() + 1)); |
378 } 379 } else { 380 DPRINTF(BusBridge, " unsuccessful\n"); 381 inRetry = true; 382 } 383 384 DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n", 385 responseQueue.size(), outstandingResponses); 386} 387 388void 389Bridge::BridgeMasterPort::recvRetry() 390{ 391 inRetry = false; | 364 } 365 } else { 366 DPRINTF(BusBridge, " unsuccessful\n"); 367 inRetry = true; 368 } 369 370 DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n", 371 responseQueue.size(), outstandingResponses); 372} 373 374void 375Bridge::BridgeMasterPort::recvRetry() 376{ 377 inRetry = false; |
392 Tick nextReady = requestQueue.front()->ready; | 378 Tick nextReady = requestQueue.front().ready; |
393 if (nextReady <= curTick()) 394 trySend(); 395 else 396 bridge->schedule(sendEvent, nextReady); 397} 398 399void 400Bridge::BridgeSlavePort::recvRetry() 401{ 402 inRetry = false; | 379 if (nextReady <= curTick()) 380 trySend(); 381 else 382 bridge->schedule(sendEvent, nextReady); 383} 384 385void 386Bridge::BridgeSlavePort::recvRetry() 387{ 388 inRetry = false; |
403 Tick nextReady = responseQueue.front()->ready; | 389 Tick nextReady = responseQueue.front().ready; |
404 if (nextReady <= curTick()) 405 trySend(); 406 else 407 bridge->schedule(sendEvent, nextReady); 408} 409 410Tick 411Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt) 412{ 413 return delay + masterPort.sendAtomic(pkt); 414} 415 416void 417Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt) 418{ | 390 if (nextReady <= curTick()) 391 trySend(); 392 else 393 bridge->schedule(sendEvent, nextReady); 394} 395 396Tick 397Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt) 398{ 399 return delay + masterPort.sendAtomic(pkt); 400} 401 402void 403Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt) 404{ |
419 std::list<PacketBuffer*>::iterator i; | 405 std::list<DeferredResponse>::iterator i; |
420 421 pkt->pushLabel(name()); 422 423 // check the response queue 424 for (i = responseQueue.begin(); i != responseQueue.end(); ++i) { | 406 407 pkt->pushLabel(name()); 408 409 // check the response queue 410 for (i = responseQueue.begin(); i != responseQueue.end(); ++i) { |
425 if (pkt->checkFunctional((*i)->pkt)) { | 411 if (pkt->checkFunctional((*i).pkt)) { |
426 pkt->makeResponse(); 427 return; 428 } 429 } 430 431 // also check the master port's request queue 432 if (masterPort.checkFunctional(pkt)) { 433 return; --- 4 unchanged lines hidden (view full) --- 438 // fall through if pkt still not satisfied 439 masterPort.sendFunctional(pkt); 440} 441 442bool 443Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt) 444{ 445 bool found = false; | 412 pkt->makeResponse(); 413 return; 414 } 415 } 416 417 // also check the master port's request queue 418 if (masterPort.checkFunctional(pkt)) { 419 return; --- 4 unchanged lines hidden (view full) --- 424 // fall through if pkt still not satisfied 425 masterPort.sendFunctional(pkt); 426} 427 428bool 429Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt) 430{ 431 bool found = false; |
446 std::list<PacketBuffer*>::iterator i = requestQueue.begin(); | 432 std::list<DeferredRequest>::iterator i = requestQueue.begin(); |
447 448 while(i != requestQueue.end() && !found) { | 433 434 while(i != requestQueue.end() && !found) { |
449 if (pkt->checkFunctional((*i)->pkt)) { | 435 if (pkt->checkFunctional((*i).pkt)) { |
450 pkt->makeResponse(); 451 found = true; 452 } 453 ++i; 454 } 455 456 return found; 457} --- 12 unchanged lines hidden --- | 436 pkt->makeResponse(); 437 found = true; 438 } 439 ++i; 440 } 441 442 return found; 443} --- 12 unchanged lines hidden --- |