packet_queue.hh revision 11168
1695SN/A/* 29262Ssascha.bischoff@arm.com * Copyright (c) 2012,2015 ARM Limited 39262Ssascha.bischoff@arm.com * All rights reserved. 49262Ssascha.bischoff@arm.com * 59262Ssascha.bischoff@arm.com * The license below extends only to copyright in the software and shall 69262Ssascha.bischoff@arm.com * not be construed as granting a license to any other intellectual 79262Ssascha.bischoff@arm.com * property including but not limited to intellectual property relating 89262Ssascha.bischoff@arm.com * to a hardware implementation of the functionality of the software 99262Ssascha.bischoff@arm.com * licensed hereunder. You may use the software subject to the license 109262Ssascha.bischoff@arm.com * terms below provided that you ensure that this notice is replicated 119262Ssascha.bischoff@arm.com * unmodified and in its entirety in all distributions of the software, 129262Ssascha.bischoff@arm.com * modified or unmodified, in source code or in binary form. 139262Ssascha.bischoff@arm.com * 141762SN/A * Copyright (c) 2006 The Regents of The University of Michigan 15695SN/A * All rights reserved. 16695SN/A * 17695SN/A * Redistribution and use in source and binary forms, with or without 18695SN/A * modification, are permitted provided that the following conditions are 19695SN/A * met: redistributions of source code must retain the above copyright 20695SN/A * notice, this list of conditions and the following disclaimer; 21695SN/A * redistributions in binary form must reproduce the above copyright 22695SN/A * notice, this list of conditions and the following disclaimer in the 23695SN/A * documentation and/or other materials provided with the distribution; 24695SN/A * neither the name of the copyright holders nor the names of its 25695SN/A * contributors may be used to endorse or promote products derived from 26695SN/A * this software without specific prior written permission. 27695SN/A * 28695SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29695SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30695SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31695SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32695SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33695SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34695SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35695SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36695SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37695SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38695SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 419262Ssascha.bischoff@arm.com * Andreas Hansson 42695SN/A */ 43695SN/A 44695SN/A#ifndef __MEM_PACKET_QUEUE_HH__ 45695SN/A#define __MEM_PACKET_QUEUE_HH__ 46695SN/A 47729SN/A/** 48695SN/A * @file 494078Sbinkertn@umich.edu * Declaration of a simple PacketQueue that is associated with 509262Ssascha.bischoff@arm.com * a port on which it attempts to send packets according to the time 519262Ssascha.bischoff@arm.com * stamp given to them at insertion. The packet queue is responsible 529262Ssascha.bischoff@arm.com * for the flow control of the port. 539262Ssascha.bischoff@arm.com */ 549262Ssascha.bischoff@arm.com 559262Ssascha.bischoff@arm.com#include <list> 569262Ssascha.bischoff@arm.com 579262Ssascha.bischoff@arm.com#include "mem/port.hh" 589262Ssascha.bischoff@arm.com#include "sim/drain.hh" 599262Ssascha.bischoff@arm.com#include "sim/eventq_impl.hh" 609262Ssascha.bischoff@arm.com 619262Ssascha.bischoff@arm.com/** 629262Ssascha.bischoff@arm.com * A packet queue is a class that holds deferred packets and later 639262Ssascha.bischoff@arm.com * sends them using the associated slave port or master port. 649262Ssascha.bischoff@arm.com */ 659262Ssascha.bischoff@arm.comclass PacketQueue : public Drainable 669262Ssascha.bischoff@arm.com{ 679262Ssascha.bischoff@arm.com private: 687823Ssteve.reinhardt@amd.com /** A deferred packet, buffered to transmit later. */ 697822Ssteve.reinhardt@amd.com class DeferredPacket { 70695SN/A public: 719262Ssascha.bischoff@arm.com Tick tick; ///< The tick when the packet is ready to transmit 729262Ssascha.bischoff@arm.com PacketPtr pkt; ///< Pointer to the packet to transmit 739262Ssascha.bischoff@arm.com DeferredPacket(Tick t, PacketPtr p) 749262Ssascha.bischoff@arm.com : tick(t), pkt(p) 759262Ssascha.bischoff@arm.com {} 769262Ssascha.bischoff@arm.com }; 779450Ssascha.bischoff@arm.com 787811Ssteve.reinhardt@amd.com typedef std::list<DeferredPacket> DeferredPacketList; 79695SN/A 80695SN/A /** 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 Do not reorder packets despite timing, but keep them 180 * in insertion order. 181 */ 182 void schedSendTiming(PacketPtr pkt, Tick when, bool force_order = false); 183 184 /** 185 * Retry sending a packet from the queue. Note that this is not 186 * necessarily the same packet if something has been added with an 187 * earlier time stamp. 188 */ 189 void retry(); 190 191 DrainState drain() override; 192}; 193 194class ReqPacketQueue : public PacketQueue 195{ 196 197 protected: 198 199 MasterPort& masterPort; 200 201 public: 202 203 /** 204 * Create a request packet queue, linked to an event manager, a 205 * master port, and a label that will be used for functional print 206 * request packets. 207 * 208 * @param _em Event manager used for scheduling this queue 209 * @param _masterPort Master port used to send the packets 210 * @param _label Label to push on the label stack for print request packets 211 */ 212 ReqPacketQueue(EventManager& _em, MasterPort& _masterPort, 213 const std::string _label = "ReqPacketQueue"); 214 215 virtual ~ReqPacketQueue() { } 216 217 const std::string name() const 218 { return masterPort.name() + "-" + label; } 219 220 bool sendTiming(PacketPtr pkt); 221 222}; 223 224class SnoopRespPacketQueue : public PacketQueue 225{ 226 227 protected: 228 229 MasterPort& masterPort; 230 231 public: 232 233 /** 234 * Create a snoop response packet queue, linked to an event 235 * manager, a master port, and a label that will be used for 236 * functional print request packets. 237 * 238 * @param _em Event manager used for scheduling this queue 239 * @param _masterPort Master port used to send the packets 240 * @param _label Label to push on the label stack for print request packets 241 */ 242 SnoopRespPacketQueue(EventManager& _em, MasterPort& _masterPort, 243 const std::string _label = "SnoopRespPacketQueue"); 244 245 virtual ~SnoopRespPacketQueue() { } 246 247 const std::string name() const 248 { return masterPort.name() + "-" + label; } 249 250 bool sendTiming(PacketPtr pkt); 251 252}; 253 254class RespPacketQueue : public PacketQueue 255{ 256 257 protected: 258 259 SlavePort& slavePort; 260 261 public: 262 263 /** 264 * Create a response packet queue, linked to an event manager, a 265 * slave port, and a label that will be used for functional print 266 * request packets. 267 * 268 * @param _em Event manager used for scheduling this queue 269 * @param _slavePort Slave port used to send the packets 270 * @param _label Label to push on the label stack for print request packets 271 */ 272 RespPacketQueue(EventManager& _em, SlavePort& _slavePort, 273 const std::string _label = "RespPacketQueue"); 274 275 virtual ~RespPacketQueue() { } 276 277 const std::string name() const 278 { return slavePort.name() + "-" + label; } 279 280 bool sendTiming(PacketPtr pkt); 281 282}; 283 284#endif // __MEM_PACKET_QUEUE_HH__ 285