packet_queue.cc revision 4490
1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 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; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Ali Saidi 29 */ 30 31#include "mem/tport.hh" 32 33void 34SimpleTimingPort::checkFunctional(PacketPtr pkt) 35{ 36 DeferredPacketIterator i = transmitList.begin(); 37 DeferredPacketIterator end = transmitList.end(); 38 39 while (i != end) { 40 PacketPtr target = i->pkt; 41 // If the target contains data, and it overlaps the 42 // probed request, need to update data 43 if (target->intersect(pkt)) { 44 if (!fixPacket(pkt, target)) { 45 // fixPacket returns true for continue, false for done 46 return; 47 } 48 } 49 50 i++; 51 } 52} 53 54void 55SimpleTimingPort::recvFunctional(PacketPtr pkt) 56{ 57 checkFunctional(pkt); 58 59 // Just do an atomic access and throw away the returned latency 60 if (pkt->result != Packet::Success) 61 recvAtomic(pkt); 62} 63 64bool 65SimpleTimingPort::recvTiming(PacketPtr pkt) 66{ 67 // If the device is only a slave, it should only be sending 68 // responses, which should never get nacked. There used to be 69 // code to hanldle nacks here, but I'm pretty sure it didn't work 70 // correctly with the drain code, so that would need to be fixed 71 // if we ever added it back. 72 assert(pkt->result != Packet::Nacked); 73 Tick latency = recvAtomic(pkt); 74 // turn packet around to go back to requester if response expected 75 if (pkt->needsResponse()) { 76 pkt->makeTimingResponse(); 77 sendTiming(pkt, latency); 78 } 79 else if (pkt->cmd != MemCmd::UpgradeReq) { 80 delete pkt->req; 81 delete pkt; 82 } 83 return true; 84} 85 86void 87SimpleTimingPort::recvRetry() 88{ 89 assert(!transmitList.empty()); 90 if (Port::sendTiming(transmitList.front().pkt)) { 91 transmitList.pop_front(); 92 DPRINTF(Bus, "No Longer waiting on retry\n"); 93 if (!transmitList.empty()) { 94 Tick time = transmitList.front().tick; 95 sendEvent->schedule(time <= curTick ? curTick+1 : time); 96 } 97 } 98 99 if (transmitList.empty() && drainEvent) { 100 drainEvent->process(); 101 drainEvent = NULL; 102 } 103} 104 105void 106SimpleTimingPort::sendTiming(PacketPtr pkt, Tick time) 107{ 108 // Nothing is on the list: add it and schedule an event 109 if (transmitList.empty()) { 110 assert(!sendEvent->scheduled()); 111 sendEvent->schedule(curTick+time); 112 transmitList.push_back(DeferredPacket(time+curTick, pkt)); 113 return; 114 } 115 116 // something is on the list and this belongs at the end 117 if (time+curTick >= transmitList.back().tick) { 118 transmitList.push_back(DeferredPacket(time+curTick, pkt)); 119 return; 120 } 121 // Something is on the list and this belongs somewhere else 122 DeferredPacketIterator i = transmitList.begin(); 123 DeferredPacketIterator end = transmitList.end(); 124 bool done = false; 125 126 while (i != end && !done) { 127 if (time+curTick < i->tick) { 128 if (i == transmitList.begin()) { 129 //Inserting at begining, reschedule 130 sendEvent->reschedule(time+curTick); 131 } 132 transmitList.insert(i, DeferredPacket(time+curTick, pkt)); 133 done = true; 134 } 135 i++; 136 } 137 assert(done); 138} 139 140void 141SimpleTimingPort::processSendEvent() 142{ 143 assert(transmitList.size()); 144 assert(transmitList.front().tick <= curTick); 145 if (Port::sendTiming(transmitList.front().pkt)) { 146 //send successful, remove packet 147 transmitList.pop_front(); 148 if (!transmitList.empty()) { 149 Tick time = transmitList.front().tick; 150 sendEvent->schedule(time <= curTick ? curTick+1 : time); 151 } 152 if (transmitList.empty() && drainEvent) { 153 drainEvent->process(); 154 drainEvent = NULL; 155 } 156 return; 157 } 158 // send unsuccessful (due to flow control). Will get retry 159 // callback later; save for then if not already 160 DPRINTF(Bus, "Waiting on retry\n"); 161} 162 163 164unsigned int 165SimpleTimingPort::drain(Event *de) 166{ 167 if (transmitList.size() == 0) 168 return 0; 169 drainEvent = de; 170 return 1; 171} 172