packet_queue.hh revision 8914
12914SN/A/*
28856SN/A * Copyright (c) 2012 ARM Limited
38856SN/A * All rights reserved.
48856SN/A *
58856SN/A * The license below extends only to copyright in the software and shall
68856SN/A * not be construed as granting a license to any other intellectual
78856SN/A * property including but not limited to intellectual property relating
88856SN/A * to a hardware implementation of the functionality of the software
98856SN/A * licensed hereunder.  You may use the software subject to the license
108856SN/A * terms below provided that you ensure that this notice is replicated
118856SN/A * unmodified and in its entirety in all distributions of the software,
128856SN/A * modified or unmodified, in source code or in binary form.
138856SN/A *
142914SN/A * Copyright (c) 2006 The Regents of The University of Michigan
152914SN/A * All rights reserved.
162914SN/A *
172914SN/A * Redistribution and use in source and binary forms, with or without
182914SN/A * modification, are permitted provided that the following conditions are
192914SN/A * met: redistributions of source code must retain the above copyright
202914SN/A * notice, this list of conditions and the following disclaimer;
212914SN/A * redistributions in binary form must reproduce the above copyright
222914SN/A * notice, this list of conditions and the following disclaimer in the
232914SN/A * documentation and/or other materials provided with the distribution;
242914SN/A * neither the name of the copyright holders nor the names of its
252914SN/A * contributors may be used to endorse or promote products derived from
262914SN/A * this software without specific prior written permission.
272914SN/A *
282914SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292914SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302914SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312914SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322914SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332914SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342914SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352914SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362914SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372914SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382914SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392914SN/A *
402914SN/A * Authors: Ali Saidi
418856SN/A *          Andreas Hansson
422914SN/A */
432914SN/A
448914Sandreas.hansson@arm.com#ifndef __MEM_PACKET_QUEUE_HH__
458914Sandreas.hansson@arm.com#define __MEM_PACKET_QUEUE_HH__
463091SN/A
472914SN/A/**
482914SN/A * @file
498914Sandreas.hansson@arm.com * Declaration of a simple PacketQueue that is associated with
508914Sandreas.hansson@arm.com * a port on which it attempts to send packets according to the time
518914Sandreas.hansson@arm.com * stamp given to them at insertion. The packet queue is responsible
528914Sandreas.hansson@arm.com * for the flow control of the port, but relies on the module
538914Sandreas.hansson@arm.com * notifying the queue when a transfer ends.
542914SN/A */
552914SN/A
568229SN/A#include <list>
578229SN/A
582914SN/A#include "mem/port.hh"
592914SN/A#include "sim/eventq.hh"
602914SN/A
613091SN/A/**
628914Sandreas.hansson@arm.com * A packet queue is a class that holds deferred packets and later
638914Sandreas.hansson@arm.com * sends them using the associated slave port or master port.
643091SN/A */
658914Sandreas.hansson@arm.comclass PacketQueue
662914SN/A{
678914Sandreas.hansson@arm.com  private:
684490SN/A    /** A deferred packet, buffered to transmit later. */
694490SN/A    class DeferredPacket {
704490SN/A      public:
714490SN/A        Tick tick;      ///< The tick when the packet is ready to transmit
724490SN/A        PacketPtr pkt;  ///< Pointer to the packet to transmit
734490SN/A        DeferredPacket(Tick t, PacketPtr p)
744490SN/A            : tick(t), pkt(p)
754490SN/A        {}
764490SN/A    };
774490SN/A
784490SN/A    typedef std::list<DeferredPacket> DeferredPacketList;
794490SN/A    typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
804490SN/A
813090SN/A    /** A list of outgoing timing response packets that haven't been
823090SN/A     * serviced yet. */
834490SN/A    DeferredPacketList transmitList;
844490SN/A
858914Sandreas.hansson@arm.com    /** The manager which is used for the event queue */
868914Sandreas.hansson@arm.com    EventManager& em;
878914Sandreas.hansson@arm.com
888856SN/A    /** Label to use for print request packets label stack. */
898856SN/A    const std::string label;
908856SN/A
914490SN/A    /** This function attempts to send deferred packets.  Scheduled to
924490SN/A     * be called in the future via SendEvent. */
934490SN/A    void processSendEvent();
943091SN/A
952914SN/A    /**
968914Sandreas.hansson@arm.com     * Event used to call processSendEvent.
973403SN/A     **/
988914Sandreas.hansson@arm.com    EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent;
992914SN/A
1002914SN/A    /** If we need to drain, keep the drain event around until we're done
1012914SN/A     * here.*/
1022914SN/A    Event *drainEvent;
1032914SN/A
1048914Sandreas.hansson@arm.com  protected:
1058914Sandreas.hansson@arm.com
1068914Sandreas.hansson@arm.com    /** The port used to send the packets. */
1078914Sandreas.hansson@arm.com    Port& port;
1088914Sandreas.hansson@arm.com
1094492SN/A    /** Remember whether we're awaiting a retry from the bus. */
1104492SN/A    bool waitingOnRetry;
1114492SN/A
1124492SN/A    /** Check whether we have a packet ready to go on the transmit list. */
1134492SN/A    bool deferredPacketReady()
1147823SN/A    { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
1154492SN/A
1164871SN/A    Tick deferredPacketReadyTime()
1174666SN/A    { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
1184666SN/A
1198708SN/A    /**
1208914Sandreas.hansson@arm.com     * Attempt to send the packet at the head of the transmit
1218914Sandreas.hansson@arm.com     * list. Caller must guarantee that the list is non-empty and that
1228914Sandreas.hansson@arm.com     * the head packet is scheduled for curTick() (or earlier). Note
1238914Sandreas.hansson@arm.com     * that a subclass of the PacketQueue can override this method and
1248914Sandreas.hansson@arm.com     * thus change the behaviour (as done by the cache).
1254492SN/A     */
1268856SN/A    virtual void sendDeferredPacket();
1278856SN/A
1288856SN/A    /**
1298856SN/A     * Attempt to send the packet at the front of the transmit list,
1308856SN/A     * and set waitingOnRetry accordingly. The packet is temporarily
1318856SN/A     * taken off the list, but put back at the front if not
1328856SN/A     * successfully sent.
1338856SN/A     */
1348856SN/A    void trySendTiming();
1358856SN/A
1368856SN/A    /**
1378856SN/A     * Based on the transmit list, or the provided time, schedule a
1388856SN/A     * send event if there are packets to send. If we are idle and
1398856SN/A     * asked to drain then do so.
1408856SN/A     *
1418856SN/A     * @param time an alternative time for the next send event
1428856SN/A     */
1438856SN/A    void scheduleSend(Tick time = MaxTick);
1442914SN/A
1453091SN/A    /**
1468711SN/A     * Simple ports are generally used as slave ports (i.e. the
1478711SN/A     * respond to requests) and thus do not expect to receive any
1488711SN/A     * range changes (as the neighbouring port has a master role and
1498711SN/A     * do not have any address ranges. A subclass can override the
1508711SN/A     * default behaviuor if needed.
1518711SN/A     */
1528711SN/A    virtual void recvRangeChange() { }
1533091SN/A
1548914Sandreas.hansson@arm.com  public:
1553091SN/A
1568914Sandreas.hansson@arm.com    /**
1578914Sandreas.hansson@arm.com     * Create a packet queue, linked to an event manager, a port used
1588914Sandreas.hansson@arm.com     * to send the packets, and potentially give it a label that will
1598914Sandreas.hansson@arm.com     * be used for functional print request packets.
1608914Sandreas.hansson@arm.com     *
1618914Sandreas.hansson@arm.com     * @param _em Event manager used for scheduling this queue
1628914Sandreas.hansson@arm.com     * @param _port Port used to send the packets
1638914Sandreas.hansson@arm.com     * @param _label Label to push on the label stack for print request packets
1648914Sandreas.hansson@arm.com     */
1658914Sandreas.hansson@arm.com    PacketQueue(EventManager& _em, Port& _port,
1668914Sandreas.hansson@arm.com                const std::string _label = "PacketQueue");
1678914Sandreas.hansson@arm.com
1688914Sandreas.hansson@arm.com    /**
1698914Sandreas.hansson@arm.com     * Virtual desctructor since the class may be used as a base class.
1708914Sandreas.hansson@arm.com     */
1718914Sandreas.hansson@arm.com    virtual ~PacketQueue();
1728914Sandreas.hansson@arm.com
1738914Sandreas.hansson@arm.com    /**
1748914Sandreas.hansson@arm.com     * Provide a name to simplify debugging. Base it on the port.
1758914Sandreas.hansson@arm.com     *
1768914Sandreas.hansson@arm.com     * @return A complete name, appended to module and port
1778914Sandreas.hansson@arm.com     */
1788914Sandreas.hansson@arm.com    const std::string name() const { return port.name() + "-queue"; }
1794490SN/A
1808856SN/A    /** Check the list of buffered packets against the supplied
1818856SN/A     * functional request. */
1828856SN/A    bool checkFunctional(PacketPtr pkt);
1838856SN/A
1848914Sandreas.hansson@arm.com    /**
1858914Sandreas.hansson@arm.com     * Schedule a send even if not already waiting for a retry. If the
1868914Sandreas.hansson@arm.com     * requested time is before an already scheduled send event it
1878914Sandreas.hansson@arm.com     * will be rescheduled.
1888914Sandreas.hansson@arm.com     *
1898914Sandreas.hansson@arm.com     * @param when
1908914Sandreas.hansson@arm.com     */
1918914Sandreas.hansson@arm.com    void schedSendEvent(Tick when);
1928914Sandreas.hansson@arm.com
1938914Sandreas.hansson@arm.com    /**
1948914Sandreas.hansson@arm.com     * Add a packet to the transmit list, and ensure that a
1958914Sandreas.hansson@arm.com     * processSendEvent is called in the future.
1968914Sandreas.hansson@arm.com     *
1978914Sandreas.hansson@arm.com     * @param pkt Packet to send
1988914Sandreas.hansson@arm.com     * @param when Absolute time (in ticks) to send packet
1998914Sandreas.hansson@arm.com     */
2008914Sandreas.hansson@arm.com    void schedSendTiming(PacketPtr pkt, Tick when);
2018914Sandreas.hansson@arm.com
2028914Sandreas.hansson@arm.com    /**
2038914Sandreas.hansson@arm.com     * Used by a port to notify the queue that a retry was received
2048914Sandreas.hansson@arm.com     * and that the queue can proceed and retry sending the packet
2058914Sandreas.hansson@arm.com     * that caused the wait.
2068914Sandreas.hansson@arm.com     */
2078914Sandreas.hansson@arm.com    void retry();
2088914Sandreas.hansson@arm.com
2098914Sandreas.hansson@arm.com    /**
2108914Sandreas.hansson@arm.com     * Hook for draining the packet queue.
2118914Sandreas.hansson@arm.com     *
2128914Sandreas.hansson@arm.com     * @param de An event which is used to signal back to the caller
2138914Sandreas.hansson@arm.com     * @return A number indicating how many times process will be called
2148914Sandreas.hansson@arm.com     */
2152914SN/A    unsigned int drain(Event *de);
2162914SN/A};
2172914SN/A
2182914SN/A#endif // __MEM_TPORT_HH__
219