tport.cc revision 4929
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
334929Sstever@gmail.combool
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
434874Sstever@eecs.umich.edu        if (pkt->checkFunctional(target)) {
444929Sstever@gmail.com            return true;
454490Sstever@eecs.umich.edu        }
463284Srdreslin@umich.edu    }
474929Sstever@gmail.com
484929Sstever@gmail.com    return false;
494490Sstever@eecs.umich.edu}
503342Srdreslin@umich.edu
514490Sstever@eecs.umich.eduvoid
524490Sstever@eecs.umich.eduSimpleTimingPort::recvFunctional(PacketPtr pkt)
534490Sstever@eecs.umich.edu{
544929Sstever@gmail.com    if (!checkFunctional(pkt)) {
554929Sstever@gmail.com        // Just do an atomic access and throw away the returned latency
563296Ssaidi@eecs.umich.edu        recvAtomic(pkt);
574929Sstever@gmail.com    }
583091Sstever@eecs.umich.edu}
593091Sstever@eecs.umich.edu
603091Sstever@eecs.umich.edubool
613349Sbinkertn@umich.eduSimpleTimingPort::recvTiming(PacketPtr pkt)
623091Sstever@eecs.umich.edu{
633091Sstever@eecs.umich.edu    // If the device is only a slave, it should only be sending
643091Sstever@eecs.umich.edu    // responses, which should never get nacked.  There used to be
653091Sstever@eecs.umich.edu    // code to hanldle nacks here, but I'm pretty sure it didn't work
663091Sstever@eecs.umich.edu    // correctly with the drain code, so that would need to be fixed
673091Sstever@eecs.umich.edu    // if we ever added it back.
684626Sstever@eecs.umich.edu    assert(pkt->isRequest());
694670Sstever@eecs.umich.edu
704670Sstever@eecs.umich.edu    if (pkt->memInhibitAsserted()) {
714670Sstever@eecs.umich.edu        // snooper will supply based on copy of packet
724670Sstever@eecs.umich.edu        // still target's responsibility to delete packet
734670Sstever@eecs.umich.edu        delete pkt;
744670Sstever@eecs.umich.edu        return true;
754670Sstever@eecs.umich.edu    }
764670Sstever@eecs.umich.edu
774626Sstever@eecs.umich.edu    bool needsResponse = pkt->needsResponse();
783091Sstever@eecs.umich.edu    Tick latency = recvAtomic(pkt);
793175Srdreslin@umich.edu    // turn packet around to go back to requester if response expected
804626Sstever@eecs.umich.edu    if (needsResponse) {
814670Sstever@eecs.umich.edu        // recvAtomic() should already have turned packet into
824670Sstever@eecs.umich.edu        // atomic response
834626Sstever@eecs.umich.edu        assert(pkt->isResponse());
844493Sstever@eecs.umich.edu        schedSendTiming(pkt, curTick + latency);
854626Sstever@eecs.umich.edu    } else {
864490Sstever@eecs.umich.edu        delete pkt->req;
874490Sstever@eecs.umich.edu        delete pkt;
883309Srdreslin@umich.edu    }
894670Sstever@eecs.umich.edu
903091Sstever@eecs.umich.edu    return true;
913091Sstever@eecs.umich.edu}
923091Sstever@eecs.umich.edu
932914Ssaidi@eecs.umich.edu
942914Ssaidi@eecs.umich.eduvoid
954492Sstever@eecs.umich.eduSimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when)
963403Ssaidi@eecs.umich.edu{
974492Sstever@eecs.umich.edu    assert(when > curTick);
984492Sstever@eecs.umich.edu
993450Ssaidi@eecs.umich.edu    // Nothing is on the list: add it and schedule an event
1004666Sstever@eecs.umich.edu    if (transmitList.empty() || when < transmitList.front().tick) {
1014666Sstever@eecs.umich.edu        transmitList.push_front(DeferredPacket(when, pkt));
1024666Sstever@eecs.umich.edu        schedSendEvent(when);
1034666Sstever@eecs.umich.edu        return;
1044666Sstever@eecs.umich.edu    }
1054666Sstever@eecs.umich.edu
1064666Sstever@eecs.umich.edu    // list is non-empty and this is not the head, so event should
1074666Sstever@eecs.umich.edu    // already be scheduled
1084666Sstever@eecs.umich.edu    assert(waitingOnRetry ||
1094666Sstever@eecs.umich.edu           (sendEvent->scheduled() && sendEvent->when() <= when));
1104666Sstever@eecs.umich.edu
1114666Sstever@eecs.umich.edu    // list is non-empty & this belongs at the end
1124666Sstever@eecs.umich.edu    if (when >= transmitList.back().tick) {
1134492Sstever@eecs.umich.edu        transmitList.push_back(DeferredPacket(when, pkt));
1143450Ssaidi@eecs.umich.edu        return;
1153403Ssaidi@eecs.umich.edu    }
1163450Ssaidi@eecs.umich.edu
1174666Sstever@eecs.umich.edu    // this belongs in the middle somewhere
1184490Sstever@eecs.umich.edu    DeferredPacketIterator i = transmitList.begin();
1194666Sstever@eecs.umich.edu    i++; // already checked for insertion at front
1204490Sstever@eecs.umich.edu    DeferredPacketIterator end = transmitList.end();
1213450Ssaidi@eecs.umich.edu
1224492Sstever@eecs.umich.edu    for (; i != end; ++i) {
1234492Sstever@eecs.umich.edu        if (when < i->tick) {
1244492Sstever@eecs.umich.edu            transmitList.insert(i, DeferredPacket(when, pkt));
1254492Sstever@eecs.umich.edu            return;
1263610Srdreslin@umich.edu        }
1273450Ssaidi@eecs.umich.edu    }
1284492Sstever@eecs.umich.edu    assert(false); // should never get here
1293403Ssaidi@eecs.umich.edu}
1303403Ssaidi@eecs.umich.edu
1314492Sstever@eecs.umich.edu
1323403Ssaidi@eecs.umich.eduvoid
1334492Sstever@eecs.umich.eduSimpleTimingPort::sendDeferredPacket()
1342914Ssaidi@eecs.umich.edu{
1354492Sstever@eecs.umich.edu    assert(deferredPacketReady());
1364870Sstever@eecs.umich.edu    // take packet off list here; if recvTiming() on the other side
1374870Sstever@eecs.umich.edu    // calls sendTiming() back on us (like SimpleTimingCpu does), then
1384870Sstever@eecs.umich.edu    // we get confused by having a non-active packet on transmitList
1394870Sstever@eecs.umich.edu    DeferredPacket dp = transmitList.front();
1404870Sstever@eecs.umich.edu    transmitList.pop_front();
1414870Sstever@eecs.umich.edu    bool success = sendTiming(dp.pkt);
1424492Sstever@eecs.umich.edu
1434492Sstever@eecs.umich.edu    if (success) {
1444870Sstever@eecs.umich.edu        if (!transmitList.empty() && !sendEvent->scheduled()) {
1454490Sstever@eecs.umich.edu            Tick time = transmitList.front().tick;
1464490Sstever@eecs.umich.edu            sendEvent->schedule(time <= curTick ? curTick+1 : time);
1473263Srdreslin@umich.edu        }
1484492Sstever@eecs.umich.edu
1494490Sstever@eecs.umich.edu        if (transmitList.empty() && drainEvent) {
1504490Sstever@eecs.umich.edu            drainEvent->process();
1514490Sstever@eecs.umich.edu            drainEvent = NULL;
1523091Sstever@eecs.umich.edu        }
1534870Sstever@eecs.umich.edu    } else {
1544870Sstever@eecs.umich.edu        // Unsuccessful, need to put back on transmitList.  Callee
1554870Sstever@eecs.umich.edu        // should not have messed with it (since it didn't accept that
1564870Sstever@eecs.umich.edu        // packet), so we can just push it back on the front.
1574870Sstever@eecs.umich.edu        assert(!sendEvent->scheduled());
1584870Sstever@eecs.umich.edu        transmitList.push_front(dp);
1593091Sstever@eecs.umich.edu    }
1604492Sstever@eecs.umich.edu
1614492Sstever@eecs.umich.edu    waitingOnRetry = !success;
1624492Sstever@eecs.umich.edu
1634492Sstever@eecs.umich.edu    if (waitingOnRetry) {
1644492Sstever@eecs.umich.edu        DPRINTF(Bus, "Send failed, waiting on retry\n");
1654492Sstever@eecs.umich.edu    }
1664492Sstever@eecs.umich.edu}
1674492Sstever@eecs.umich.edu
1684492Sstever@eecs.umich.edu
1694492Sstever@eecs.umich.eduvoid
1704492Sstever@eecs.umich.eduSimpleTimingPort::recvRetry()
1714492Sstever@eecs.umich.edu{
1724492Sstever@eecs.umich.edu    DPRINTF(Bus, "Received retry\n");
1734492Sstever@eecs.umich.edu    assert(waitingOnRetry);
1744492Sstever@eecs.umich.edu    sendDeferredPacket();
1754492Sstever@eecs.umich.edu}
1764492Sstever@eecs.umich.edu
1774492Sstever@eecs.umich.edu
1784492Sstever@eecs.umich.eduvoid
1794492Sstever@eecs.umich.eduSimpleTimingPort::processSendEvent()
1804492Sstever@eecs.umich.edu{
1814492Sstever@eecs.umich.edu    assert(!waitingOnRetry);
1824492Sstever@eecs.umich.edu    sendDeferredPacket();
1832914Ssaidi@eecs.umich.edu}
1842914Ssaidi@eecs.umich.edu
1852914Ssaidi@eecs.umich.edu
1862914Ssaidi@eecs.umich.eduunsigned int
1872914Ssaidi@eecs.umich.eduSimpleTimingPort::drain(Event *de)
1882914Ssaidi@eecs.umich.edu{
1893403Ssaidi@eecs.umich.edu    if (transmitList.size() == 0)
1902914Ssaidi@eecs.umich.edu        return 0;
1912914Ssaidi@eecs.umich.edu    drainEvent = de;
1922914Ssaidi@eecs.umich.edu    return 1;
1932914Ssaidi@eecs.umich.edu}
194