queued.hh revision 14013:aeb3ca1762bb
1/* 2 * Copyright (c) 2014-2015 ARM Limited 3 * All rights reserved 4 * 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. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Mitch Hayenga 38 */ 39 40#ifndef __MEM_CACHE_PREFETCH_QUEUED_HH__ 41#define __MEM_CACHE_PREFETCH_QUEUED_HH__ 42 43#include <cstdint> 44#include <list> 45#include <utility> 46 47#include "base/statistics.hh" 48#include "base/types.hh" 49#include "mem/cache/prefetch/base.hh" 50#include "mem/packet.hh" 51 52struct QueuedPrefetcherParams; 53 54class QueuedPrefetcher : public BasePrefetcher 55{ 56 protected: 57 struct DeferredPacket : public BaseTLB::Translation { 58 /** Owner of the packet */ 59 QueuedPrefetcher *owner; 60 /** Prefetch info corresponding to this packet */ 61 PrefetchInfo pfInfo; 62 /** Time when this prefetch becomes ready */ 63 Tick tick; 64 /** The memory packet generated by this prefetch */ 65 PacketPtr pkt; 66 /** The priority of this prefetch */ 67 int32_t priority; 68 /** Request used when a translation is needed */ 69 RequestPtr translationRequest; 70 ThreadContext *tc; 71 bool ongoingTranslation; 72 73 /** 74 * Constructor 75 * @param o QueuedPrefetcher in charge of this request 76 * @param pfi PrefechInfo object associated to this packet 77 * @param t Time when this prefetch becomes ready 78 * @param p PacketPtr with the memory request of the prefetch 79 * @param prio This prefetch priority 80 */ 81 DeferredPacket(QueuedPrefetcher *o, PrefetchInfo const &pfi, Tick t, 82 int32_t prio) : owner(o), pfInfo(pfi), tick(t), pkt(nullptr), 83 priority(prio), translationRequest() { 84 } 85 86 bool operator>(const DeferredPacket& that) const 87 { 88 return priority > that.priority; 89 } 90 bool operator<(const DeferredPacket& that) const 91 { 92 return priority < that.priority; 93 } 94 bool operator<=(const DeferredPacket& that) const 95 { 96 return !(*this > that); 97 } 98 99 /** 100 * Create the associated memory packet 101 * @param paddr physical address of this packet 102 * @param blk_size block size used by the prefetcher 103 * @param mid Requester ID of the access that generated this prefetch 104 * @param tag_prefetch flag to indicate if the packet needs to be 105 * tagged 106 * @param t time when the prefetch becomes ready 107 */ 108 void createPkt(Addr paddr, unsigned blk_size, MasterID mid, 109 bool tag_prefetch, Tick t); 110 111 /** 112 * Sets the translation request needed to obtain the physical address 113 * of this request. 114 * @param req The Request with the virtual address of this request 115 */ 116 void setTranslationRequest(const RequestPtr &req) 117 { 118 translationRequest = req; 119 } 120 121 void markDelayed() override 122 {} 123 124 void finish(const Fault &fault, const RequestPtr &req, 125 ThreadContext *tc, BaseTLB::Mode mode) override; 126 127 /** 128 * Issues the translation request to the provided TLB 129 * @param tlb the tlb that has to translate the address 130 */ 131 void startTranslation(BaseTLB *tlb); 132 }; 133 134 std::list<DeferredPacket> pfq; 135 std::list<DeferredPacket> pfqMissingTranslation; 136 137 using const_iterator = std::list<DeferredPacket>::const_iterator; 138 using iterator = std::list<DeferredPacket>::iterator; 139 140 // PARAMETERS 141 142 /** Maximum size of the prefetch queue */ 143 const unsigned queueSize; 144 145 /** 146 * Maximum size of the queue holding prefetch requests with missing 147 * address translations 148 */ 149 const unsigned missingTranslationQueueSize; 150 151 /** Cycles after generation when a prefetch can first be issued */ 152 const Cycles latency; 153 154 /** Squash queued prefetch if demand access observed */ 155 const bool queueSquash; 156 157 /** Filter prefetches if already queued */ 158 const bool queueFilter; 159 160 /** Snoop the cache before generating prefetch (cheating basically) */ 161 const bool cacheSnoop; 162 163 /** Tag prefetch with PC of generating access? */ 164 const bool tagPrefetch; 165 166 // STATS 167 Stats::Scalar pfIdentified; 168 Stats::Scalar pfBufferHit; 169 Stats::Scalar pfInCache; 170 Stats::Scalar pfRemovedFull; 171 Stats::Scalar pfSpanPage; 172 173 public: 174 using AddrPriority = std::pair<Addr, int32_t>; 175 176 QueuedPrefetcher(const QueuedPrefetcherParams *p); 177 virtual ~QueuedPrefetcher(); 178 179 void notify(const PacketPtr &pkt, const PrefetchInfo &pfi) override; 180 181 void insert(const PacketPtr &pkt, PrefetchInfo &new_pfi, int32_t priority); 182 183 virtual void calculatePrefetch(const PrefetchInfo &pfi, 184 std::vector<AddrPriority> &addresses) = 0; 185 PacketPtr getPacket() override; 186 187 Tick nextPrefetchReadyTime() const override 188 { 189 return pfq.empty() ? MaxTick : pfq.front().tick; 190 } 191 192 void regStats() override; 193 194 private: 195 196 /** 197 * Adds a DeferredPacket to the specified queue 198 * @param queue selected queue to use 199 * @param dpp DeferredPacket to add 200 */ 201 void addToQueue(std::list<DeferredPacket> &queue, DeferredPacket &dpp); 202 203 /** 204 * Starts the translations of the queued prefetches with a 205 * missing translation. It performs a maximum specified number of 206 * translations. Successful translations cause the prefetch request to be 207 * queued in the queue of ready requests. 208 * @param max maximum number of translations to perform 209 */ 210 void processMissingTranslations(unsigned max); 211 212 /** 213 * Indicates that the translation of the address of the provided deferred 214 * packet has been successfully completed, and it can be enqueued as a 215 * new prefetch request. 216 * @param dp the deferred packet that has completed the translation request 217 * @param failed whether the translation was successful 218 */ 219 void translationComplete(DeferredPacket *dp, bool failed); 220 221 /** 222 * Checks whether the specified prefetch request is already in the 223 * specified queue. If the request is found, its priority is updated. 224 * @param queue selected queue to check 225 * @param pfi information of the prefetch request to be added 226 * @param priority priority of the prefetch request to be added 227 * @return True if the prefetch request was found in the queue 228 */ 229 bool alreadyInQueue(std::list<DeferredPacket> &queue, 230 const PrefetchInfo &pfi, int32_t priority); 231 232 RequestPtr createPrefetchRequest(Addr addr, PrefetchInfo const &pfi, 233 PacketPtr pkt); 234}; 235 236#endif //__MEM_CACHE_PREFETCH_QUEUED_HH__ 237 238