packet_queue.hh revision 8948
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
738948Sandreas.hansson@arm.com        bool sendAsSnoop; ///< Should it be sent as a snoop or not
748948Sandreas.hansson@arm.com        DeferredPacket(Tick t, PacketPtr p, bool send_as_snoop)
758948Sandreas.hansson@arm.com            : tick(t), pkt(p), sendAsSnoop(send_as_snoop)
764490SN/A        {}
774490SN/A    };
784490SN/A
794490SN/A    typedef std::list<DeferredPacket> DeferredPacketList;
804490SN/A    typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
814490SN/A
823090SN/A    /** A list of outgoing timing response packets that haven't been
833090SN/A     * serviced yet. */
844490SN/A    DeferredPacketList transmitList;
854490SN/A
868914Sandreas.hansson@arm.com    /** The manager which is used for the event queue */
878914Sandreas.hansson@arm.com    EventManager& em;
888914Sandreas.hansson@arm.com
898856SN/A    /** Label to use for print request packets label stack. */
908856SN/A    const std::string label;
918856SN/A
924490SN/A    /** This function attempts to send deferred packets.  Scheduled to
934490SN/A     * be called in the future via SendEvent. */
944490SN/A    void processSendEvent();
953091SN/A
962914SN/A    /**
978914Sandreas.hansson@arm.com     * Event used to call processSendEvent.
983403SN/A     **/
998914Sandreas.hansson@arm.com    EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent;
1002914SN/A
1012914SN/A    /** If we need to drain, keep the drain event around until we're done
1022914SN/A     * here.*/
1032914SN/A    Event *drainEvent;
1042914SN/A
1058914Sandreas.hansson@arm.com  protected:
1068914Sandreas.hansson@arm.com
1078914Sandreas.hansson@arm.com    /** The port used to send the packets. */
1088914Sandreas.hansson@arm.com    Port& port;
1098914Sandreas.hansson@arm.com
1104492SN/A    /** Remember whether we're awaiting a retry from the bus. */
1114492SN/A    bool waitingOnRetry;
1124492SN/A
1134492SN/A    /** Check whether we have a packet ready to go on the transmit list. */
1144492SN/A    bool deferredPacketReady()
1157823SN/A    { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
1164492SN/A
1174871SN/A    Tick deferredPacketReadyTime()
1184666SN/A    { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
1194666SN/A
1208708SN/A    /**
1218914Sandreas.hansson@arm.com     * Attempt to send the packet at the head of the transmit
1228914Sandreas.hansson@arm.com     * list. Caller must guarantee that the list is non-empty and that
1238914Sandreas.hansson@arm.com     * the head packet is scheduled for curTick() (or earlier). Note
1248914Sandreas.hansson@arm.com     * that a subclass of the PacketQueue can override this method and
1258914Sandreas.hansson@arm.com     * thus change the behaviour (as done by the cache).
1264492SN/A     */
1278856SN/A    virtual void sendDeferredPacket();
1288856SN/A
1298856SN/A    /**
1308856SN/A     * Attempt to send the packet at the front of the transmit list,
1318856SN/A     * and set waitingOnRetry accordingly. The packet is temporarily
1328856SN/A     * taken off the list, but put back at the front if not
1338856SN/A     * successfully sent.
1348856SN/A     */
1358856SN/A    void trySendTiming();
1368856SN/A
1378856SN/A    /**
1388856SN/A     * Based on the transmit list, or the provided time, schedule a
1398856SN/A     * send event if there are packets to send. If we are idle and
1408856SN/A     * asked to drain then do so.
1418856SN/A     *
1428856SN/A     * @param time an alternative time for the next send event
1438856SN/A     */
1448856SN/A    void scheduleSend(Tick time = MaxTick);
1452914SN/A
1463091SN/A    /**
1478711SN/A     * Simple ports are generally used as slave ports (i.e. the
1488711SN/A     * respond to requests) and thus do not expect to receive any
1498711SN/A     * range changes (as the neighbouring port has a master role and
1508711SN/A     * do not have any address ranges. A subclass can override the
1518711SN/A     * default behaviuor if needed.
1528711SN/A     */
1538711SN/A    virtual void recvRangeChange() { }
1543091SN/A
1558914Sandreas.hansson@arm.com  public:
1563091SN/A
1578914Sandreas.hansson@arm.com    /**
1588914Sandreas.hansson@arm.com     * Create a packet queue, linked to an event manager, a port used
1598914Sandreas.hansson@arm.com     * to send the packets, and potentially give it a label that will
1608914Sandreas.hansson@arm.com     * be used for functional print request packets.
1618914Sandreas.hansson@arm.com     *
1628914Sandreas.hansson@arm.com     * @param _em Event manager used for scheduling this queue
1638914Sandreas.hansson@arm.com     * @param _port Port used to send the packets
1648914Sandreas.hansson@arm.com     * @param _label Label to push on the label stack for print request packets
1658914Sandreas.hansson@arm.com     */
1668914Sandreas.hansson@arm.com    PacketQueue(EventManager& _em, Port& _port,
1678914Sandreas.hansson@arm.com                const std::string _label = "PacketQueue");
1688914Sandreas.hansson@arm.com
1698914Sandreas.hansson@arm.com    /**
1708914Sandreas.hansson@arm.com     * Virtual desctructor since the class may be used as a base class.
1718914Sandreas.hansson@arm.com     */
1728914Sandreas.hansson@arm.com    virtual ~PacketQueue();
1738914Sandreas.hansson@arm.com
1748914Sandreas.hansson@arm.com    /**
1758914Sandreas.hansson@arm.com     * Provide a name to simplify debugging. Base it on the port.
1768914Sandreas.hansson@arm.com     *
1778914Sandreas.hansson@arm.com     * @return A complete name, appended to module and port
1788914Sandreas.hansson@arm.com     */
1798914Sandreas.hansson@arm.com    const std::string name() const { return port.name() + "-queue"; }
1804490SN/A
1818856SN/A    /** Check the list of buffered packets against the supplied
1828856SN/A     * functional request. */
1838856SN/A    bool checkFunctional(PacketPtr pkt);
1848856SN/A
1858914Sandreas.hansson@arm.com    /**
1868914Sandreas.hansson@arm.com     * Schedule a send even if not already waiting for a retry. If the
1878914Sandreas.hansson@arm.com     * requested time is before an already scheduled send event it
1888914Sandreas.hansson@arm.com     * will be rescheduled.
1898914Sandreas.hansson@arm.com     *
1908914Sandreas.hansson@arm.com     * @param when
1918914Sandreas.hansson@arm.com     */
1928914Sandreas.hansson@arm.com    void schedSendEvent(Tick when);
1938914Sandreas.hansson@arm.com
1948914Sandreas.hansson@arm.com    /**
1958914Sandreas.hansson@arm.com     * Add a packet to the transmit list, and ensure that a
1968914Sandreas.hansson@arm.com     * processSendEvent is called in the future.
1978914Sandreas.hansson@arm.com     *
1988914Sandreas.hansson@arm.com     * @param pkt Packet to send
1998914Sandreas.hansson@arm.com     * @param when Absolute time (in ticks) to send packet
2008948Sandreas.hansson@arm.com     * @param send_as_snoop Send the packet as a snoop or not
2018914Sandreas.hansson@arm.com     */
2028948Sandreas.hansson@arm.com    void schedSendTiming(PacketPtr pkt, Tick when, bool send_as_snoop = false);
2038914Sandreas.hansson@arm.com
2048914Sandreas.hansson@arm.com    /**
2058914Sandreas.hansson@arm.com     * Used by a port to notify the queue that a retry was received
2068914Sandreas.hansson@arm.com     * and that the queue can proceed and retry sending the packet
2078914Sandreas.hansson@arm.com     * that caused the wait.
2088914Sandreas.hansson@arm.com     */
2098914Sandreas.hansson@arm.com    void retry();
2108914Sandreas.hansson@arm.com
2118914Sandreas.hansson@arm.com    /**
2128914Sandreas.hansson@arm.com     * Hook for draining the packet queue.
2138914Sandreas.hansson@arm.com     *
2148914Sandreas.hansson@arm.com     * @param de An event which is used to signal back to the caller
2158914Sandreas.hansson@arm.com     * @return A number indicating how many times process will be called
2168914Sandreas.hansson@arm.com     */
2172914SN/A    unsigned int drain(Event *de);
2182914SN/A};
2192914SN/A
2208948Sandreas.hansson@arm.com#endif // __MEM_PACKET_QUEUE_HH__
221