packet_queue.hh revision 11195:6f8b2a005abb
15390SN/A/* 25443SN/A * Copyright (c) 2012,2015 ARM Limited 35390SN/A * All rights reserved. 45390SN/A * 55390SN/A * The license below extends only to copyright in the software and shall 65390SN/A * not be construed as granting a license to any other intellectual 75390SN/A * property including but not limited to intellectual property relating 85390SN/A * to a hardware implementation of the functionality of the software 95390SN/A * licensed hereunder. You may use the software subject to the license 105390SN/A * terms below provided that you ensure that this notice is replicated 115390SN/A * unmodified and in its entirety in all distributions of the software, 125390SN/A * modified or unmodified, in source code or in binary form. 135390SN/A * 145390SN/A * Copyright (c) 2006 The Regents of The University of Michigan 155390SN/A * All rights reserved. 165390SN/A * 175390SN/A * Redistribution and use in source and binary forms, with or without 185390SN/A * modification, are permitted provided that the following conditions are 195390SN/A * met: redistributions of source code must retain the above copyright 205390SN/A * notice, this list of conditions and the following disclaimer; 215390SN/A * redistributions in binary form must reproduce the above copyright 225390SN/A * notice, this list of conditions and the following disclaimer in the 235390SN/A * documentation and/or other materials provided with the distribution; 245390SN/A * neither the name of the copyright holders nor the names of its 255390SN/A * contributors may be used to endorse or promote products derived from 265390SN/A * this software without specific prior written permission. 275390SN/A * 285390SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 295390SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 305390SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 315636Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 325636Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 335390SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 345390SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 355390SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 365390SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 375390SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 385390SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 395636Sgblack@eecs.umich.edu * 405636Sgblack@eecs.umich.edu * Authors: Ali Saidi 415636Sgblack@eecs.umich.edu * Andreas Hansson 425636Sgblack@eecs.umich.edu */ 435443SN/A 445636Sgblack@eecs.umich.edu#ifndef __MEM_PACKET_QUEUE_HH__ 455390SN/A#define __MEM_PACKET_QUEUE_HH__ 465390SN/A 475443SN/A/** 485390SN/A * @file 495390SN/A * Declaration of a simple PacketQueue that is associated with 505390SN/A * a port on which it attempts to send packets according to the time 515390SN/A * stamp given to them at insertion. The packet queue is responsible 525390SN/A * for the flow control of the port. 535390SN/A */ 545636Sgblack@eecs.umich.edu 555636Sgblack@eecs.umich.edu#include <list> 565636Sgblack@eecs.umich.edu 575636Sgblack@eecs.umich.edu#include "mem/port.hh" 585443SN/A#include "sim/drain.hh" 595636Sgblack@eecs.umich.edu#include "sim/eventq_impl.hh" 605390SN/A 615390SN/A/** 625443SN/A * A packet queue is a class that holds deferred packets and later 635390SN/A * sends them using the associated slave port or master port. 645636Sgblack@eecs.umich.edu */ 655636Sgblack@eecs.umich.educlass PacketQueue : public Drainable 665636Sgblack@eecs.umich.edu{ 675636Sgblack@eecs.umich.edu private: 685636Sgblack@eecs.umich.edu /** A deferred packet, buffered to transmit later. */ 695636Sgblack@eecs.umich.edu class DeferredPacket { 70 public: 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) 74 : tick(t), pkt(p) 75 {} 76 }; 77 78 typedef std::list<DeferredPacket> DeferredPacketList; 79 80 /** A list of outgoing packets. */ 81 DeferredPacketList transmitList; 82 83 /** The manager which is used for the event queue */ 84 EventManager& em; 85 86 /** Used to schedule sending of deferred packets. */ 87 void processSendEvent(); 88 89 /** Event used to call processSendEvent. */ 90 EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent; 91 92 protected: 93 94 /** Label to use for print request packets label stack. */ 95 const std::string label; 96 97 /** Remember whether we're awaiting a retry. */ 98 bool waitingOnRetry; 99 100 /** Check whether we have a packet ready to go on the transmit list. */ 101 bool deferredPacketReady() const 102 { return !transmitList.empty() && transmitList.front().tick <= curTick(); } 103 104 /** 105 * Attempt to send a packet. Note that a subclass of the 106 * PacketQueue can override this method and thus change the 107 * behaviour (as done by the cache for the request queue). The 108 * default implementation sends the head of the transmit list. The 109 * caller must guarantee that the list is non-empty and that the 110 * head packet is scheduled for curTick() (or earlier). 111 */ 112 virtual void sendDeferredPacket(); 113 114 /** 115 * Send a packet using the appropriate method for the specific 116 * subclass (reuest, response or snoop response). 117 */ 118 virtual bool sendTiming(PacketPtr pkt) = 0; 119 120 /** 121 * Create a packet queue, linked to an event manager, and a label 122 * that will be used for functional print request packets. 123 * 124 * @param _em Event manager used for scheduling this queue 125 * @param _label Label to push on the label stack for print request packets 126 */ 127 PacketQueue(EventManager& _em, const std::string& _label); 128 129 /** 130 * Virtual desctructor since the class may be used as a base class. 131 */ 132 virtual ~PacketQueue(); 133 134 public: 135 136 /** 137 * Provide a name to simplify debugging. 138 * 139 * @return A complete name, appended to module and port 140 */ 141 virtual const std::string name() const = 0; 142 143 /** 144 * Get the size of the queue. 145 */ 146 size_t size() const { return transmitList.size(); } 147 148 /** 149 * Get the next packet ready time. 150 */ 151 Tick deferredPacketReadyTime() const 152 { return transmitList.empty() ? MaxTick : transmitList.front().tick; } 153 154 /** 155 * Check if a packets address exists in the queue. 156 */ 157 bool hasAddr(Addr addr) const; 158 159 /** Check the list of buffered packets against the supplied 160 * functional request. */ 161 bool checkFunctional(PacketPtr pkt); 162 163 /** 164 * Schedule a send event if we are not already waiting for a 165 * retry. If the requested time is before an already scheduled 166 * send event, the event will be rescheduled. If MaxTick is 167 * passed, no event is scheduled. Instead, if we are idle and 168 * asked to drain then check and signal drained. 169 * 170 * @param when time to schedule an event 171 */ 172 void schedSendEvent(Tick when); 173 174 /** 175 * Add a packet to the transmit list, and schedule a send event. 176 * 177 * @param pkt Packet to send 178 * @param when Absolute time (in ticks) to send packet 179 * @param force_order Force insertion order for packets with same address 180 */ 181 void schedSendTiming(PacketPtr pkt, Tick when, bool force_order = false); 182 183 /** 184 * Retry sending a packet from the queue. Note that this is not 185 * necessarily the same packet if something has been added with an 186 * earlier time stamp. 187 */ 188 void retry(); 189 190 DrainState drain() override; 191}; 192 193class ReqPacketQueue : public PacketQueue 194{ 195 196 protected: 197 198 MasterPort& masterPort; 199 200 public: 201 202 /** 203 * Create a request packet queue, linked to an event manager, a 204 * master port, and a label that will be used for functional print 205 * request packets. 206 * 207 * @param _em Event manager used for scheduling this queue 208 * @param _masterPort Master port used to send the packets 209 * @param _label Label to push on the label stack for print request packets 210 */ 211 ReqPacketQueue(EventManager& _em, MasterPort& _masterPort, 212 const std::string _label = "ReqPacketQueue"); 213 214 virtual ~ReqPacketQueue() { } 215 216 const std::string name() const 217 { return masterPort.name() + "-" + label; } 218 219 bool sendTiming(PacketPtr pkt); 220 221}; 222 223class SnoopRespPacketQueue : public PacketQueue 224{ 225 226 protected: 227 228 MasterPort& masterPort; 229 230 public: 231 232 /** 233 * Create a snoop response packet queue, linked to an event 234 * manager, a master port, and a label that will be used for 235 * functional print request packets. 236 * 237 * @param _em Event manager used for scheduling this queue 238 * @param _masterPort Master port used to send the packets 239 * @param _label Label to push on the label stack for print request packets 240 */ 241 SnoopRespPacketQueue(EventManager& _em, MasterPort& _masterPort, 242 const std::string _label = "SnoopRespPacketQueue"); 243 244 virtual ~SnoopRespPacketQueue() { } 245 246 const std::string name() const 247 { return masterPort.name() + "-" + label; } 248 249 bool sendTiming(PacketPtr pkt); 250 251}; 252 253class RespPacketQueue : public PacketQueue 254{ 255 256 protected: 257 258 SlavePort& slavePort; 259 260 public: 261 262 /** 263 * Create a response packet queue, linked to an event manager, a 264 * slave port, and a label that will be used for functional print 265 * request packets. 266 * 267 * @param _em Event manager used for scheduling this queue 268 * @param _slavePort Slave port used to send the packets 269 * @param _label Label to push on the label stack for print request packets 270 */ 271 RespPacketQueue(EventManager& _em, SlavePort& _slavePort, 272 const std::string _label = "RespPacketQueue"); 273 274 virtual ~RespPacketQueue() { } 275 276 const std::string name() const 277 { return slavePort.name() + "-" + label; } 278 279 bool sendTiming(PacketPtr pkt); 280 281}; 282 283#endif // __MEM_PACKET_QUEUE_HH__ 284