tport.cc revision 4626
12914Ssaidi@eecs.umich.edu/* 22914Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 32914Ssaidi@eecs.umich.edu * All rights reserved. 42914Ssaidi@eecs.umich.edu * 52914Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 62914Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 72914Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 82914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 92914Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 102914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 112914Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 122914Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 132914Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 142914Ssaidi@eecs.umich.edu * this software without specific prior written permission. 152914Ssaidi@eecs.umich.edu * 162914Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172914Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182914Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192914Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202914Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212914Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222914Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232914Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242914Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252914Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262914Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272914Ssaidi@eecs.umich.edu * 282914Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292914Ssaidi@eecs.umich.edu */ 302914Ssaidi@eecs.umich.edu 312914Ssaidi@eecs.umich.edu#include "mem/tport.hh" 322914Ssaidi@eecs.umich.edu 332914Ssaidi@eecs.umich.eduvoid 344490Sstever@eecs.umich.eduSimpleTimingPort::checkFunctional(PacketPtr pkt) 353091Sstever@eecs.umich.edu{ 364490Sstever@eecs.umich.edu DeferredPacketIterator i = transmitList.begin(); 374490Sstever@eecs.umich.edu DeferredPacketIterator end = transmitList.end(); 383296Ssaidi@eecs.umich.edu 394492Sstever@eecs.umich.edu for (; i != end; ++i) { 404490Sstever@eecs.umich.edu PacketPtr target = i->pkt; 413284Srdreslin@umich.edu // If the target contains data, and it overlaps the 423284Srdreslin@umich.edu // probed request, need to update data 434490Sstever@eecs.umich.edu if (target->intersect(pkt)) { 444490Sstever@eecs.umich.edu if (!fixPacket(pkt, target)) { 454490Sstever@eecs.umich.edu // fixPacket returns true for continue, false for done 464490Sstever@eecs.umich.edu return; 474490Sstever@eecs.umich.edu } 484490Sstever@eecs.umich.edu } 493284Srdreslin@umich.edu } 504490Sstever@eecs.umich.edu} 513342Srdreslin@umich.edu 524490Sstever@eecs.umich.eduvoid 534490Sstever@eecs.umich.eduSimpleTimingPort::recvFunctional(PacketPtr pkt) 544490Sstever@eecs.umich.edu{ 554490Sstever@eecs.umich.edu checkFunctional(pkt); 564490Sstever@eecs.umich.edu 574490Sstever@eecs.umich.edu // Just do an atomic access and throw away the returned latency 583342Srdreslin@umich.edu if (pkt->result != Packet::Success) 593296Ssaidi@eecs.umich.edu recvAtomic(pkt); 603091Sstever@eecs.umich.edu} 613091Sstever@eecs.umich.edu 623091Sstever@eecs.umich.edubool 633349Sbinkertn@umich.eduSimpleTimingPort::recvTiming(PacketPtr pkt) 643091Sstever@eecs.umich.edu{ 653091Sstever@eecs.umich.edu // If the device is only a slave, it should only be sending 663091Sstever@eecs.umich.edu // responses, which should never get nacked. There used to be 673091Sstever@eecs.umich.edu // code to hanldle nacks here, but I'm pretty sure it didn't work 683091Sstever@eecs.umich.edu // correctly with the drain code, so that would need to be fixed 693091Sstever@eecs.umich.edu // if we ever added it back. 704626Sstever@eecs.umich.edu assert(pkt->isRequest()); 714626Sstever@eecs.umich.edu assert(pkt->result == Packet::Unknown); 724626Sstever@eecs.umich.edu bool needsResponse = pkt->needsResponse(); 733091Sstever@eecs.umich.edu Tick latency = recvAtomic(pkt); 743175Srdreslin@umich.edu // turn packet around to go back to requester if response expected 754626Sstever@eecs.umich.edu if (needsResponse) { 764626Sstever@eecs.umich.edu // recvAtomic() should already have turned packet into atomic response 774626Sstever@eecs.umich.edu assert(pkt->isResponse()); 784626Sstever@eecs.umich.edu pkt->convertAtomicToTimingResponse(); 794493Sstever@eecs.umich.edu schedSendTiming(pkt, curTick + latency); 804626Sstever@eecs.umich.edu } else { 814490Sstever@eecs.umich.edu delete pkt->req; 824490Sstever@eecs.umich.edu delete pkt; 833309Srdreslin@umich.edu } 843091Sstever@eecs.umich.edu return true; 853091Sstever@eecs.umich.edu} 863091Sstever@eecs.umich.edu 872914Ssaidi@eecs.umich.edu 882914Ssaidi@eecs.umich.eduvoid 894492Sstever@eecs.umich.eduSimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when) 903403Ssaidi@eecs.umich.edu{ 914492Sstever@eecs.umich.edu assert(when > curTick); 924492Sstever@eecs.umich.edu 933450Ssaidi@eecs.umich.edu // Nothing is on the list: add it and schedule an event 943403Ssaidi@eecs.umich.edu if (transmitList.empty()) { 954490Sstever@eecs.umich.edu assert(!sendEvent->scheduled()); 964492Sstever@eecs.umich.edu sendEvent->schedule(when); 974492Sstever@eecs.umich.edu transmitList.push_back(DeferredPacket(when, pkt)); 983450Ssaidi@eecs.umich.edu return; 993403Ssaidi@eecs.umich.edu } 1003450Ssaidi@eecs.umich.edu 1013450Ssaidi@eecs.umich.edu // something is on the list and this belongs at the end 1024492Sstever@eecs.umich.edu if (when >= transmitList.back().tick) { 1034492Sstever@eecs.umich.edu transmitList.push_back(DeferredPacket(when, pkt)); 1043450Ssaidi@eecs.umich.edu return; 1053450Ssaidi@eecs.umich.edu } 1063450Ssaidi@eecs.umich.edu // Something is on the list and this belongs somewhere else 1074490Sstever@eecs.umich.edu DeferredPacketIterator i = transmitList.begin(); 1084490Sstever@eecs.umich.edu DeferredPacketIterator end = transmitList.end(); 1093450Ssaidi@eecs.umich.edu 1104492Sstever@eecs.umich.edu for (; i != end; ++i) { 1114492Sstever@eecs.umich.edu if (when < i->tick) { 1123610Srdreslin@umich.edu if (i == transmitList.begin()) { 1133610Srdreslin@umich.edu //Inserting at begining, reschedule 1144492Sstever@eecs.umich.edu sendEvent->reschedule(when); 1153610Srdreslin@umich.edu } 1164492Sstever@eecs.umich.edu transmitList.insert(i, DeferredPacket(when, pkt)); 1174492Sstever@eecs.umich.edu return; 1183610Srdreslin@umich.edu } 1193450Ssaidi@eecs.umich.edu } 1204492Sstever@eecs.umich.edu assert(false); // should never get here 1213403Ssaidi@eecs.umich.edu} 1223403Ssaidi@eecs.umich.edu 1234492Sstever@eecs.umich.edu 1243403Ssaidi@eecs.umich.eduvoid 1254492Sstever@eecs.umich.eduSimpleTimingPort::sendDeferredPacket() 1262914Ssaidi@eecs.umich.edu{ 1274492Sstever@eecs.umich.edu assert(deferredPacketReady()); 1284492Sstever@eecs.umich.edu bool success = sendTiming(transmitList.front().pkt); 1294492Sstever@eecs.umich.edu 1304492Sstever@eecs.umich.edu if (success) { 1313403Ssaidi@eecs.umich.edu //send successful, remove packet 1324490Sstever@eecs.umich.edu transmitList.pop_front(); 1334490Sstever@eecs.umich.edu if (!transmitList.empty()) { 1344490Sstever@eecs.umich.edu Tick time = transmitList.front().tick; 1354490Sstever@eecs.umich.edu sendEvent->schedule(time <= curTick ? curTick+1 : time); 1363263Srdreslin@umich.edu } 1374492Sstever@eecs.umich.edu 1384490Sstever@eecs.umich.edu if (transmitList.empty() && drainEvent) { 1394490Sstever@eecs.umich.edu drainEvent->process(); 1404490Sstever@eecs.umich.edu drainEvent = NULL; 1413091Sstever@eecs.umich.edu } 1423091Sstever@eecs.umich.edu } 1434492Sstever@eecs.umich.edu 1444492Sstever@eecs.umich.edu waitingOnRetry = !success; 1454492Sstever@eecs.umich.edu 1464492Sstever@eecs.umich.edu if (waitingOnRetry) { 1474492Sstever@eecs.umich.edu DPRINTF(Bus, "Send failed, waiting on retry\n"); 1484492Sstever@eecs.umich.edu } 1494492Sstever@eecs.umich.edu} 1504492Sstever@eecs.umich.edu 1514492Sstever@eecs.umich.edu 1524492Sstever@eecs.umich.eduvoid 1534492Sstever@eecs.umich.eduSimpleTimingPort::recvRetry() 1544492Sstever@eecs.umich.edu{ 1554492Sstever@eecs.umich.edu DPRINTF(Bus, "Received retry\n"); 1564492Sstever@eecs.umich.edu assert(waitingOnRetry); 1574492Sstever@eecs.umich.edu sendDeferredPacket(); 1584492Sstever@eecs.umich.edu} 1594492Sstever@eecs.umich.edu 1604492Sstever@eecs.umich.edu 1614492Sstever@eecs.umich.eduvoid 1624492Sstever@eecs.umich.eduSimpleTimingPort::processSendEvent() 1634492Sstever@eecs.umich.edu{ 1644492Sstever@eecs.umich.edu assert(!waitingOnRetry); 1654492Sstever@eecs.umich.edu sendDeferredPacket(); 1662914Ssaidi@eecs.umich.edu} 1672914Ssaidi@eecs.umich.edu 1682914Ssaidi@eecs.umich.edu 1692914Ssaidi@eecs.umich.eduunsigned int 1702914Ssaidi@eecs.umich.eduSimpleTimingPort::drain(Event *de) 1712914Ssaidi@eecs.umich.edu{ 1723403Ssaidi@eecs.umich.edu if (transmitList.size() == 0) 1732914Ssaidi@eecs.umich.edu return 0; 1742914Ssaidi@eecs.umich.edu drainEvent = de; 1752914Ssaidi@eecs.umich.edu return 1; 1762914Ssaidi@eecs.umich.edu} 177