tport.cc revision 4870
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 584870Sstever@eecs.umich.edu if (!pkt->isResponse()) 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()); 714670Sstever@eecs.umich.edu 724670Sstever@eecs.umich.edu if (pkt->memInhibitAsserted()) { 734670Sstever@eecs.umich.edu // snooper will supply based on copy of packet 744670Sstever@eecs.umich.edu // still target's responsibility to delete packet 754670Sstever@eecs.umich.edu delete pkt->req; 764670Sstever@eecs.umich.edu delete pkt; 774670Sstever@eecs.umich.edu return true; 784670Sstever@eecs.umich.edu } 794670Sstever@eecs.umich.edu 804626Sstever@eecs.umich.edu bool needsResponse = pkt->needsResponse(); 813091Sstever@eecs.umich.edu Tick latency = recvAtomic(pkt); 823175Srdreslin@umich.edu // turn packet around to go back to requester if response expected 834626Sstever@eecs.umich.edu if (needsResponse) { 844670Sstever@eecs.umich.edu // recvAtomic() should already have turned packet into 854670Sstever@eecs.umich.edu // atomic response 864626Sstever@eecs.umich.edu assert(pkt->isResponse()); 874493Sstever@eecs.umich.edu schedSendTiming(pkt, curTick + latency); 884626Sstever@eecs.umich.edu } else { 894490Sstever@eecs.umich.edu delete pkt->req; 904490Sstever@eecs.umich.edu delete pkt; 913309Srdreslin@umich.edu } 924670Sstever@eecs.umich.edu 933091Sstever@eecs.umich.edu return true; 943091Sstever@eecs.umich.edu} 953091Sstever@eecs.umich.edu 962914Ssaidi@eecs.umich.edu 972914Ssaidi@eecs.umich.eduvoid 984492Sstever@eecs.umich.eduSimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when) 993403Ssaidi@eecs.umich.edu{ 1004492Sstever@eecs.umich.edu assert(when > curTick); 1014492Sstever@eecs.umich.edu 1023450Ssaidi@eecs.umich.edu // Nothing is on the list: add it and schedule an event 1034666Sstever@eecs.umich.edu if (transmitList.empty() || when < transmitList.front().tick) { 1044666Sstever@eecs.umich.edu transmitList.push_front(DeferredPacket(when, pkt)); 1054666Sstever@eecs.umich.edu schedSendEvent(when); 1064666Sstever@eecs.umich.edu return; 1074666Sstever@eecs.umich.edu } 1084666Sstever@eecs.umich.edu 1094666Sstever@eecs.umich.edu // list is non-empty and this is not the head, so event should 1104666Sstever@eecs.umich.edu // already be scheduled 1114666Sstever@eecs.umich.edu assert(waitingOnRetry || 1124666Sstever@eecs.umich.edu (sendEvent->scheduled() && sendEvent->when() <= when)); 1134666Sstever@eecs.umich.edu 1144666Sstever@eecs.umich.edu // list is non-empty & this belongs at the end 1154666Sstever@eecs.umich.edu if (when >= transmitList.back().tick) { 1164492Sstever@eecs.umich.edu transmitList.push_back(DeferredPacket(when, pkt)); 1173450Ssaidi@eecs.umich.edu return; 1183403Ssaidi@eecs.umich.edu } 1193450Ssaidi@eecs.umich.edu 1204666Sstever@eecs.umich.edu // this belongs in the middle somewhere 1214490Sstever@eecs.umich.edu DeferredPacketIterator i = transmitList.begin(); 1224666Sstever@eecs.umich.edu i++; // already checked for insertion at front 1234490Sstever@eecs.umich.edu DeferredPacketIterator end = transmitList.end(); 1243450Ssaidi@eecs.umich.edu 1254492Sstever@eecs.umich.edu for (; i != end; ++i) { 1264492Sstever@eecs.umich.edu if (when < i->tick) { 1274492Sstever@eecs.umich.edu transmitList.insert(i, DeferredPacket(when, pkt)); 1284492Sstever@eecs.umich.edu return; 1293610Srdreslin@umich.edu } 1303450Ssaidi@eecs.umich.edu } 1314492Sstever@eecs.umich.edu assert(false); // should never get here 1323403Ssaidi@eecs.umich.edu} 1333403Ssaidi@eecs.umich.edu 1344492Sstever@eecs.umich.edu 1353403Ssaidi@eecs.umich.eduvoid 1364492Sstever@eecs.umich.eduSimpleTimingPort::sendDeferredPacket() 1372914Ssaidi@eecs.umich.edu{ 1384492Sstever@eecs.umich.edu assert(deferredPacketReady()); 1394870Sstever@eecs.umich.edu // take packet off list here; if recvTiming() on the other side 1404870Sstever@eecs.umich.edu // calls sendTiming() back on us (like SimpleTimingCpu does), then 1414870Sstever@eecs.umich.edu // we get confused by having a non-active packet on transmitList 1424870Sstever@eecs.umich.edu DeferredPacket dp = transmitList.front(); 1434870Sstever@eecs.umich.edu transmitList.pop_front(); 1444870Sstever@eecs.umich.edu bool success = sendTiming(dp.pkt); 1454492Sstever@eecs.umich.edu 1464492Sstever@eecs.umich.edu if (success) { 1474870Sstever@eecs.umich.edu if (!transmitList.empty() && !sendEvent->scheduled()) { 1484490Sstever@eecs.umich.edu Tick time = transmitList.front().tick; 1494490Sstever@eecs.umich.edu sendEvent->schedule(time <= curTick ? curTick+1 : time); 1503263Srdreslin@umich.edu } 1514492Sstever@eecs.umich.edu 1524490Sstever@eecs.umich.edu if (transmitList.empty() && drainEvent) { 1534490Sstever@eecs.umich.edu drainEvent->process(); 1544490Sstever@eecs.umich.edu drainEvent = NULL; 1553091Sstever@eecs.umich.edu } 1564870Sstever@eecs.umich.edu } else { 1574870Sstever@eecs.umich.edu // Unsuccessful, need to put back on transmitList. Callee 1584870Sstever@eecs.umich.edu // should not have messed with it (since it didn't accept that 1594870Sstever@eecs.umich.edu // packet), so we can just push it back on the front. 1604870Sstever@eecs.umich.edu assert(!sendEvent->scheduled()); 1614870Sstever@eecs.umich.edu transmitList.push_front(dp); 1623091Sstever@eecs.umich.edu } 1634492Sstever@eecs.umich.edu 1644492Sstever@eecs.umich.edu waitingOnRetry = !success; 1654492Sstever@eecs.umich.edu 1664492Sstever@eecs.umich.edu if (waitingOnRetry) { 1674492Sstever@eecs.umich.edu DPRINTF(Bus, "Send failed, waiting on retry\n"); 1684492Sstever@eecs.umich.edu } 1694492Sstever@eecs.umich.edu} 1704492Sstever@eecs.umich.edu 1714492Sstever@eecs.umich.edu 1724492Sstever@eecs.umich.eduvoid 1734492Sstever@eecs.umich.eduSimpleTimingPort::recvRetry() 1744492Sstever@eecs.umich.edu{ 1754492Sstever@eecs.umich.edu DPRINTF(Bus, "Received retry\n"); 1764492Sstever@eecs.umich.edu assert(waitingOnRetry); 1774492Sstever@eecs.umich.edu sendDeferredPacket(); 1784492Sstever@eecs.umich.edu} 1794492Sstever@eecs.umich.edu 1804492Sstever@eecs.umich.edu 1814492Sstever@eecs.umich.eduvoid 1824492Sstever@eecs.umich.eduSimpleTimingPort::processSendEvent() 1834492Sstever@eecs.umich.edu{ 1844492Sstever@eecs.umich.edu assert(!waitingOnRetry); 1854492Sstever@eecs.umich.edu sendDeferredPacket(); 1862914Ssaidi@eecs.umich.edu} 1872914Ssaidi@eecs.umich.edu 1882914Ssaidi@eecs.umich.edu 1892914Ssaidi@eecs.umich.eduunsigned int 1902914Ssaidi@eecs.umich.eduSimpleTimingPort::drain(Event *de) 1912914Ssaidi@eecs.umich.edu{ 1923403Ssaidi@eecs.umich.edu if (transmitList.size() == 0) 1932914Ssaidi@eecs.umich.edu return 0; 1942914Ssaidi@eecs.umich.edu drainEvent = de; 1952914Ssaidi@eecs.umich.edu return 1; 1962914Ssaidi@eecs.umich.edu} 197