tport.cc revision 4666
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
944666Sstever@eecs.umich.edu    if (transmitList.empty() || when < transmitList.front().tick) {
954666Sstever@eecs.umich.edu        transmitList.push_front(DeferredPacket(when, pkt));
964666Sstever@eecs.umich.edu        schedSendEvent(when);
974666Sstever@eecs.umich.edu        return;
984666Sstever@eecs.umich.edu    }
994666Sstever@eecs.umich.edu
1004666Sstever@eecs.umich.edu    // list is non-empty and this is not the head, so event should
1014666Sstever@eecs.umich.edu    // already be scheduled
1024666Sstever@eecs.umich.edu    assert(waitingOnRetry ||
1034666Sstever@eecs.umich.edu           (sendEvent->scheduled() && sendEvent->when() <= when));
1044666Sstever@eecs.umich.edu
1054666Sstever@eecs.umich.edu    // list is non-empty & this belongs at the end
1064666Sstever@eecs.umich.edu    if (when >= transmitList.back().tick) {
1074492Sstever@eecs.umich.edu        transmitList.push_back(DeferredPacket(when, pkt));
1083450Ssaidi@eecs.umich.edu        return;
1093403Ssaidi@eecs.umich.edu    }
1103450Ssaidi@eecs.umich.edu
1114666Sstever@eecs.umich.edu    // this belongs in the middle somewhere
1124490Sstever@eecs.umich.edu    DeferredPacketIterator i = transmitList.begin();
1134666Sstever@eecs.umich.edu    i++; // already checked for insertion at front
1144490Sstever@eecs.umich.edu    DeferredPacketIterator end = transmitList.end();
1153450Ssaidi@eecs.umich.edu
1164492Sstever@eecs.umich.edu    for (; i != end; ++i) {
1174492Sstever@eecs.umich.edu        if (when < i->tick) {
1184492Sstever@eecs.umich.edu            transmitList.insert(i, DeferredPacket(when, pkt));
1194492Sstever@eecs.umich.edu            return;
1203610Srdreslin@umich.edu        }
1213450Ssaidi@eecs.umich.edu    }
1224492Sstever@eecs.umich.edu    assert(false); // should never get here
1233403Ssaidi@eecs.umich.edu}
1243403Ssaidi@eecs.umich.edu
1254492Sstever@eecs.umich.edu
1263403Ssaidi@eecs.umich.eduvoid
1274492Sstever@eecs.umich.eduSimpleTimingPort::sendDeferredPacket()
1282914Ssaidi@eecs.umich.edu{
1294492Sstever@eecs.umich.edu    assert(deferredPacketReady());
1304492Sstever@eecs.umich.edu    bool success = sendTiming(transmitList.front().pkt);
1314492Sstever@eecs.umich.edu
1324492Sstever@eecs.umich.edu    if (success) {
1333403Ssaidi@eecs.umich.edu        //send successful, remove packet
1344490Sstever@eecs.umich.edu        transmitList.pop_front();
1354490Sstever@eecs.umich.edu        if (!transmitList.empty()) {
1364490Sstever@eecs.umich.edu            Tick time = transmitList.front().tick;
1374490Sstever@eecs.umich.edu            sendEvent->schedule(time <= curTick ? curTick+1 : time);
1383263Srdreslin@umich.edu        }
1394492Sstever@eecs.umich.edu
1404490Sstever@eecs.umich.edu        if (transmitList.empty() && drainEvent) {
1414490Sstever@eecs.umich.edu            drainEvent->process();
1424490Sstever@eecs.umich.edu            drainEvent = NULL;
1433091Sstever@eecs.umich.edu        }
1443091Sstever@eecs.umich.edu    }
1454492Sstever@eecs.umich.edu
1464492Sstever@eecs.umich.edu    waitingOnRetry = !success;
1474492Sstever@eecs.umich.edu
1484492Sstever@eecs.umich.edu    if (waitingOnRetry) {
1494492Sstever@eecs.umich.edu        DPRINTF(Bus, "Send failed, waiting on retry\n");
1504492Sstever@eecs.umich.edu    }
1514492Sstever@eecs.umich.edu}
1524492Sstever@eecs.umich.edu
1534492Sstever@eecs.umich.edu
1544492Sstever@eecs.umich.eduvoid
1554492Sstever@eecs.umich.eduSimpleTimingPort::recvRetry()
1564492Sstever@eecs.umich.edu{
1574492Sstever@eecs.umich.edu    DPRINTF(Bus, "Received retry\n");
1584492Sstever@eecs.umich.edu    assert(waitingOnRetry);
1594492Sstever@eecs.umich.edu    sendDeferredPacket();
1604492Sstever@eecs.umich.edu}
1614492Sstever@eecs.umich.edu
1624492Sstever@eecs.umich.edu
1634492Sstever@eecs.umich.eduvoid
1644492Sstever@eecs.umich.eduSimpleTimingPort::processSendEvent()
1654492Sstever@eecs.umich.edu{
1664492Sstever@eecs.umich.edu    assert(!waitingOnRetry);
1674492Sstever@eecs.umich.edu    sendDeferredPacket();
1682914Ssaidi@eecs.umich.edu}
1692914Ssaidi@eecs.umich.edu
1702914Ssaidi@eecs.umich.edu
1712914Ssaidi@eecs.umich.eduunsigned int
1722914Ssaidi@eecs.umich.eduSimpleTimingPort::drain(Event *de)
1732914Ssaidi@eecs.umich.edu{
1743403Ssaidi@eecs.umich.edu    if (transmitList.size() == 0)
1752914Ssaidi@eecs.umich.edu        return 0;
1762914Ssaidi@eecs.umich.edu    drainEvent = de;
1772914Ssaidi@eecs.umich.edu    return 1;
1782914Ssaidi@eecs.umich.edu}
179