2 * Copyright (c) 2012,2015 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #ifndef __MEM_PACKET_QUEUE_HH__
45 #define __MEM_PACKET_QUEUE_HH__
49 * Declaration of a simple PacketQueue that is associated with
50 * a port on which it attempts to send packets according to the time
51 * stamp given to them at insertion. The packet queue is responsible
52 * for the flow control of the port.
57 #include "mem/port.hh"
58 #include "sim/drain.hh"
59 #include "sim/eventq_impl.hh"
62 * A packet queue is a class that holds deferred packets and later
63 * sends them using the associated slave port or master port.
65 class PacketQueue : public Drainable
68 /** A deferred packet, buffered to transmit later. */
69 class DeferredPacket {
71 Tick tick; ///< The tick when the packet is ready to transmit
72 PacketPtr pkt; ///< Pointer to the packet to transmit
73 DeferredPacket(Tick t, PacketPtr p)
78 typedef std::list<DeferredPacket> DeferredPacketList;
80 /** A list of outgoing packets. */
81 DeferredPacketList transmitList;
83 /** The manager which is used for the event queue */
86 /** Used to schedule sending of deferred packets. */
87 void processSendEvent();
89 /** Event used to call processSendEvent. */
90 EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent;
92 /** If we need to drain, keep the drain manager around until we're done
94 DrainManager *drainManager;
98 /** Label to use for print request packets label stack. */
99 const std::string label;
101 /** Remember whether we're awaiting a retry. */
104 /** Check whether we have a packet ready to go on the transmit list. */
105 bool deferredPacketReady() const
106 { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
109 * Attempt to send a packet. Note that a subclass of the
110 * PacketQueue can override this method and thus change the
111 * behaviour (as done by the cache for the request queue). The
112 * default implementation sends the head of the transmit list. The
113 * caller must guarantee that the list is non-empty and that the
114 * head packet is scheduled for curTick() (or earlier).
116 virtual void sendDeferredPacket();
119 * Send a packet using the appropriate method for the specific
120 * subclass (reuest, response or snoop response).
122 virtual bool sendTiming(PacketPtr pkt) = 0;
125 * Create a packet queue, linked to an event manager, and a label
126 * that will be used for functional print request packets.
128 * @param _em Event manager used for scheduling this queue
129 * @param _label Label to push on the label stack for print request packets
131 PacketQueue(EventManager& _em, const std::string& _label);
134 * Virtual desctructor since the class may be used as a base class.
136 virtual ~PacketQueue();
141 * Provide a name to simplify debugging.
143 * @return A complete name, appended to module and port
145 virtual const std::string name() const = 0;
148 * Get the size of the queue.
150 size_t size() const { return transmitList.size(); }
153 * Get the next packet ready time.
155 Tick deferredPacketReadyTime() const
156 { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
159 * Check if a packets address exists in the queue.
161 bool hasAddr(Addr addr) const;
163 /** Check the list of buffered packets against the supplied
164 * functional request. */
165 bool checkFunctional(PacketPtr pkt);
168 * Schedule a send event if we are not already waiting for a
169 * retry. If the requested time is before an already scheduled
170 * send event, the event will be rescheduled. If MaxTick is
171 * passed, no event is scheduled. Instead, if we are idle and
172 * asked to drain then check and signal drained.
174 * @param when time to schedule an event
176 void schedSendEvent(Tick when);
179 * Add a packet to the transmit list, and schedule a send event.
181 * @param pkt Packet to send
182 * @param when Absolute time (in ticks) to send packet
183 * @param force_order Do not reorder packets despite timing, but keep them
184 * in insertion order.
186 void schedSendTiming(PacketPtr pkt, Tick when, bool force_order = false);
189 * Retry sending a packet from the queue. Note that this is not
190 * necessarily the same packet if something has been added with an
191 * earlier time stamp.
195 unsigned int drain(DrainManager *dm);
198 class ReqPacketQueue : public PacketQueue
203 MasterPort& masterPort;
208 * Create a request packet queue, linked to an event manager, a
209 * master port, and a label that will be used for functional print
212 * @param _em Event manager used for scheduling this queue
213 * @param _masterPort Master port used to send the packets
214 * @param _label Label to push on the label stack for print request packets
216 ReqPacketQueue(EventManager& _em, MasterPort& _masterPort,
217 const std::string _label = "ReqPacketQueue");
219 virtual ~ReqPacketQueue() { }
221 const std::string name() const
222 { return masterPort.name() + "-" + label; }
224 bool sendTiming(PacketPtr pkt);
228 class SnoopRespPacketQueue : public PacketQueue
233 MasterPort& masterPort;
238 * Create a snoop response packet queue, linked to an event
239 * manager, a master port, and a label that will be used for
240 * functional print request packets.
242 * @param _em Event manager used for scheduling this queue
243 * @param _masterPort Master port used to send the packets
244 * @param _label Label to push on the label stack for print request packets
246 SnoopRespPacketQueue(EventManager& _em, MasterPort& _masterPort,
247 const std::string _label = "SnoopRespPacketQueue");
249 virtual ~SnoopRespPacketQueue() { }
251 const std::string name() const
252 { return masterPort.name() + "-" + label; }
254 bool sendTiming(PacketPtr pkt);
258 class RespPacketQueue : public PacketQueue
263 SlavePort& slavePort;
268 * Create a response packet queue, linked to an event manager, a
269 * slave port, and a label that will be used for functional print
272 * @param _em Event manager used for scheduling this queue
273 * @param _slavePort Slave port used to send the packets
274 * @param _label Label to push on the label stack for print request packets
276 RespPacketQueue(EventManager& _em, SlavePort& _slavePort,
277 const std::string _label = "RespPacketQueue");
279 virtual ~RespPacketQueue() { }
281 const std::string name() const
282 { return slavePort.name() + "-" + label; }
284 bool sendTiming(PacketPtr pkt);
288 #endif // __MEM_PACKET_QUEUE_HH__